Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Prevent webhooks from affecting admission requests for WebhookConfiguration objects #59840

Merged

Conversation

jennybuckley
Copy link

@jennybuckley jennybuckley commented Feb 14, 2018

What this PR does / why we need it:
As it stands now webhooks can be added to the system which make it impossible for a user to remove that webhook, or two webhooks could be registered which make it impossible to remove each other.

The first commit of this will add a test to make sure webhook deletion is never blocked by a webhook. This test will fail until the second commit is added which will prevent webhooks from affecting admission requests for ValidatingWebhookConfiguration and MutatingWebhookConfiguration objects in the admissionregistration.k8s.io group

  • Test that webhook deletion is never blocked by a webhook (test fails before second commit)
  • Prevent webhooks from being called on admission requests for [Validating|Mutating]WebhookConfiguration objects
  • Document this new behavior maybe in another PR

Which issue(s) this PR fixes (optional, in fixes #<issue number>(, fixes #<issue_number>, ...) format, will close the issue(s) when PR gets merged):
Part of fixing #59124 (Verifies that it can remove the broken webhook.)

Release note:

ValidatingWebhooks and MutatingWebhooks will not be called on admission requests for ValidatingWebhookConfiguration and MutatingWebhookConfiguration objects in the admissionregistration.k8s.io group

@k8s-ci-robot k8s-ci-robot added do-not-merge/work-in-progress Indicates that a PR should not merge because it is a work in progress. release-note Denotes a PR that will be considered when it comes time to generate release notes. size/L Denotes a PR that changes 100-499 lines, ignoring generated files. cncf-cla: yes Indicates the PR's author has signed the CNCF CLA. labels Feb 14, 2018
@k8s-ci-robot k8s-ci-robot added the sig/api-machinery Categorizes an issue or PR as relevant to SIG API Machinery. label Feb 14, 2018
@jennybuckley jennybuckley changed the title [WIP] Prevent webhooks from affecting admission requests for WebhookConfiguration objects Prevent webhooks from affecting admission requests for WebhookConfiguration objects Feb 14, 2018
@k8s-ci-robot k8s-ci-robot removed the do-not-merge/work-in-progress Indicates that a PR should not merge because it is a work in progress. label Feb 14, 2018
@jennybuckley
Copy link
Author

Besides
https://github.com/kubernetes/kubernetes/blob/master/staging/src/k8s.io/api/admissionregistration/v1beta1/types.go#L136-L138
and maybe
kubernetes/website#6836
Is there anywhere else that this behavior needs to be documented?

@mbohlool
Copy link
Contributor

/assign @caesarxuchao

@@ -123,6 +125,12 @@ var _ = SIGDescribe("AdmissionWebhook", func() {
testCRDWebhook(f, testcrd.Crd, testcrd.DynamicClient)
})

It("Should not be able to prevent deleting validating-webhook-configurations", func() {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The same is true for the mutating-webhook-configurations, could you expand the test?

// NOTE: This path isn't something the service knows how to handle.
Path: strPtr("/validating-webhook-configurations"),
},
// Without CA bundle, the call to webhook always fails
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Could you add to the comment that the failure policy is "Fail"? Otherwise this test would have given us false negative.

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I am working on changing this to use the correct CA and updating the webhook test image to handle a function that always denies requests so this test doesn't have to rely on a broken CA and failing closed to deny requests.

I think that will be a more clear way of testing this.

@caesarxuchao
Copy link
Member

Why is the new e2e test passing? I thought we haven't built in the mechanism to skip webhook configurations.

@jennybuckley
Copy link
Author

jennybuckley commented Feb 20, 2018

@caesarxuchao We haven't built that mechanism yet (this test isn't working how it should)

edit: now the test fails as expected before the second commit, and passes after the second commit.

@jennybuckley jennybuckley force-pushed the webhooks-on-webhooks branch 2 times, most recently from bdbf2c0 to 174033d Compare February 27, 2018 22:34
@jennybuckley
Copy link
Author

/kind bug

@k8s-ci-robot k8s-ci-robot added the kind/bug Categorizes issue or PR as related to a bug. label Feb 28, 2018
return true
} else {
return false
}
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

optional nit (shorter/prettier/clearer):

  if gvk.Group == "admissionregistration.k8s.io" {
    if gvk.Kind == "ValidatingWebhookConfiguration" || gvk.Kind == "MutatingWebhookConfiguration" {
      return true
    }
  }
  return false

Maybe this could go in k8s.io/apiserver/pkg/admission/plugin/webhook/config or k8s.io/apiserver/pkg/admission/plugin/webhook/request? It looks like there's already a few packages there that might be appropriate.

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think webhook/config is for the plugin config passed to the apiserver at startup, and webhook/request "creates admissionReview request based on admission attributes" according to the doc.go, maybe a new package like "common" or "util"?
or are we trying to avoid that.

