How can I password-protect my /sidekiq route (i.e. require authentication for the Sidekiq::Web tool)?
Put the following into your sidekiq initializer
require 'sidekiq'
require 'sidekiq/web'
Sidekiq::Web.use(Rack::Auth::Basic) do |user, password|
# Protect against timing attacks:
# - See https://codahale.com/a-lesson-in-timing-attacks/
# - See https://thisdata.com/blog/timing-attacks-against-string-comparison/
# - Use & (do not use &&) so that it doesn't short circuit.
# - Use digests to stop length information leaking
Rack::Utils.secure_compare(::Digest::SHA256.hexdigest(user), ::Digest::SHA256.hexdigest(ENV["SIDEKIQ_USER"])) &
Rack::Utils.secure_compare(::Digest::SHA256.hexdigest(password), ::Digest::SHA256.hexdigest(ENV["SIDEKIQ_PASSWORD"]))
end
And in the routes file:
mount Sidekiq::Web => '/sidekiq'
Rails 5 Protect Sidekiq UI
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.
Sidekiq freezes application
The issue was in Redis config. It used Sentinel, turning Sentinel off for the development solved it.
how to detach sidekiq process once started in terminal
The right answer is lower case -d:
bundle exec sidekiq -d -q mailer,5 -q default -e production
sidekiq --help
will list the options:
-d, --daemon Daemonize process
When running -d option, sidekiq will ask for a log file, so the complete command is:
bundle exec sidekiq -d -L sidekiq.log -q mailer,5 -q default -e production
Related Topics
Capybara: Select an Option by Value Not Text
How to Drop to the Irb Prompt from a Running Script
How to Customize Gemfile Per Developer
How to Check to See If a File Exists (On the Remote Server) in Capistrano
Guidelines for Where to Put Classes in Rails Apps That Don't Fit Anywhere
How to Call a Super Class Method
How to Change Hash Keys from 'Symbol's to 'String'S
What Are the Differences Between Rbenv, Rvm, and Chruby
Rails: Hasmanythroughassociationnotfounderror
Monkey-Patching VS. S.O.L.I.D. Principles
Phusion Passenger Error: You Have Activated Rack 1.2.1, But Your Gemfile Requires Rack 1.2.2
Rails-Like Database Migrations
How to Calculate the Offset, in Hours, of a Given Timezone from Utc in Ruby
How to Manage Ruby Threads So They Finish All Their Work
Parsing Atom & Rss in Ruby/Rails