Skip to content

Commit 5dfe86a

Browse files
committed
Fix Sidekiq UI auth
1 parent b294e37 commit 5dfe86a

File tree

1 file changed

+16
-11
lines changed

1 file changed

+16
-11
lines changed

config.ru

Lines changed: 16 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -20,17 +20,22 @@ use Airbrake::Rack::Middleware if ENV['AIRBRAKE_PROJECT_ID'].present?
2020
map '/sidekiq' do
2121
unless MR.env == 'development'
2222
use Rack::Auth::Basic, 'Protected Area' do |username, password|
23-
username_matches = Rack::Utils.secure_compare(
24-
Digest::SHA256.hexdigest(username),
25-
Digest::SHA256.hexdigest(ENV.fetch('SIDEKIQ_USERNAME', nil))
26-
)
27-
28-
password_matches = Rack::Utils.secure_compare(
29-
Digest::SHA256.hexdigest(password),
30-
Digest::SHA256.hexdigest(ENV.fetch('SIDEKIQ_PASSWORD', nil))
31-
)
32-
33-
username_matches && password_matches
23+
if ENV.key?('SIDEKIQ_USERNAME') && ENV.key?('SIDEKIQ_PASSWORD')
24+
username_matches = Rack::Utils.secure_compare(
25+
Digest::SHA256.hexdigest(username),
26+
Digest::SHA256.hexdigest(ENV.fetch('SIDEKIQ_USERNAME', nil))
27+
)
28+
29+
password_matches = Rack::Utils.secure_compare(
30+
Digest::SHA256.hexdigest(password),
31+
Digest::SHA256.hexdigest(ENV.fetch('SIDEKIQ_PASSWORD', nil))
32+
)
33+
34+
username_matches && password_matches
35+
else
36+
MR.logger.warn("SIDEKIQ_USERNAME or SIDEKIQ_PASSWORD is missing")
37+
false
38+
end
3439
end
3540
end
3641

0 commit comments

Comments
 (0)