From ba6a85cb1614a4424d8ecc6d28249e7e816da0a6 Mon Sep 17 00:00:00 2001 From: Alvar Penning Date: Tue, 30 Jul 2024 17:08:05 +0200 Subject: [PATCH] redis: Configurable Username The Redis ACL system was introduced with Redis 6.0. It introduced users with precisely granular permissions. This change allows Icinga DB to connect to a Redis with an ACL user. --- redis/client.go | 1 + redis/config.go | 5 +++++ 2 files changed, 6 insertions(+) diff --git a/redis/client.go b/redis/client.go index 876d55b1..541414ff 100644 --- a/redis/client.go +++ b/redis/client.go @@ -52,6 +52,7 @@ func NewClientFromConfig(c *Config, logger *logging.Logger) (*Client, error) { options := &redis.Options{ Dialer: dialWithLogging(dialer, logger), + Username: c.Username, Password: c.Password, DB: 0, // Use default DB, ReadTimeout: c.Options.Timeout, diff --git a/redis/config.go b/redis/config.go index d59d37fb..2dd226bd 100644 --- a/redis/config.go +++ b/redis/config.go @@ -44,6 +44,7 @@ func (o *Options) Validate() error { type Config struct { Host string `yaml:"host"` Port int `yaml:"port"` + Username string `yaml:"username"` Password string `yaml:"password"` TlsOptions config.TLS `yaml:",inline"` Options Options `yaml:"options"` @@ -55,5 +56,9 @@ func (r *Config) Validate() error { return errors.New("Redis host missing") } + if r.Username != "" && r.Password == "" { + return errors.New("A Redis username requires a password as well") + } + return r.Options.Validate() }