feat: allow specifying Redis Sentinel auth (#3905)

Signed-off-by: Dani Maarouf <dmaarouf@cisco.com>
Co-authored-by: Yaron Schneider <schneider.yaron@live.com>
This commit is contained in:
Dani Maarouf 2025-07-30 08:45:32 -04:00 committed by GitHub
parent adc76bd6ec
commit 456330f76f
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
9 changed files with 118 additions and 0 deletions

View File

@ -42,6 +42,30 @@ authenticationProfiles:
secret reference secret reference
example: "KeFg23!" example: "KeFg23!"
default: "" default: ""
- name: sentinelUsername
type: string
required: false
description: |
Username for Redis Sentinel. Applicable only when "failover" is true, and
Redis Sentinel has authentication enabled. Defaults to empty.
example: "my-sentinel-username"
default: ""
url:
title: "Redis Sentinel authentication documentation"
url: "https://redis.io/docs/latest/operate/oss_and_stack/management/sentinel/#configuring-sentinel-instances-with-authentication"
- name: sentinelPassword
type: string
required: false
sensitive: true
description: |
Password for Redis Sentinel. Applicable only when "failover" is true, and
Redis Sentinel has authentication enabled. Use secretKeyRef for
secret reference. Defaults to empty.
example: "KeFg23!"
default: ""
url:
title: "Redis Sentinel authentication documentation"
url: "https://redis.io/docs/latest/operate/oss_and_stack/management/sentinel/#configuring-sentinel-instances-with-authentication"
metadata: metadata:
- name: redisHost - name: redisHost
required: true required: true

View File

@ -25,6 +25,8 @@ const (
host = "redisHost" host = "redisHost"
password = "redisPassword" password = "redisPassword"
username = "redisUsername" username = "redisUsername"
sentinelUsername = "sentinelUsername"
sentinelPassword = "sentinelPassword"
db = "redisDB" db = "redisDB"
redisType = "redisType" redisType = "redisType"
redisMaxRetries = "redisMaxRetries" redisMaxRetries = "redisMaxRetries"
@ -51,6 +53,8 @@ func getFakeProperties() map[string]string {
host: "fake.redis.com", host: "fake.redis.com",
password: "fakePassword", password: "fakePassword",
username: "fakeUsername", username: "fakeUsername",
sentinelUsername: "fakeSentinelUsername",
sentinelPassword: "fakeSentinelPassword",
redisType: "node", redisType: "node",
enableTLS: "true", enableTLS: "true",
clientCert: "fakeCert", clientCert: "fakeCert",
@ -86,6 +90,8 @@ func TestParseRedisMetadata(t *testing.T) {
assert.Equal(t, fakeProperties[host], m.Host) assert.Equal(t, fakeProperties[host], m.Host)
assert.Equal(t, fakeProperties[password], m.Password) assert.Equal(t, fakeProperties[password], m.Password)
assert.Equal(t, fakeProperties[username], m.Username) assert.Equal(t, fakeProperties[username], m.Username)
assert.Equal(t, fakeProperties[sentinelUsername], m.SentinelUsername)
assert.Equal(t, fakeProperties[sentinelPassword], m.SentinelPassword)
assert.Equal(t, fakeProperties[redisType], m.RedisType) assert.Equal(t, fakeProperties[redisType], m.RedisType)
assert.True(t, m.EnableTLS) assert.True(t, m.EnableTLS)
assert.Equal(t, fakeProperties[clientCert], m.ClientCert) assert.Equal(t, fakeProperties[clientCert], m.ClientCert)

View File

@ -29,6 +29,10 @@ type Settings struct {
Password string `mapstructure:"redisPassword"` Password string `mapstructure:"redisPassword"`
// The Redis username // The Redis username
Username string `mapstructure:"redisUsername"` Username string `mapstructure:"redisUsername"`
// The Redis Sentinel password
SentinelPassword string `mapstructure:"sentinelPassword"`
// The Redis Sentinel username
SentinelUsername string `mapstructure:"sentinelUsername"`
// Database to be selected after connecting to the server. // Database to be selected after connecting to the server.
DB int `mapstructure:"redisDB"` DB int `mapstructure:"redisDB"`
// The redis type node or cluster // The redis type node or cluster

View File

@ -330,6 +330,8 @@ func newV8FailoverClient(s *Settings) (RedisClient, error) {
DB: s.DB, DB: s.DB,
MasterName: s.SentinelMasterName, MasterName: s.SentinelMasterName,
SentinelAddrs: []string{s.Host}, SentinelAddrs: []string{s.Host},
SentinelUsername: s.SentinelUsername,
SentinelPassword: s.SentinelPassword,
Password: s.Password, Password: s.Password,
Username: s.Username, Username: s.Username,
MaxRetries: s.RedisMaxRetries, MaxRetries: s.RedisMaxRetries,

View File

@ -330,6 +330,8 @@ func newV9FailoverClient(s *Settings) (RedisClient, error) {
DB: s.DB, DB: s.DB,
MasterName: s.SentinelMasterName, MasterName: s.SentinelMasterName,
SentinelAddrs: []string{s.Host}, SentinelAddrs: []string{s.Host},
SentinelUsername: s.SentinelUsername,
SentinelPassword: s.SentinelPassword,
Password: s.Password, Password: s.Password,
Username: s.Username, Username: s.Username,
MaxRetries: s.RedisMaxRetries, MaxRetries: s.RedisMaxRetries,

View File

@ -30,6 +30,30 @@ authenticationProfiles:
secret reference secret reference
example: "KeFg23!" example: "KeFg23!"
default: "" default: ""
- name: sentinelUsername
type: string
required: false
description: |
Username for Redis Sentinel. Applicable only when "failover" is true, and
Redis Sentinel has authentication enabled. Defaults to empty.
example: "my-sentinel-username"
default: ""
url:
title: "Redis Sentinel authentication documentation"
url: "https://redis.io/docs/latest/operate/oss_and_stack/management/sentinel/#configuring-sentinel-instances-with-authentication"
- name: sentinelPassword
type: string
required: false
sensitive: true
description: |
Password for Redis Sentinel. Applicable only when "failover" is true, and
Redis Sentinel has authentication enabled. Use secretKeyRef for
secret reference. Defaults to empty.
example: "KeFg23!"
default: ""
url:
title: "Redis Sentinel authentication documentation"
url: "https://redis.io/docs/latest/operate/oss_and_stack/management/sentinel/#configuring-sentinel-instances-with-authentication"
metadata: metadata:
- name: redisHost - name: redisHost
required: true required: true

View File

@ -244,6 +244,8 @@ func Test_parseRedisMetadata(t *testing.T) {
testProperties := make(map[string]string) testProperties := make(map[string]string)
testProperties["redisHost"] = "testHost" testProperties["redisHost"] = "testHost"
testProperties["redisPassword"] = "testPassword" testProperties["redisPassword"] = "testPassword"
testProperties["sentinelUsername"] = "testSentinelUsername"
testProperties["sentinelPassword"] = "testSentinelPassword"
testProperties["enableTLS"] = "true" testProperties["enableTLS"] = "true"
testProperties["redisMaxRetries"] = "10" testProperties["redisMaxRetries"] = "10"
testProperties["redisMaxRetryInterval"] = "100ms" testProperties["redisMaxRetryInterval"] = "100ms"
@ -254,6 +256,8 @@ func Test_parseRedisMetadata(t *testing.T) {
testSettings := redisComponent.Settings{ testSettings := redisComponent.Settings{
Host: "testHost", Host: "testHost",
Password: "testPassword", Password: "testPassword",
SentinelUsername: "testSentinelUsername",
SentinelPassword: "testSentinelPassword",
EnableTLS: true, EnableTLS: true,
RedisMaxRetries: 10, RedisMaxRetries: 10,
RedisMaxRetryInterval: redisComponent.Duration(100 * time.Millisecond), RedisMaxRetryInterval: redisComponent.Duration(100 * time.Millisecond),
@ -268,6 +272,8 @@ func Test_parseRedisMetadata(t *testing.T) {
defaultSettings := redisComponent.Settings{ defaultSettings := redisComponent.Settings{
Host: "testHost", Host: "testHost",
Password: "", Password: "",
SentinelUsername: "",
SentinelPassword: "",
EnableTLS: false, EnableTLS: false,
RedisMaxRetries: 3, RedisMaxRetries: 3,
RedisMaxRetryInterval: redisComponent.Duration(time.Second * 2), RedisMaxRetryInterval: redisComponent.Duration(time.Second * 2),
@ -311,6 +317,8 @@ func Test_parseRedisMetadata(t *testing.T) {
} }
assert.Equal(t, tt.want.Host, got.Host) assert.Equal(t, tt.want.Host, got.Host)
assert.Equal(t, tt.want.Password, got.Password) assert.Equal(t, tt.want.Password, got.Password)
assert.Equal(t, tt.want.SentinelUsername, got.SentinelUsername)
assert.Equal(t, tt.want.SentinelPassword, got.SentinelPassword)
assert.Equal(t, tt.want.EnableTLS, got.EnableTLS) assert.Equal(t, tt.want.EnableTLS, got.EnableTLS)
assert.Equal(t, tt.want.RedisMaxRetries, got.RedisMaxRetries) assert.Equal(t, tt.want.RedisMaxRetries, got.RedisMaxRetries)
assert.Equal(t, tt.want.RedisMaxRetryInterval, got.RedisMaxRetryInterval) assert.Equal(t, tt.want.RedisMaxRetryInterval, got.RedisMaxRetryInterval)

View File

@ -31,6 +31,30 @@ authenticationProfiles:
secret reference secret reference
example: "KeFg23!" example: "KeFg23!"
default: "" default: ""
- name: sentinelUsername
type: string
required: false
description: |
Username for Redis Sentinel. Applicable only when "failover" is true, and
Redis Sentinel has authentication enabled. Defaults to empty.
example: "my-sentinel-username"
default: ""
url:
title: "Redis Sentinel authentication documentation"
url: "https://redis.io/docs/latest/operate/oss_and_stack/management/sentinel/#configuring-sentinel-instances-with-authentication"
- name: sentinelPassword
type: string
required: false
sensitive: true
description: |
Password for Redis Sentinel. Applicable only when "failover" is true, and
Redis Sentinel has authentication enabled. Use secretKeyRef for
secret reference. Defaults to empty.
example: "KeFg23!"
default: ""
url:
title: "Redis Sentinel authentication documentation"
url: "https://redis.io/docs/latest/operate/oss_and_stack/management/sentinel/#configuring-sentinel-instances-with-authentication"
metadata: metadata:
- name: redisHost - name: redisHost
required: true required: true

View File

@ -36,6 +36,30 @@ authenticationProfiles:
secret reference secret reference
example: "KeFg23!" example: "KeFg23!"
default: "" default: ""
- name: sentinelUsername
type: string
required: false
description: |
Username for Redis Sentinel. Applicable only when "failover" is true, and
Redis Sentinel has authentication enabled. Defaults to empty.
example: "my-sentinel-username"
default: ""
url:
title: "Redis Sentinel authentication documentation"
url: "https://redis.io/docs/latest/operate/oss_and_stack/management/sentinel/#configuring-sentinel-instances-with-authentication"
- name: sentinelPassword
type: string
required: false
sensitive: true
description: |
Password for Redis Sentinel. Applicable only when "failover" is true, and
Redis Sentinel has authentication enabled. Use secretKeyRef for
secret reference. Defaults to empty.
example: "KeFg23!"
default: ""
url:
title: "Redis Sentinel authentication documentation"
url: "https://redis.io/docs/latest/operate/oss_and_stack/management/sentinel/#configuring-sentinel-instances-with-authentication"
metadata: metadata:
- name: redisHost - name: redisHost
required: true required: true