Skip to content

Commit

Permalink
redis: Configurable Username
Browse files Browse the repository at this point in the history
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.
  • Loading branch information
oxzi committed Jul 30, 2024
1 parent ee07796 commit ba6a85c
Show file tree
Hide file tree
Showing 2 changed files with 6 additions and 0 deletions.
1 change: 1 addition & 0 deletions redis/client.go
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down
5 changes: 5 additions & 0 deletions redis/config.go
Original file line number Diff line number Diff line change
Expand Up @@ -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"`
Expand All @@ -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()
}

0 comments on commit ba6a85c

Please sign in to comment.