From 0a79fb41abc881ecb0933d3296b659b33fb230e2 Mon Sep 17 00:00:00 2001 From: Yingrong Zhao <22300958+VinozzZ@users.noreply.github.com> Date: Fri, 16 Aug 2024 17:01:43 -0400 Subject: [PATCH] fix: support TLS connections to Redis (#1285) MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Currently, we are not setting the tls config for go-redis even through we do have `UseTLS` configuration option. - log the pubsub publish error - configure redis client tls --- internal/peer/pubsub_redis.go | 2 +- pubsub/pubsub_goredis.go | 16 +++++----------- 2 files changed, 6 insertions(+), 12 deletions(-) diff --git a/internal/peer/pubsub_redis.go b/internal/peer/pubsub_redis.go index c0f4b8f672..0441a1040e 100644 --- a/internal/peer/pubsub_redis.go +++ b/internal/peer/pubsub_redis.go @@ -197,6 +197,7 @@ func (p *RedisPubsubPeers) stop() { p.Logger.Error().Logf("failed to get public address") return } + err = p.PubSub.Publish(context.Background(), "peers", newPeerCommand(Unregister, myaddr).marshal()) if err != nil { p.Logger.Error().WithFields(map[string]interface{}{ @@ -204,7 +205,6 @@ func (p *RedisPubsubPeers) stop() { "hostaddress": myaddr, }).Logf("failed to publish peer address") } - } func (p *RedisPubsubPeers) GetPeers() ([]string, error) { diff --git a/pubsub/pubsub_goredis.go b/pubsub/pubsub_goredis.go index f24eced625..ba96cfdb20 100644 --- a/pubsub/pubsub_goredis.go +++ b/pubsub/pubsub_goredis.go @@ -70,21 +70,15 @@ func (ps *GoRedisPubSub) Start() error { options.Username = username options.Password = pw options.DB = ps.Config.GetRedisDatabase() - useTLS := ps.Config.GetUseTLS() - tlsInsecure := ps.Config.GetUseTLSInsecure() - if useTLS { - tlsConfig := &tls.Config{ - MinVersion: tls.VersionTLS12, - } - if tlsInsecure { - tlsConfig.InsecureSkipVerify = true + if ps.Config.GetUseTLS() { + options.TLSConfig = &tls.Config{ + MinVersion: tls.VersionTLS12, + InsecureSkipVerify: ps.Config.GetUseTLSInsecure(), } - - options.TLSConfig = tlsConfig } - } + client := redis.NewUniversalClient(options) // if an authcode was provided, use it to authenticate the connection