Repository navigation
Description
Gap
redis.TLSConfig supports a server-verification trust anchor but has no way to present a client certificate, so mutual-TLS Redis endpoints can't be reached through redis.NewClient:
// redis/config.go
type TLSConfig struct {
InsecureSkipVerify bool
CACert []byte
}BuildTLSConfig populates MinVersion, InsecureSkipVerify, and RootCAs, but never Certificates:
// redis/client.go
tc := &tls.Config{
MinVersion: tls.VersionTLS12,
InsecureSkipVerify: cfg.InsecureSkipVerify,
}
if len(cfg.CACert) > 0 { /* RootCAs */ }A managed Redis configured for mTLS (or any deployment where the server sets ClientAuth: RequireAndVerifyClientCert) rejects the connection at handshake, and there is no config surface to fix it from the caller side — BuildTLSConfig returns a fresh *tls.Config and the standalone/cluster/sentinel builders consume it directly, so a caller can't inject Certificates after the fact either.
Why we're asking
We're adopting toolhive-core/redis in stacklok/mecatl to replace a hand-rolled go-redis connection layer (duplicated TLS assembly, no cluster/sentinel support, no timeout defaults — all of which this package already does well). The one thing we had that we've now had to drop to adopt it is client-certificate authentication: our previous adapter loaded a Secret-mounted cert/key pair via tls.LoadX509KeyPair and set Certificates.
We'd rather remove the local duplicate and carry the gap than keep two implementations, so we've shipped without mTLS and pointed our ADR at this issue.
Suggested change
Two fields on TLSConfig, mirroring the existing CACert byte-slice style so callers keep owning file/Secret reading:
type TLSConfig struct {
InsecureSkipVerify bool
CACert []byte
// ClientCert and ClientKey are a PEM-encoded client certificate/key pair
// presented to the server for mutual TLS. Both or neither.
ClientCert []byte
ClientKey []byte
}and in BuildTLSConfig:
if len(cfg.ClientCert) > 0 || len(cfg.ClientKey) > 0 {
cert, err := tls.X509KeyPair(cfg.ClientCert, cfg.ClientKey)
if err != nil {
return nil, fmt.Errorf("redis: failed to load client certificate/key pair")
}
tc.Certificates = []tls.Certificate{cert}
}Notes:
- Byte slices rather than paths keeps the package free of filesystem concerns, consistent with
CACert. - Please do not include the underlying
tls.X509KeyPairerror verbatim — it can echo key material into logs. A fixed message is enough; the caller knows which pair it passed. - No change needed in the three builders: they all route through
BuildTLSConfig, and the sentinel path's per-address dialer picks up master vs. sentinel configs independently, so an mTLS pair set onTLS(and/orSentinelTLS) flows through unchanged. - An unpaired cert/key should be a
Validate()/BuildTLSConfigerror rather than a silent no-op — a half-configured pair means the operator expected mTLS and would otherwise get a confusing handshake failure.
Happy to open the PR if the shape looks right.
Activity
redis: add client certificate support for mTLS
feat(redisstore): support authenticated TLS Redis connections (#374)
feat(redisstore): support authenticated TLS Redis connections (#374)
feat(redisstore): support authenticated TLS Redis connections (#374)
feat(redisstore): support authenticated TLS Redis connections (#374) (#…
redis: add client certificate support for mTLS