Skip to content

fix(ari): issuer checks in secret for ari - #9124

Merged
cert-manager-prow[bot] merged 2 commits into
cert-manager:masterfrom
hjoshi123:fix/ari-replaces-bug
Aug 20, 2026
Merged

cert-manager-prow[bot] merged 2 commits into
cert-manager:masterfrom
hjoshi123:fix/ari-replaces-bug

Conversation

@hjoshi123

@hjoshi123 hjoshi123 commented Aug 11, 2026 •

Copy link
Copy Markdown
Collaborator

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 SecretIssuerAnnotationsMatch and 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

Fixed a bug where `replaces` field was being populated for the wrong issuer on issuer changes

@cert-manager-prow cert-manager-prow Bot added release-note-none Denotes a PR that doesn't merit a release note. kind/bug Categorizes issue or PR as related to a bug. dco-signoff: yes Indicates that all commits in the pull request have the valid DCO sign-off message. area/acme Indicates a PR directly modifies the ACME Issuer code size/L Denotes a PR that changes 100-499 lines, ignoring generated files. labels Aug 11, 2026
@hjoshi123

Copy link
Copy Markdown
Collaborator Author

/label tide/merge-method-squash

@cert-manager-prow cert-manager-prow Bot added the tide/merge-method-squash Denotes a PR that should be squashed by tide when it merges. label Aug 11, 2026
@hjoshi123
hjoshi123 requested a lite review from Copilot August 11, 2026 16:18
@hjoshi123

Copy link
Copy Markdown
Collaborator Author

/release-note-edit

Fixed a bug where `replaces` field was being populated for the wrong issuer on issuer changes

@cert-manager-prow cert-manager-prow Bot added release-note Denotes a PR that will be considered when it comes time to generate release notes. and removed release-note-none Denotes a PR that doesn't merit a release note. labels Aug 11, 2026

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

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 SecretIssuerAnnotationsMatch helper 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.

Comment thread pkg/api/util/issuers.go
Comment on lines +68 to +82
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)
}

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

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

Comment thread pkg/controller/acmeorders/sync.go Resolved

@wallrj wallrj left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

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) {

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

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?

Copy link
Copy Markdown
Collaborator Author

Choose a reason for hiding this comment

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

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

Comment thread pkg/api/util/issuers.go Resolved
@hjoshi123
hjoshi123 force-pushed the fix/ari-replaces-bug branch from 87e64db to 390cd4d Compare August 17, 2026 17:04
@hjoshi123
hjoshi123 requested a review from wallrj August 17, 2026 17:05
Signed-off-by: hjoshi123 <[email protected]>
Signed-off-by: Hemant Joshi <[email protected]>
@hjoshi123
hjoshi123 force-pushed the fix/ari-replaces-bug branch from 390cd4d to 6198b1d Compare August 20, 2026 16:11

@wallrj wallrj left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

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

Comment thread pkg/api/util/issuers.go Resolved
Comment thread pkg/util/pki/match.go Resolved
Signed-off-by: hjoshi123 <[email protected]>
Signed-off-by: Hemant Joshi <[email protected]>
@hjoshi123
hjoshi123 force-pushed the fix/ari-replaces-bug branch from 6198b1d to 6e9560b Compare August 20, 2026 18:03
@hjoshi123
hjoshi123 requested a review from wallrj August 20, 2026 18:03

@wallrj wallrj left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Thanks @hjoshi123 — both suggestions applied, all review points addressed.

with claude fable-5

@wallrj

wallrj commented Aug 20, 2026

Copy link
Copy Markdown
Member

/approve
/lgtm
/label tide/merge-method-squash

@cert-manager-prow

Copy link
Copy Markdown
Contributor

[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

Details Needs approval from an approver in each of these files:

Approvers can indicate their approval by writing /approve in a comment
Approvers can cancel approval by writing /approve cancel in a comment

@cert-manager-prow cert-manager-prow Bot added lgtm Indicates that a PR is ready to be merged. approved Indicates a PR has been approved by an approver from all required OWNERS files. labels Aug 20, 2026
@cert-manager-prow
cert-manager-prow Bot merged commit d041736 into cert-manager:master Aug 20, 2026
6 checks passed
@wallrj

wallrj commented Sep 1, 2026

Copy link
Copy Markdown
Member

/cherry-pick release-1.21

with claude fable-5

@cert-manager-bot

Copy link
Copy Markdown
Contributor

@wallrj: #9124 failed to apply on top of branch "release-1.21":

Applying: adding secret issuer checks
Using index info to reconstruct a base tree...
M	pkg/controller/acmeorders/sync.go
M	pkg/controller/certificaterequests/acme/acme.go
M	pkg/controller/certificates/readiness/readiness_controller.go
Falling back to patching base and 3-way merge...
Auto-merging pkg/controller/certificates/readiness/readiness_controller.go
CONFLICT (content): Merge conflict in pkg/controller/certificates/readiness/readiness_controller.go
Auto-merging pkg/controller/certificaterequests/acme/acme.go
Auto-merging pkg/controller/acmeorders/sync.go
CONFLICT (content): Merge conflict in pkg/controller/acmeorders/sync.go
error: Failed to merge in the changes.
hint: Use 'git am --show-current-patch=diff' to see the failed patch
hint: When you have resolved this problem, run "git am --continue".
hint: If you prefer to skip this patch, run "git am --skip" instead.
hint: To restore the original branch and stop patching, run "git am --abort".
hint: Disable this message with "git config set advice.mergeConflict false"
Patch failed at 0001 adding secret issuer checks

Details

In response to this:

/cherry-pick release-1.21

with claude fable-5

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.

cert-manager-prow Bot pushed a commit that referenced this pull request Sep 2, 2026
* 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]>
@wallrj

wallrj commented Sep 11, 2026

Copy link
Copy Markdown
Member

@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.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

approved Indicates a PR has been approved by an approver from all required OWNERS files. area/acme Indicates a PR directly modifies the ACME Issuer code dco-signoff: yes Indicates that all commits in the pull request have the valid DCO sign-off message. kind/bug Categorizes issue or PR as related to a bug. lgtm Indicates that a PR is ready to be merged. release-note Denotes a PR that will be considered when it comes time to generate release notes. size/L Denotes a PR that changes 100-499 lines, ignoring generated files. tide/merge-method-squash Denotes a PR that should be squashed by tide when it merges.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

ARI-checking can prevent changing the issuer of a certificate

4 participants