Skip to content

Commit

Permalink
Fix non-local tls cert validation
Browse files Browse the repository at this point in the history
  • Loading branch information
secwall committed Apr 5, 2024
1 parent f6872df commit 98a4fcb
Show file tree
Hide file tree
Showing 3 changed files with 6 additions and 4 deletions.
2 changes: 1 addition & 1 deletion internal/redis/node.go
Original file line number Diff line number Diff line change
Expand Up @@ -65,7 +65,7 @@ func NewNode(config *config.Config, logger *slog.Logger, fqdn string) (*Node, er
Protocol: 2,
}
if config.Redis.UseTLS {
tlsConf, err := getTLSConfig(config, config.Redis.TLSCAPath)
tlsConf, err := getTLSConfig(config, config.Redis.TLSCAPath, host)
if err != nil {
return nil, err
}
Expand Down
2 changes: 1 addition & 1 deletion internal/redis/senticache.go
Original file line number Diff line number Diff line change
Expand Up @@ -78,7 +78,7 @@ func NewSentiCacheNode(config *config.Config, logger *slog.Logger) (*SentiCacheN
Protocol: 2,
}
if config.SentinelMode.UseTLS {
tlsConf, err := getTLSConfig(config, config.SentinelMode.TLSCAPath)
tlsConf, err := getTLSConfig(config, config.SentinelMode.TLSCAPath, localhost)
if err != nil {
return nil, err
}
Expand Down
6 changes: 4 additions & 2 deletions internal/redis/tls.go
Original file line number Diff line number Diff line change
Expand Up @@ -9,9 +9,11 @@ import (
"github.com/yandex/rdsync/internal/config"
)

func getTLSConfig(config *config.Config, CAPath string) (*tls.Config, error) {
func getTLSConfig(config *config.Config, CAPath, host string) (*tls.Config, error) {
c := &tls.Config{}
c.ServerName = config.Hostname
if host == localhost {
c.ServerName = config.Hostname
}
if CAPath != "" {
cert, err := os.ReadFile(CAPath)
if err != nil {
Expand Down

0 comments on commit 98a4fcb

Please sign in to comment.