Skip to content

Commit bfbe59f

Browse files
JoshVanLcicoyle
andauthored
fix(common/redis): stop unconditionally skipping TLS certificate verification (#4261)
Signed-off-by: joshvanl <me@joshvanl.dev> Co-authored-by: Cassie Coyle <cassie.i.coyle@gmail.com>
1 parent d13c7b0 commit bfbe59f

File tree

9 files changed

+60
-9
lines changed

9 files changed

+60
-9
lines changed

bindings/redis/metadata.yaml

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -89,10 +89,17 @@ metadata:
8989
- name: enableTLS
9090
type: bool
9191
required: false
92-
description: |
92+
description: |
9393
If the Redis instance supports TLS; can be configured to be enabled or disabled.
9494
example: "true"
9595
default: "false"
96+
- name: insecureSkipTLSVerify
97+
type: bool
98+
required: false
99+
description: |
100+
Skip TLS certificate verification (insecure). Only use for testing.
101+
example: "false"
102+
default: "false"
96103
- name: clientCert
97104
required: false
98105
description: Client certificate for Redis host. No Default. Can be secretKeyRef to use a secret reference

common/component/redis/redis_test.go

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -112,6 +112,18 @@ func TestParseRedisMetadata(t *testing.T) {
112112
assert.True(t, m.Failover)
113113
assert.Equal(t, "master", m.SentinelMasterName)
114114
assert.False(t, m.UseEntraID)
115+
assert.False(t, m.InsecureSkipTLSVerify, "InsecureSkipTLSVerify should default to false when not set")
116+
})
117+
118+
t.Run("insecureSkipTLSVerify is set to true", func(t *testing.T) {
119+
fakeProperties := getFakeProperties()
120+
fakeProperties["insecureSkipTLSVerify"] = "true"
121+
122+
m := &Settings{}
123+
err := m.Decode(fakeProperties)
124+
125+
require.NoError(t, err)
126+
assert.True(t, m.InsecureSkipTLSVerify)
115127
})
116128

117129
// TODO: Refactor shared redis code to throw error for missing properties

