簡體   English   中英

密碼保護rails登台環境

[英]Password protecting a rails staging environment

我正在努力找出保護我的臨時環境的最佳方法。 目前我在同一台服務器上運行暫存和生產。

我能想到的兩個選擇是:

使用rails摘要身份驗證

我可以把這樣的東西放在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

這是從Ryan Daigle的博客中扯下來 我正在運行最新的Rails 2.3,所以我應該擺脫他們對此的安全問題。

使用Web服務器身份驗證

我也可以使用.htaccess或apache權限實現這一點,但是它使我的服務器配置稍微復雜一些(我使用Chef,並且需要不同的apache配置用於登台/生產)。


現在我有第一個實施和工作,你看到它的問題嗎? 我錯過了明顯的東西嗎? 提前致謝!

碰到這個以幫助其他人,就像我自己讀到這個,然后再解決類似但更清潔的解決方案。

# 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

我寫了一篇關於它的短篇博文

如果要使用多階段環境進行部署,並且擁有生產環境和暫存環境,則只需將這些行添加到config / environments / 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。

我使用Ruby 2和Rails 4,它就像一個魅力!

我會使用http基本身份驗證,我發現它沒有固有的問題。

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM