Skip to content

feat: per-role client certificate duration and renewal window - #11342

Merged
mnencia merged 7 commits into
mainfrom
dev/11312
Nov 2, 2026
Merged

mnencia merged 7 commits into
mainfrom
dev/11312

Conversation

@armru

@armru armru commented Aug 19, 2026 •

Copy link
Copy Markdown
Member

The clientCertificate stanza of a DatabaseRole took its lifetime and renewal window from CERTIFICATE_DURATION and EXPIRING_CHECK_THRESHOLD, which apply to every certificate the operator signs, so a role could not have a policy of its own.

Add optional duration and renewBefore to that stanza. A role that sets neither keeps the operator-wide values. duration must be at least one minute. renewBefore needs duration and must be between 30 seconds and half of it. The API server enforces this through CEL, since a DatabaseRole has no admission webhook.

Two things had to change underneath. The fixed five-minute backdate of leaf certificates would put notAfter in the past for lifetimes below five minutes, so the allowance now scales with the lifetime, capped at five minutes. And renewal is no longer decided by RenewLeafCertificate, which only knows the operator-wide threshold: the role reconciler compares the stored certificate with the role's own lifetime and window.

Roles that set neither field see three changes. Renewal generates a new private key along with the certificate. Changing CERTIFICATE_DURATION re-issues their certificate. The default renewal window is capped at half the lifetime. For every role, a missing cluster or client CA is now reported in status.clientCertificate.message and as a warning event. The docs also gain a short walkthrough for using the generated Secret with psql.

Closes #11312

@armru
armru requested review from a team, NiccoloFei and litaocdl as code owners August 19, 2026 13:12
@dosubot dosubot Bot added size:L This PR changes 100-499 lines, ignoring generated files. do not backport This PR must not be backported - it will be in the next minor release enhancement 🪄 New feature or request labels Aug 19, 2026
@cnpg-bot cnpg-bot added backport-requested ◀️ This pull request should be backported to all supported releases release-1.28 release-1.29 release-1.30 labels Aug 19, 2026
@github-actions

Copy link
Copy Markdown
Contributor

❗ By default, the pull request is configured to backport to all release branches.

  • To stop backporting this pr, remove the label: backport-requested ◀️ or add the label 'do not backport'
  • To stop backporting this pr to a certain release branch, remove the specific branch label: release-x.y

@armru

armru commented Aug 19, 2026

Copy link
Copy Markdown
Member Author

/test

@github-actions

Copy link
Copy Markdown
Contributor

@cnpg-bot cnpg-bot added the ok to merge 👌 This PR can be merged label Aug 19, 2026
@armru

armru commented Aug 19, 2026

Copy link
Copy Markdown
Member Author

/test

@armru armru removed backport-requested ◀️ This pull request should be backported to all supported releases release-1.28 release-1.29 release-1.30 labels Aug 19, 2026
@github-actions

Copy link
Copy Markdown
Contributor

@armru

armru commented Aug 21, 2026

Copy link
Copy Markdown
Member Author

/test

@github-actions

Copy link
Copy Markdown
Contributor

@armru
armru force-pushed the dev/11312 branch 2 times, most recently from 216e4a2 to 4aca23f Compare August 25, 2026 16:13
@dosubot dosubot Bot added size:XL This PR changes 500-999 lines, ignoring generated files. and removed size:L This PR changes 100-499 lines, ignoring generated files. labels Aug 25, 2026
@armru

armru commented Aug 25, 2026

Copy link
Copy Markdown
Member Author

/test

@github-actions

Copy link
Copy Markdown
Contributor

@github-actions

Copy link
Copy Markdown
Contributor

@armru

armru commented Aug 31, 2026

Copy link
Copy Markdown
Member Author

/test

@github-actions

Copy link
Copy Markdown
Contributor

@litaocdl
litaocdl force-pushed the dev/11312 branch 3 times, most recently from 0112d38 to 16fbbed Compare September 7, 2026 07:23
@litaocdl

litaocdl commented Sep 7, 2026

Copy link
Copy Markdown
Collaborator

/test

@github-actions

github-actions Bot commented Sep 7, 2026

Copy link
Copy Markdown
Contributor

@leonardoce

Copy link
Copy Markdown
Contributor

/test

@github-actions

Copy link
Copy Markdown
Contributor

@mnencia

mnencia commented Nov 2, 2026

Copy link
Copy Markdown
Member

/test depth=push ft=declarative-database-roles tl=2

@github-actions

