Search code examples
ruby-on-railsdeviseomniauthsidekiq

Protect sidekiq admin with devise (documented way not working)


I have an app that uses devise/omniauth for authentication, and runs a bunch of sidekiq workers.

I would like to protect /sidekiq and /sidekiq_monitor routes with devise as well, but so far I am running into a lot of trouble doing that.

The documented solution is to do this in routes.rb:

authenticate :user do
  mount Sidekiq::Web => '/sidekiq'
end

But that isn't working for me - what happens when I add that is that if a user goes to /sidekiq they are prompted to login regardless of their auth status, and if they login and go back to /sidekiq they are once again prompted to login.

Possible wrinkles - I am logging in via omniauth-saml, which means some redirects are happening in the mix here - but that's working fine with all other auth on my site. I am also only using a very minimal bit of devise, just:

devise :rememberable, :trackable, :omniauthable, :omniauth_providers => [:saml]

Solution

  • Try changing in your routes.rb file to this:

    authenticate :user do
      mount Sidekiq::Web, at: "/sidekiq"
    end
    

    Also notice that :user refers to your app user model. If your user model has another name, let's say :admin, you should replace :user to :admin in the snipped code above.