Skip to content

Commit

Permalink
Allow setting Redis SSL verify_mode via env var
Browse files Browse the repository at this point in the history
When using Redis 6 and above, Heroku Redis requires TLS [1] but uses
self-signed certificates. As a result, Sidekiq cannot connect to Redis
on Heroku.

The official Heroku docs specify configuring `verify_mode` to `none`
is the right move here. Heroku terminates SSL at the router and internal
requests are all HTTP anyway.

We obviously don't want this as the default setting, so we can turn off
verification via an env var that we'll just set in Heroku environments.

See also https://stackoverflow.com/q/65834575

[1] https://devcenter.heroku.com/articles/heroku-redis#security-and-compliance
  • Loading branch information
jackbot committed Oct 7, 2024
1 parent 2b0b846 commit 27c60b5
Show file tree
Hide file tree
Showing 3 changed files with 21 additions and 3 deletions.
4 changes: 4 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,3 +1,7 @@
# Unreleased

* Allow setting of Redis SSL `verify_mode` to none via environment variable

# 9.0.0

* Switch from using `redis` gem to `redis-client`
Expand Down
10 changes: 7 additions & 3 deletions lib/govuk_sidekiq/railtie.rb
Original file line number Diff line number Diff line change
Expand Up @@ -3,9 +3,13 @@
module GovukSidekiq
class Railtie < Rails::Railtie
initializer "govuk_sidekiq.initialize_sidekiq" do
SidekiqInitializer.setup_sidekiq(
{ url: ENV.fetch("REDIS_URL", "redis://127.0.0.1:6379") },
)
redis_options = { url: ENV.fetch("REDIS_URL", "redis://127.0.0.1:6379") }

if ENV["REDIS_SSL_VERIFY_NONE"] == "true"
redis_options[:ssl_params] = { verify_mode: OpenSSL::SSL::VERIFY_NONE }
end

SidekiqInitializer.setup_sidekiq(redis_options)
end

rake_tasks do
Expand Down
10 changes: 10 additions & 0 deletions spec/govuk_sidekiq/railtie_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -25,4 +25,14 @@
described_class.initializers.first.run(app)
end
end

it "can set Redis SSL verify_mode to none via an env var" do
ClimateControl.modify REDIS_SSL_VERIFY_NONE: "true" do
expect(GovukSidekiq::SidekiqInitializer)
.to receive(:setup_sidekiq)
.with(default_redis_configuration.merge({ ssl_params: { verify_mode: OpenSSL::SSL::VERIFY_NONE } }))

described_class.initializers.first.run(app)
end
end
end

0 comments on commit 27c60b5

Please sign in to comment.