Skip to content

feat(redisconn): add CACertFile to TLSConfig - #386

Open
reyortiz3 wants to merge 1 commit into
mainfrom
redisconn-ca-cert-file
Open

reyortiz3 wants to merge 1 commit into
mainfrom
redisconn-ca-cert-file

Conversation

@reyortiz3

Copy link
Copy Markdown
Contributor

Summary

redisconn.TLSConfig only accepts a CA bundle as bytes (CACert), so every consumer that configures Redis TLS from a file has to read, empty-check and validate the bundle itself before calling BuildTLSConfig. toolhive does exactly this in pkg/redisconfig, alongside a second, parallel serializable TLS type for the auth server.

This adds CACertFile so the library owns file loading, with the same strictness consumers already apply by hand.

  • BuildTLSConfig reads CACertFile when set. A missing, empty, or malformed file is an error; it never falls back to system roots or plaintext.
  • CACert and CACertFile are mutually exclusive.
  • Config.Validate() stays free of filesystem access; the file is read when the TLS configuration is built (which NewClient reaches).
  • InsecureSkipVerify and CACertFile gain json/yaml tags (insecureSkipVerify, caCertFile) so the type can be used in serialized configuration. Decoding stays compatible; encoding InsecureSkipVerify now emits the camelCase key.
  • The deprecated redis package aliases this type and picks up the field automatically.

Type of change

  • New feature
  • Bug fix
  • Breaking change

Test plan

  • go test -race for redisconn, including a new table-driven TestBuildTLSConfigCACertFile (valid, missing, empty, malformed, and both fields set)
  • task lint (0 issues) and task license-check

Notes for reviewers

  • The PEM byte fields (CACert, ClientCert, ClientKey) are intentionally left untagged. Serializing key material should be a deliberate decision, so the struct is partly tagged for now.
  • The CA file is read once when the TLS configuration is built; changing its contents requires a new client.
  • redisconn is released as its own module, so consumers need a new redisconn release to use this.

🤖 Generated with Claude Code

Consumers that configure Redis TLS from files had to read and validate
the CA bundle themselves before populating CACert. Add CACertFile so
BuildTLSConfig loads it, rejecting missing, empty, and malformed files
instead of falling back to system roots.

CACert and CACertFile are mutually exclusive. Config.Validate still
avoids filesystem access; the file is read when the TLS configuration
is built. InsecureSkipVerify and CACertFile gain json/yaml tags so the
type can be used in serialized configuration.

Co-Authored-By: Claude Sonnet 5.5 <noreply@anthropic.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant