Skip to content

Commit 456330f

Browse files
dani-maaroufyaron2
andauthored
feat: allow specifying Redis Sentinel auth (#3905)
Signed-off-by: Dani Maarouf <[email protected]> Co-authored-by: Yaron Schneider <[email protected]>
1 parent adc76bd commit 456330f

File tree

9 files changed

+118
-0
lines changed

9 files changed

+118
-0
lines changed

bindings/redis/metadata.yaml

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -42,6 +42,30 @@ authenticationProfiles:
4242
secret reference
4343
example: "KeFg23!"
4444
default: ""
45+
- name: sentinelUsername
46+
type: string
47+
required: false
48+
description: |
49+
Username for Redis Sentinel. Applicable only when "failover" is true, and
50+
Redis Sentinel has authentication enabled. Defaults to empty.
51+
example: "my-sentinel-username"
52+
default: ""
53+
url:
54+
title: "Redis Sentinel authentication documentation"
55+
url: "https://redis.io/docs/latest/operate/oss_and_stack/management/sentinel/#configuring-sentinel-instances-with-authentication"
56+
- name: sentinelPassword
57+
type: string
58+
required: false
59+
sensitive: true
60+
description: |
61+
Password for Redis Sentinel. Applicable only when "failover" is true, and
62+
Redis Sentinel has authentication enabled. Use secretKeyRef for
63+
secret reference. Defaults to empty.
64+
example: "KeFg23!"
65+
default: ""
66+
url:
67+
title: "Redis Sentinel authentication documentation"
68+
url: "https://redis.io/docs/latest/operate/oss_and_stack/management/sentinel/#configuring-sentinel-instances-with-authentication"
4569
metadata:
4670
- name: redisHost
4771
required: true

common/component/redis/redis_test.go

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,8 @@ const (
2525
host = "redisHost"
2626
password = "redisPassword"
2727
username = "redisUsername"
28+
sentinelUsername = "sentinelUsername"
29+
sentinelPassword = "sentinelPassword"
2830
db = "redisDB"
2931
redisType = "redisType"
3032
redisMaxRetries = "redisMaxRetries"
@@ -51,6 +53,8 @@ func getFakeProperties() map[string]string {
5153
host: "fake.redis.com",
5254
password: "fakePassword",
5355
username: "fakeUsername",
56+
sentinelUsername: "fakeSentinelUsername",
57+
sentinelPassword: "fakeSentinelPassword",
5458
redisType: "node",
5559
enableTLS: "true",
5660
clientCert: "fakeCert",
@@ -86,6 +90,8 @@ func TestParseRedisMetadata(t *testing.T) {
8690
assert.Equal(t, fakeProperties[host], m.Host)
8791
assert.Equal(t, fakeProperties[password], m.Password)
8892
assert.Equal(t, fakeProperties[username], m.Username)
93+
assert.Equal(t, fakeProperties[sentinelUsername], m.SentinelUsername)
94+
assert.Equal(t, fakeProperties[sentinelPassword], m.SentinelPassword)
8995
assert.Equal(t, fakeProperties[redisType], m.RedisType)
9096
assert.True(t, m.EnableTLS)
9197
assert.Equal(t, fakeProperties[clientCert], m.ClientCert)

common/component/redis/settings.go

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -29,6 +29,10 @@ type Settings struct {
2929
Password string `mapstructure:"redisPassword"`
3030
// The Redis username
3131
Username string `mapstructure:"redisUsername"`
32+
// The Redis Sentinel password
33+
SentinelPassword string `mapstructure:"sentinelPassword"`
34+
// The Redis Sentinel username
35+
SentinelUsername string `mapstructure:"sentinelUsername"`
3236
// Database to be selected after connecting to the server.
3337
DB int `mapstructure:"redisDB"`
3438
// The redis type node or cluster

common/component/redis/v8client.go

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -330,6 +330,8 @@ func newV8FailoverClient(s *Settings) (RedisClient, error) {
330330
DB: s.DB,
331331
MasterName: s.SentinelMasterName,
332332
SentinelAddrs: []string{s.Host},
333+
SentinelUsername: s.SentinelUsername,
334+
SentinelPassword: s.SentinelPassword,
333335
Password: s.Password,
334336
Username: s.Username,
335337
MaxRetries: s.RedisMaxRetries,

common/component/redis/v9client.go

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -330,6 +330,8 @@ func newV9FailoverClient(s *Settings) (RedisClient, error) {
330330
DB: s.DB,
331331
MasterName: s.SentinelMasterName,
332332
SentinelAddrs: []string{s.Host},
333+
SentinelUsername: s.SentinelUsername,
334+
SentinelPassword: s.SentinelPassword,
333335
Password: s.Password,
334336
Username: s.Username,
335337
MaxRetries: s.RedisMaxRetries,

configuration/redis/metadata.yaml

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -30,6 +30,30 @@ authenticationProfiles:
3030
secret reference
3131
example: "KeFg23!"
3232
default: ""
33+
- name: sentinelUsername
34+
type: string
35+
required: false
36+
description: |
37+
Username for Redis Sentinel. Applicable only when "failover" is true, and
38+
Redis Sentinel has authentication enabled. Defaults to empty.
39+
example: "my-sentinel-username"
40+
default: ""
41+
url:
42+
title: "Redis Sentinel authentication documentation"
43+
url: "https://redis.io/docs/latest/operate/oss_and_stack/management/sentinel/#configuring-sentinel-instances-with-authentication"
44+
- name: sentinelPassword
45+
type: string
46+
required: false
47+
sensitive: true
48+
description: |
49+
Password for Redis Sentinel. Applicable only when "failover" is true, and
50+
Redis Sentinel has authentication enabled. Use secretKeyRef for
51+
secret reference. Defaults to empty.
52+
example: "KeFg23!"
53+
default: ""
54+
url:
55+
title: "Redis Sentinel authentication documentation"
56+
url: "https://redis.io/docs/latest/operate/oss_and_stack/management/sentinel/#configuring-sentinel-instances-with-authentication"
3357
metadata:
3458
- name: redisHost
3559
required: true

configuration/redis/redis_test.go

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -244,6 +244,8 @@ func Test_parseRedisMetadata(t *testing.T) {
244244
testProperties := make(map[string]string)
245245
testProperties["redisHost"] = "testHost"
246246
testProperties["redisPassword"] = "testPassword"
247+
testProperties["sentinelUsername"] = "testSentinelUsername"
248+
testProperties["sentinelPassword"] = "testSentinelPassword"
247249
testProperties["enableTLS"] = "true"
248250
testProperties["redisMaxRetries"] = "10"
249251
testProperties["redisMaxRetryInterval"] = "100ms"
@@ -254,6 +256,8 @@ func Test_parseRedisMetadata(t *testing.T) {
254256
testSettings := redisComponent.Settings{
255257
Host: "testHost",
256258
Password: "testPassword",
259+
SentinelUsername: "testSentinelUsername",
260+
SentinelPassword: "testSentinelPassword",
257261
EnableTLS: true,
258262
RedisMaxRetries: 10,
259263
RedisMaxRetryInterval: redisComponent.Duration(100 * time.Millisecond),
@@ -268,6 +272,8 @@ func Test_parseRedisMetadata(t *testing.T) {
268272
defaultSettings := redisComponent.Settings{
269273
Host: "testHost",
270274
Password: "",
275+
SentinelUsername: "",
276+
SentinelPassword: "",
271277
EnableTLS: false,
272278
RedisMaxRetries: 3,
273279
RedisMaxRetryInterval: redisComponent.Duration(time.Second * 2),
@@ -311,6 +317,8 @@ func Test_parseRedisMetadata(t *testing.T) {
311317
}
312318
assert.Equal(t, tt.want.Host, got.Host)
313319
assert.Equal(t, tt.want.Password, got.Password)
320+
assert.Equal(t, tt.want.SentinelUsername, got.SentinelUsername)
321+
assert.Equal(t, tt.want.SentinelPassword, got.SentinelPassword)
314322
assert.Equal(t, tt.want.EnableTLS, got.EnableTLS)
315323
assert.Equal(t, tt.want.RedisMaxRetries, got.RedisMaxRetries)
316324
assert.Equal(t, tt.want.RedisMaxRetryInterval, got.RedisMaxRetryInterval)

pubsub/redis/metadata.yaml

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -31,6 +31,30 @@ authenticationProfiles:
3131
secret reference
3232
example: "KeFg23!"
3333
default: ""
34+
- name: sentinelUsername
35+
type: string
36+
required: false
37+
description: |
38+
Username for Redis Sentinel. Applicable only when "failover" is true, and
39+
Redis Sentinel has authentication enabled. Defaults to empty.
40+
example: "my-sentinel-username"
41+
default: ""
42+
url:
43+
title: "Redis Sentinel authentication documentation"
44+
url: "https://redis.io/docs/latest/operate/oss_and_stack/management/sentinel/#configuring-sentinel-instances-with-authentication"
45+
- name: sentinelPassword
46+
type: string
47+
required: false
48+
sensitive: true
49+
description: |
50+
Password for Redis Sentinel. Applicable only when "failover" is true, and
51+
Redis Sentinel has authentication enabled. Use secretKeyRef for
52+
secret reference. Defaults to empty.
53+
example: "KeFg23!"
54+
default: ""
55+
url:
56+
title: "Redis Sentinel authentication documentation"
57+
url: "https://redis.io/docs/latest/operate/oss_and_stack/management/sentinel/#configuring-sentinel-instances-with-authentication"
3458
metadata:
3559
- name: redisHost
3660
required: true

state/redis/metadata.yaml

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -36,6 +36,30 @@ authenticationProfiles:
3636
secret reference
3737
example: "KeFg23!"
3838
default: ""
39+
- name: sentinelUsername
40+
type: string
41+
required: false
42+
description: |
43+
Username for Redis Sentinel. Applicable only when "failover" is true, and
44+
Redis Sentinel has authentication enabled. Defaults to empty.
45+
example: "my-sentinel-username"
46+
default: ""
47+
url:
48+
title: "Redis Sentinel authentication documentation"
49+
url: "https://redis.io/docs/latest/operate/oss_and_stack/management/sentinel/#configuring-sentinel-instances-with-authentication"
50+
- name: sentinelPassword
51+
type: string
52+
required: false
53+
sensitive: true
54+
description: |
55+
Password for Redis Sentinel. Applicable only when "failover" is true, and
56+
Redis Sentinel has authentication enabled. Use secretKeyRef for
57+
secret reference. Defaults to empty.
58+
example: "KeFg23!"
59+
default: ""
60+
url:
61+
title: "Redis Sentinel authentication documentation"
62+
url: "https://redis.io/docs/latest/operate/oss_and_stack/management/sentinel/#configuring-sentinel-instances-with-authentication"
3963
metadata:
4064
- name: redisHost
4165
required: true

0 commit comments

Comments
 (0)