English 中文(简体)
Capistrano安全最佳实践
原标题:Capistrano security best practice

我工作的公司一直在使用capistrano进行Rails应用程序部署。我们为每个web应用程序创建了应用程序用户(例如foo.app),它们都属于一个没有密码sudo权限的webapp组:

%webapp ALL=(ALL) NOPASSWD: ALL

在capdeploy.rb中,我们设置了一个ssh密钥对,允许capistrano以应用程序用户的身份ssh到服务器并执行所有cap任务。

set :ssh_options, {:username=> foo_app , :keys => File.join(ENV[ HOME ], .ssh ,  id_rsa_deploy )}

它工作得很好,但让nopasswd sudoer运行我的应用程序进程让我感到有点不舒服,如果应用程序进程受到攻击,攻击者很容易接管整个服务器

我的问题是,有没有办法让另一个用户运行我的应用程序,最好是在没有sudo权限的情况下?理想情况下,我希望有一个部署用户来执行所有capistrano远程任务:

set :ssh_options, {:username=> deploy , :keys => File.join(ENV[ HOME ], .ssh ,  id_rsa_deploy )}

但我想让capistrano使用特定于应用程序的用户来运行我的流程,比如独角兽、延迟作业等。

我玩过:admin_runner,:runner变量,但它们并没有像我预期的那样工作。在启动独角兽、延迟作业等进程时,我可以将一些第三方食谱更改为sudo作为foo_app,但要保持它们的更新需要做很多工作。

有什么想法吗?

谢谢

问题回答

首先,你可能想考虑稍微限制一下nopasswd规则。我不确定你的部署的具体细节,但我通常会创建一个专门用于部署的用户,并为他提供nopasswd-rules,用于我在部署过程中需要升级的命令——这通常只会是服务重启命令,也可能是特定的chown命令。如果你需要更多的互动帮助,请在美国太平洋白天登录#capistrano,我很乐意帮助你——我刚刚在这个周末想念你。

一个受限制的nopasswd规则示例,以防您需要引用:

webapp ALL=(root) NOPASSWD:/usr/sbin/sv restart myservice

生成的规则集:

webapp@host:~$ sudo -ll
User torrancew may run the following commands on this host:

Sudoers entry:
    RunAsUsers: root
    Commands:
        NOPASSWD: /usr/bin/sv restart myservice

-托兰斯w





相关问题
rails collection_select vs. select

collection_select and select Rails helpers: Which one should I use? I can t see a difference in both ways. Both helpers take a collection and generates options tags inside a select tag. Is there a ...

SSL slowness in EC2

We ve deployed our rails app to EC2. In our setup, we have two proxies on small instances behind round-robin DNS. These run nginx load balancers for a dynamically growing and shrinking farm of web ...

Auth-code with A-Za-z0-9 to use in an URL parameter

As part of a web application I need an auth-code to pass as a URL parameter. I am currently using (in Rails) : Digest::SHA1.hexdigest((object_id + rand(255)).to_s) Which provides long strings like : ...

RubyCAS-Client question: Rails

I ve installed RubyCAS-Client version 2.1.0 as a plugin within a rails app. It s working, but I d like to remove the ?ticket= in the url. Is this possible?

activerecord has_many :through find with one sql call

I have a these 3 models: class User < ActiveRecord::Base has_many :permissions, :dependent => :destroy has_many :roles, :through => :permissions end class Permission < ActiveRecord::...

Ordering a hash to xml: Rails

I m building an xml document from a hash. The xml attributes need to be in order. How can this be accomplished? hash.to_xml

Text Editor for Ruby-on-Rails

guys which text editor is good for Rubyonrails? i m using Windows and i was using E-Texteditor but its not free n its expired now can anyone plese tell me any free texteditor? n which one is best an ...

How to get SQL queries for each user where env is production

I’m developing an application dedicated to generate statistical reports, I would like that user after saving their stat report they save sql queries too. To do that I wrote the following module: ...