Skip to content

Commit

Permalink
TLS config pointer is never nil which regresses TLS Support (envoypro…
Browse files Browse the repository at this point in the history
…xy#318)

* TLS config pointer is never nil, fixes regression in pull envoyproxy#289 fixes isssue envoyproxy#303

Signed-off-by: Vito Sabella <[email protected]>

* Accidentally put the initialization before the environment variable reading.

Signed-off-by: Vito Sabella <[email protected]>

* Unit test for settings tlsConfig fix

Signed-off-by: Vito Sabella <[email protected]>

* Fixing pre-commits

Signed-off-by: Vito Sabella <[email protected]>

Co-authored-by: Vito Sabella <[email protected]>
  • Loading branch information
2 people authored and barroca committed Sep 1, 2023
1 parent 7f9c71f commit 44c2512
Show file tree
Hide file tree
Showing 4 changed files with 23 additions and 7 deletions.
6 changes: 1 addition & 5 deletions src/redis/driver_impl.go
Original file line number Diff line number Diff line change
Expand Up @@ -71,11 +71,7 @@ func NewClientImpl(scope stats.Scope, useTls bool, auth, redisSocketType, redisT
var dialOpts []radix.DialOpt

if useTls {
if tlsConfig != nil {
dialOpts = append(dialOpts, radix.DialUseTLS(tlsConfig))
} else {
dialOpts = append(dialOpts, radix.DialUseTLS(&tls.Config{}))
}
dialOpts = append(dialOpts, radix.DialUseTLS(tlsConfig))
}

if auth != "" {
Expand Down
7 changes: 6 additions & 1 deletion src/settings/settings.go
Original file line number Diff line number Diff line change
Expand Up @@ -109,8 +109,13 @@ type Option func(*Settings)

func NewSettings() Settings {
var s Settings

err := envconfig.Process("", &s)

// Golang copy-by-value causes the RootCAs to no longer be nil
// which isn't the expected default behavior of continuing to use system roots
// so let's just initialize to what we want the correct value to be.
s.RedisTlsConfig = &tls.Config{}

if err != nil {
panic(err)
}
Expand Down
13 changes: 13 additions & 0 deletions src/settings/settings_test.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
package settings

import (
"testing"

"github.com/stretchr/testify/assert"
)

func TestSettingsTlsConfigUnmodified(t *testing.T) {
settings := NewSettings()
assert.NotNil(t, settings.RedisTlsConfig)
assert.Nil(t, settings.RedisTlsConfig.RootCAs)
}
4 changes: 3 additions & 1 deletion test/integration/integration_test.go
Original file line number Diff line number Diff line change
@@ -1,8 +1,10 @@
//go:build integration
// +build integration

package integration_test

import (
"crypto/tls"
"fmt"
"io"
"math/rand"
Expand Down Expand Up @@ -236,7 +238,7 @@ func TestMultiNodeMemcache(t *testing.T) {

func testBasicConfigAuthTLS(perSecond bool, local_cache_size int) func(*testing.T) {
s := makeSimpleRedisSettings(16381, 16382, perSecond, local_cache_size)
s.RedisTlsConfig = nil
s.RedisTlsConfig = &tls.Config{}
s.RedisAuth = "password123"
s.RedisTls = true
s.RedisPerSecondAuth = "password123"
Expand Down

0 comments on commit 44c2512

Please sign in to comment.