New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Basic auth for /sidekiq in Rails API only project #4061
Comments
Throw away Devise. You want to add Basic Auth to the Sidekiq **Rack** app. Search accordingly.
… On Dec 19, 2018, at 04:32, Nico Saueressig ***@***.***> wrote:
Ruby version: ruby 2.5.3p105 (2018-10-18 revision 65156) [x86_64-darwin17]
Rails version: 5.2.1.1
Sidekiq / Pro / Enterprise version(s): 5.2.3 free version
We are running a brand new Rails project as an api only project with devise.
Now I added Sidekiq and I realised that it is actually not that easy to add basic auth to it in this case. We'd be fine with just basic auth for the endpoint (/sidekiq) as well. However since our app and therefore devise does not have a UI, how would I sign in? That is also why using this wont work:
authenticate :user, lambda { |u| u.admin? } do
mount Sidekiq::Web => '/sidekiq'
end
Does anyone have any suggestions on how we could cleanly add Basic Auth on the /sidekiq endpoint in an api only rails project?
—
You are receiving this because you are subscribed to this thread.
Reply to this email directly, view it on GitHub, or mute the thread.
|
Thanks. Throwing away Devise is not an option ;) Searching for it on the rack level was a good hint though! Found something and this works:
|
Thank you for posting this @NicoSa = I have updated this slightly. Sidekiq::Web.use(Rack::Auth::Basic) do |username, password|
username == Rails.application.credentials[Rails.env.to_sym][:sidekiqweb][:username] &&
password == Rails.application.credentials[Rails.env.to_sym][:sidekiqweb][:password]
end
mount(Sidekiq::Web => "/#{Time.now.strftime("%Y%m%d")}sidekiqadmin") |
@chrishough Don't use |
thank you @Nowaker |
@Nowaker based on
also I think that we should use |
@mbronek7 They need to be the same length for But you're right about |
@Nowaker yes you're right forgive me I looked at Oh and they changed this recently and it is not in current version od documentation |
In case others come across this post, here is my latest variation for this: Sidekiq::Web.use(Rack::Auth::Basic) do |username, password|
ActiveSupport::SecurityUtils.secure_compare(::Digest::SHA256.hexdigest(username), ::Digest::SHA256.hexdigest(Rails.application.credentials.dig(:sidekiqweb, :username))) &
ActiveSupport::SecurityUtils.secure_compare(::Digest::SHA256.hexdigest(password), ::Digest::SHA256.hexdigest(Rails.application.credentials.dig(:sidekiqweb, :password)))
end
mount(Sidekiq::Web => "/sidekiqadmin") |
Ruby version: ruby 2.5.3p105 (2018-10-18 revision 65156) [x86_64-darwin17]
Rails version: 5.2.1.1
Sidekiq / Pro / Enterprise version(s): 5.2.3 free version
We are running a brand new Rails project as an api only project with devise.
Now I added Sidekiq and I realised that it is actually not that easy to add basic auth to it in this case. We'd be fine with just basic auth for the endpoint (
/sidekiq
) as well. However since our app and therefore devise does not have a UI, how would I sign in? That is also why using this wont work:Does anyone have any suggestions on how we could cleanly add Basic Auth on the
/sidekiq
endpoint in an api only rails project?The text was updated successfully, but these errors were encountered: