Repository navigation
fix(ari): issuer checks in secret for ari - #9124
Conversation
|
/label tide/merge-method-squash |
|
/release-note-edit |
There was a problem hiding this comment.
Pull request overview
Warning
Copilot couldn't run its full agentic review because it didn't start before the timeout. Make sure your repository has a runner available, or add a copilot-code-review.yml file specifying one with the runs-on attribute. See the docs for more details.
This PR fixes ACME ARI renewal/replaces behavior when a Certificate’s issuer changes by ensuring the existing Secret’s issuer annotations match the current IssuerRef before using ARI-specific fields.
Changes:
- Add
SecretIssuerAnnotationsMatchhelper and reuse it in certificate policy checks and ARI code paths. - Skip ARI renewal/replaces when Secret issuer annotations don’t match, and clear ACME status in readiness.
- Expand ARI “replaces” rejection detection and add tests for resolving ARI replaces CertID.
Reviewed changes
Copilot reviewed 6 out of 6 changed files in this pull request and generated 5 comments.
Show a summary per file
| File | Description |
|---|---|
| pkg/controller/certificates/readiness/readiness_controller.go | Gate ARI renewal on Secret issuer-annotation match and clear ACME status when mismatched. |
| pkg/controller/certificaterequests/acme/acme_test.go | Add test coverage for replaces in orders and for resolving ARI replaces CertID. |
| pkg/controller/certificaterequests/acme/acme.go | Skip ARI replaces resolution when Secret issuer annotations don’t match the CR IssuerRef. |
| pkg/controller/acmeorders/sync.go | Broaden detection of “replaces” related ACME 4xx errors. |
| pkg/api/util/issuers.go | Introduce SecretIssuerAnnotationsMatch and defaulting helpers. |
| internal/controller/certificates/policies/checks.go | Refactor issuer-annotation mismatch policy to use the new shared helper. |
💡 Add a code-review agent skill or configure MCP servers for context-aware, tailored reviews. Learn more in the docs.
| func SecretIssuerAnnotationsMatch(secret *corev1.Secret, issuerRef cmmeta.IssuerReference) bool { | ||
| if secret == nil { | ||
| return false | ||
| } | ||
|
|
||
| name, hasName := secret.Annotations[cmapi.IssuerNameAnnotationKey] | ||
| kind, hasKind := secret.Annotations[cmapi.IssuerKindAnnotationKey] | ||
| group, hasGroup := secret.Annotations[cmapi.IssuerGroupAnnotationKey] | ||
|
|
||
| if (hasName || hasKind || hasGroup) && name != issuerRef.Name { | ||
| return false | ||
| } | ||
| return issuerKindOrDefault(kind) == issuerKindOrDefault(issuerRef.Kind) && | ||
| issuerGroupOrDefault(group) == issuerGroupOrDefault(issuerRef.Group) | ||
| } |
There was a problem hiding this comment.
There is a flip side to making annotation-less Secrets match unconditionally: a Secret pre-created by the user with a certificate from another CA (a common bootstrap pattern) carries no cert-manager annotations, and matching it would send that foreign certificate's CertID in replaces — the very bug this PR fixes.
Note the current behaviour is also inconsistent for that case: an annotation-less Secret matches a default-kind Issuer ref (the name check is skipped when no annotations are present, and kind/group fall back to defaults) but mismatches a ClusterIssuer ref. Whichever semantics you pick, please make the no-annotations case explicit and add a doc comment — this is an exported function in a public package.
with claude fable-5
wallrj
left a comment
There was a problem hiding this comment.
I ran a review over this and replied in the Copilot threads where the findings overlapped (the broad 4xx Detail match, the annotation-less Secret semantics, and the debug log). Four further points inline. The main questions are whether the annotation check — which identifies the issuer resource rather than the ACME account — should drop replaces on same-CA issuer renames, and whether wiping status.acme silently is intended.
with claude fable-5
| return "" | ||
| } | ||
|
|
||
| if !apiutil.SecretIssuerAnnotationsMatch(secret, cr.Spec.IssuerRef) { |
There was a problem hiding this comment.
This also drops replaces when two issuer resources point at the same ACME server and account — e.g. renaming letsencrypt to letsencrypt-prod, or moving from Issuer to ClusterIssuer. The forced reissuance then loses the RFC 9773 rate-limit exemption at exactly the moment many Certificates renew at once. The annotations identify the issuer resource, not the ACME account; is that trade-off intended?
There was a problem hiding this comment.
I think so.. we would have to match the account details if we are to do that.. its a reasonable compromise I think because issuer changes should be intentional from an user's perspective.. we can discuss this tomorrow to see if everyone agrees on this
87e64db to
390cd4d
Compare
Signed-off-by: hjoshi123 <[email protected]> Signed-off-by: Hemant Joshi <[email protected]>
390cd4d to
6198b1d
Compare
wallrj
left a comment
There was a problem hiding this comment.
Thanks @hjoshi123 — scoping the fallback to malformed, the warning event, the helper consolidation and the log wording all look good, and the touched packages' tests pass locally. Two one-liners left and I'll approve.
with claude fable-5
Signed-off-by: hjoshi123 <[email protected]> Signed-off-by: Hemant Joshi <[email protected]>
6198b1d to
6e9560b
Compare
wallrj
left a comment
There was a problem hiding this comment.
Thanks @hjoshi123 — both suggestions applied, all review points addressed.
with claude fable-5
|
/approve |
|
[APPROVALNOTIFIER] This PR is APPROVED This pull-request has been approved by: wallrj The full list of commands accepted by this bot can be found here. The pull request process is described here DetailsNeeds approval from an approver in each of these files:
Approvers can indicate their approval by writing |
|
/cherry-pick release-1.21 with claude fable-5 |
|
@wallrj: #9124 failed to apply on top of branch "release-1.21": DetailsIn response to this:
Instructions for interacting with me using PR comments are available here. If you have questions or suggestions related to my behavior, please file an issue against the kubernetes-sigs/prow repository. |
* adding secret issuer checks Signed-off-by: hjoshi123 <[email protected]> Signed-off-by: Hemant Joshi <[email protected]> * adding tests for isssuer check Signed-off-by: hjoshi123 <[email protected]> Signed-off-by: Hemant Joshi <[email protected]> --------- Signed-off-by: hjoshi123 <[email protected]> Signed-off-by: Hemant Joshi <[email protected]> (cherry picked from commit d041736) Signed-off-by: Richard Wall <[email protected]> Co-Authored-By: Claude Fable 5 <[email protected]>
|
@hjoshi123 This change has been included in v1.21.2, which is now published. If you are able to install the release and verify that the change works as expected in your environment, that would be much appreciated. Thank you for the contribution. |
Pull Request Motivation
Whenever we change the issuer on the cert, ARI would basically try to use the old config and fail. This PR tries to fix that by introducing
SecretIssuerAnnotationsMatchand calling it in readiness_controller and cert requests controller. If it doesn't match we dont pass in replaces and also remove the acme status object.Fixes #9074
Kind
/kind bug
Release Note