Skip to content

TLS: return an error when the CA file holds no certificates - #7908

Open
sarankumar1325 wants to merge 1 commit into
cortexproject:masterfrom
sarankumar1325:fix-tls-empty-ca-pool
Open

sarankumar1325 wants to merge 1 commit into
cortexproject:masterfrom
sarankumar1325:fix-tls-empty-ca-pool

Conversation

@sarankumar1325

Copy link
Copy Markdown
Contributor

What this PR does:

ClientConfig.GetTLSConfig in pkg/util/tls ignored the return value of AppendCertsFromPEM. If the file set with a -<prefix>.tls-ca-path flag holds no PEM certificates (an empty file, the wrong file, or a key instead of a certificate), the root pool stayed empty and setup went on as normal. Every TLS connection then failed later with x509: certificate signed by unknown authority, which doesn't point at the CA file.

GetTLSConfig now returns an error naming the file when no certificates can be parsed from it, so a bad CA file shows up at startup.

Tests: added cases to TestGetTLSConfig_CA for an empty file, a non-PEM file and a key-only file. They fail on master and pass with this change. go test ./pkg/util/tls/... ./pkg/util/grpcclient/... passes, and golangci-lint run ./pkg/util/tls/... reports 0 issues.

I used an AI assistant to help find and fix this, and I reviewed and tested the change myself.

Which issue(s) this PR fixes:
None, found while reading the code.

Checklist

  • Tests updated
  • Documentation added
  • CHANGELOG.md updated - the order of entries should be [CHANGE], [FEATURE], [ENHANCEMENT], [BUGFIX]
  • docs/configuration/v1-guarantees.md updated if this PR introduces experimental flags

GetTLSConfig ignored the result of AppendCertsFromPEM. A tls_ca_path
file with no PEM certificates (empty, wrong file, a key) produced an
empty root pool, so every TLS connection failed later with
"certificate signed by unknown authority" and no hint about the file.
Return an error naming the file instead.

Signed-off-by: sarankumar1325 <120080287+sarankumar1325@users.noreply.github.com>
@sarankumar1325
sarankumar1325 requested a review from a team as a code owner October 31, 2026 06:24
@sarankumar1325
sarankumar1325 requested a review from yeya24 October 31, 2026 06:24

This branch has not been deployed

No deployments
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant