Repository navigation
fix(webhook): validate decoded ResourceGroup objects and fail closed on label errors - #2345
Conversation
|
Hi @Uhudsavasindankacanokcu2. Thanks for your PR. I'm waiting for a GoogleContainerTools member to verify that this patch is reasonable to test. If it is, they should reply with 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/test-infra repository. |
|
[APPROVALNOTIFIER] This PR is NOT APPROVED This pull-request has been approved by: 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 |
Problem
In
Validator.Handle(pkg/webhook/validate.go), incomingadmission.Requestpayloads are decoded from raw JSON bytes viaconvertObjects(req)intooldObjandnewObj. However,handleResourceGroupRequest(req)did not receiveoldObjornewObjand instead readreq.OldObject.Object/req.Object.Objectdirectly insidefromConfigSync.When live
kube-apiserverAdmissionReviewJSON requests arrive over HTTP,RawExtension.Rawcontains serialized JSON whileRawExtension.Objectremainsnil. As a result:metadataAccessor.Labels(nil)returns an error.handleResourceGroupRequestlogged the error and returnedallow()(failing open on liveResourceGroupadmission requests).Existing unit tests in
pkg/webhook/validate_test.gopopulatedRawExtension.Objectin-memory and therefore did not exercise liveRawExtension.Rawdecoding forResourceGroupCRs.Changes
oldObjandnewObj(client.Object) fromValidator.HandleintohandleResourceGroupRequestandfromConfigSync.deny(metav1.StatusReasonForbidden, ...)) when both objects arenilor labels cannot be read, instead of callingallow().fromConfigSyncdenial reason withmetav1.StatusReasonForbidden.TestValidator_Handle_RawJSONResourceGroupcoveringCREATE,UPDATE, andDELETEwith serialized JSONRawExtension.Rawpayloads and a fail-closed nil-object check.Testing
go test -mod=vendor -vet=off -v ./pkg/webhook/...:pkg/webhook: PASS (1.094s)pkg/webhook/configuration: PASS (0.944s)