Redis
 sql >> Base de Dados >  >> NoSQL >> Redis

Como posso proteger com senha minha rota /sidekiq (ou seja, exigir autenticação para a ferramenta Sidekiq::Web)?


Coloque o seguinte no seu inicializador sidekiq
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

E no arquivo de rotas:
mount Sidekiq::Web => '/sidekiq'