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

EACCESS: permission denied #523

Closed
gavanfantom opened this issue Mar 3, 2021 · 23 comments · Fixed by #530
Closed

EACCESS: permission denied #523

gavanfantom opened this issue Mar 3, 2021 · 23 comments · Fixed by #530
Labels
bug Something isn't working released

Comments

@gavanfantom
Copy link

Describe the bug

Running a simple ag command fails with a permission error

How to Reproduce

$ sudo npm -g install @asyncapi/html-template --unsafe-perm=true
...

$ sudo npm -g install @asyncapi/generator
...

$ ag --debug api_description.yml @asyncapi/html-template
Errors while trying to resolve package location at undefined TypeError [ERR_INVALID_ARG_TYPE]: The "path" argument must be of type string. Received undefined
    at validateString (internal/validators.js:124:11)
    at Object.join (path.js:1039:7)
    at /usr/local/lib/node_modules/@asyncapi/generator/lib/generator.js:353:41
    at new Promise (<anonymous>)
    at Generator.installTemplate (/usr/local/lib/node_modules/@asyncapi/generator/lib/generator.js:339:12)
    at Generator.generate (/usr/local/lib/node_modules/@asyncapi/generator/lib/generator.js:168:73)
    at processTicksAndRejections (internal/process/task_queues.js:93:5)
    at async /usr/local/lib/node_modules/@asyncapi/generator/cli.js:132:9 {
  code: 'ERR_INVALID_ARG_TYPE'
}
Template installation started because the template cannot be found on disk
Something went wrong:
Error: EACCES: permission denied, mkdir '/usr/local/lib/node_modules/@asyncapi/generator/node_modules/@asyncapi/html-template'

Expected behavior

I expected ag to generate some nice pretty HTML, not try to install files in a system location. I expected ag to find the previously installed template. I also expected that if ag did need to download anything, it would not do so into a place that needed root privileges.

@gavanfantom gavanfantom added the bug Something isn't working label Mar 3, 2021
@gavanfantom
Copy link
Author

I should note that this is with version 1.2.0.

@github-actions
Copy link
Contributor

github-actions bot commented Mar 3, 2021

Welcome to AsyncAPI. Thanks a lot for reporting your first issue. Please check out our contributors guide and the instructions about a basic recommended setup useful for opening a pull request.

Keep in mind there are also other channels you can use to interact with AsyncAPI community. For more details check out this issue.

@jonaslagoni
Copy link
Member

@gavanfantom thanks for the issue. Just to get some more information are you saying this worked in the previous version?

@derberg
Copy link
Member

derberg commented Mar 3, 2021

@gavanfantom yes, please specify if the previous version has the same effect for you. From debug I can see that all looks good on the generator side, and looks like the app just doesn't have the right to do any changes in /usr/local/lib/

@jonaslagoni
Copy link
Member

jonaslagoni commented Mar 3, 2021

@derberg just a side question does the generator actually check the global node_modules directory for the template? 🤔 i.e. if he had permissions to read in /usr/local/lib/node_modules/ would it use this path /usr/local/lib/node_modules/@asyncapi/html-template or only look in /usr/local/lib/node_modules/@asyncapi/generator/node_modules/?

@gavanfantom
Copy link
Author

I have the same problem with version 1.1.11.

@derberg
Copy link
Member

derberg commented Mar 3, 2021

Yeap, this use case never worked and won't work with the latest version we released today. We use https://github.com/sindresorhus/resolve-pkg to resolve dependencies, and we look as @jonaslagoni wrote, into /usr/local/lib/node_modules/@asyncapi/generator/node_modules/.

this is why you are getting

Errors while trying to resolve package location at undefined TypeError [ERR_INVALID_ARG_TYPE]: The "path" argument must be of type string. Received undefined
    at validateString (internal/validators.js:124:11)
    at Object.join (path.js:1039:7)
    at /usr/local/lib/node_modules/@asyncapi/generator/lib/generator.js:353:41
    at new Promise (<anonymous>)
    at Generator.installTemplate (/usr/local/lib/node_modules/@asyncapi/generator/lib/generator.js:339:12)
    at Generator.generate (/usr/local/lib/node_modules/@asyncapi/generator/lib/generator.js:168:73)
    at processTicksAndRejections (internal/process/task_queues.js:93:5)
    at async /usr/local/lib/node_modules/@asyncapi/generator/cli.js:132:9 {
  code: 'ERR_INVALID_ARG_TYPE'
}
Template installation started because the template cannot be found on disk

but then we try to install it again, into /usr/local/lib/node_modules/@asyncapi/generator/node_modules/, which is good, just fails on your side.

did you try installing generator with sudo npm install generator --unsafe-perm=true -g or sudo npm install generator --unsafe-perm=true --allow-root -g ?

@gavanfantom
Copy link
Author

I have just tried reinstalling with:

sudo npm -g install @asyncapi/generator --unsafe-perm=true --allow-root

