Repository navigation
Conversation
… current CA RenewLeafCertificate only regenerated a leaf certificate when it was expiring or its DNS names changed. When the CA changes while the leaf is still valid (operator-driven CA rotation with diverging lifetimes, or a switch to a different serverCASecret), the operator trusts only the new CA while the instances keep serving the old leaf, and every status call fails with "x509: certificate signed by unknown authority" until someone deletes the leaf secret by hand. Also require that the leaf verifies against the current CA, using the same verification the operator applies when talking to the instances. Closes cloudnative-pg#10433 Signed-off-by: Christian Zöpfchen <[email protected]> Co-Authored-By: Claude Fable 5.1 <[email protected]>
Contributor
|
❗ By default, the pull request is configured to backport to all release branches.
|
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.
Closes #10433
What
RenewLeafCertificate()decided whether to regenerate a leaf certificate (<cluster>-server,<cluster>-replication, webhook certificate) only by two criteria: the leaf is expiring, or its DNS names changed. It never checked whether the leaf still verifies against the current CA.This PR adds that third criterion: if the leaf cannot be verified against the CA passed in (
x509.VerifywithExtKeyUsageAny, the same verification the operator applies when it talks to the instances), the leaf is regenerated even though it is not expiring.Why
Whenever the CA changes while the leaf is still valid, the operator trusts only the new CA but the instances keep serving the old leaf. The operator then fails every status call with
x509: certificate signed by unknown authorityand the cluster is stuck (Instance Status Extraction Error/Ready=False), as described in #10433 in several variants (operator-driven CA rotation when leaf and CA lifetimes diverge, stale-replicationsecret breaking joins, and the latent "running pods fine, next restart = outage" state).We hit the same thing today on CNPG 1.30.0 through a different entry point: switching an existing cluster to a user-provided
spec.certificates.serverCASecret. The leaf was 8 days old and nowhere near expiry, so it was never regenerated; the operator immediately lost the cluster. Deleting<cluster>-servermade the operator recreate it from the new CA and everything recovered within seconds — which is exactly what the operator can now do by itself.How
pkg/certs/k8s.go: parse the CA before the early return and requirepair.IsValid(caPair, ExtKeyUsageAny) == nilin addition to "not expiring" and "DNS names match".pkg/certs/leaf_renewal_test.go: unit tests — no renewal for server and client leaves signed by the current CA; renewal for both leaf types when the CA differs, with the renewed leaf verifying against the new CA and no longer against the old one.go test ./pkg/certs/... ./internal/controller/...,gofmtandgo vetpass.Notes
KeyPair.IsValid, so it applies to user-provided CAs as well as operator-managed ones. With a user-providedserverCASecretthat has noca.key,RenewLeafCertificateis not reached (the operator only validates), so behaviour there is unchanged.IsValidrunsx509.Verify, which also rejects a leaf whose validity window does not contain "now"; that case already triggers a renewal throughIsExpiring, so it does not change behaviour.