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

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

Closed
jnawk opened this issue Sep 17, 2022 · 5 comments · Fixed by #22111 or #22112
Closed
Labels
bug This issue is a bug. management/tracking Issues that track a subject or multiple issues p0 package/tools Related to AWS CDK Tools or CLI

Comments

@jnawk
Copy link

jnawk commented Sep 17, 2022

Please add your +1 👍 to let us know you have encountered this

Status: RESOLVED

Overview:

Can't initialize a new app with v2.42.0

Complete Error Message:

cdk init app --language typescript
Applying project template app for typescript
Unable to create glove80-firmware-pipeline: EACCES: permission denied, mkdir '/usr/lib/node_modules/cdk/node_modules/aws-cdk/lib/init-templates/app/tmp-myapp'
Executing npm install...
npm ERR! code ENOENT
npm ERR! syscall open
npm ERR! path /path/to/myapp/package.json
npm ERR! errno -2
npm ERR! enoent ENOENT: no such file or directory, open '/path/to/myapp/package.json'
npm ERR! enoent This is related to npm not being able to find a file.
npm ERR! enoent 

npm ERR! A complete log of this run can be found in:
npm ERR!     /home/me/.npm/_logs/2022-09-17T09_26_32_543Z-debug-0.log
npm install failed: npm exited with status 254
✅ All done!

Workaround: None. Don't install the CLI using root or inside a root owned directory

Solution: Upgrade to 2.42.1


Original report:


Describe the bug

Can't bootstrap a new app with v2.42.0. v2.41.0 works fine.

Expected Behavior

$ cdk init -l typescript
Applying project template app for typescript
# Welcome to your CDK TypeScript project

This is a blank project for CDK development with TypeScript.

The `cdk.json` file tells the CDK Toolkit how to execute your app.

## Useful commands

* `npm run build`   compile typescript to js
* `npm run watch`   watch for changes and compile
* `npm run test`    perform the jest unit tests
* `cdk deploy`      deploy this stack to your default AWS account/region
* `cdk diff`        compare deployed stack with current state
* `cdk synth`       emits the synthesized CloudFormation template

Executing npm install...
✅ All done!

Current Behavior

$ cdk init app --language typescript
Applying project template app for typescript
Unable to create glove80-firmware-pipeline: EACCES: permission denied, mkdir '/usr/lib/node_modules/cdk/node_modules/aws-cdk/lib/init-templates/app/tmp-myapp'
Executing npm install...
npm ERR! code ENOENT
npm ERR! syscall open
npm ERR! path /path/to/myapp/package.json
npm ERR! errno -2
npm ERR! enoent ENOENT: no such file or directory, open '/path/to/myapp/package.json'
npm ERR! enoent This is related to npm not being able to find a file.
npm ERR! enoent 

npm ERR! A complete log of this run can be found in:
npm ERR!     /home/me/.npm/_logs/2022-09-17T09_26_32_543Z-debug-0.log
npm install failed: npm exited with status 254
✅ All done!

Reproduction Steps

$ cdk init app --language typescript

Possible Solution

Downgrade to 2.41.0

Additional Information/Context

No response

CDK CLI Version

2.42.0

Framework Version

2.42.0

Node.js Version

v16.17.0

OS

Ubuntu 22.04.1 LTS

Language

Typescript

Language Version

No response

Other information

No response

@jnawk jnawk added bug This issue is a bug. needs-triage This issue or PR still needs to be triaged. labels Sep 17, 2022
@github-actions github-actions bot added the package/tools Related to AWS CDK Tools or CLI label Sep 17, 2022
@marciocadev
Copy link
Contributor

marciocadev commented Sep 17, 2022

Same problem here, only on version 2.42.0

2.41.0 is fine

$ cdk init --language typescript
Applying project template app for typescript
Unable to create stream-cdk: EACCES: permission denied, mkdir '/usr/lib/node_modules/aws-cdk/lib/init-templates/app/tmp-stream-cdk'
Initializing a new git repository...
On branch main

Initial commit

