NO-JIRA: csr: fix RequestCommonNameFilter and the self-signing denial path - #2370
NO-JIRA: csr: fix RequestCommonNameFilter and the self-signing denial path#2370arpitjain099 wants to merge 1 commit into
Conversation
RequestCommonNameFilter could not be used as a CSRFilter: its method was named Match while the interface requires Matches, so it never satisfied the interface. It also parsed .spec.request as raw DER, but that field is PEM-armored, so the parse always failed and the filter never matched. sync() already decodes the PEM block before parsing. Separately, the self-signing check in sync() dropped denyCSR's error and fell through into the approval path instead of returning. The two other denyCSR call sites in the same switch already return. Signed-off-by: Arpit Jain <arpitjain099@gmail.com>
|
@arpitjain099: This pull request explicitly references no jira issue. DetailsIn response to this:
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 openshift-eng/jira-lifecycle-plugin repository. |
|
[APPROVALNOTIFIER] This PR is NOT APPROVED This pull-request has been approved by: arpitjain099 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 |
|
No actionable comments were generated in the recent review. 🎉 ℹ️ Recent review info⚙️ Run configurationConfiguration used: Repository: openshift/coderabbit/.coderabbit.yaml Review profile: CHILL Plan: Enterprise Run ID: 📒 Files selected for processing (2)
WalkthroughThe CSR approver now returns after denying self-requesting CSRs. ChangesCSR approver corrections
🚥 Pre-merge checks | ✅ 15✅ Passed checks (15 passed)
✨ Finishing Touches🧪 Generate unit tests (beta)
Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out. Comment |
|
Hi @arpitjain099. Thanks for your PR. I'm waiting for a openshift member to verify that this patch is reasonable to test. If it is, they should reply with Regular contributors should join the org to skip this step. 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. |
Three small fixes in
pkg/operator/csr/csr_approver.go. All of them are correctness issues, not security issues, since every one of the broken paths fails closed. Details below.RequestCommonNameFilterdoesn't satisfyCSRFilterThe method is declared as
Match, but the interface wantsMatches.AndFilter,OrFilter,LabelFilterandNamesFilterall declareMatches, so this one is the odd one out and the type can't actually be passed toNewCSRApproverController. Renamed it.This is technically a rename of an exported method, but since the type never satisfied the interface it was meant for, there's no working filter-chain usage to break. Nothing in the tree calls it.
RequestCommonNameFilterparses PEM as DER.spec.requestis PEM-armored, and the filter handed it straight tox509.ParseCertificateRequest. That parse always fails, so the filter logged at V(4) and returned false for everything.sync()a bit further up gets this right: it runspem.Decodefirst and bails if the block is nil. Did the same here, returning false on a nil block rather than erroring, which matches how the other filters behave.Fail-closed, so the worst case was a filter that silently matched nothing.
Self-signing denial falls through to approval
In
sync(), thex509CSR.Subject.CommonName == csr.Spec.Usernamebranch calleddenyCSRbut threw away the error and had noreturn, so it kept going and ran the approver. The two otherdenyCSRcalls right below it (theCSRApprovingFailedandCSRDeniedcases) both return. Added thereturn.Worth being clear about the impact: this is not a bypass. The API server enforces mutual exclusion between Approved and Denied conditions, so the follow-up approval update doesn't land on an already-denied CSR. The real bug is that a failed denial got swallowed instead of surfacing, and the sync did extra work it shouldn't have.
Testing
Added
TestRequestCommonNameFiltercovering a PEM CSR with a listed CN, one with an unlisted CN, a non-PEM request, and an empty request, plus avar _ CSRFilter = ...assertion.Checked it fails before the fix, both parts. With the method renamed back to
Match:And with only the
pem.Decodereverted (keeping the rename so it compiles):After the fix,
go build ./...is clean andgo test -count=1 ./pkg/operator/csr/...passes:The existing
Test_csrApproverController_synccases still pass with the addedreturn.Summary by CodeRabbit
Bug Fixes
Tests