Sidekiq Monitoring Authentication With Devise on Ruby on Rails

Sidekiq Monitoring displays the information of works in the background. This screen is very useful in our business development and production environment. But we may want protect access to this information. We can use the devise authentication of routing:

Allow a authenticated user:

We can change the routing as below:

# config/routes.rb
authenticate :user do
  mount Sidekiq::Web => '/sidekiq'
end

Also we can use the condition as below*(Condition result must be to access sidekiq monitoring page)*:

# config/routes.rb
authenticate :user, lambda { |user| user.admin? } do
  mount Sidekiq::Web => '/sidekiq'
end

We can use role methods for user object if roles defined as enum in user model.

For example:

# app/models/user.rb
class User < ActiveRecord::Base
  enum role: [:user, :moderator, :admin, :system_admin]
end
# config/routes.rb
authenticate :user, lambda { |user| user.admin? or user.system_admin? } do
  mount Sidekiq::Web => '/sidekiq'
end

Thank you for reading.