Skip to content

fix(webhook): validate decoded ResourceGroup objects and fail closed on label errors - #2345

Open
Uhudsavasindankacanokcu2 wants to merge 1 commit into
GoogleContainerTools:mainfrom
Uhudsavasindankacanokcu2:fix/resourcegroup-webhook-raw-json
Open

Uhudsavasindankacanokcu2 wants to merge 1 commit into
GoogleContainerTools:mainfrom
Uhudsavasindankacanokcu2:fix/resourcegroup-webhook-raw-json

Conversation

@Uhudsavasindankacanokcu2

Copy link
Copy Markdown

Problem

In Validator.Handle (pkg/webhook/validate.go), incoming admission.Request payloads are decoded from raw JSON bytes via convertObjects(req) into oldObj and newObj. However, handleResourceGroupRequest(req) did not receive oldObj or newObj and instead read req.OldObject.Object / req.Object.Object directly inside fromConfigSync.

When live kube-apiserver AdmissionReview JSON requests arrive over HTTP, RawExtension.Raw contains serialized JSON while RawExtension.Object remains nil. As a result:

  1. metadataAccessor.Labels(nil) returns an error.
  2. handleResourceGroupRequest logged the error and returned allow() (failing open on live ResourceGroup admission requests).

Existing unit tests in pkg/webhook/validate_test.go populated RawExtension.Object in-memory and therefore did not exercise live RawExtension.Raw decoding for ResourceGroup CRs.

Changes

  • Pass decoded oldObj and newObj (client.Object) from Validator.Handle into handleResourceGroupRequest and fromConfigSync.
  • Fail closed (deny(metav1.StatusReasonForbidden, ...)) when both objects are nil or labels cannot be read, instead of calling allow().
  • Align fromConfigSync denial reason with metav1.StatusReasonForbidden.
  • Add TestValidator_Handle_RawJSONResourceGroup covering CREATE, UPDATE, and DELETE with serialized JSON RawExtension.Raw payloads and a fail-closed nil-object check.

Testing

  • Ran go test -mod=vendor -vet=off -v ./pkg/webhook/...:
    • pkg/webhook: PASS (1.094s)
    • pkg/webhook/configuration: PASS (0.944s)

@google-oss-prow

Copy link
Copy Markdown

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 /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/test-infra repository.

@google-oss-prow

Copy link
Copy Markdown

[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 cowsking for approval. For more information see the Kubernetes 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

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

/ok-to-test

This branch has not been deployed

No deployments
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants