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 only the sidekiq part. How can i do that?
相关问题
- Eager-loading association count with Arel (Rails 3
- Getting Redis Master address from Sentinel C#
- How to specify memcache server to Rack::Session::M
- Why am I getting a “C compiler cannot create execu
- reference to a method?
Sorry to late to the party, but Sidekiq's wiki recommends the following for Devise:
To allow any authenticated
User
:To restrict access to
User.admin?
This wiki post also has many other security schemes.
This was tested using Rails 5.1.3, Devise 4.3 and Sidekiq 5.0
The accepted answer is good, but I think that it can be implemented more securely, as Sidekiq documentation mentions.
To protect your app against timing attacks, use
ActiveSupport::SecurityUtils.secure_compare
.Also, use
&
(do not use&&
) so that it doesn't short circuit.And finally, use digests to stop length information leaking (default of
secure_compare
in Active Support 5).Active Support 5: Thanks to Rails PR #24510, parameters passed to
secure_compare
are going throughDigest::SHA256.hexdigest
by default.Active Support 4:
If you're using Sorcery for authentication, here's how to use Rails routes constraints to protect certain routes.
Copied here from the sorcery wiki for redundancy:
This tutorial shows how to use Rails routes constraints with Sorcery gem. Thanks to @anthonator for writing it!
First, define
UserConstraint
module that will be used for all constraints:Then, having that module defined, you can specify specific constraint classes. In these examples, first route will work only if there's no user logged in, the second will work only for logged user who is an admin:
Finally, you can add the constraints to the
config/routes.rb
:Put the following into your sidekiq initializer
And in the routes file:
Another option would be to add something like CanCan and special access based on roles.
See "Security" under https://github.com/mperham/sidekiq/wiki/Monitoring