Skip to content

K8SPG-994: allow multi-cert pem bundles in CustomRootCATLSSecret - #1680

Merged
mayankshah1607 merged 3 commits into
mainfrom
K8SPG-994
Jul 16, 2026
Merged

K8SPG-994: allow multi-cert pem bundles in CustomRootCATLSSecret#1680
mayankshah1607 merged 3 commits into
mainfrom
K8SPG-994

Conversation

@mayankshah1607

Copy link
Copy Markdown
Member

CHANGE DESCRIPTION

Problem:
When customRootCATLSSecret provides a root.crt containing multiple PEM-encoded certificates (intermediate CA + root CA), the operator copies only the first PEM block into per-instance patroni.ca-roots and 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

  • Is the Jira ticket created and referenced properly?
  • Does the Jira ticket have the proper statuses for documentation (Needs Doc) and QA (Needs QA)?
  • Does the Jira ticket link to the proper milestone (Fix Version field)?

Tests

  • Is an E2E test/test case added for the new feature/change?
  • Are unit tests added where appropriate?

Config/Logging/Testability

  • Are all needed new/changed options added to default YAML files?
  • Are all needed new/changed options added to the Helm Chart?
  • Did we add proper logging messages for operator actions?
  • Did we ensure compatibility with the previous version or cluster upgrade process?
  • Does the change support oldest and newest supported PG version?
  • Does the change support oldest and newest supported Kubernetes version?

Signed-off-by: Mayank Shah <mayank.shah@percona.com>

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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.Certificate to retain and re-emit additional PEM certificates found after the first certificate in a bundle.
  • Update Certificate.MarshalText/UnmarshalText to 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.

Comment on lines 61 to +64
var sink Certificate
assert.NilError(t, sink.UnmarshalText(bundle))
assert.DeepEqual(t, cert, sink)

@mayankshah1607
mayankshah1607 marked this pull request as ready for review July 14, 2026 07:53
Comment thread internal/pki/encoding.go
Comment on lines +71 to +80
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)...)
}
}

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'm not sure what the limit should be, do you have a number in mind?

@egegunes egegunes added this to the v3.1.0 milestone Jul 15, 2026
@JNKPercona

Copy link
Copy Markdown
Collaborator
Test Name Result Time
backup-enable-disable passed 00:00:00
builtin-extensions passed 00:00:00
cert-manager-tls passed 00:00:00
custom-envs passed 00:00:00
custom-tls passed 00:00:00
database-init-sql passed 00:00:00
demand-backup passed 00:00:00
demand-backup-offline-snapshot passed 00:00:00
dynamic-configuration passed 00:00:00
finalizers passed 00:00:00
init-deploy passed 00:00:00
huge-pages passed 00:00:00
major-upgrade-14-to-15 passed 00:00:00
major-upgrade-15-to-16 passed 00:00:00
major-upgrade-16-to-17 passed 00:00:00
major-upgrade-17-to-18 passed 00:00:00
ldap passed 00:00:00
ldap-tls passed 00:00:00
monitoring passed 00:00:00
monitoring-pmm3 passed 00:00:00
one-pod passed 00:00:00
operator-self-healing passed 00:00:00
pitr passed 00:00:00
scaling passed 00:00:00
scheduled-backup passed 00:00:00
self-healing passed 00:00:00
sidecars passed 00:00:00
standby-pgbackrest passed 00:00:00
standby-streaming passed 00:00:00
start-from-backup passed 00:00:00
tablespaces passed 00:00:00
telemetry-transfer passed 00:00:00
upgrade-consistency passed 00:00:00
upgrade-minor passed 00:00:00
users passed 00:00:00
migration-from-crunchy-standby passed 00:00:00
migration-from-crunchy-pv passed 00:00:00
migration-from-crunchy-backup-restore passed 00:14:56
Summary Value
Tests Run 38/38
Job Duration 01:01:57
Total Test Time 00:14:56

commit: e7170fc
image: perconalab/percona-postgresql-operator:PR-1680-e7170fc7a

@mayankshah1607
mayankshah1607 merged commit 5e0cf1f into main Jul 16, 2026
17 checks passed
@mayankshah1607
mayankshah1607 deleted the K8SPG-994 branch July 16, 2026 11:04
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.

6 participants