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

AdmissionWebhookMatchConditions feature documentation #40058

Merged
merged 14 commits into from
Apr 3, 2023

Conversation

tallclair
Copy link
Member

@k8s-ci-robot k8s-ci-robot added this to the 1.27 milestone Mar 16, 2023
@k8s-ci-robot
Copy link
Contributor

@tallclair: GitHub didn't allow me to request PR reviews from the following users: maxsmythe.

Note that only kubernetes members and repo collaborators can review this PR, and authors cannot review their own PRs.

In response to this:

Documentation for the AdmissionWebhookMatchConditions (alpha) feature.

KEP: https://github.com/kubernetes/enhancements/tree/master/keps/sig-api-machinery/3716-admission-webhook-match-conditions

/cc @ivelichkovich @maxsmythe @liggitt

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.

@k8s-ci-robot k8s-ci-robot added cncf-cla: yes Indicates the PR's author has signed the CNCF CLA. language/en Issues or PRs related to English language sig/docs Categorizes an issue or PR as relevant to SIG Docs. size/M Denotes a PR that changes 30-99 lines, ignoring generated files. labels Mar 16, 2023
Copy link
Contributor

@sftim sftim left a comment

Choose a reason for hiding this comment

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

Thanks. Some thoughts / feedback.

@tallclair tallclair force-pushed the match-conditions-1.27 branch from 9f8fb44 to 78211e8 Compare March 17, 2023 00:15
@tallclair
Copy link
Member Author

Thanks for the feedback, comments addressed.

Copy link
Contributor

@sftim sftim left a comment

Choose a reason for hiding this comment

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

LGTM for docs; ready for tech review.

Copy link
Contributor

@jpbetz jpbetz left a comment

Choose a reason for hiding this comment

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

Looks good! I left a few small comments but I'm happy with how this looks.

- name: 'breakglass'
# Skip requests made by users authorized to 'breakglass' on this webhook.
# The 'breakglass' API verb does not need to exist outside this check.
expression: 'authorizer.group('admissionregistration.k8s.io').resource('validatingwebhookconfigurations').name('my-webhook.example.com').check('breakglass').denied()'
Copy link
Contributor

Choose a reason for hiding this comment

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

I love everything about this example.

@jpbetz
Copy link
Contributor

jpbetz commented Mar 20, 2023

/lgtm
For technical content

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

LGTM label has been added.

Git tree hash: 3edc1fa69c704cff8764d7e211237a07f0bf9830

@k8s-ci-robot k8s-ci-robot removed the lgtm "Looks good to me", indicates that a PR is ready to be merged. label Mar 21, 2023
@k8s-ci-robot k8s-ci-robot requested a review from jpbetz March 21, 2023 01:15
expression: '!(request.resource.group == "coordination.k8s.io" && request.resource.resource == "leases")' # Match non-lease resources.
- name: 'exclude-kubelet-requests'
expression: '!("system:nodes" in request.userInfo.groups)' # Match requests made by non-node users.
- name: 'breakglass'
Copy link
Member

@liggitt liggitt Mar 21, 2023

Choose a reason for hiding this comment

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

