Repository navigation
fix: prevent nil pointer panic when renewal policy is Disabled - #9067
archy-rock3t-cloud wants to merge 1 commit into
Conversation
Signed-off-by: Artem Muterko <[email protected]>
|
[APPROVALNOTIFIER] This PR is NOT APPROVED This pull-request has been approved by: The full list of commands accepted by this bot can be found here. DetailsNeeds approval from an approver in each of these files:Approvers can indicate their approval by writing |
|
Hi @archy-rock3t-cloud. 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 Tip We noticed you've done this a few times! Consider joining the org to skip this step and gain 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. |
|
Thanks for looking into this! /ok-to-test |
There was a problem hiding this comment.
Pull request overview
Fixes a crash-looping panic in the certificates trigger controller when spec.renewal.policy: Disabled causes pki.RenewalTime to return nil, which was then dereferenced by CurrentCertificateNearingExpiry.
Changes:
- Add a
nilguard forrenewalTimeinCurrentCertificateNearingExpiryto avoid dereferencing anilpointer. - Add a regression test ensuring
CurrentCertificateNearingExpirydoes not trigger renewal (or panic) when renewal policy isDisabled.
Reviewed changes
Copilot reviewed 2 out of 2 changed files in this pull request and generated 1 comment.
| File | Description |
|---|---|
| internal/controller/certificates/policies/checks.go | Adds an early return when renewalTime is nil to prevent a panic during renewal checks. |
| internal/controller/certificates/policies/checks_test.go | Adds a unit test covering the renewal.policy: Disabled behavior for the nearing-expiry policy. |
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
| if renewalTime == nil { | ||
| return "", "", false | ||
| } |
wallrj
left a comment
There was a problem hiding this comment.
Thanks for looking into this! The renewalTime == nil guard is in the right place — it's actually a more complete fix than it might look, because pki.RenewalTime returns (nil, err) for renewal-window errors too, not just renewal.policy: Disabled. So this guard also covers a second, currently-unfixed nil-panic that I've just reproduced and filed as #9100.
A few notes:
-
Rebase needed. This branch is based on code from before #9032 merged (the merge base is ~263 commits behind
master). On currentmaster, #9032 already added an early return forrenewal.policy: Disabledin this same function:// If the certificate renewal policy is set to Disabled, do not renew. if crt.Spec.Renewal != nil && crt.Spec.Renewal.Policy == cmapi.CertificateRenewalPolicyDisabled { return "", "", false }
Once you rebase, your
renewalTime == nilguard makes that block redundant — it can be deleted, since the nil return frompki.RenewalTimealready handlesDisabled. Consolidating to one guard at the call site is cleaner than two guards for the same condition. -
RenewalDisabledconstant is dead. #9032 also addedRenewalDisabled = "Disabled"inconstants.go, which isn't referenced anywhere in the code. Worth removing in the same PR while you're here. -
Error path still swallowed. The nil check is placed after the
if err != nilbranch, so on a genuine window error (see #9100)reason/messageget set toWindowErrorand then discarded by thereturn "", "", false. To also fix that panic properly, consider returning the violation on the error path:renewalTime, err := pki.RenewalTime(...) if err != nil { return WindowError, err.Error(), true } if renewalTime == nil { return "", "", false }
If you'd rather keep this PR narrowly scoped to Disabled, that's fine — but a rebase is needed either way since the current diff conflicts with #9032.
with claude fable 5
|
Thanks again for this fix, @archy-rock3t-cloud. I wanted to rebase it and push directly to your branch, but the fork is organization-owned and GitHub's "allow edits from maintainers" doesn't grant push access for org-owned forks (both SSH and HTTPS gave me a 403, despite the API reporting So I've opened #9109, which carries your commit rebased onto
Closing this in favour of #9109. Thanks for spotting and reporting the panic! with claude opus 4.8 |
Pull Request Motivation
pki.RenewalTimereturns a nil renewal time forspec.renewal.policy: Disabled. TheCurrentCertificateNearingExpirytrigger policy only checks the returned error and then dereferencesrenewalTime.Time, so an issued Certificate that setsrenewal.policy: Disabledtriggers a nil-pointer dereference in the trigger controller. The panic is not recovered anywhere on the reconcile path, so it crashes the controller and the pod crash-loops as the Certificate is re-processed on restart. This returns early with no renewal when the renewal time is nil, matching the intent thatDisablednever schedules a renewal.Kind
/kind bug
Release Note