Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix(cli): "EACCES: Permission denied" on 'cdk init' #22111

Merged
merged 5 commits into from
Sep 20, 2022
Merged

Conversation

rix0rrr
Copy link
Contributor

@rix0rrr rix0rrr commented Sep 19, 2022

Historically, cdk init used to create a dedicated temporary directory for hook scripts and copy *.hook.* scripts into there.

In #21049, the logic was changed to create that temporary directory inside the CLI source directory. If that CLI source directory is mounted in a read-only location (say, /usr/lib/node_modules) then that directory could not be created and cdk init would fail.

Historically, hook scripts were arbitrary scripts outside the scope of the CLI, but the previous change tried to reuse code from the CLI. That does not work because the CLI is now being bundled (all code and dependencies in one giant .js file), so reusing from the outside using a different entry point cannot work. (It's not clear that this is happening because we leave the source files in the original location inside the NPM package, to try and halfway not break people using the CLI in ways that are unsupported but happen to work).

Instead, bundle the hook logic into the CLI itself, so it all uses the same mechanism.

Fixes #22090.


By submitting this pull request, I confirm that my contribution is made under the terms of the Apache-2.0 license

@rix0rrr rix0rrr requested a review from a team September 19, 2022 12:23
@rix0rrr rix0rrr self-assigned this Sep 19, 2022
@gitpod-io
Copy link

gitpod-io bot commented Sep 19, 2022

@mergify mergify bot added the contribution/core This is a PR that came from AWS. label Sep 19, 2022
@github-actions github-actions bot added bug This issue is a bug. p0 labels Sep 19, 2022
@aws-cdk-automation aws-cdk-automation requested a review from a team September 19, 2022 12:23
@rix0rrr rix0rrr added pr/do-not-merge This PR should not be merged at this time. pr-linter/exempt-test The PR linter will not require test changes labels Sep 19, 2022
Historically, `cdk init` used to create a dedicated temporary directory
for hook scripts and copy `*.hook.*` scripts into there.

In #21049, the logic was changed to create that temporary directory
inside the CLI source directory. If that CLI source directory is mounted
in a read-only location (say, `/usr/lib/node_modules`) then that
directory could not be created and `cdk init` would fail.

It looks like historically we might copy and postprocess hook scripts
so that they could have variables replaced... but given that hook
scripts are code, they could just read the variables directly, so
we don't have to copy them into a temporary directory at all: we
can directly run them from the source location.

Fixes #22090.
@TheRealAmazonKendra
Copy link
Contributor

crying on the inside

@TheRealAmazonKendra
Copy link
Contributor

On the other hand, my original fix for this, before revisions, would not have this issue. It wasn't ideal, by any means, but I think I can revise it to be slightly better and not cause this error.

@TheRealAmazonKendra
Copy link
Contributor

but still , crying on the inside

@rix0rrr rix0rrr removed the pr/do-not-merge This PR should not be merged at this time. label Sep 20, 2022
@mergify
Copy link
Contributor

mergify bot commented Sep 20, 2022

Thank you for contributing! Your pull request will be updated from main and then merged automatically (do not update manually, and be sure to allow changes to be pushed to your fork).

@aws-cdk-automation
Copy link
Collaborator

AWS CodeBuild CI Report

  • CodeBuild project: AutoBuildv2Project1C6BFA3F-wQm2hXv2jqQv
  • Commit ID: b38d125
  • Result: SUCCEEDED
  • Build Logs (available for 30 days)

Powered by github-codebuild-logs, available on the AWS Serverless Application Repository

@mergify mergify bot merged commit 384ba2b into main Sep 20, 2022
@mergify mergify bot deleted the huijbers/fix-init branch September 20, 2022 10:28
@mergify
Copy link
Contributor

mergify bot commented Sep 20, 2022

Thank you for contributing! Your pull request will be updated from main and then merged automatically (do not update manually, and be sure to allow changes to be pushed to your fork).

homakk pushed a commit to homakk/aws-cdk that referenced this pull request Dec 1, 2022
Historically, `cdk init` used to create a dedicated temporary directory for hook scripts and copy `*.hook.*` scripts into there.

In aws#21049, the logic was changed to create that temporary directory inside the CLI source directory. If that CLI source directory is mounted in a read-only location (say, `/usr/lib/node_modules`) then that directory could not be created and `cdk init` would fail.

Historically, hook scripts were arbitrary scripts outside the scope of the CLI, but the previous change tried to reuse code from the CLI. That does not work because the CLI is now being bundled (all code and dependencies in one giant `.js` file), so reusing from the outside using a different entry point cannot work. (It's not clear that this is happening because we leave the source files in the original location inside the NPM package, to try and halfway not break people using the CLI in ways that are unsupported but happen to work).

Instead, bundle the hook logic into the CLI itself, so it all uses the same mechanism.

Fixes aws#22090.

----

*By submitting this pull request, I confirm that my contribution is made under the terms of the Apache-2.0 license*
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug This issue is a bug. contribution/core This is a PR that came from AWS. p0 pr-linter/exempt-test The PR linter will not require test changes
Projects
None yet
Development

Successfully merging this pull request may close these issues.

‼️ NOTICE | CLI: cdk init produces EACCES: permission denied and does not fill the directory
4 participants