3

我正在尝试配置我们的Node.js应用程序以与Amazon Elastic Beanstalk一起部署。AWS Elastic Beanstalk - 用户权限问题

其实我在.ebextensions里面做了一些配置文件来启用Websockets,为几个模块做yum安装并安装我们需要的一些定制软件。

到目前为止,App部署工作并且所有配置的软件都由Beanstalk安装。

我遇到的问题是nodejs用户运行节点应用程序,没有权限执行我们的beanstalk自定义配置安装的命令行工具。

更具体:

  1. 该应用程序支持用户文件上传和上传文件保存 在实例上一些临时文件夹(就像它应该)。

  2. 然后该应用程式做一个命令执行到上传 文件转换到自定义的文件格式,什么执行类似 /家庭/ EC2用户/转换器/ BIN将文件名输出文件名。

在这一点上,我得到这个错误: {[错误:产卵EACCES]代码: 'EACCES',错误号: 'EACCES',系统调用: '重生'}

总体应用程序需要几个用于这些转换任务的命令行工具可以正确运行。 其实他们都有同样的问题。即使yum安装的工具,比如Imagemagick,也不会被应用程序执行。

通过使用ec2用户帐户,我可以执行所有这些操作,所有文件都放在正确的系统路径上,并且工作正常。所以所有的安装似乎都是正确的。

我已经尝试手动向用户nodejs授予权限并执行chmod文件,但是这似乎并没有在这里产生任何效果。

大问题是..如何可以授予所需的权限的NodeJS用户或作为替代如何使用定义的用户执行的node.js?

回答

2

我相信nodejs用户没有权限来使用shell:

[[email protected] ~]$ cat /etc/passwd 
.... 
nodejs:x:497:497::/tmp:/sbin/nologin 

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

我也试过:

[[email protected] ~]$ pwd 
/home/ec2-user 
[[email protected] ~]$ 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); 
}); 
[[email protected] ~]$ ls -l 
total 4 
-rwxrwxrwx 1 ec2-user ec2-user 169 Nov 3 21:49 test.js 
[[email protected] ~]$ sudo -u nodejs /home/ec2-user/test.js 
sudo: unable to execute /home/ec2-user/test.js: Permission denied 

我会说,这个工程,其中即时通讯困惑(也许有人可以附和澄清):

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

然而,作为一个旁观者它看起来更像Beanstalk并不适合你。一般来说,魔豆是由设计,并与文件系统权限和用户权限乱搞放手全面管理的抽象过步进这些边界。另外,也许你想consider moving to OpsWorks。从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.

+0

嗨,除了这个问题,即时通讯使用Beanstalk很不错。我需要的所有东西都已经安装完毕,并且使得缩放应用变得更加容易我了解到,Beanstalk的文档缺乏这方面的知识,所以我仍然希望有人知道如何处理这个权限问题。 – user2458046 2014-11-03 22:53:21

+0

没有与nodejs用户的shell访问是有意义的。当您执行“sudo su nodejs”时,它不允许您使用该帐户。 – user2458046 2014-11-03 22:57:39

+0

在这方面缺乏文档是因为亚马逊不希望你搞乱权限。但这取决于你;我只能给我的建议:)是的,如果你看看我在那里做什么,在一个简单的脚本中运行一个简单的'exec'命令就会失败。所以,如果你真的想解决这个问题(我不推荐),你可以尝试改变缺省shell为bash:'sudo chsh -s/bin/bash nodejs'。 – mattr 2014-11-03 23:02:22

1

我终于找到了解决办法:

魔豆是使用EC2用户帐户运行的bash命令。 因此,由命令行安装的所有内容都不能由nodejs用户帐户执行,因为权限冲突。

解决方案是将所有安装的工具复制到/ usr/local/bin中,并由任何用户执行。

07_myprogram: 
     command: sudo cp bin/* /usr/local/bin 
     cwd: /home/ec2-user/myprogram 
     ignoreErrors: true