Skip to content

redis: TLSConfig cannot present a client certificate (no mTLS support) #240

Closed

Description

@jhrozek

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.X509KeyPair error 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 on TLS (and/or SentinelTLS) flows through unchanged.
  • An unpaired cert/key should be a Validate()/BuildTLSConfig error 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

  1. added
    needs-triage
    on Aug 19, 2026
  2. removed
    needs-triage
    on Aug 19, 2026
  3. added 5 commits that reference this issue on Aug 19, 2026
    e36eefe
    32ec9eb
    4ff5bb9
    778f273
    5243a20
  4. added a commit that references this issue on Oct 2, 2026
    4f07f54
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions