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