Skip to content

fix: prevent nil pointer panic when renewal policy is Disabled - #9067

Closed
archy-rock3t-cloud wants to merge 1 commit into
cert-manager:masterfrom
sophotechlabs:fix/renewal-disabled-nil-panic
Closed

archy-rock3t-cloud wants to merge 1 commit into
cert-manager:masterfrom
sophotechlabs:fix/renewal-disabled-nil-panic

Conversation

@archy-rock3t-cloud

Copy link
Copy Markdown
Contributor

Pull Request Motivation

pki.RenewalTime returns a nil renewal time for spec.renewal.policy: Disabled. The CurrentCertificateNearingExpiry trigger policy only checks the returned error and then dereferences renewalTime.Time, so an issued Certificate that sets renewal.policy: Disabled triggers 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 that Disabled never schedules a renewal.

Kind

/kind bug

Release Note

Fixed a panic in the certificates controller when a Certificate has `spec.renewal.policy` set to `Disabled`.

@cert-manager-prow cert-manager-prow Bot added kind/bug Categorizes issue or PR as related to a bug. release-note Denotes a PR that will be considered when it comes time to generate release notes. dco-signoff: yes Indicates that all commits in the pull request have the valid DCO sign-off message. labels Jul 24, 2026
@cert-manager-prow

Copy link
Copy Markdown
Contributor

[APPROVALNOTIFIER] This PR is NOT APPROVED

This pull-request has been approved by:
Once this PR has been reviewed and has the lgtm label, please assign maelvls for approval. For more information see the Code Review Process.

The full list of commands accepted by this bot can be found 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 the needs-ok-to-test Indicates a PR that requires an org member to verify it is safe to test. label Jul 24, 2026
@cert-manager-prow

Copy link
Copy Markdown
Contributor

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 /ok-to-test on its own line. Until that is done, I will not automatically test new commits in this PR, but the usual testing commands by org members will still work.

Tip

We noticed you've done this a few times! Consider joining the org to skip this step and gain /lgtm and other bot rights. We recommend asking approvers on your previous PRs to sponsor you.

Once the patch is verified, the new status will be reflected by the ok-to-test label.

I understand the commands that are listed here.

Details

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 cert-manager-prow Bot added the size/S Denotes a PR that changes 10-29 lines, ignoring generated files. label Jul 24, 2026
@ThatsMrTalbot

Copy link
Copy Markdown
Contributor

Thanks for looking into this!

/ok-to-test

@cert-manager-prow cert-manager-prow Bot added ok-to-test and removed needs-ok-to-test Indicates a PR that requires an org member to verify it is safe to test. labels Jul 24, 2026
@ThatsMrTalbot
ThatsMrTalbot requested a review from Copilot July 27, 2026 14:18

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

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 nil guard for renewalTime in CurrentCertificateNearingExpiry to avoid dereferencing a nil pointer.
  • Add a regression test ensuring CurrentCertificateNearingExpiry does not trigger renewal (or panic) when renewal policy is Disabled.

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.

Comment on lines +283 to +285
if renewalTime == nil {
return "", "", false
}

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

  1. Rebase needed. This branch is based on code from before #9032 merged (the merge base is ~263 commits behind master). On current master, #9032 already added an early return for renewal.policy: Disabled in 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 == nil guard makes that block redundant — it can be deleted, since the nil return from pki.RenewalTime already handles Disabled. Consolidating to one guard at the call site is cleaner than two guards for the same condition.

  2. RenewalDisabled constant is dead. #9032 also added RenewalDisabled = "Disabled" in constants.go, which isn't referenced anywhere in the code. Worth removing in the same PR while you're here.

  3. Error path still swallowed. The nil check is placed after the if err != nil branch, so on a genuine window error (see #9100) reason/message get set to WindowError and then discarded by the return "", "", 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

@wallrj

wallrj commented Aug 8, 2026

Copy link
Copy Markdown
Member

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 maintainer_can_modify: true).

So I've opened #9109, which carries your commit rebased onto master (your authorship is preserved) with one follow-up on top:

Closing this in favour of #9109. Thanks for spotting and reporting the panic!

with claude opus 4.8

@wallrj wallrj closed this Aug 8, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

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. ok-to-test release-note Denotes a PR that will be considered when it comes time to generate release notes. size/S Denotes a PR that changes 10-29 lines, ignoring generated files.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants