Repository navigation
fix: Reject invalid CIDRs in Certificate nameConstraints at admission time - #9184
Conversation
Signed-off-by: Yuedong Wu <[email protected]>
There was a problem hiding this comment.
Pull request overview
This PR fixes a bug where Certificate resources with invalid CIDRs in spec.nameConstraints.{permitted,excluded}.ipRanges were accepted by the validating webhook but could never be issued, by moving CIDR parsing/validation into admission-time validation.
Changes:
- Refactors nameConstraints validation into a dedicated helper and runs it during
ValidateCertificateSpec. - Adds admission-time validation for each entry in
permitted.ipRangesandexcluded.ipRangesusingnet.ParseCIDR. - Extends unit tests to cover valid and invalid CIDR scenarios (and confirms feature-gate short-circuiting).
Reviewed changes
Copilot reviewed 2 out of 2 changed files in this pull request and generated no comments.
| File | Description |
|---|---|
| internal/apis/certmanager/validation/certificate.go | Adds admission-time CIDR parsing for nameConstraints ipRanges and refactors the validation into helper functions. |
| internal/apis/certmanager/validation/certificate_test.go | Adds test cases for valid/invalid CIDR entries in nameConstraints ipRanges and preserves feature-gate behavior. |
💡 Add a code-review agent skill or configure MCP servers for context-aware, tailored reviews. Learn more in the docs.
erikgb
left a comment
There was a problem hiding this comment.
CI is passing and this looks like a good improvement! Thanks @lunarwhite! 🚀
/lgtm
/approve
|
[APPROVALNOTIFIER] This PR is APPROVED This pull-request has been approved by: erikgb 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 |
Pull Request Motivation
A
Certificatewith an invalid CIDR such as10.0.0.0(no prefix length) inspec.nameConstraints.permitted.ipRangesorspec.nameConstraints.excluded.ipRangeswas accepted by the validating webhook, and then failed on every CSR-generation attempt withinvalid CIDR address: 10.0.0.0. Because the failure is derived entirely from the spec, retrying could never succeed, the Certificate was permanently un-issuable.Fixes #9181
E2E Verification
Rejection with exact message (permitted.ipRanges)
Rejection via excluded.ipRanges
A valid Certificate cannot be edited into an invalid one
This is the desirable direction of the UPDATE coverage. It prevents a Ready Certificate from being broken.
Kind
/kind bug
Release Note