Repository navigation
Re-queue Issuer/ClusterIssuer on ACME DNS-01 solver Secret events - #9042
cert-manager-prow[bot] merged 7 commits into
Conversation
issuersForSecret only matched the ACME account private key and EAB secret. After cert-manager#8255, Setup() marks issuers InvalidSolver when a DNS-01 solver Secret is missing, but creating that Secret never re-queued the Issuer. Match the same solver secretRefs ValidateACMEChallengeSolverDNS01 collects so Ready recovers without waiting for resync. Fixes cert-manager#9036 Signed-off-by: Sebastien Tardif <[email protected]>
|
Hi @SebTardif. Thanks for your PR. I'm waiting for a cert-manager member to verify that this patch is reasonable to test. If it is, they should reply with Regular contributors should join the org to skip this step. Once the patch is verified, the new status will be reflected by the I understand the commands that are listed here. DetailsInstructions 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. |
|
/ok-to-test |
|
Thanks for this — verified the root cause and fix locally, and it matches an independent reproduction on the issue from @gecube. One suggestion for consideration, not a blocker: rather than hard-coding the DNS-01 provider secret names again in |
There was a problem hiding this comment.
Pull request overview
This PR fixes a cert-manager controller requeue gap where Issuer/ClusterIssuer ACME DNS-01 solver Secret creation/updates would not trigger reconciliation, leaving resources stuck Ready=False/InvalidSolver until a periodic resync or restart.
Changes:
- Extend Secret-to-Issuer matching logic to include ACME DNS-01 solver Secret references (in addition to ACME account key and EAB key).
- Add unit tests for the new ACME secret reference matcher in both issuer and clusterissuer controllers.
Reviewed changes
Copilot reviewed 4 out of 4 changed files in this pull request and generated 2 comments.
| File | Description |
|---|---|
| pkg/controller/issuers/checks.go | Requeue Issuers when a referenced ACME DNS-01 solver Secret changes. |
| pkg/controller/issuers/checks_test.go | Unit tests covering account key, EAB, DNS-01 solver secrets, and unrelated secrets. |
| pkg/controller/clusterissuers/checks.go | Requeue ClusterIssuers when a referenced ACME DNS-01 solver Secret changes. |
| pkg/controller/clusterissuers/checks_test.go | Unit tests covering account key, EAB, DNS-01 solver secrets, and unrelated secrets. |
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
|
Thanks again for tracking down and fixing this, @SebTardif — since there hadn't been a chance to follow up on the refactor suggested above (and echoed independently by Copilot on both What it does:
Net effect is the same behaviour as your original commit, but a new DNS-01 provider's secretRefs now only need wiring into Verified locally: Feel free to build on top of this or push further changes to the branch as usual — happy to iterate further if you'd like a different approach. |
|
/retest-required |
|
/cherry-pick release-1.21 |
|
@wallrj-cyberark: once the present PR merges, I will cherry-pick it on top of 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. |
issuersForSecret() in pkg/controller/issuers and pkg/controller/clusterissuers duplicated the per-provider DNS-01 solver secretRef list, both between the two controllers and relative to the source of truth in ValidateACMEChallengeSolverDNS01. Flagged independently by Copilot on both files and raised in review: this risks drift if a DNS-01 provider's secretRefs change, potentially reintroducing the stuck Ready=False/InvalidSolver behaviour from cert-manager#9036 for that provider. Add pkg/acme.RequiredDNS01SolverSecrets, extracted from the existing extractSecrets() helper in pkg/issuer/acme (which already derives the same list from ValidateACMEChallengeSolverDNS01 for the purpose of checking solver Secrets exist), and call it from both issuersForSecret() implementations and from pkg/issuer/acme's validateDNSSolvers(). A new DNS-01 provider's secretRefs now only need wiring into ValidateACMEChallengeSolverDNS01 once for both the admission-validation and requeue-trigger paths to pick them up. Replace the two checks_test.go files' unit tests of the removed per-provider matcher with a higher-level regression test exercising issuersForSecret() end-to-end, covering PrivateKey, EAB, DNS-01 solver, CA and cross-namespace/cross-scope cases. Handle acme.RequiredDNS01SolverSecrets() errors per-issuer rather than aborting issuersForSecret() entirely: converting one issuer's DNS-01 solver config to its internal type is not expected to fail in practice, but propagating that error out of the whole function would have blocked Secret-triggered requeueing for every other issuer too, not just the one that failed to convert. Log and skip that issuer instead, matching the existing pattern in pkg/controller/acmeorders/checks.go. Signed-off-by: Richard Wall <[email protected]>
7991126 to
bdbde69
Compare
TestRequiredDNS01SolverSecrets only exercised Route53 and CloudDNS, even though the whole point of extracting RequiredDNS01SolverSecrets was to keep the requeue-trigger secret list automatically in sync with ValidateACMEChallengeSolverDNS01 as DNS-01 providers change. Without coverage for the other providers, a future change to how one of them collects its secretRefs could silently break the requeue path with nothing in CI to catch it. Add one case each for Akamai, AzureDNS, Cloudflare, AcmeDNS, DigitalOcean and RFC2136, matching the existing Route53/CloudDNS case style. Verified against internal/apis/certmanager/validation/issuer.go to set the minimum fields each provider needs for its secretRef(s) to be collected. Signed-off-by: Richard Wall <[email protected]>
expectErr was declared in the test table and checked in the test loop, but no case ever set it to true, so the "conversion failed" branch was dead code that gave false confidence the error path was covered. It isn't reachable in practice: RequiredDNS01SolverSecrets' only error comes from api.Scheme.Convert converting the external ACMEChallengeSolver to its internal type, and that conversion (see internal/apis/acme/v1/zz_generated.conversion.go) is generated field-by-field copying with no parsing or validation, so it cannot fail for any value of the external Go struct type. Drop the unused field and branch, and note why in a comment so a future reader doesn't assume the gap is accidental. Signed-off-by: Richard Wall <[email protected]>
|
After a Claude-assisted self-review of the changes above, pushed a couple of follow-up fixes: 7991126→bdbde6983 makes the DNS-01 solver-secret lookup fail safe per-issuer instead of aborting the whole match on a conversion error, and bdbde69→3b6d4ead3 broadens |
| // Match DNS-01 solver secrets so creating a missing solver Secret | ||
| // re-queues the Issuer (see #9036). | ||
| solverSecrets, err := acme.RequiredDNS01SolverSecrets(iss) | ||
| if err != nil { | ||
| // Don't let one issuer's conversion error stop every other | ||
| // issuer from being matched against this Secret event. | ||
| runtime.HandleError(fmt.Errorf("error determining ACME DNS-01 solver secrets for issuer %s/%s: %w", iss.Namespace, iss.Name, err)) | ||
| continue | ||
| } | ||
| for _, s := range solverSecrets { | ||
| if s.Name == secret.Name { | ||
| affected = append(affected, iss) | ||
| continue | ||
| break | ||
| } | ||
| } |
There was a problem hiding this comment.
Fair point, and not something I'd dismiss outright, but I don't think it warrants blocking this fix.
Some context: issuersForSecret() already did an O(numIssuers) linear scan per Secret event before this PR (the CA/Venafi/Vault cases below all do per-issuer field comparisons too) - what changed is the per-ACME-issuer constant factor, from a handful of string comparisons to a Scheme.Convert (a map lookup to a generated field-copy function, not reflection-based marshaling) plus a validation walk over that issuer's own DNS-01 solvers. That's heavier, but bounded by the number of solvers on a single issuer, not cluster-wide Secret count.
Indexing Issuers by referenced Secret name (including solver secrets) would need to stay in sync as Issuers themselves are added/updated, which is a real design task in its own right, and this PR is aimed at a v1.21.1 patch release fixing a stuck-forever bug - I'd rather not couple that timeline to a cache-invalidation design. Happy to be overruled if a maintainer wants it done here rather than as a follow-up, since it's a legitimate scalability question for very large ACME-issuer counts with high Secret churn - leaving this open for code reviewer to weigh in.
There was a problem hiding this comment.
I agree with richard here.. that we should fix the bug before handling the scalability issue but I would love to see a comment with a TODO.. maybe assigned to some maintainer me or @wallrj-cyberark so that we can come back and fix it later and not forget about it
There was a problem hiding this comment.
I would love to see a TODO with the scalability comment so that we can address it in a different PR
Added in-tree // TODO(hjoshi123, wallrj): on issuersForSecret in both:
pkg/controller/issuers/checks.gopkg/controller/clusterissuers/checks.go
It notes the O(numIssuers) Secret-event walk, the extra ACME DNS-01 conversion cost, and the follow-up (index by referenced Secret names). Commit c76589b06.
…crets RequiredDNS01SolverSecrets is an exported function in pkg/acme, a non-internal package, but returned []*internal/apis/meta.SecretKeySelector - an internal/... type. Any consumer of this module outside github.com/cert-manager/cert-manager cannot import that internal package, so it could receive the return value but never name its element type directly. Flagged by Copilot on re-review. Convert each internal SecretKeySelector to the external pkg/apis/meta/v1 type (identical Name/Key shape, existing generated conversion function) before returning, so the public function only ever exposes public types. No caller needed to change: every call site only accesses the exported Name/Key fields, which behave the same whether the slice holds pointers or values. Signed-off-by: Richard Wall <[email protected]>
pkg/controller/clusterissuers/checks.go logged "for issuer %s" when handling a solver-secret conversion error for a ClusterIssuer, unlike the equivalent message in pkg/controller/issuers/checks.go which correctly names its resource kind. Flagged by Copilot on re-review: using the generic term here makes it harder to tell which controller logged the error when diagnosing. Signed-off-by: Richard Wall <[email protected]>
|
Mostly looks good to be me @SebTardif @wallrj-cyberark. I would love to see a TODO with the scalability comment so that we can address it in a different PR |
hjoshi123 asked for an in-tree TODO so the O(numIssuers) Secret-event scan and per-ACME RequiredDNS01SolverSecrets cost are not forgotten after the Signed-off-by: Sebastien Tardif <[email protected]> cert-manager#9036 re-queue fix lands. Follow-up: index by referenced Secret names.
Added in-tree
It notes the O(numIssuers) Secret-event walk, the extra ACME DNS-01 conversion cost, and the follow-up (index by referenced Secret names). Commit |
|
Thank you @SebTardif for making the changes.. LGTM! @wallrj-cyberark if you can add the final approval as an indication that you approve too! /lgtm |
|
/approve |
|
/approve |
|
[APPROVALNOTIFIER] This PR is APPROVED This pull-request has been approved by: wallrj, wallrj-cyberark 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 |
|
@wallrj-cyberark: new pull request created: #9083 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. |
|
/cherry-pick release-1.21 |
|
@wallrj-cyberark: new pull request could not be created: failed to create pull request against cert-manager/cert-manager#release-1.21 from head cert-manager-bot:cherry-pick-9042-to-release-1.21: status code 422 not one of [201], body: {"message":"Validation Failed","errors":[{"resource":"PullRequest","code":"custom","message":"A pull request already exists for cert-manager-bot:cherry-pick-9042-to-release-1.21."}],"documentation_url":"https://docs.github.com/rest/pulls/pulls#create-a-pull-request","status":"422"} 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. |
Pull Request Motivation
Fixes #9036
Since #8255, ACME Issuer/ClusterIssuer
Setup()validates DNS-01 solver Secrets and can leave the issuer atReady: False/InvalidSolverwhen a Secret is missing. Creating that Secret later never re-queued the issuer becauseissuersForSecretonly matched the ACME account private key and EAB key, not solver secretRefs. Recovery required a 10h resync, a spec change, or a restart.Changes
issuersForSecretin bothpkg/controller/issuersandpkg/controller/clusterissuersto match DNS-01 solver secrets (same set of secret names collected byValidateACMEChallengeSolverDNS01: Route53, CloudDNS, Cloudflare, Akamai, AzureDNS, AcmeDNS, DigitalOcean, RFC2136, etc.).Kind
/kind bug
Release Note
Verification
Both packages: pass (including new
TestACMEIssuerReferencesSecret).Related