AWS Elastic Beanstalk - User Permission Problems

孤街醉人 提交于 2019-12-04 07:07:04

I believe that the nodejs user doesn't have privileges to use the shell:

[ec2-user@host ~]$ cat /etc/passwd
....
nodejs:x:497:497::/tmp:/sbin/nologin

According to the docs, node runs the command in a shell and returns it.

I also tried:

[ec2-user@host ~]$ pwd
/home/ec2-user
[ec2-user@host ~]$ cat test.js 
#!/opt/elasticbeanstalk/node-install/node-v0.10.31-linux-x64/bin/node
require('child_process').exec('/usr/bin/whoami', function (err, data) {
    console.log(data);
});
[ec2-user@host ~]$ ls -l
total 4
-rwxrwxrwx 1 ec2-user ec2-user 169 Nov  3 21:49 test.js
[ec2-user@host ~]$ sudo -u nodejs /home/ec2-user/test.js 
sudo: unable to execute /home/ec2-user/test.js: Permission denied

I will say that this works, which im confused about (maybe someone can chime in to clarify):

$ sudo -u nodejs /usr/bin/whoami
nodejs

HOWEVER, as an outside observer it seems more like Beanstalk isn't a good fit for you. Generally, Beanstalk is a hands-off fully managed abstraction by design and messing around with the file system permissions and user permissions is over-stepping those boundaries.

As an aside, maybe you want to consider moving to OpsWorks instead. From http://aws.amazon.com/opsworks/faqs/:

Q: How is AWS OpsWorks different than AWS Elastic Beanstalk?

AWS OpsWorks and AWS Elastic Beanstalk both focus on operations, but with very different orientations. AWS Elastic Beanstalk seeks to automatically provide key operations activities so that developers can maximize the time they spend on development and minimize the time they spend on operations. In contrast, AWS OpsWorks delivers integrated experiences for IT administrators and ops-minded developers who want a high degree of productivity and control over operations.

I finally found the solution:

Beanstalk is using the ec2-user account to run bash commands. So everything installed by commandline cannot be executed by the nodejs user account because of permission conflicts.

Solution was to copy all installed tools in to /usr/local/bin, where they can be executed by any user.

07_myprogram:
        command: sudo cp bin/* /usr/local/bin
        cwd: /home/ec2-user/myprogram
        ignoreErrors: true
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!