common/component/redis/settings.go

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -86,9 +86,14 @@ type Settings struct {
8686
// Use Redis Sentinel for automatic failover.
8787
Failover bool `mapstructure:"failover"`
8888

89-
// A flag to enables TLS by setting InsecureSkipVerify to true
89+
// A flag to enable TLS for the Redis connection
9090
EnableTLS bool `mapstructure:"enableTLS"`
9191

92+
// A flag to skip TLS certificate verification (insecure, use only for testing).
93+
// Defaults to false. When EnableTLS is true and this is false, proper certificate
94+
// verification is performed.
95+
InsecureSkipTLSVerify bool `mapstructure:"insecureSkipTLSVerify"`
96+
9297
// Client certificate and key
9398
ClientCert string `mapstructure:"clientCert"`
9499
ClientKey string `mapstructure:"clientKey"`

common/component/redis/v8client.go

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -351,7 +351,7 @@ func newV8FailoverClient(s *Settings) (RedisClient, error) {
351351

352352
if s.EnableTLS {
353353
opts.TLSConfig = &tls.Config{
354-
InsecureSkipVerify: s.EnableTLS, //nolint:gosec
354+
InsecureSkipVerify: s.InsecureSkipTLSVerify, //nolint:gosec
355355
}
356356
err := s.SetCertificate(func(cert *tls.Certificate) {
357357
opts.TLSConfig.Certificates = []tls.Certificate{*cert}
@@ -408,7 +408,7 @@ func newV8Client(s *Settings) (RedisClient, error) {
408408
/* #nosec */
409409
if s.EnableTLS {
410410
options.TLSConfig = &tls.Config{
411-
InsecureSkipVerify: s.EnableTLS,
411+
InsecureSkipVerify: s.InsecureSkipTLSVerify,
412412
}
413413
err := s.SetCertificate(func(cert *tls.Certificate) {
414414
options.TLSConfig.Certificates = []tls.Certificate{*cert}
@@ -448,7 +448,7 @@ func newV8Client(s *Settings) (RedisClient, error) {
448448
/* #nosec */
449449
if s.EnableTLS {
450450
options.TLSConfig = &tls.Config{
451-
InsecureSkipVerify: s.EnableTLS,
451+
InsecureSkipVerify: s.InsecureSkipTLSVerify,
452452
}
453453
err := s.SetCertificate(func(cert *tls.Certificate) {
454454
options.TLSConfig.Certificates = []tls.Certificate{*cert}

common/component/redis/v9client.go

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -352,7 +352,7 @@ func newV9FailoverClient(s *Settings) (RedisClient, error) {
352352
/* #nosec */
353353
if s.EnableTLS {
354354
opts.TLSConfig = &tls.Config{
355-
InsecureSkipVerify: s.EnableTLS,
355+
InsecureSkipVerify: s.InsecureSkipTLSVerify,
356356
}
357357
err := s.SetCertificate(func(cert *tls.Certificate) {
358358
opts.TLSConfig.Certificates = []tls.Certificate{*cert}
@@ -411,7 +411,7 @@ func newV9Client(s *Settings) (RedisClient, error) {
411411
if s.EnableTLS {
412412
/* #nosec */
413413
options.TLSConfig = &tls.Config{
414-
InsecureSkipVerify: s.EnableTLS,
414+
InsecureSkipVerify: s.InsecureSkipTLSVerify,
415415
}
416416
err := s.SetCertificate(func(cert *tls.Certificate) {
417417
options.TLSConfig.Certificates = []tls.Certificate{*cert}
@@ -451,7 +451,7 @@ func newV9Client(s *Settings) (RedisClient, error) {
451451
if s.EnableTLS {
452452
/* #nosec */
453453
options.TLSConfig = &tls.Config{
454-
InsecureSkipVerify: s.EnableTLS,
454+
InsecureSkipVerify: s.InsecureSkipTLSVerify,
455455
}
456456
err := s.SetCertificate(func(cert *tls.Certificate) {
457457
options.TLSConfig.Certificates = []tls.Certificate{*cert}

configuration/redis/metadata.yaml

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -77,10 +77,17 @@ metadata:
7777
- name: enableTLS
7878
type: bool
7979
required: false
80-
description: |
80+
description: |
8181
If the Redis instance supports TLS; can be configured to be enabled or disabled.
8282
example: "true"
8383
default: "false"
84+
- name: insecureSkipTLSVerify
85+
type: bool
86+
required: false
87+
description: |
88+
Skip TLS certificate verification (insecure). Only use for testing.
89+
example: "false"
90+
default: "false"
8491
- name: clientCert
8592
required: false
8693
description: Client certificate for Redis host. No Default. Can be secretKeyRef to use a secret reference

lock/redis/metadata.yaml

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -173,6 +173,12 @@ metadata:
173173
description: "Whether to enable TLS encryption"
174174
example: "false"
175175
default: "false"
176+
- name: insecureSkipTLSVerify
177+
required: false
178+
type: bool
179+
description: "Skip TLS certificate verification (insecure). Only use for testing."
180+
example: "false"
181+
default: "false"
176182
- name: useEntraID
177183
required: false
178184
type: bool

pubsub/redis/metadata.yaml

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -87,6 +87,13 @@ metadata:
8787
example: "false"
8888
type: bool
8989
default: "false"
90+
- name: insecureSkipTLSVerify
91+
required: false
92+
description: |
93+
Skip TLS certificate verification (insecure). Only use for testing.
94+
example: "false"
95+
type: bool
96+
default: "false"
9097
- name: clientCert
9198
required: false
9299
description: Client certificate for Redis host. No Default. Can be secretKeyRef to use a secret reference

state/redis/metadata.yaml

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -85,6 +85,13 @@ metadata:
8585
description: If the Redis instance supports TLS with public certificates, can be configured to be enabled or disabled. Defaults to false.
8686
example: "false"
8787
type: bool
88+
- name: insecureSkipTLSVerify
89+
required: false
90+
description: |
91+
Skip TLS certificate verification (insecure). Only use for testing.
92+
example: "false"
93+
type: bool
94+
default: "false"
8895
- name: clientCert
8996
required: false
9097
description: Client certificate for Redis host. No Default. Can be secretKeyRef to use a secret reference

0 commit comments

Comments
 (0)