-
Notifications
You must be signed in to change notification settings - Fork 17
/
config.ru
28 lines (23 loc) · 940 Bytes
/
config.ru
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
# inspiration from
# https://github.com/mperham/sidekiq/wiki/Monitoring#standalone-with-basic-auth
require 'sidekiq'
Sidekiq.configure_client do |config|
config.redis = {
url: ENV.fetch('REDIS_URL','redis://localhost:6379'),
size: 1,
namespace: ENV.fetch('REDIS_NAMESPACE', 'sidekiq')
}
end
require 'sidekiq/web'
map '/' do
if ENV['USERNAME'] && ENV['PASSWORD']
use Rack::Auth::Basic, "Protected Area" do |username, password|
# Protect against timing attacks: (https://codahale.com/a-lesson-in-timing-attacks/)
# - 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(username), ::Digest::SHA256.hexdigest(ENV["USERNAME"])) &
Rack::Utils.secure_compare(::Digest::SHA256.hexdigest(password), ::Digest::SHA256.hexdigest(ENV["PASSWORD"]))
end
end
run Sidekiq::Web
end