Password protecting a rails staging environment

后端 未结 3 1172
爱一瞬间的悲伤
爱一瞬间的悲伤 2020-12-30 08:42

I\'m trying to work out what the best way to secure my staging environment would be. Currently I\'m running both staging and production on the same server.

The two

相关标签:
3条回答
  • 2020-12-30 09:16

    bumping this to help others, like myself as I read this before settling on an similar, but cleaner solution.

    # 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
    

    I wrote a short blog post about it.

    0 讨论(0)
  • 2020-12-30 09:22

    I would go with the http basic authentication, I see no inherent problems with it.

    0 讨论(0)
  • 2020-12-30 09:40

    If you are deploying with multi-staging environments and so you have production environment and staging environment, you only need to add these lines to 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
    

    By doing so, you don't need to configure Apache.

    I am using Ruby 2 with Rails 4 and it works like a charm!

    0 讨论(0)
提交回复
热议问题