Skip to content

A platform for community discussion. Free, open, simple.

DEV: Support connecting to Redis with a username. (#31710)

Kevin Hwange080712c24b7
diff --git a/app/models/global_setting.rb b/app/models/global_setting.rb
index c143dea6838..246a99866ac 100644
--- a/app/models/global_setting.rb
+++ b/app/models/global_setting.rb
@@ -214,6 +214,7 @@ class GlobalSetting
c[:connector] = RailsFailover::Redis::Connector
end
+ c[:username] = redis_username if redis_username.present?
c[:password] = redis_password if redis_password.present?
c[:db] = redis_db if redis_db != 0
c[:db] = 1 if Rails.env == "test"
@@ -238,6 +239,7 @@ class GlobalSetting
c[:connector] = RailsFailover::Redis::Connector
end
+ c[:username] = message_bus_redis_username if message_bus_redis_username.present?
c[:password] = message_bus_redis_password if message_bus_redis_password.present?
c[:db] = message_bus_redis_db if message_bus_redis_db != 0
c[:db] = 1 if Rails.env == "test"
diff --git a/config/discourse_defaults.conf b/config/discourse_defaults.conf
index 8e7e0aeaa51..2a0f2dbccce 100644
--- a/config/discourse_defaults.conf
+++ b/config/discourse_defaults.conf
@@ -147,6 +147,9 @@ redis_replica_port = 6379
# redis database
redis_db = 0
+# redis username
+redis_username =
+
# redis password
redis_password =
@@ -174,6 +177,9 @@ message_bus_redis_replica_port = 6379
# message bus redis database
message_bus_redis_db = 0
+# message bus redis username
+message_bus_redis_username =
+
# message bus redis password
message_bus_redis_password =
diff --git a/script/cache_critical_dns b/script/cache_critical_dns
index 51886aa7b83..fc2099c289e 100755
--- a/script/cache_critical_dns
+++ b/script/cache_critical_dns
@@ -283,11 +283,12 @@ class HealthyCache
end
end
-def redis_healthcheck(host:, password:, port: DEFAULT_REDIS_PORT)
+def redis_healthcheck(host:, port: DEFAULT_REDIS_PORT, username: nil, password: nil)
client_opts = {
host: host,
- password: password,
port: port,
+ username: username,
+ password: password,
timeout: 1,
}
if !nilempty(ENV['DISCOURSE_REDIS_USE_SSL']).nil? then
@@ -342,20 +343,26 @@ HEALTH_CHECKS = Hash.new(
"DISCOURSE_REDIS_HOST": lambda { |addr|
redis_healthcheck(
host: addr,
+ port: env_as_int("DISCOURSE_REDIS_PORT", DEFAULT_REDIS_PORT),
+ username: ENV["DISCOURSE_REDIS_USERNAME"],
password: ENV["DISCOURSE_REDIS_PASSWORD"])},
"DISCOURSE_REDIS_REPLICA_HOST": lambda { |addr|
redis_healthcheck(
host: addr,
+ port: env_as_int("DISCOURSE_REDIS_PORT", DEFAULT_REDIS_PORT),
+ username: ENV["DISCOURSE_REDIS_USERNAME"],
password: ENV["DISCOURSE_REDIS_PASSWORD"])},
"DISCOURSE_MESSAGE_BUS_REDIS_HOST": lambda { |addr|
redis_healthcheck(
host: addr,
port: env_as_int("DISCOURSE_MESSAGE_BUS_REDIS_PORT", DEFAULT_REDIS_PORT),
+ username: ENV["DISCOURSE_MESSAGE_BUS_REDIS_USERNAME"],
password: ENV["DISCOURSE_MESSAGE_BUS_REDIS_PASSWORD"])},
"DISCOURSE_MESSAGE_BUS_REDIS_REPLICA_HOST": lambda { |addr|
redis_healthcheck(
host: addr,
port: env_as_int("DISCOURSE_MESSAGE_BUS_REDIS_REPLICA_PORT", DEFAULT_REDIS_PORT),
+ username: ENV["DISCOURSE_MESSAGE_BUS_REDIS_REPLICA_USERNAME"],
password: ENV["DISCOURSE_MESSAGE_BUS_REDIS_PASSWORD"])},
})