(you did mean @asyncapi/generator rather than generator, right?)

I'm still getting the same error.

@derberg
Copy link
Member

derberg commented Mar 4, 2021

yeap, sorry, thinking with shortcuts 😄

can you try doing chmod +w /usr/local/lib/node_modules or chmod u+w /usr/local/lib/node_modules

@chatne
Copy link

chatne commented Mar 6, 2021

I was getting some issues when using generator version >=1.2.0. I used yarn but was able to contain the issue using npm with Docker. I simplified this as much I could. Using Node 14:

FROM ubuntu:20.04

RUN apt-get update \
 && apt-get -y install curl git
RUN curl -sL https://deb.nodesource.com/setup_14.x | bash \
 && apt-get update \
 && apt-get -y install nodejs

# Install generator
RUN npm install --global --unsafe-perm=true --allow-root @asyncapi/generator@1.1.11

# Generate with dummy yaml
RUN echo "asyncapi: 2.0.0\ninfo:\n  title: dummy\n  version: 0.0.0\nchannels: {}" > dummy.yaml \
 && mkdir html \
 && ag --debug dummy.yaml @asyncapi/html-template -o html

This works and generates fine. However if generator version is changed to 1.2.0 or newer this will fail:

Step 5/5 : RUN echo "asyncapi: 2.0.0\ninfo:\n  title: dummy\n  version: 0.0.0\nchannels: {}" > dummy.yaml  && mkdir html  && ag --debug dummy.yaml @asyncapi/html-template -o html
 ---> Running in 8fbc46b82b94
Errors while trying to resolve package location at undefined TypeError [ERR_INVALID_ARG_TYPE]: The "path" argument must be of type string. Received undefined
    at validateString (internal/validators.js:124:11)
    at Object.join (path.js:1039:7)
    at /usr/lib/node_modules/@asyncapi/generator/lib/generator.js:353:41
    at new Promise (<anonymous>)
    at Generator.installTemplate (/usr/lib/node_modules/@asyncapi/generator/lib/generator.js:339:12)
    at Generator.generate (/usr/lib/node_modules/@asyncapi/generator/lib/generator.js:168:73)
    at async /usr/lib/node_modules/@asyncapi/generator/cli.js:132:9 {
  code: 'ERR_INVALID_ARG_TYPE'
}
Template installation started because the template cannot be found on disk
Template @asyncapi/html-template successfully installed in /usr/lib/node_modules/@asyncapi/generator/node_modules/@asyncapi/html-template
Version of used template is 0.18.1.
Something went wrong:
Error: Cannot find module '/usr/lib/node_modules/@asyncapi/generator/node_modules/@asyncapi/html-template/node_modules/@asyncapi/generator-filters'
Require stack:
- /usr/lib/node_modules/@asyncapi/generator/lib/filtersRegistry.js
- /usr/lib/node_modules/@asyncapi/generator/lib/generator.js
- /usr/lib/node_modules/@asyncapi/generator/cli.js
    at Function.Module._resolveFilename (internal/modules/cjs/loader.js:880:15)
    at Function.Module._load (internal/modules/cjs/loader.js:725:27)
    at Module.require (internal/modules/cjs/loader.js:952:19)
    at require (internal/modules/cjs/helpers.js:88:18)
    at /usr/lib/node_modules/@asyncapi/generator/lib/filtersRegistry.js:79:13
    at Array.map (<anonymous>)
    at registerConfigFilters (/usr/lib/node_modules/@asyncapi/generator/lib/filtersRegistry.js:71:32)
    at module.exports.registerFilters (/usr/lib/node_modules/@asyncapi/generator/lib/filtersRegistry.js:14:9)
    at async Generator.generate (/usr/lib/node_modules/@asyncapi/generator/lib/generator.js:177:7)
    at async /usr/lib/node_modules/@asyncapi/generator/cli.js:132:9

Hopefully this helps

@gavanfantom
Copy link
Author

drwxr-xr-x 6 root root 4096 Mar 3 12:37 /usr/local/lib/node_modules/

It does have write permission, but only for root. Allowing non-root users write access to this directory can not possibly be the right answer.

I'm also a bit confused as to why "this use case never worked and won't work with the latest version we released today." This use case is literally the one documented in README.md ("Install the CLI"). Is there a different installation method that I should be using?

@jonaslagoni
Copy link
Member

It does have write permission, but only for root. Allowing non-root users write access to this directory can not possibly be the right answer.

