4

I'm trying to protect the Sidekiq UI with Devise. I'm running Rails 5.1, Devise 4.3 and Sidekiq 5.0. I tried the following post:

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

but I get the following error:

Undefined method failure_app for nil:NilClass

My routes file looks like this:

Rails.application.routes.draw do
  constraint = lambda do |request|
    request.env['warden'].authenticate!({ scope: :admin_user })
  end

  constraints constraint do
    mount Sidekiq::Web => '/admin/sidekiq'
  end

  devise_for :users
  resources :users
end

How can I protect Sidekiq UI with Devise on Rails 5.1?

Ken J
  • 4,312
  • 12
  • 50
  • 86

1 Answers1

4

I stumbled across this page that outlines how to secure the Web UI with Devise:

Devise

Allow any authenticated User

# Allow any user access
authenticate :user do
  mount Sidekiq::Web => '/sidekiq'
end

# Allow only admin users
authenticate :user, lambda { |u| u.admin? } do
  mount Sidekiq::Web => '/sidekiq'
end

I've confirmed that this works with Rails 5.1 and Devise 4.3.

user3063045
  • 2,019
  • 2
  • 22
  • 35