How can I password-protect my /sidekiq route (i.e. require authentication for the Sidekiq::Web tool)?

前端 未结 8 1258
太阳男子
太阳男子 2021-02-01 00:52

I am using sidekiq in my rails application. By Default, Sidekiq can be accessed by anybody by appending \"/sidekiq\" after the url. I want to password protect / authenticate onl

8条回答
  •  不思量自难忘°
    2021-02-01 01:26

    If you're using Devise (or other Warden-based authentication), you can do this, supposing you have an AdminUser model in your app.

    # config/routes.rb
    # This defines the authentication constraint
    constraint = lambda do |request|
                   request.env['warden'].authenticate!({ scope: :admin_user })
                 end
    
    # This mounts the route using the constraint.
    # You could use any other path to make it less obvious
    constraints constraint do
      mount Sidekiq::Web => '/sidekiq'
    end
    

提交回复
热议问题