Skip to content

Fix nil pointer dereference in certificateRequestIdentity.Validate - #9081

Closed
zanarellidev wants to merge 1 commit into
cert-manager:masterfrom
zanarellidev:fix/nil-pointer-certificaterequestidentity-validate
Closed

zanarellidev wants to merge 1 commit into
cert-manager:masterfrom
zanarellidev:fix/nil-pointer-certificaterequestidentity-validate

Conversation

@zanarellidev

Copy link
Copy Markdown

Pull Request Motivation

Fixes #9064. request.RequestResource is optional on the AdmissionRequest API and can be nil, for example when an AdmissionReview is posted directly to the webhook without populating requestResource. certificateRequestIdentity.Validate dereferenced it unconditionally, causing a nil pointer panic instead of returning a clean validation error.

Added a regression test (TestValidate_NilRequestResource) that reproduces the panic before the fix and passes after it. Ran the full internal/webhook/... and pkg/webhook/... test suites with no regressions.

This same unguarded pattern also exists in a few other admission webhook functions in the codebase (Mutate in the same file, plus two other files) — left out of this PR to keep it scoped to exactly what #9064 reports; happy to follow up separately if useful.

AI-assisted (Claude) for investigation and implementation, reviewed by me before submission.

Kind

/kind bug

Release Note

Fix a nil pointer panic in the CertificateRequest identity admission webhook when an AdmissionReview is received without `requestResource` populated.

request.RequestResource is optional on the AdmissionRequest API and
can be nil, for example when an AdmissionReview is posted directly to
the webhook without populating requestResource. Validate dereferenced
it unconditionally, causing a panic instead of a clean validation
error.

Fixes cert-manager#9064


Signed-off-by: zanarelli <[email protected]>
@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 28, 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 jakexks 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 28, 2026
@cert-manager-prow

Copy link
Copy Markdown
Contributor

Hi @zanarellidev. 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/M Denotes a PR that changes 30-99 lines, ignoring generated files. label Jul 28, 2026
@wallrj wallrj mentioned this pull request Jul 29, 2026
13 tasks done
@zanarellidev
zanarellidev force-pushed the fix/nil-pointer-certificaterequestidentity-validate branch from 430a1a9 to 3886271 Compare August 1, 2026 21:25
@zanarellidev

Copy link
Copy Markdown
Author

Friendly ping: still waiting on /ok-to-test from a cert-manager org member so Prow can run CI. Happy to address any review feedback.

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

@zanarellidev really appreciate your work on this.

A small process note for future contributions: #9064 was already assigned which indicating work was in progress (days before you raised #9086). It's generally good practice to check the assignee / comments before starting a fix, to avoid duplicated effort :) No harm done here this time.

I've opened #9086 with a slightly different approach: instead of guarding against nil RequestResource, it switches the plugins to route on Resource/SubResource. The reason I prefer that direction:

  • Resource is the always-populated, webhook-facing GVR; RequestResource is optional and only relevant for Equivalent-match conversion.
  • A nil guard that returns early or errors still breaks Certificate admission (skips validation or surfaces an internal error on legitimate traffic).
  • Routing on Resource also handles version skew under conversion correctly.

@zanarellidev

Copy link
Copy Markdown
Author

Good point, I should have checked the issue assignee first. Closing in favor of #9086 which addresses the root cause more thoroughly.

@wallrj wallrj mentioned this pull request Sep 1, 2026
39 of 41 tasks
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. needs-ok-to-test Indicates a PR that requires an org member to verify it is safe 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.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Nil pointer dereference in certificateRequestIdentity.Validate() when admission request lacks TLS client certificate

2 participants