@@ -253,6 +257,18 @@ func (a *MutatingWebhook) Admit(attr admission.Attributes) error {
return a.convertor.Convert(versionedAttr.Object, attr.GetObject())
}

// TODO: factor into a common place along with the validating webhook version.
func (a *MutatingWebhook) shouldSkipAllHooks(attr admission.Attributes) bool {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Optional nit: in this case I think it's best to highlight the reason for skipping-- maybe "isWebhookConfigurationResource"?

If we grow additional reasons here, then I'd go for the current name.

@lavalamp
Copy link
Member

This is clearly a bug fix, seems OK.

@k8s-ci-robot k8s-ci-robot added the needs-rebase Indicates a PR cannot be merged because it has merge conflicts with HEAD. label Feb 28, 2018
@k8s-ci-robot k8s-ci-robot removed the needs-rebase Indicates a PR cannot be merged because it has merge conflicts with HEAD. label Feb 28, 2018
@jennybuckley
Copy link
Author

/retest

1 similar comment
@jennybuckley
Copy link
Author

/retest

@jennybuckley
Copy link
Author

/priority important-soon

@k8s-ci-robot k8s-ci-robot added the priority/important-soon Must be staffed and worked on either currently, or very soon, ideally in time for the next release. label Mar 2, 2018
// However, in order to prevent ValidatingAdmissionWebhooks and MutatingAdmissionWebhooks
// from putting the cluster in a state which cannot be recovered from without completely
// disabling the plugin, ValidatingAdmissionWebhooks and MutatingAdmissionWebhooks are never called
// on admission requests for ValidatingWebhookConfiguration and MutatingWebhookConfiguration objects
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Nit: missing final period. (this goes into the api documentation or I wouldn't care)

Service: &v1beta1.ServiceReference{
Namespace: namespace,
Name: serviceName,
Path: strPtr(""),
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Add a comment explaining what the webhook will do when called?

}
}

func testWebhookForWebhookConfigurations(f *framework.Framework) {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Perhaps add a comment that this test assumes the deletion-rejecting webhook from registerWebhookForWebhookConfigurations is in place?

@lavalamp
Copy link
Member

lavalamp commented Mar 5, 2018

Sorry I found a few more things--no more, I promise. Can you fix and squash non-generated changes, then I will lgtm & approve.

@jennybuckley
Copy link
Author

@lavalamp should be good now

@lavalamp
Copy link
Member

lavalamp commented Mar 6, 2018

/retest

@lavalamp
Copy link
Member

lavalamp commented Mar 6, 2018

/lgtm
/approve

@k8s-ci-robot k8s-ci-robot added the lgtm "Looks good to me", indicates that a PR is ready to be merged. label Mar 6, 2018
@k8s-ci-robot
Copy link
Contributor

[APPROVALNOTIFIER] This PR is APPROVED

This pull-request has been approved by: jennybuckley, lavalamp

The full list of commands accepted by this bot can be found here.

The pull request process is described here

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

@k8s-ci-robot k8s-ci-robot added the approved Indicates a PR has been approved by an approver from all required OWNERS files. label Mar 6, 2018
@k8s-github-robot
Copy link

[MILESTONENOTIFIER] Milestone Pull Request: Up-to-date for process

@caesarxuchao @jennybuckley @lavalamp

Pull Request Labels
  • sig/api-machinery: Pull Request will be escalated to these SIGs if needed.
  • priority/important-soon: Escalate to the pull request owners and SIG owner; move out of milestone after several unsuccessful escalation attempts.
  • kind/bug: Fixes a bug discovered during the current release.
Help

@k8s-ci-robot
Copy link
Contributor

k8s-ci-robot commented Mar 6, 2018

@jennybuckley: The following test failed, say /retest to rerun them all:

Test name Commit Details Rerun command
pull-kubernetes-unit ed109f7 link /test pull-kubernetes-unit

Full PR test history. Your PR dashboard. Please help us cut down on flakes by linking to an open issue when you hit one in your PR.

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. I understand the commands that are listed here.

@jennybuckley
Copy link
Author

/retest

@k8s-github-robot
Copy link

/test all [submit-queue is verifying that this PR is safe to merge]

@k8s-github-robot
Copy link

Automatic merge from submit-queue. If you want to cherry-pick this change to another branch, please follow the instructions here.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
approved Indicates a PR has been approved by an approver from all required OWNERS files. cncf-cla: yes Indicates the PR's author has signed the CNCF CLA. kind/bug Categorizes issue or PR as related to a bug. lgtm "Looks good to me", indicates that a PR is ready to be merged. priority/important-soon Must be staffed and worked on either currently, or very soon, ideally in time for the next release. release-note Denotes a PR that will be considered when it comes time to generate release notes. sig/api-machinery Categorizes an issue or PR as relevant to SIG API Machinery. size/L Denotes a PR that changes 100-499 lines, ignoring generated files.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

6 participants