From d5691e6dd155eacb4462000bcb12607c8f00a12d Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Jo=C3=A3o=20Calisto?= Date: Wed, 11 Oct 2023 09:45:24 +0100 Subject: [PATCH] Live: Allow setting the engine password (#76289) --- conf/defaults.ini | 3 +++ conf/sample.ini | 3 +++ pkg/services/live/live.go | 6 ++++-- pkg/setting/setting.go | 4 +++- 4 files changed, 13 insertions(+), 3 deletions(-) diff --git a/conf/defaults.ini b/conf/defaults.ini index 6712b15c734..d200015e520 100644 --- a/conf/defaults.ini +++ b/conf/defaults.ini @@ -1525,6 +1525,9 @@ ha_engine = # This option is EXPERIMENTAL. ha_engine_address = "127.0.0.1:6379" +# ha_engine_password allows setting an optional password to authenticate with the engine +ha_engine_password = "" + #################################### Grafana Image Renderer Plugin ########################## [plugin.grafana-image-renderer] # Instruct headless browser instance to use a default timezone when not provided by Grafana, e.g. when rendering panel image of alert. diff --git a/conf/sample.ini b/conf/sample.ini index 6972722789c..126a4aa594f 100644 --- a/conf/sample.ini +++ b/conf/sample.ini @@ -1418,6 +1418,9 @@ # This option is EXPERIMENTAL. ;ha_engine_address = "127.0.0.1:6379" +# ha_engine_password allows setting an optional password to authenticate with the engine +;ha_engine_password = "" + #################################### Grafana Image Renderer Plugin ########################## [plugin.grafana-image-renderer] # Instruct headless browser instance to use a default timezone when not provided by Grafana, e.g. when rendering panel image of alert. diff --git a/pkg/services/live/live.go b/pkg/services/live/live.go index bb6babd1292..eb802c8b236 100644 --- a/pkg/services/live/live.go +++ b/pkg/services/live/live.go @@ -124,8 +124,9 @@ func ProvideService(plugCtxProvider *plugincontext.Provider, cfg *setting.Cfg, r // will be connected over Redis PUB/SUB. Presence will work // globally since kept inside Redis. redisAddress := g.Cfg.LiveHAEngineAddress + redisPassword := g.Cfg.LiveHAEnginePassword redisShardConfigs := []centrifuge.RedisShardConfig{ - {Address: redisAddress}, + {Address: redisAddress, Password: redisPassword}, } var redisShards []*centrifuge.RedisShard for _, redisConf := range redisShardConfigs { @@ -160,7 +161,8 @@ func ProvideService(plugCtxProvider *plugincontext.Provider, cfg *setting.Cfg, r var managedStreamRunner *managedstream.Runner if g.IsHA() { redisClient := redis.NewClient(&redis.Options{ - Addr: g.Cfg.LiveHAEngineAddress, + Addr: g.Cfg.LiveHAEngineAddress, + Password: g.Cfg.LiveHAEnginePassword, }) cmd := redisClient.Ping(context.Background()) if _, err := cmd.Result(); err != nil { diff --git a/pkg/setting/setting.go b/pkg/setting/setting.go index 5c86c56fc4d..1ea1b0bfe77 100644 --- a/pkg/setting/setting.go +++ b/pkg/setting/setting.go @@ -482,7 +482,8 @@ type Cfg struct { // Zero value means in-memory single node setup. LiveHAEngine string // LiveHAEngineAddress is a connection address for Live HA engine. - LiveHAEngineAddress string + LiveHAEngineAddress string + LiveHAEnginePassword string // LiveAllowedOrigins is a set of origins accepted by Live. If not provided // then Live uses AppURL as the only allowed origin. LiveAllowedOrigins []string @@ -1989,6 +1990,7 @@ func (cfg *Cfg) readLiveSettings(iniFile *ini.File) error { return fmt.Errorf("unsupported live HA engine type: %s", cfg.LiveHAEngine) } cfg.LiveHAEngineAddress = section.Key("ha_engine_address").MustString("127.0.0.1:6379") + cfg.LiveHAEnginePassword = section.Key("ha_engine_password").MustString("") var originPatterns []string allowedOrigins := section.Key("allowed_origins").MustString("")