K8SPG-994: allow multi-cert pem bundles in CustomRootCATLSSecret - #1680
Conversation
Signed-off-by: Mayank Shah <mayank.shah@percona.com>
There was a problem hiding this comment.
Pull request overview
This PR updates the operator’s PKI certificate (un)marshaling so that a customRootCATLSSecret containing a multi-certificate PEM bundle (e.g., intermediate + root) is preserved and propagated into per-instance trust stores (e.g., patroni.ca-roots), avoiding TLS verification failures during bootstrap.
Changes:
- Extend
pki.Certificateto retain and re-emit additional PEM certificates found after the first certificate in a bundle. - Update
Certificate.MarshalText/UnmarshalTextto round-trip multi-cert bundles while ignoring non-certificate PEM blocks. - Add/extend unit tests, including a Patroni reconciliation test that asserts the CA bundle is preserved.
Reviewed changes
Copilot reviewed 4 out of 4 changed files in this pull request and generated 1 comment.
| File | Description |
|---|---|
| internal/pki/pki.go | Adds a chain field to Certificate to store additional cert PEM blocks from bundles. |
| internal/pki/encoding.go | Implements bundle-preserving marshal/unmarshal logic for certificates (keeps extra certs, ignores non-cert blocks). |
| internal/pki/encoding_test.go | Adds coverage for bundle round-trip and ignoring non-certificate PEM blocks (one assertion needs adjustment). |
| internal/patroni/reconcile_test.go | Adds a reconciliation test ensuring patroni.ca-roots contains the full CA bundle. |
| var sink Certificate | ||
| assert.NilError(t, sink.UnmarshalText(bundle)) | ||
| assert.DeepEqual(t, cert, sink) | ||
|
|
| for { | ||
| var next *pem.Block | ||
| next, rest = pem.Decode(rest) | ||
| if next == nil { | ||
| break | ||
| } | ||
| if next.Type == pemLabelCertificate { | ||
| c.chain = append(c.chain, pem.EncodeToMemory(next)...) | ||
| } | ||
| } |
There was a problem hiding this comment.
Just wondering if we should set a reasonable limit for the number of certs. This loop can potentially go wild if for some reason (intentionally or not) the chain is too long
There was a problem hiding this comment.
I'm not sure what the limit should be, do you have a number in mind?
commit: e7170fc |
CHANGE DESCRIPTION
Problem:
When
customRootCATLSSecretprovides aroot.crtcontaining multiple PEM-encoded certificates (intermediate CA + root CA), the operator copies only the first PEM block into per-instancepatroni.ca-rootsand the pgBackRest trust store. This breaks TLS verification for any deployment using intermediate CAs and prevents fresh cluster bootstrap.Cause:
The current certificate parsing logic only decodes the first certificate and drops the rest.
Solution:
Fix the certificate decoding logic to keep all intermediate certs, only the first one is used for signing.
CHECKLIST
Jira
Needs Doc) and QA (Needs QA)?Tests
Config/Logging/Testability