Skip to content

fix(issuing): do not panic on a failed request with no Ready condition - #9118

Merged
cert-manager-prow[bot] merged 1 commit into
cert-manager:masterfrom
thc1006:fix-nil-ready-condition-panic
Aug 12, 2026
Merged

cert-manager-prow[bot] merged 1 commit into
cert-manager:masterfrom
thc1006:fix-nil-ready-condition-panic

Conversation

@thc1006

@thc1006 thc1006 commented Aug 10, 2026 •

Copy link
Copy Markdown
Contributor

Pull Request Motivation

Fixes #9119

Spotted by @wallrj while reviewing #9116, and split out as he suggested since it is reachable on its own.

ProcessItem reads crReadyCond.Reason in the guard that skips a CertificateRequest which failed during a previous issuance:

if req.Status.FailureTime != nil &&
req.Status.FailureTime.Before(certIssuingCond.LastTransitionTime) && crReadyCond.Reason == cmapi.CertificateRequestReasonFailed {
log.V(logf.InfoLevel).Info("Found a failed CertificateRequest from previous issuance, waiting for it to be deleted...")
return nil
}

but crReadyCond is only checked for nil further down, after the Denied and InvalidRequest branches:

if crReadyCond == nil {
log.V(logf.DebugLevel).Info("CertificateRequest does not have Ready condition, waiting...")
return nil
}

A CertificateRequest that carries status.failureTime and has no Ready condition therefore dereferences a nil pointer, and since this runs in the controller's process it takes the whole thing down rather than failing the one Certificate.

I added the nil check to the guard instead of hoisting the existing one, because hoisting changes behaviour. CertificateRequestIsDenied does not depend on the Ready condition, so a request denied before an issuer set Ready currently fails issuance; moving the nil check above that branch would make it wait instead. Adding the check where the dereference happens leaves every other path exactly as it was.

Kind

/kind bug

Testing

TestIssuingController gains a case with failureTime set and no Ready condition. On master it does not fail an assertion, it panics:

panic: runtime error: invalid memory address or nil pointer dereference
--- FAIL: TestIssuingController/if_certificate_is_in_Issuing_state,_one_CertificateRequest_with_a_failure_time_but_no_Ready_condition,_do_nothing

Release Note

Fixed a panic in the certificates-issuing controller when a CertificateRequest has a failure time set but no Ready condition.

Documentation updates

NONE

@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. 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. needs-ok-to-test Indicates a PR that requires an org member to verify it is safe to test. labels Aug 10, 2026
@cert-manager-prow

Copy link
Copy Markdown
Contributor

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

Regular contributors should join the org to skip this step.

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 Aug 10, 2026
@wallrj
wallrj requested a lite review from Copilot August 10, 2026 16:04
@wallrj

wallrj commented Aug 10, 2026

Copy link
Copy Markdown
Member

/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 Aug 10, 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.

Fixes a panic in the certificates-issuing controller when handling CertificateRequests that have status.failureTime set but do not have a Ready condition.

Changes:

  • Guard the “previous failed CertificateRequest” skip logic against a nil Ready condition to prevent nil dereference.
  • Add a regression test case covering failureTime set with no Ready condition.

Reviewed changes

Copilot reviewed 2 out of 2 changed files in this pull request and generated 1 comment.

File Description
pkg/controller/certificates/issuing/issuing_controller.go Adds a nil check for crReadyCond before reading Reason, preventing controller panic.
pkg/controller/certificates/issuing/issuing_controller_test.go Adds a regression test scenario for a CertificateRequest with failureTime but no Ready condition.

💡 Add a code-review agent skill or configure MCP servers for context-aware, tailored reviews. Learn more in the docs.

Comment on lines +449 to +459
"if certificate is in Issuing state, one CertificateRequest with a failure time but no Ready condition, do nothing": {
certificate: exampleBundle.Certificate,
builder: &testpkg.Builder{
CertManagerObjects: []runtime.Object{
gen.CertificateFrom(issuingCert),
gen.CertificateRequestFrom(exampleBundle.CertificateRequest,
gen.AddCertificateRequestAnnotations(map[string]string{
cmapi.CertificateRequestRevisionAnnotationKey: "2", // Current Certificate revision=1
}),
gen.SetCertificateRequestFailureTime(metav1.Time{Time: metaFixedClockStart.Time.Add(time.Hour * -1)}),
)},

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

Good catch, thank you. Fixed in 3779161.

The bundle helper in test/unit/crypto never sets Status.Conditions, so the case does exercise the nil path today, but only by accident of the fixture. It now clears them itself:

gen.CertificateRequestFrom(exampleBundle.CertificateRequest,
    // Explicit, so the case keeps covering the missing condition.
    func(cr *cmapi.CertificateRequest) { cr.Status.Conditions = nil },
    ...

Re-checked both directions afterwards: the case passes with the fix, and reverting the crReadyCond != nil guard still panics with the nil dereference.

@cert-manager-prow cert-manager-prow Bot added size/M Denotes a PR that changes 30-99 lines, ignoring generated files. and removed size/S Denotes a PR that changes 10-29 lines, ignoring generated files. labels Aug 10, 2026
@cert-manager-prow cert-manager-prow Bot added the needs-rebase Indicates a PR cannot be merged because it has merge conflicts with HEAD. label Aug 10, 2026
The previous-issuance guard reads crReadyCond.Reason, but crReadyCond is only
checked for nil further down, after the Denied and InvalidRequest branches. A
CertificateRequest that carries status.failureTime and has no Ready condition
therefore dereferences a nil pointer and takes the controller down.

The nil check is added to the guard rather than hoisted, because hoisting would
change behaviour: a request that has been denied before an issuer set its Ready
condition currently fails issuance, and moving the nil check above the Denied
branch would make it wait instead.

Signed-off-by: thc1006 <[email protected]>
@thc1006
thc1006 force-pushed the fix-nil-ready-condition-panic branch from 3779161 to a7927c3 Compare August 11, 2026 00:48
@cert-manager-prow cert-manager-prow Bot removed the needs-rebase Indicates a PR cannot be merged because it has merge conflicts with HEAD. label Aug 11, 2026
@thc1006

thc1006 commented Aug 11, 2026

Copy link
Copy Markdown
Contributor Author

/test pull-cert-manager-master-e2e-v1-36

@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 @thc1006!

The review confirmed the new test reproduces the panic from #9119 on the parent commit and passes with this fix, and I agree with your reasoning for failing (rather than waiting on) denied/invalid requests that have no Ready condition. Two non-blocking comments inline.

with claude fable-5

// revision. Leave it to the certificate-requests controller to delete the
// CertificateRequest and create a new one.
if req.Status.FailureTime != nil &&
if req.Status.FailureTime != nil && crReadyCond != nil &&

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.

Non-blocking: with this guard, a CertificateRequest which has status.failureTime but never gains a Ready condition falls through to the crReadyCond == nil wait branch below, and nothing ever unsticks it — the requestmanager controller skips deletion when the Ready condition is nil:

if crReadyCond == nil || crReadyCond.Status != cmmeta.ConditionFalse || crReadyCond.Reason != cmapi.CertificateRequestReasonFailed {

So the Certificate stays Issuing=True forever with only a debug-level log. The reorder suggested in #9119 has the same outcome, so this isn't a regression — and it takes an external status writer to hit, since the in-tree reporter sets failureTime and the Ready condition in the same status update — but the silent stall probably deserves an Event or an Info-level log. Happy for that to be a follow-up issue.

A related behaviour note: a stale request carrying Denied=True but no Ready condition now falls past this guard and fails the current issuance via CertificateRequestIsDenied. I think that's the right call — the wait path could never resolve it, for the same requestmanager reason above — just noting it's deliberate.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

Checked all three and they hold. requestmanager_controller.go:251 keeps a request whose Ready condition is nil in remaining rather than deleting it, and the branch this now falls into only logs at debug level, so the Certificate does sit at Issuing=True with nothing to move it along.

Worth saying plainly since you were kind about it: on main that path panics, so this change turns a crash into a silent stall. Better, but the silence is the part that should not stay.

Reporter.Failed sets FailureTime and the Ready condition in the same mutation, so the in-tree path cannot produce this state on its own, which matches what you said about an external status writer.

I will open the follow-up for the Event or Info-level log rather than grow this PR.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

Filed as #9126.

gen.CertificateFrom(issuingCert),
gen.CertificateRequestFrom(exampleBundle.CertificateRequest,
// Explicit, so the case keeps covering the missing condition.
func(cr *cmapi.CertificateRequest) { cr.Status.Conditions = nil },

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.

nit: exampleBundle.CertificateRequest (built from test/unit/crypto's bare certificateRequest) never sets any status conditions, so this closure is a no-op today. The comment makes the defensive intent clear, so I'm happy either way — just noting it's the only inline-closure modifier in a file that otherwise sticks to gen.* modifiers.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

You are right that it does nothing today. test/unit/crypto never sets Status.Conditions on that request.

I would rather keep it, for the reason it is a closure at all: gen has SetCertificateRequestStatusCondition and AddCertificateRequestStatusCondition but nothing that clears them, and the fixture is shared with other suites. If a Ready condition is ever added there, this case would quietly stop covering the missing-condition path and still pass. Happy to drop it if you would rather the file stayed uniform.

@cert-manager-prow cert-manager-prow Bot added the approved Indicates a PR has been approved by an approver from all required OWNERS files. label Aug 12, 2026
@wallrj

wallrj commented Aug 12, 2026

Copy link
Copy Markdown
Member

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

@cert-manager-prow cert-manager-prow Bot added tide/merge-method-squash Denotes a PR that should be squashed by tide when it merges. lgtm Indicates that a PR is ready to be merged. labels Aug 12, 2026
@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 merged commit 30e06c9 into cert-manager:master Aug 12, 2026
6 checks passed
@thc1006
thc1006 deleted the fix-nil-ready-condition-panic branch August 12, 2026 17:59
@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: new pull request created: #9238

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.

@wallrj

wallrj commented Sep 11, 2026

Copy link
Copy Markdown
Member

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

@thc1006

thc1006 commented Sep 11, 2026

Copy link
Copy Markdown
Contributor Author

Verified on a single-node kubeadm cluster (Kubernetes v1.37.0) that had cert-manager v1.21.1 installed from the Helm chart, by reproducing the crash on v1.21.1 first and then upgrading with the bad object left in place.

v1.21.1. A Certificate whose issuerRef names an external group nothing handles, so its CertificateRequest sits with no conditions at all. Setting status.failureTime on it to an hour before the Certificate's Issuing transition crashed the controller within six seconds:

panic: runtime error: invalid memory address or nil pointer dereference [recovered, repanicked]
github.com/cert-manager/cert-manager/pkg/controller/certificates/issuing.(*controller).ProcessItem(...)
	.../pkg/controller/certificates/issuing/issuing_controller.go:287

It kept crashing: restarts went 4 to 8 in about 100 seconds, reason=Error exitCode=2, CrashLoopBackOff. One request in that state takes the controller down for the whole cluster.

v1.21.2. helm upgrade to oci://quay.io/jetstack/charts/cert-manager:v1.21.2 (chart sha256:634dce9c…, controller image sha256:70f532fd…) with --reuse-values and the same CertificateRequest still there. The new controller came up, held at 0 restarts for 90 seconds, and its log has no panic. With global.logLevel=4, a forced reconcile of that request logs

issuing_controller.go:323] "CertificateRequest does not have Ready condition, waiting..." key="verify-9118/stalled" resource_name="stalled-1"

The Certificate stays at Issuing=True, which is the expected result in this release: the Stalled event is #9324 and the recovery is #9287, both for later.

Thanks for including it.

with claude opus-5

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. 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. ok-to-test release-note Denotes a PR that will be considered when it comes time to generate release notes. size/M Denotes a PR that changes 30-99 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.

issuing controller panics (nil deref) on a CertificateRequest with FailureTime but no Ready condition

4 participants