I know this is just an example, but I would hate to see people mimic putting an authorizer condition on an admission policy that matches */*/* ... doesn't this mean we run another authorization check on every API request?

edit: I guess the part I consider an anti-pattern is matching */*/*, not necessarily the authz check, but I worry that people who previously wouldn't dream of matching */*/* will think it's ok to do so if they guard it with an authz check, which can be somewhat expensive depending on webhook authz config

Copy link
Contributor

Choose a reason for hiding this comment

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

To narrow it, how about changing it to be a restriction on RBAC changes? That's a believable-enough story and something often worth protecting.

Copy link
Member Author

Choose a reason for hiding this comment

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

Narrowing the rules weakens the "everything except leases" example. How about this: use short-circuiting to scope just the authorization check to RBAC? Is that getting too convoluted?

Copy link
Member

@liggitt liggitt Mar 21, 2023

Choose a reason for hiding this comment

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

Narrowing the rules weakens the "everything except leases" example.

I agree

How about this: use short-circuiting to scope just the authorization check to RBAC? Is that getting too convoluted?

Maybe a little? Would two different examples be easier to follow?

  • A */*/* policy that excludes leases, and node requests using conditions
  • A policy on something important like RBAC or networkpolicies that has an authorization-based breakglass

Copy link
Member Author

Choose a reason for hiding this comment

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

How's this? I put the RBAC check on a separate webhook (and also added a couple missing fields)

Copy link
Member

Choose a reason for hiding this comment

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

I like that better, thanks

@liggitt
Copy link
Member

liggitt commented Mar 21, 2023

lgtm overall

@tallclair
Copy link
Member Author

/label tide/merge-method-squash

@k8s-ci-robot k8s-ci-robot added the tide/merge-method-squash Denotes a PR that should be squashed by tide when it merges. label Mar 21, 2023
sideEffects: None
clientConfig: {} # Omitted for this example
matchConditions:
- name: 'breakglass'
Copy link
Contributor

Choose a reason for hiding this comment

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

Suggested change
- name: 'breakglass'
- name: 'breakglass' # again, each match condition must have a unique name

Copy link
Member Author

Choose a reason for hiding this comment

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

They don't need to be globally unique. This feels superfluous here?

@netlify
Copy link

netlify bot commented Mar 28, 2023

👷 Deploy Preview for kubernetes-io-vnext-staging processing.

Name Link
🔨 Latest commit d481c4e
🔍 Latest deploy log https://app.netlify.com/sites/kubernetes-io-vnext-staging/deploys/64234d6ea076d60008ca608d

{{< feature-state state="alpha" for_k8s_version="v1.27" >}}

{{< note >}}
Use of `matchConditions` requires the [featuregate](/docs/reference/command-line-tools-reference/feature-gates/)
Copy link
Contributor

Choose a reason for hiding this comment

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

Suggested change
Use of `matchConditions` requires the [featuregate](/docs/reference/command-line-tools-reference/feature-gates/)
Use of `matchConditions` requires the [feature gate](/docs/reference/command-line-tools-reference/feature-gates/)

`AdmissionWebhookMatchConditions` to be explicitly enabled on the kube-apiserver before this feature can be used.
{{< /note >}}

You can define _match conditions_for webhooks if you need fine-grained request filtering. These
Copy link
Contributor

Choose a reason for hiding this comment

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

Suggested change
You can define _match conditions_for webhooks if you need fine-grained request filtering. These
You can define _match conditions_ for webhooks if you need fine-grained request filtering. These

{{< /note >}}

You can define _match conditions_for webhooks if you need fine-grained request filtering. These
conditions are useful if you find that match rules, `objectSelectors` and `namespaceSelectors` still
Copy link
Contributor

Choose a reason for hiding this comment

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

Suggested change
conditions are useful if you find that match rules, `objectSelectors` and `namespaceSelectors` still
conditions are useful if you find that match rules, `objectSelectors` and `namespaceSelectors`, still

Comment on lines +762 to +763
- for [`failurePolicy: Fail`](#failure-policy), reject the request (without calling the webhook).
- for [`failurePolicy: Ignore`](#failure-policy), proceed with the request but skip the webhook.
Copy link
Contributor

Choose a reason for hiding this comment

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

Nit: Avoid 4-spaces indentation when possible. Sometimes the YAML parser may treat it as a code snippet.

Suggested change
- for [`failurePolicy: Fail`](#failure-policy), reject the request (without calling the webhook).
- for [`failurePolicy: Ignore`](#failure-policy), proceed with the request but skip the webhook.
- for [`failurePolicy: Fail`](#failure-policy), reject the request (without calling the webhook).
- for [`failurePolicy: Ignore`](#failure-policy), proceed with the request but skip the webhook.

@@ -56,6 +56,7 @@ For a reference to old feature gates that are removed, please refer to

| Feature | Default | Stage | Since | Until |
|---------|---------|-------|-------|-------|
| `AdmissionWebhookMatchConditions` | Alpha | `false` | 1.27 | |
Copy link
Contributor

Choose a reason for hiding this comment

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

Move this before line 70?

@@ -368,6 +369,7 @@ A *General Availability* (GA) feature is also referred to as a *stable* feature.

Each feature gate is designed for enabling/disabling a specific feature:

- `AdmissionWebhookMatchConditions`: Enable [match conditions](/docs/reference/access-authn-authz/extensible-admission-controllers/#matching-requests-matchconditions) on mutating & validating admission webhooks.
Copy link
Contributor

Choose a reason for hiding this comment

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

Suggested change
- `AdmissionWebhookMatchConditions`: Enable [match conditions](/docs/reference/access-authn-authz/extensible-admission-controllers/#matching-requests-matchconditions) on mutating & validating admission webhooks.
- `AdmissionWebhookMatchConditions`: Enable [match conditions](/docs/reference/access-authn-authz/extensible-admission-controllers/#matching-requests-matchconditions)
on mutating & validating admission webhooks.

@tengqm
Copy link
Contributor

tengqm commented Mar 31, 2023

/approve
There are some nits to fix if there is another commit.

@k8s-ci-robot
Copy link
Contributor

[APPROVALNOTIFIER] This PR is APPROVED

This pull-request has been approved by: tengqm

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 31, 2023
@reylejano
Copy link
Member

/lgtm

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

LGTM label has been added.

Git tree hash: 2628295bcd8762d7e6eb0e1f43ef79cd409b38fe

@k8s-ci-robot k8s-ci-robot merged commit 27460b2 into kubernetes:dev-1.27 Apr 3, 2023
DonatoHorn pushed a commit to DonatoHorn/website that referenced this pull request Jun 25, 2023
* AdmissionWebhookMatchConditions feature documentation

* #squash ivelichkovich feedback

* #squash sftim feedback

* Correct statement about request.object

* #squash: sftim feedback

* #squash jpbetz feedback

* #squash: denied function removed

* #squash fix match conditions example

* #squash fix expression quoting

* #squash scope authorizatoin check example

* #squash separate RBAC webhook example

* #squash sftim feedback

* #squash add shared client config for example

* Don't use yaml anchors in example
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. language/en Issues or PRs related to English language lgtm "Looks good to me", indicates that a PR is ready to be merged. sig/docs Categorizes an issue or PR as relevant to SIG Docs. size/M Denotes a PR that changes 30-99 lines, ignoring generated files. tide/merge-method-squash Denotes a PR that should be squashed by tide when it merges.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

8 participants