nothing to commit (create/copy files and use "git add" to track)
Unable to initialize git repository for your project.
Executing npm install...
npm ERR! code ENOENT
npm ERR! syscall open
npm ERR! path /home/marcio/marcio/tests/stream-cdk/package.json
npm ERR! errno -2
npm ERR! enoent ENOENT: no such file or directory, open '/home/marcio/marcio/tests/stream-cdk/package.json'
npm ERR! enoent This is related to npm not being able to find a file.
npm ERR! enoent

npm ERR! A complete log of this run can be found in:
npm ERR!     /home/marcio/.npm/_logs/2022-09-17T13_36_02_592Z-debug-0.log
npm install failed: npm exited with status 254
✅ All done!

$ ls -la
total 16
drwxr-xr-x  3 marcio marcio 4096 Sep 17 10:42 .
drwxr-xr-x 12 marcio marcio 4096 Sep 17 10:19 ..
drwxr-xr-x  7 marcio marcio 4096 Sep 17 10:42 .git
-rw-r--r--  1 marcio marcio   89 Sep 17 10:42 package-lock.json

@marciocadev
Copy link
Contributor

marciocadev commented Sep 17, 2022

Same problem with python project too

$ cdk init --language python
Applying project template app for python
Unable to create stream-cdk: EACCES: permission denied, mkdir '/usr/lib/node_modules/aws-cdk/lib/init-templates/app/tmp-stream-cdk'
Initializing a new git repository...
On branch main

Initial commit

nothing to commit (create/copy files and use "git add" to track)
Unable to initialize git repository for your project.
Please run 'python3 -m venv .venv'!
Executing Creating virtualenv...
✅ All done!

$ ls -la
total 16
drwxr-xr-x  4 marcio marcio 4096 Sep 17 10:39 .
drwxr-xr-x 12 marcio marcio 4096 Sep 17 10:19 ..
drwxr-xr-x  7 marcio marcio 4096 Sep 17 10:39 .git
drwxr-xr-x  6 marcio marcio 4096 Sep 17 10:39 .venv

@rix0rrr rix0rrr added the p0 label Sep 19, 2022
@rix0rrr rix0rrr changed the title aws-cdk: can't init typescript app CLI: cdk init produces EACCES: permission denied and does not fill the directory Sep 19, 2022
@rix0rrr rix0rrr pinned this issue Sep 19, 2022
@iliapolo iliapolo changed the title CLI: cdk init produces EACCES: permission denied and does not fill the directory (‼️ NOTICE) CLI: cdk init produces EACCES: permission denied and does not fill the directory Sep 19, 2022
@iliapolo iliapolo changed the title (‼️ NOTICE) CLI: cdk init produces EACCES: permission denied and does not fill the directory ‼️ NOTICE | CLI: cdk init produces EACCES: permission denied and does not fill the directory Sep 19, 2022
@iliapolo iliapolo added management/tracking Issues that track a subject or multiple issues and removed needs-triage This issue or PR still needs to be triaged. labels Sep 19, 2022
iliapolo added a commit to cdklabs/aws-cdk-notices that referenced this issue Sep 19, 2022
@iliapolo
Copy link
Contributor

@jnawk Thanks for reporting. We are on it.

rix0rrr added a commit that referenced this issue 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.
@rix0rrr rix0rrr removed their assignment Sep 19, 2022
@mergify mergify bot closed this as completed in #22112 Sep 19, 2022
mergify bot pushed a commit that referenced this issue Sep 19, 2022
@github-actions
Copy link

⚠️COMMENT VISIBILITY WARNING⚠️

Comments on closed issues are hard for our team to see.
If you need more assistance, please either tag a team member or open a new issue that references this one.
If you wish to keep having a conversation with other community members under this issue feel free to do so.

rix0rrr added a commit that referenced this issue 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.
iliapolo added a commit that referenced this issue Sep 19, 2022
mergify bot pushed a commit that referenced this issue Sep 20, 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*
@iliapolo
Copy link
Contributor

@kaizencc kaizencc unpinned this issue Oct 24, 2022
homakk pushed a commit to homakk/aws-cdk that referenced this issue 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. management/tracking Issues that track a subject or multiple issues p0 package/tools Related to AWS CDK Tools or CLI
Projects
None yet
4 participants