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

Permission Error running npm install on elasticbeanstalk #4

Open
sevab opened this issue Dec 27, 2016 · 17 comments
Open

Permission Error running npm install on elasticbeanstalk #4

sevab opened this issue Dec 27, 2016 · 17 comments

Comments

@sevab
Copy link

sevab commented Dec 27, 2016

I've managed to successfully create an Elastic Beanstalk app following the documentation.

The ember app itself is zipped and deployed to S3 via ember-cli-deploy-elastic-beanstalk, which the eb server manages to successfully download and unzip, however a permission error is logged when fastboot-s3-downloader tries to run cd deploy-dist && npm install:

No FASTBOOT_REDIS_HOST or FASTBOOT_REDIS_PORT provided; caching is disabled.
[2016-12-27T17:04:27.885Z][m3467] downloading app
[2016-12-27T17:04:27.886Z][m3467] fetching current app version from cb-ember-assets-staging/fastboot-dist.json
[2016-12-27T17:04:28.007Z][m3467] got config { bucket: 'cb-ember-assets-staging',
  key: 'deploy-dist-be5a0f41c7886b05bfe3bbaa36f48985.zip' }
[2016-12-27T17:04:28.012Z][m3467] removing deploy-dist
[2016-12-27T17:04:28.023Z][m3467] saving S3 object cb-ember-assets-staging/deploy-dist-be5a0f41c7886b05bfe3bbaa36f48985.zip to deploy-dist-be5a0f41c7886b05bfe3bbaa36f48985.zip
[2016-12-27T17:04:28.234Z][m3467] unzipped deploy-dist-be5a0f41c7886b05bfe3bbaa36f48985.zip
[2016-12-27T17:04:28.881Z][m3467] error running command cd deploy-dist && npm install
[2016-12-27T17:04:28.881Z][m3467] npm WARN locking Error: EACCES: permission denied, open '/tmp/.npm/_locks/staging-f212e8d64a01707f.lock'
npm WARN locking     at Error (native)
npm WARN locking  /tmp/.npm/_locks/staging-f212e8d64a01707f.lock failed { Error: EACCES: permission denied, open '/tmp/.npm/_locks/staging-f212e8d64a01707f.lock'
npm WARN locking     at Error (native)
npm WARN locking   errno: -13,
npm WARN locking   code: 'EACCES',
npm WARN locking   syscall: 'open',
npm WARN locking   path: '/tmp/.npm/_locks/staging-f212e8d64a01707f.lock' }
npm WARN deploy-dist No description
npm WARN deploy-dist No repository field.
npm WARN deploy-dist No license field.
npm ERR! Linux 4.4.35-33.55.amzn1.x86_64
npm ERR! argv "/opt/elasticbeanstalk/node-install/node-v6.9.1-linux-x64/bin/node" "/opt/elasticbeanstalk/node-install/node-v6.9.1-linux-x64/bin/npm" "install"
npm ERR! node v6.9.1
npm ERR! npm  v3.10.8
npm ERR! path /tmp/.npm/_locks/staging-f212e8d64a01707f.lock
npm ERR! code EACCES
npm ERR! errno -13
npm ERR! syscall open

npm ERR! Error: EACCES: permission denied, open '/tmp/.npm/_locks/staging-f212e8d64a01707f.lock'
npm ERR!     at Error (native)
npm ERR!  { Error: EACCES: permission denied, open '/tmp/.npm/_locks/staging-f212e8d64a01707f.lock'
npm ERR!     at Error (native)
npm ERR!   errno: -13,
npm ERR!   code: 'EACCES',
npm ERR!   syscall: 'open',
npm ERR!   path: '/tmp/.npm/_locks/staging-f212e8d64a01707f.lock' }
npm ERR!
npm ERR! Please try running this command again as root/Administrator.

npm ERR! Please include the following file with any support request:
npm ERR!     /var/app/current/deploy-dist/npm-debug.log

[2016-12-27T17:04:28.881Z][m3467] unable to install npm dependencies
[2016-12-27T17:04:28.882Z][m3467] subscribing to update notifications
[2016-12-27T17:04:28.918Z][m3467] forked worker 3530
[2016-12-27T17:04:28.919Z][m3467] worker online
No FASTBOOT_REDIS_HOST or FASTBOOT_REDIS_PORT provided; caching is disabled.
[2016-12-27T17:04:29.697Z][w3530] starting HTTP server
[2016-12-27T17:04:29.708Z][w3530] HTTP server started; url=http://:::8081

The server is able to start regardless, because ember-deploy includes node_modules as part of dist-deploy.zip, but it would be nice to avoid this error.

A brute force solution would be to have fastboot-s3-downloader run npm install with sudo, but that probably should be avoided.

Would appreciate any help if anyone dealt with this issue as well.

Things tried so far that didn't work:

@sevab
Copy link
Author

sevab commented Jan 13, 2017

The solution is to add permissions to the nodejs user, so it can access /tmp/.npm. In ElasticBeanstalk this can be achieved by adding a file .ebextensions/00_change_npm_permissions.config with the following contents:

files:
  "/opt/elasticbeanstalk/hooks/appdeploy/post/00_set_tmp_permissions.sh":
    mode: "000755"
    owner: root
    group: root
    content: |
      #!/usr/bin/env bash
      chown -R nodejs:nodejs /tmp/.npm

Then committing it into the repo and making an eb deploy.

I can submit a documentation PR regarding this.

@ghost
Copy link

ghost commented Jan 13, 2017

Thanks @sevab - this was very helpful :)

@IAmJulianAcosta
Copy link

Hi @sevab, where should I put .ebextensions/00_change_npm_permissions.config file?

@sevab
Copy link
Author

sevab commented Mar 9, 2017

@IAmJulianAcosta in the .ebextensions directory at the root of your elasticbean project.

@cubbuk
Copy link

cubbuk commented Mar 29, 2017

Thanks @sevab it was very helpful indeed.

vicsz pushed a commit to vicsz/atlasboard-demo that referenced this issue Apr 6, 2017
@klemensz
Copy link

klemensz commented Aug 3, 2017

Thanks! We had the same issue with the "sharp" library and that fixed the problem. Basically it would install correctly when launching a new environment, but not when doing an eb deploy. Leading to

51771 error code ELIFECYCLE
51772 error [email protected] install: `node-gyp rebuild`
51772 error Exit status 1
51773 error Failed at the [email protected] install script 'node-gyp rebuild'.

The permission config fixed it.

@holyjak
Copy link

holyjak commented Sep 1, 2017

Unrelated to fastboot, I had also permission denied errors when running node-gyp. I found out that while npm install was run by root, node-gyp invocations it started were run by the user ec2-user, which obviously lacked access to the root-owned directories /tmp/deployment/application/node_modules/, /tmp/.npm, and /tmp/.config.

My solution was to instruct npm to use the same user (i.e. root via unsafe-perm=true) - see https://stackoverflow.com/questions/46001516/beanstalk-node-js-deployment-node-gyp-fails-due-to-permission-denied/46001517#46001517

I wonder whether it would work also in this ☝️ case, instead of changing permissions on /tmp?

@klemensz
Copy link

klemensz commented Sep 1, 2017

@jakubholynet Interesting... actually I need to revert my comment from above, the permission config didn't fix the error (only temporarily). In the end moving away to another library that doesn't need node-gyp was the "solution" for us.

@nnnikolay
Copy link

@jakubholynet I faced with the similar problem, but I know that starting npm install from root it's not the best idea, so I've made following changes in my scripts

sudo -u ec2-user -H npm install --production

And then problem has been gone

@sauravazad
Copy link

Use .npmrc file to configure unsafe-perm to true for node-gyp commands on aws.

https://stackoverflow.com/questions/46001516/beanstalk-node-js-deployment-node-gyp-fails-due-to-permission-denied/46001517#46001517

@holyjak
Copy link

holyjak commented Jan 9, 2018 via email

@chuks
Copy link

chuks commented Jan 25, 2018

This does not work. Everyone has pointed to this link https://stackoverflow.com/questions/46001516/beanstalk-node-js-deployment-node-gyp-fails-due-to-permission-denied/46001517#46001517. However setting that unsafe-perm to true still doesn't work.

jaypinho added a commit to FrontPages/backend that referenced this issue Jul 31, 2018
@klemensz
Copy link

@nnnikolay The documentation says that Elastic Beanstalks runs npm install --production by default: https://docs.aws.amazon.com/de_de/elasticbeanstalk/latest/dg/nodejs-platform-packagejson.html

@nbimc
Copy link

nbimc commented Jan 7, 2019

Hi there,
I had the same issue, tried with .npmrc file that solved it. After a month got again a permission issue on /tmp/.npm, and /tmp/.config.
It happen to be that those folders where suddenly missing from the environment. I needed to change the elastic beanstalk deployment configuration to "immutable" which force deployment from scratch. And that solved the issue. Hope it helps...

@bthiban
Copy link

bthiban commented Jan 16, 2019

If you do not already have a .ebextensions folder in the root of your project, create it. Then create a file in .ebextensions named 01_fix_permissions.config. EB knows to run files in the .ebextensions folder at the beginning of the deployment in order, which is why the “01” prefix is used. Inside this file enter the following:

files:
  "/opt/elasticbeanstalk/hooks/appdeploy/pre/49_change_permissions.sh":
    mode: "000755"
    owner: root
    group: root
    content: |
      #!/usr/bin/env bash
      sudo chown -R ec2-user:ec2-user tmp/
      set -xe
      /opt/elasticbeanstalk/bin/healthd-track-pidfile --proxy nginx

@junhua
Copy link

junhua commented Dec 19, 2019

@jakubholynet I faced with the similar problem, but I know that starting npm install from root it's not the best idea, so I've made following changes in my scripts

sudo -u ec2-user -H npm install --production

And then problem has been gone

Which script?

@akashgangrade
Copy link

Add a file named .npmrc to the application with the content:

unsafe-perm=true
Now use the following command before pushing it to ElasticBeanStalk:

git add .npmrc
 git commit -m"EB issue fix"

Now deploy your code. It should work.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging a pull request may close this issue.