feat(spec.tls.additionalTrustedCAs) - #1784
Open
yoav-katz wants to merge 13 commits into
Open
Conversation
yoav-katz
requested review from
egegunes,
gkech,
hors,
mayankshah1607,
nmarukovich,
oksana-grishchenko and
pooknull
as code owners
August 25, 2026 12:30
yoav-katz
requested review from
DhruthiKV,
eleo007,
jvpasinatto and
valmiranogueira
as code owners
August 25, 2026 16:58
Co-authored-by: Copilot Autofix powered by AI <175728472+Copilot@users.noreply.github.com>
…ckend, watch additionalTrustedCAs secrets
…iation Add a field index and Secret watch for spec.tls.additionalTrustedCAs so that creating a previously-missing CA Secret or rotating an existing one's ca.crt enqueues the referencing PostgresCluster, instead of requiring an unrelated reconcile to pick up the change. Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
…rcona-postgresql-operator into clusterAdditionalTrustedCAs
Collaborator
commit: c16ea2a |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Problem:
When a PostgresCluster is configured with a TLS issuer that returns no CA certificate of its own - most commonly an ACME issuer such as Let's Encrypt, which writes only tls.crt and tls.key into the issued Secret - the operator has nothing to put in the files that verify peers. Every internal TLS path that needs a trust anchor breaks:
ssl_ca_file(/pgconf/tls/ca.crt), which Postgres uses to verify the _crunchyrepl client certificatesslrootcert(/pgconf/tls/replication/ca.crt), used by Patroni for replication and pg_rewindpgbackrest.ca-roots, the single file pgBackRest uses both as tls-server-ca-file and as pgN-/repoN-host-ca-fileReconciliation previously failed outright with external issuer did not return a CA certificate for the instance - an accurate message pointing at a field the user cannot change, since an ACME issuer never returns one.
Cause:
The operator only ever trusted CA material it could obtain itself: the internal PKI root, or the ca.crt returned by the configured cert-manager Issuer/ClusterIssuer. There was no way to supply a supplementary anchor, so a valid, correctly-configured ACME setup produced an incomplete (or entirely empty) trust bundle.
Solution:
A new optional field,
spec.tls.additionalTrustedCAs, takes a list of Secret references. Each Secret carries a PEM-encoded CA bundle under keyca.crt. The operator merges them into every trust file listed above.Merging, not replacing. The additional CAs are always concatenated with whatever the issuer already provided - the issuer CA, the internal PKI root, or nothing at all. Anything that verified before the field was set still verifies after. Concatenation goes through
pki.TrustBundle, which:Where the merged bundle is written. For the internal-PKI path the operator owns the certificate Secrets, so the merge happens in place (
<cluster>-tls ca.crt, and the replication Secret'sca.crt). When cert-manager owns the certificate Secrets the operator must not write into them - cert-manager rebuilds them on every issuance and the operator's apply takes field ownership by force, so the two controllers would overwrite each other indefinitely. In that case the merged bundle goes to a Secret the operator does own,<cluster>-ca-bundle, projected into the certificate volume at bothca.crtpaths. The certificate Secrets' ownca.crtitems are stripped from their projections (withoutCA), because a projected volume rejects two sources writing the same path.Unlike the certificate Secrets, which K8SPG-330 deliberately retains after cluster deletion,
<cluster>-ca-bundleholds nothing that can't be rebuilt and is owned by the cluster, so it's garbage-collected with it.pgBouncer. The backend authority projection switches to the merged bundle when one exists. The cluster-wide anchors are also appended to pgBouncer's frontend bundle, alongside the pre-existing
spec.proxy.pgBouncer.additionalTrustedCAs(K8SPG-952) - without them an ACME-issued frontend certificate has nothing to chain to.Rotation and late creation. The referenced Secrets are indexed (IndexFieldAdditionalTrustedCASecrets) and watched, so creating a previously-missing CA Secret or rotating an existing one's ca.crt enqueues the cluster immediately, instead of leaving the bundle absent or stale until some unrelated reconcile happens to fire.
Error handling.
No-op when unset. With the field absent, the certificate volume and every trust file are byte-identical to before. The merge is also skipped entirely under
certManagementPolicy: userProvidedOnlyand whenspec.customTLSSecretis set - in both cases the operator owns no Secret to merge into.Note that setting the field adds a source to the certificate volume, which rolls the instances.
Coverage.
e2e-tests/tests/cert-manager-tls/29-verify-additional-trusted-cas.yamlsigns a standalone CA that no issuer in the test chain uses, adds it to a running cluster, and asserts both anchors (the issuer's and the added one) are present in/pgconf/tls/ca.crt, the replicationca.crt, and the pgBackRest roots.CHECKLIST
Jira
Needs Doc) and QA (Needs QA)?Tests
Config/Logging/Testability