专注收集记录技术开发学习笔记、技术难点、解决方案
网站信息搜索 >> 请输入关键词:
您当前的位置: 首页 > Ruby/Rails

rubygems.org guides 通译七(安全)

发布时间:2011-06-29 17:56:00 文章来源:www.iduyao.cn 采编人员:星星草
rubygems.org guides 翻译七(安全)

目录

1.梗概

2.使用gem

3.构建gem

4.报告安全漏洞

 

一、梗概

安装一个gem后,允许你在你的app作用域中运行gem代码。同时他也暗指,如果你在gem server上安装了一个恶意的gem,那么你的server将被渗透。因此,gem的安全也是ruby社区经常讨论的一个主题。

rubygems已经有能力 cryptographically sign gems (加密签名gem)自从 version 0.8.11,这个签名使用gem cert产生一对秘钥,然后打包签名信息到gem中。gem install命令提供了一个可选的安全策略选项,使你可以在安装gem之前验证gem的签名。

然而,安全加密gem的方式并没有广泛使用。他需要许多 manual steps on the part of the developer,而且目前还没有一个完善的方式来验证gem的签名。新的签名模型例如X509 and OpenPGP可以去 rubygems-trust wiki, the RubyGems-Developers list and in IRC.

他的目标是改善签名系统,使之更加简单、透明。

 

二、使用gem

使用信任策略安装gem

  • gem install gemname -P HighSecurity: All dependent gems must be signed and verified.

  • gem install gemname -P MediumSecurity: All signed dependent gems must be verified.

  • bundle --trust-policy MediumSecurity: Same as above, except Bundler only recognizes the long --trust-policy flag, not the short -P.

  • Caveat: Gem certificates are trusted globally, such that adding a cert.pem for one gem automatically trusts all gems signed by that cert.

验证checksum

gem fetch gemname -v version
ruby -rdigest/sha2 -e "puts Digest::SHA512.new.hexdigest(File.read('gemname-version.gem'))

Know the risks of being pwned, as described by Benjamin Smith’s Hacking with Gems talk

 

 

三、构建gem

使用gem cert命令签名

1.创建自己的签名证书

cd ~/.ssh
gem cert --build your@email.com
chmod 600 gem-p*

使用你gemspecs中的邮箱

2.配置gemspec with cert

添加证书公钥到你的仓库

cd /path/to/your/gem
mkdir certs
cp ~/.ssh/gem-public_cert.pem certs/yourhandle.pem
git add certs/yourhandle.pem
添加证书路径到gemspec
s.cert_chain  = ['certs/yourhandle.pem']
s.signing_key = File.expand_path("~/.ssh/gem-private_key.pem") if $0 =~ /gem\z/
3.Add your own cert to your approved list, 如下
gem cert --add certs/yourhandle.pem
4.编译、测试gem以便安装它
gem build gemname.gemspec
gem install gemname-version.gem -P HighSecurity
# or -P MediumSecurity if your gem depends on unsigned gems
5.Example text for installation documentation

MetricFu is cryptographically signed(加密签名方式)。 确定你安装的gem没有被 tampered(篡改) with:

添加公钥作为可信任的证书

gem cert --add <(curl -Ls https://raw.github.com/metricfu/metric_fu/master/certs/bf4.pem)

gem install metric_fu -P MediumSecurity

The MediumSecurity trust profile 会验证签名的gems, 但是允许安装未签名的依赖.

这是必须的,因为不是所有的 MetricFu’s 依赖都签名了,所以不能使用 HighSecurity。

引入release gem的checksum到你的仓库中
require 'digest/sha2'
built_gem_path = 'pkg/gemname-version.gem'
checksum = Digest::SHA512.new.hexdigest(File.read(built_gem_path))
checksum_path = 'checksum/gemname-version.gem.sha512'
File.open(checksum_path, 'w' ) {|f| f.write(checksum) }
# add and commit 'checksum_path'
OpenPGP不建议使用,因为没有被支持。

is not recommended due to lack of support.请查看 with Yorick Peterse.

四、报告安全漏洞

1.报告他人gem的安全漏洞

如果了发现了某人的gem存在安全漏洞,第一步就是检查他是否一个已知的漏洞。

如果是一个未被发现的漏洞,你可以私下联系作者,尽量不要pull request或者issue在开源的项目中,解释这个漏洞,并提供解决方案。

 

2.报告自己gem的安全漏洞

首先request a CVE identifier by mailing cve-assign@mitre.org。这个identifier指明这个漏洞在讨论中具有唯一性。

然后找出哪些人使用了你的gem,需要解决这个漏洞。这样牵涉到更新一补丁,并建议他们更新。

最后,你需要告知人们这个漏洞,目前没有很好的地方来发布这些漏洞信息,但是你可以使用以下这些方案:

  • 发送一封邮件到 Ruby Talk mailing list (ruby-talk@ruby-lang.org) ,主题 prefix [ANN][Security] outlining the vulnerabilty, which versions of your gem it affects and what actions those depending on the gem should take.

  • 把他添加到开源漏洞数据库,例如 OSVDB。You can do this by emailing moderators@osvdb.org and/or messaging @osvdb on GitHub or Twitter.

 

五、扩展阅读

Several sources were used for content for this guide:

  • How to cryptographically sign your RubyGem - Step-by-step guide
  • Signing rubygems - Pasteable instructions
  • Twitter gem gemspec
  • RubyGems Trust Model Overview, doc
  • Let’s figure out a way to start signing RubyGems
  • A Practical Guide to Using Signed Ruby Gems - Part 3: Signing your Own
  • Also see the Resources page.

 

 

友情提示:
信息收集于互联网,如果您发现错误或造成侵权,请及时通知本站更正或删除,具体联系方式见页面底部联系我们,谢谢。

其他相似内容:

热门推荐: