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

CEL Admission Plugin #112858

Merged
merged 5 commits into from Oct 20, 2022
Merged

Conversation

alexzielenski
Copy link
Contributor

@alexzielenski alexzielenski commented Oct 4, 2022

What type of PR is this?

/kind feature

What this PR does / why we need it:

This PR is a core dependency of other incoming CEL PRs implementing various bits of functionality from the KEP.

This PR adds support for consuming CEL policy definitions and policy bindings to enforce validation constraints on objects. It also defines interfaces for those types to implement with their CEL data source.

It is not yet integrated or hooked into anything yet. Is only expected to pass its tests for now until the other parts of the feature merge.

83% test coverage in the cel package

Which issue(s) this PR fixes:

Special notes for your reviewer:

Does this PR introduce a user-facing change?

NONE

Additional documentation e.g., KEPs (Kubernetes Enhancement Proposals), usage docs, etc.:

[KEP]: https://github.com/kubernetes/enhancements/tree/master/keps/sig-api-machinery/3488-cel-admission-control

/cc @cici37 @jpbetz @DangerOnTheRanger @jiahuif

@k8s-ci-robot k8s-ci-robot added the do-not-merge/work-in-progress Indicates that a PR should not merge because it is a work in progress. label Oct 4, 2022
@k8s-ci-robot k8s-ci-robot added the release-note-none Denotes a PR that doesn't merit a release note. label Oct 4, 2022
@k8s-ci-robot k8s-ci-robot added size/XL Denotes a PR that changes 500-999 lines, ignoring generated files. kind/feature Categorizes issue or PR as related to a new feature. cncf-cla: yes Indicates the PR's author has signed the CNCF CLA. do-not-merge/needs-sig Indicates an issue or PR lacks a `sig/foo` label and requires one. needs-triage Indicates an issue or PR lacks a `triage/foo` label and requires one. needs-priority Indicates a PR lacks a `priority/foo` label and requires one. area/apiserver sig/api-machinery Categorizes an issue or PR as relevant to SIG API Machinery. and removed do-not-merge/needs-sig Indicates an issue or PR lacks a `sig/foo` label and requires one. labels Oct 4, 2022
Copy link
Contributor Author

@alexzielenski alexzielenski left a comment

Choose a reason for hiding this comment

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

pointing out some things maybe others can illuminate for me

pkg/kubeapiserver/options/plugins.go Outdated Show resolved Hide resolved
pkg/kubeapiserver/options/plugins.go Outdated Show resolved Hide resolved
staging/src/k8s.io/apiserver/pkg/server/plugins.go Outdated Show resolved Hide resolved
@alexzielenski
Copy link
Contributor Author

/sig api-machinery

@fedebongio
Copy link
Contributor

/cc @jpbetz @cici37 @leilajal
/triage accepted

@k8s-ci-robot k8s-ci-robot added triage/accepted Indicates an issue or PR is ready to be actively worked on. and removed needs-triage Indicates an issue or PR lacks a `triage/foo` label and requires one. labels Oct 4, 2022
@k8s-ci-robot k8s-ci-robot added size/XXL Denotes a PR that changes 1000+ lines, ignoring generated files. and removed size/XL Denotes a PR that changes 500-999 lines, ignoring generated files. labels Oct 5, 2022
Copy link
Contributor Author

@alexzielenski alexzielenski left a comment

Choose a reason for hiding this comment

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

some discussion points

}

if len(allDecisions) > 0 {
return errors.New("deny")
Copy link
Contributor

Choose a reason for hiding this comment

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

Maybe future work, but we want to ultimately be able to respond with message(s), and a status and code here like webhooks do. The response back to the client request (the one being validated for admission) should use the status and code.

Copy link
Contributor

Choose a reason for hiding this comment

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

This brings up a question I didn't fully cover in the KEP:

When multiple policy definition validations deny admission, which status and code are returned? The alternatives I'm aware of:

  1. Agree on an order of precedent of http response codes, use the "most severe" code
  2. Use the code of whatever policy fails first

If we go with (2) we need to make sure we validate policies (and bindings) in a consistent order. But I would love to see (1) work, I just haven't thought it through carefully enough to know if there is a sane ordering.

Copy link
Contributor

Choose a reason for hiding this comment

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

Since we only return one status/code back, do we include all validation failures in messages?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

I was assuming if, for any reason, any validation is a Deny, then the response code is unconditionally 409 Conflict. Should policy definitions be able to control the HTTP status code? Are there other codes that one might choose?

Re: returning multiple errors. I believe we can return a JSON-formatted error string with some metadata like web hooks do. In this case we can return an JSON array with an entry for each validation that failed where the requestor can look for more information.

Copy link
Contributor

@cici37 cici37 left a comment

Choose a reason for hiding this comment

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

The interface generally looks good to me. Thank you!

}

if len(allDecisions) > 0 {
return errors.New("deny")
Copy link
Contributor

Choose a reason for hiding this comment

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

Since we only return one status/code back, do we include all validation failures in messages?

@alexzielenski alexzielenski force-pushed the cel-admission-hook branch 2 times, most recently from ec09b77 to 1eb00eb Compare October 12, 2022 18:03
@alexzielenski alexzielenski force-pushed the cel-admission-hook branch 2 times, most recently from b0659fb to aec92bb Compare October 17, 2022 20:39
@jpbetz
Copy link
Contributor

jpbetz commented Oct 19, 2022

/approve

@jpbetz
Copy link
Contributor

jpbetz commented Oct 19, 2022

/approve
/lgtm

@k8s-ci-robot k8s-ci-robot added the lgtm "Looks good to me", indicates that a PR is ready to be merged. label Oct 19, 2022
@jpbetz
Copy link
Contributor

jpbetz commented Oct 19, 2022

/priority important-soon

@k8s-ci-robot k8s-ci-robot added priority/important-soon Must be staffed and worked on either currently, or very soon, ideally in time for the next release. and removed needs-priority Indicates a PR lacks a `priority/foo` label and requires one. labels Oct 19, 2022
@alexzielenski
Copy link
Contributor Author

/retest

@k8s-ci-robot
Copy link
Contributor

k8s-ci-robot commented Oct 19, 2022

@alexzielenski: The following test failed, say /retest to rerun all failed tests or /retest-required to rerun all mandatory failed tests:

Test name Commit Details Required Rerun command
pull-kubernetes-e2e-gce-alpha-features faad7848d1057e6c50d5abccaad45d206052804f link false /test pull-kubernetes-e2e-gce-alpha-features

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.

@alexzielenski
Copy link
Contributor Author

/retest

@lavalamp
Copy link
Member

/approve

@k8s-ci-robot
Copy link
Contributor

[APPROVALNOTIFIER] This PR is APPROVED

This pull-request has been approved by: alexzielenski, jpbetz, 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 Oct 19, 2022
@k8s-ci-robot k8s-ci-robot merged commit 0a689af into kubernetes:master Oct 20, 2022
@k8s-ci-robot k8s-ci-robot added this to the v1.26 milestone Oct 20, 2022
@cici37 cici37 mentioned this pull request Oct 28, 2022
9 tasks
@alexzielenski alexzielenski deleted the cel-admission-hook branch November 16, 2022 18:49
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. area/apiserver cncf-cla: yes Indicates the PR's author has signed the CNCF CLA. kind/feature Categorizes issue or PR as related to a new feature. 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-none Denotes a PR that doesn't merit a release note. sig/api-machinery Categorizes an issue or PR as relevant to SIG API Machinery. size/XXL Denotes a PR that changes 1000+ lines, ignoring generated files. triage/accepted Indicates an issue or PR is ready to be actively worked on.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

8 participants