github-actions Bot commented Nov 2, 2026

Copy link
Copy Markdown
Contributor

@mnencia
mnencia force-pushed the dev/11312 branch 2 times, most recently from 8a38b9a to a33f70a Compare November 2, 2026 12:54
armru and others added 7 commits November 2, 2026 14:01
The `clientCertificate` stanza of a `DatabaseRole` took its lifetime and renewal
window from `CERTIFICATE_DURATION` and `EXPIRING_CHECK_THRESHOLD`, which apply to
every certificate the operator signs, so a role could not have a policy of its
own.

Add optional `duration` and `renewBefore` to that stanza; a role that sets
neither behaves as before. `duration` must be at least one minute, and
`renewBefore` is accepted only together with `duration` and must be at most half
of it. Both bounds are enforced by the API server through CEL, since a
`DatabaseRole` has no admission webhook.

Two things had to change underneath. Leaf certificates were backdated a fixed
five minutes to tolerate clock skew, which for any lifetime below ten minutes put
`notAfter` in the past; the allowance now scales with the lifetime, capped at five
minutes. Renewal is no longer decided by `RenewLeafCertificate`, whose notion of
expiring is the operator-wide threshold: the role reconciler compares the stored
certificate against the role's own lifetime and window.

Roles that set neither field see two changes: renewal now generates a new private
key along with the certificate, and changing `CERTIFICATE_DURATION` re-issues
their certificate so the issued lifetime matches the configured one.

Closes #11312

Signed-off-by: Armando Ruocco <[email protected]>
if secrets is not owned by databaseRole, the previous detected
`role.Status.ClientCertificate.Expiration` may become invalid as it can be
set by external.

Signed-off-by: Tao Li <[email protected]>
Signed-off-by: Leonardo Cecchi <[email protected]>
The certificate in the Secret is still valid, so its expiration stays in
the status. Only a Secret the role does not own clears it.

Signed-off-by: Marco Nenciarini <[email protected]>
Signed-off-by: Marco Nenciarini <[email protected]>
@mnencia
mnencia merged commit 357fb9f into main Nov 2, 2026
@mnencia
mnencia deleted the dev/11312 branch November 2, 2026 13:14
cnpg-bot pushed a commit to cloudnative-pg/api that referenced this pull request Nov 2, 2026
…ative-pg/cloudnative-pg#11342)

The `clientCertificate` stanza of a `DatabaseRole` took its lifetime and
renewal window from `CERTIFICATE_DURATION` and
`EXPIRING_CHECK_THRESHOLD`, which apply to every certificate the
operator signs, so a role could not have a policy of its own.

Add optional `duration` and `renewBefore` to that stanza. A role that
sets neither keeps the operator-wide values. `duration` must be at least
one minute. `renewBefore` needs `duration` and must be between 30
seconds and half of it. The API server enforces this through CEL, since
a `DatabaseRole` has no admission webhook.

Two things had to change underneath. The fixed five-minute backdate of
leaf certificates would put `notAfter` in the past for lifetimes below
five minutes, so the allowance now scales with the lifetime, capped at
five minutes. And renewal is no longer decided by
`RenewLeafCertificate`, which only knows the operator-wide threshold:
the role reconciler compares the stored certificate with the role's own
lifetime and window.

Roles that set neither field see three changes. Renewal generates a new
private key along with the certificate. Changing `CERTIFICATE_DURATION`
re-issues their certificate. The default renewal window is capped at
half the lifetime. For every role, a missing cluster or client CA is now
reported in `status.clientCertificate.message` and as a warning event.
The docs also gain a short walkthrough for using the generated Secret
with `psql`.

Closes cloudnative-pg/cloudnative-pg#11312

Signed-off-by: Armando Ruocco <[email protected]>
Signed-off-by: Tao Li <[email protected]>
Signed-off-by: Leonardo Cecchi <[email protected]>
Signed-off-by: Marco Nenciarini <[email protected]>
Co-authored-by: Tao Li <[email protected]>
Co-authored-by: Leonardo Cecchi <[email protected]>
Co-authored-by: Marco Nenciarini <[email protected]>

(cherry picked from commit cloudnative-pg/cloudnative-pg@357fb9f)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

do not backport This PR must not be backported - it will be in the next minor release enhancement 🪄 New feature or request ok to merge 👌 This PR can be merged size:L This PR changes 100-499 lines, ignoring generated files.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

[Feature]: Add duration and renewBefore to the clientCertificate stanza on DatabaseRole

5 participants