Yea I agree with you here, @gavanfantom what would you like to see it changed to (in case we don't install templates where the generator is installed)?

@derberg
Copy link
Member

derberg commented Mar 8, 2021

It does have write permission, but only for root. Allowing non-root users write access to this directory can not possibly be the right answer.

I'm not sure what is your expectation here towards the generator

I'm also a bit confused as to why "this use case never worked and won't work with the latest version we released today." This use case is literally the one documented in README.md ("Install the CLI"). Is there a different installation method that I should be using?

I guess I didn't make myself clear, sorry. I meant that npm -g install @asyncapi/html-template global installation of templates was never supported. Just to imply that it is not a bug that generator cannot access a global template. I'm gonna try to enable support this week #482 (comment)

@gavanfantom
Copy link
Author

I'm not really sure what the ideal solution would be.

I would have thought though, that something like the following should work:

  • Provide a way to explicitly install a template (and do nothing else). Ideally with npm -g, but if it's a separate ag invocation that is documented to require root, and promises not to do anything other than installation, that would probably be ok.
  • If a template is not found, and can't be installed, issue a message saying so, to prompt the user to perform the installation manually, and/or
  • Perform the installation in a user-local directory (but not the current directory, ideally)
  • Test that after using sudo npm -g install @asyncapi/generator (plus any other documented install steps) that a non-root user can run ag.

@derberg
Copy link
Member

derberg commented Mar 8, 2021

let us then first make sure we support globally installed templates too. Once this works, let us reiterate again to see what else could be done on the generator side.

If a template is not found, and can't be installed, issue a message saying so, to prompt the user to perform the installation manually, and/or

I'll make sure to extend logs as much as possible when I will work on enabling global templates support.

Perform the installation in a user-local directory (but not the current directory, ideally)

if you use CLI it will install under user local where the generator is installed globally. Otherwise, it will install in the project where you use the generator as a library

@derberg
Copy link
Member

derberg commented Mar 10, 2021

PR is opened #530

@asyncapi-bot
Copy link
Contributor

🎉 This issue has been resolved in version 1.6.0 🎉

The release is available on:

Your semantic-release bot 📦🚀

@gavanfantom
Copy link
Author

Unfortunately this doesn't entirely resolve the issue, as even with the new version we still get:

$ ag --debug api_description.yml @asyncapi/html-template
Errors while trying to resolve package location at undefined TypeError [ERR_INVALID_ARG_TYPE]: The "path" argument must be of type string. Received undefined
at validateString (internal/validators.js:124:11)
at Object.join (path.js:1039:7)
at /usr/local/lib/node_modules/@asyncapi/generator/lib/generator.js:353:41
at new Promise ()
at Generator.installTemplate (/usr/local/lib/node_modules/@asyncapi/generator/lib/generator.js:339:12)
at Generator.generate (/usr/local/lib/node_modules/@asyncapi/generator/lib/generator.js:168:73)
at processTicksAndRejections (internal/process/task_queues.js:93:5)
at async /usr/local/lib/node_modules/@asyncapi/generator/cli.js:132:9 {
code: 'ERR_INVALID_ARG_TYPE'
}
Template installation started because the template cannot be found on disk
Something went wrong:
Error: EACCES: permission denied, rename '/usr/local/lib/node_modules/@asyncapi/generator/node_modules/caniuse-lite' -> '/usr/local/lib/node_modules/@asyncapi/generator/node_modules/.caniuse-lite-Nv6pSXC8'

This is with @asyncapi/html-template installed globally.

@derberg
Copy link
Member

derberg commented Mar 12, 2021

This is with @asyncapi/html-template installed globally.

If the template is installed globally, it should not log Template installation started because the template cannot be found on disk. What do you mean by "installed globally"? Where is the html-template located + are you sure you are on latest generator? Errors while trying to resolve - this error has changed a bit in new version

@gavanfantom
Copy link
Author

Not to worry, it turns out that somehow an old version had got installed that npm didn't replace with the latest. I have manually cleaned up after npm, and reinstalled, and it works much better now.

@derberg
Copy link
Member

derberg commented Mar 12, 2021

Awesome 🚀

@bjhartin
Copy link

I'm receiving this error when trying to use the asyncapi/cli docker container:

Is this expected?

docker run --rm -it -v asyncapi.json:/app/asyncapi.json -v output:/app/output asynca
pi/cli generate fromTemplate -o output asyncapi.json @asyncapi/html-template
Generation in progress. Keep calm and wait a bit... done

Generator Error: EACCES: permission denied, mkdir '/usr/local/lib/node_modules/@asyncapi/cli/node_modules/@asyncapi/generator/node_modules/node-fetch/node_modules'

@nicodewet
Copy link

I'm receiving this error when trying to use the asyncapi/cli docker container:

Is this expected?

docker run --rm -it -v asyncapi.json:/app/asyncapi.json -v output:/app/output asynca
pi/cli generate fromTemplate -o output asyncapi.json @asyncapi/html-template
Generation in progress. Keep calm and wait a bit... done

Generator Error: EACCES: permission denied, mkdir '/usr/local/lib/node_modules/@asyncapi/cli/node_modules/@asyncapi/generator/node_modules/node-fetch/node_modules'

Adding this fixed it for me: --user=root

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working released
Projects
None yet
Development

Successfully merging a pull request may close this issue.

7 participants