Skip to content

config: don't require CA to be configured when rotating client cert#902

Open
zakcutner wants to merge 1 commit intoprometheus:mainfrom
zakcutner:fix-tlsroundtripper-nil-ca
Open

config: don't require CA to be configured when rotating client cert#902
zakcutner wants to merge 1 commit intoprometheus:mainfrom
zakcutner:fix-tlsroundtripper-nil-ca

Conversation

@zakcutner
Copy link
Copy Markdown

Summary

When cert_file and key_file are configured but ca_file is not, tlsRoundTripper.RoundTrip rebuilds the transport on every rotation of the cert or key. The rebuild path unconditionally calls updateRootCA with empty CA data, which always fails (x509.CertPool.AppendCertsFromPEM returns false on empty input), surfacing a spurious unable to use specified CA cert: none configured error on every subsequent request.

This error is sticky: once a rotation triggers it, the RoundTripper never recovers without a process restart. It is easy to hit in practice with short-lived client certificates managed by tools such as cert-manager.

Background

#792 landed a guard in this same code path to prevent a nil-pointer panic when t.settings.CA == nil. It correctly stopped the crash, but it preserved the underlying logic error: the rebuild path is entered whenever the cert or key hash changes, not only when the CA changes, and it then tries to parse a CA that was never configured.

This PR fixes the root cause: when no CA is configured, skip the updateRootCA call entirely and keep using the originally configured TLS roots (typically the system trust store). Rotation of cert_file/key_file now works whether or not a CA is configured.

When `cert_file` and `key_file` are configured but `ca_file` is not,
`tlsRoundTripper.RoundTrip` rebuilds the transport on every rotation
of the cert or key. The rebuild path unconditionally calls
`updateRootCA` with empty CA data, which always fails
(`x509.CertPool.AppendCertsFromPEM` returns false on empty input),
surfacing a spurious "unable to use specified CA cert: none
configured" error on every subsequent request.

This error is sticky: once a rotation triggers it, the `RoundTripper`
never recovers without a process restart. It is easy to hit in
practice with short-lived client certificates managed by tools such
as cert-manager.

Skip the `updateRootCA` call when no CA is configured, so rotation of
`cert_file`/`key_file` works without requiring a CA.

Signed-off-by: Zak Cutner <zak@cloudflare.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.

2 participants