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

Add messageExpression field for CRD validation #115969

Merged

Conversation

DangerOnTheRanger
Copy link
Contributor

@DangerOnTheRanger DangerOnTheRanger commented Feb 22, 2023

What type of PR is this?

/kind feature
/kind api-change

What this PR does / why we need it:

This PR implements the KEP update outlined in kubernetes/enhancements#3747.

Special notes for your reviewer:

The planned API changes have been implemented in this PR (so discussion/API review can start), but this PR currently pins a dependency on google/cel-go#645. When that PR merges and a cel-go version bump PR is merged into k8s, then the WIP tag will be taken off. Other than the pin, the PR should be considered ready to merge and reviewed as such.

Does this PR introduce a user-facing change?

Added messageExpression field to ValidationRule. (#115969, @DangerOnTheRanger)

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

- [KEP]: https://github.com/kubernetes/enhancements/pull/3747

@k8s-ci-robot k8s-ci-robot added release-note Denotes a PR that will be considered when it comes time to generate release notes. do-not-merge/work-in-progress Indicates that a PR should not merge because it is a work in progress. kind/feature Categorizes issue or PR as related to a new feature. kind/api-change Categorizes issue or PR as related to adding, removing, or otherwise changing an API size/XL Denotes a PR that changes 500-999 lines, ignoring generated files. 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. labels Feb 22, 2023
@k8s-ci-robot k8s-ci-robot added area/apiserver area/cloudprovider area/code-generation area/dependency Issues or PRs related to dependency changes area/kubectl area/test sig/api-machinery Categorizes an issue or PR as relevant to SIG API Machinery. sig/architecture Categorizes an issue or PR as relevant to SIG Architecture. sig/auth Categorizes an issue or PR as relevant to SIG Auth. sig/cli Categorizes an issue or PR as relevant to SIG CLI. sig/cloud-provider Categorizes an issue or PR as relevant to SIG Cloud Provider. sig/instrumentation Categorizes an issue or PR as relevant to SIG Instrumentation. sig/node Categorizes an issue or PR as relevant to SIG Node. sig/testing Categorizes an issue or PR as relevant to SIG Testing. and removed do-not-merge/needs-sig Indicates an issue or PR lacks a `sig/foo` label and requires one. labels Feb 22, 2023
klog.Warningf("runtime cost could not be calculated for message expression %q")
}
if err != nil {
klog.Warningf("error evaluating message expression, falling back: %v", err.Error())
Copy link
Contributor

Choose a reason for hiding this comment

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

We should keep an eye on this. I'm a bit concerned someone will flood logs with this.

Copy link
Contributor

Choose a reason for hiding this comment

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

An alternative would be to return a client warning..

@bart0sh bart0sh added this to WIP in SIG Node PR Triage Feb 23, 2023
@DangerOnTheRanger
Copy link
Contributor Author

(force push to address #115969 (comment))

@liggitt
Copy link
Member

liggitt commented Mar 9, 2023

I didn't review the CEL bits, just the API type and validation change, leaning on @cici37 / @jpbetz for implementation review here.

API surface is small, just had a few questions/clarifications around edge cases that need docs/test coverage

@liggitt liggitt moved this from In progress to API review completed, 1.27 in API Reviews Mar 9, 2023
@liggitt liggitt moved this from API review completed, 1.27 to Changes requested in API Reviews Mar 9, 2023
Update docs to note that generating line breaks from messageExpression is not allowed.
@k8s-ci-robot
Copy link
Contributor

k8s-ci-robot commented Mar 10, 2023

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

Test name Commit Details Required Rerun command
check-dependency-stats bab60bb22b6c3a2d3f2d336dc0c39aa839bded10 link false /test check-dependency-stats
pull-kubernetes-e2e-gce-cos-alpha-features bab60bb22b6c3a2d3f2d336dc0c39aa839bded10 link false /test pull-kubernetes-e2e-gce-cos-alpha-features
pull-kubernetes-kind-dra bab60bb22b6c3a2d3f2d336dc0c39aa839bded10 link false /test pull-kubernetes-kind-dra

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.

@DangerOnTheRanger
Copy link
Contributor Author

/retest

@liggitt
Copy link
Member

liggitt commented Mar 10, 2023

/approve
API bits (types, docs, and validation) lgtm
@cici37 @jpbetz have lgtm for impl

@liggitt liggitt moved this from Changes requested to API review completed, 1.27 in API Reviews Mar 10, 2023
@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 10, 2023
// as if the messageExpression field were unset. If messageExpression evaluates to an empty string, a string with only spaces, or a string
// that contains line breaks, then the validation failure message will also be produced as if the messageExpression field were unset, and
// the fact that messageExpression produced an empty string/string with only spaces/string with line breaks will be logged.
// messageExpression has access to all the same variables as the rule; the only difference is the return type.
Copy link
Member

Choose a reason for hiding this comment

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

@jpbetz - did the env scoping get put in place so CRD CEL validation didn't automatically get access to the authorizer variable? is there anything that verifies validation rules and messageExpressions don't have that variable?

Copy link
Contributor

Choose a reason for hiding this comment

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

Yes. CRD validation rules go different path from ValidatingAdmissionPolicy hence it will not have access to authorizer related variables

Copy link
Contributor

@cici37 cici37 Mar 10, 2023

Choose a reason for hiding this comment

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

We will make sure messageExpression in ValidatingAdmissionPolicy not allowed to access to authorizer in here: #116397

Copy link
Contributor

Choose a reason for hiding this comment

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

Joe Betz - did the env scoping get put in place so CRD CEL validation didn't automatically get access to the authorizer variable?

Yes, that's all in place.

is there anything that verifies validation rules and messageExpressions don't have that variable?

Yes, when the secondary authz PR merged it included this test:

"authorizer.path('/healthz').check('get').isAllowed()": "undeclared reference to 'authorizer'",

@cici37
Copy link
Contributor

cici37 commented Mar 10, 2023

/lgtm
/approve
Thank you!

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

LGTM label has been added.

Git tree hash: bdaad98a95ab79fbb6590f4b1cbf99a13ae153a5

@k8s-ci-robot
Copy link
Contributor

[APPROVALNOTIFIER] This PR is APPROVED

This pull-request has been approved by: cici37, DangerOnTheRanger, liggitt

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 merged commit 16d2d55 into kubernetes:master Mar 10, 2023
SIG Node CI/Test Board automation moved this from PRs Waiting on Author to Done Mar 10, 2023
SIG Node PR Triage automation moved this from WIP to Done Mar 10, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
api-review Categorizes an issue or PR as actively needing an API review. approved Indicates a PR has been approved by an approver from all required OWNERS files. area/apiserver area/cloudprovider area/code-generation area/dependency Issues or PRs related to dependency changes area/kubectl area/test cncf-cla: yes Indicates the PR's author has signed the CNCF CLA. kind/api-change Categorizes issue or PR as related to adding, removing, or otherwise changing an API 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. needs-priority Indicates a PR lacks a `priority/foo` label and requires one. 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. sig/architecture Categorizes an issue or PR as relevant to SIG Architecture. sig/auth Categorizes an issue or PR as relevant to SIG Auth. sig/cli Categorizes an issue or PR as relevant to SIG CLI. sig/cloud-provider Categorizes an issue or PR as relevant to SIG Cloud Provider. sig/instrumentation Categorizes an issue or PR as relevant to SIG Instrumentation. sig/node Categorizes an issue or PR as relevant to SIG Node. sig/testing Categorizes an issue or PR as relevant to SIG Testing. size/XL Denotes a PR that changes 500-999 lines, ignoring generated files. triage/accepted Indicates an issue or PR is ready to be actively worked on.
Projects
Status: API review completed, 1.27
Archived in project
Archived in project
Archived in project
Archived in project
Development

Successfully merging this pull request may close these issues.

None yet

6 participants