-->

密码保护的轨道临时环境(Password protecting a rails staging en

2019-07-19 17:43发布

我试图找出什么是最好的办法,以确保我的临时环境会。 目前我同时运行升级和生产在同一台服务器上。

这两个选项我能想到的将是:

使用轨道摘要式身份验证

我可以把这样的事情在application_controller.rb

# Password protection for staging environment
if RAILS_ENV == 'staging'
  before_filter :authenticate_for_staging
end

def authenticate_for_staging
  success = authenticate_or_request_with_http_digest("Staging") do |username|
    if username == "staging"
      "staging_password"
    end
  end
  unless success
    request_http_digest_authentication("Admin", "Authentication failed")
  end
end

这是从撕开瑞安英对照精华文章的博客 。 我最新的Rails 2.3运行,所以我应该从安全性的问题,他们与这个自由。

使用Web服务器身份验证

我也可以做到这一点使用的.htaccess或Apache许可,但它使我的服务器配置稍微复杂一些(我使用的是厨师,并需要分期/生产不同阿帕奇CONFIGS)。


现在我有第一个实施和工作,你看到它AY问题? 我错过了一些东西明显? 提前致谢!

Answer 1:

这个碰撞帮助别人,比如我自己,因为我解决上的相似,但简洁的解决方案之前,先阅读。

# config/environments/staging.rb

MyApp::Application.configure do
  config.middleware.insert_after(::Rack::Lock, "::Rack::Auth::Basic", "Staging") do |u, p|
    [u, p] == ['username', 'password']
  end

 #... other config
end

我写了一篇简短的博客文章了。



Answer 2:

如果您正在使用多级化环境中部署等你的生产环境和临时环境,您只需要添加这些行配置/环境/ staging.rb

MyApp::Application.configure do
  # RESTRICTING ACCESS TO THE STAGE ENVIRONMENT
  config.middleware.insert_before(::Rack::Runtime, "::Rack::Auth::Basic", "Staging") do |u, p|
    u == 'tester' && p == 'secret'
  end

  ...

end

通过这样做,你不需要配置Apache。

我使用的红宝石2与轨道4,它就像一个魅力!



Answer 3:

我将与HTTP基本身份验证去,我看到它没有固有的问题。



文章来源: Password protecting a rails staging environment