From 970a32287a3916791ea70b497329925952461d53 Mon Sep 17 00:00:00 2001 From: allegroai <> Date: Sun, 13 Feb 2022 19:37:52 +0200 Subject: [PATCH] Add Redis password support --- apiserver/redis_manager.py | 12 ++++++++++++ 1 file changed, 12 insertions(+) diff --git a/apiserver/redis_manager.py b/apiserver/redis_manager.py index 77a936d..1e3a4b8 100644 --- a/apiserver/redis_manager.py +++ b/apiserver/redis_manager.py @@ -21,6 +21,11 @@ OVERRIDE_PORT_ENV_KEY = ( "TRAINS_REDIS_SERVICE_PORT", "REDIS_SERVICE_PORT", ) +OVERRIDE_PASSWORD_ENV_KEY = ( + "CLEARML_REDIS_SERVICE_PASSWORD", + "TRAINS_REDIS_SERVICE_PASSWORD", + "REDIS_SERVICE_PASSWORD", +) OVERRIDE_HOST = first(filter(None, map(getenv, OVERRIDE_HOST_ENV_KEY))) if OVERRIDE_HOST: @@ -30,6 +35,8 @@ OVERRIDE_PORT = first(filter(None, map(getenv, OVERRIDE_PORT_ENV_KEY))) if OVERRIDE_PORT: log.info(f"Using override redis port {OVERRIDE_PORT}") +OVERRIDE_PASSWORD = first(filter(None, map(getenv, OVERRIDE_PASSWORD_ENV_KEY))) + class MyPubSubWorkerThread(threading.Thread): def __init__(self, sentinel, on_new_master, msg_sleep_time, daemon=True): @@ -131,6 +138,7 @@ class RedisManager(object): for alias, alias_config in redis_config_dict.items(): alias_config = alias_config.as_plain_ordered_dict() + alias_config["password"] = config.get(f"secure.redis.{alias}.password", None) is_cluster = alias_config.get("cluster", False) @@ -142,6 +150,10 @@ class RedisManager(object): if port: alias_config["port"] = port + password = OVERRIDE_PASSWORD or alias_config.get("password", None) + if password: + alias_config["password"] = password + db = alias_config.get("db", 0) sentinels = alias_config.get("sentinels", None)