-
Notifications
You must be signed in to change notification settings - Fork 38.7k
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
Add messageExpression field for CRD validation #115969
Conversation
staging/src/k8s.io/apiextensions-apiserver/pkg/apis/apiextensions/types_jsonschema.go
Outdated
Show resolved
Hide resolved
staging/src/k8s.io/apiextensions-apiserver/pkg/apiserver/schema/cel/celcoststability_test.go
Outdated
Show resolved
Hide resolved
staging/src/k8s.io/apiextensions-apiserver/pkg/apiserver/schema/cel/validation.go
Outdated
Show resolved
Hide resolved
staging/src/k8s.io/apiextensions-apiserver/pkg/apiserver/schema/cel/validation.go
Outdated
Show resolved
Hide resolved
00bfc82
to
4c81329
Compare
staging/src/k8s.io/apiextensions-apiserver/pkg/apis/apiextensions/types_jsonschema.go
Outdated
Show resolved
Hide resolved
staging/src/k8s.io/apiextensions-apiserver/pkg/apis/apiextensions/types_jsonschema.go
Outdated
Show resolved
Hide resolved
staging/src/k8s.io/apiextensions-apiserver/pkg/apis/apiextensions/types_jsonschema.go
Outdated
Show resolved
Hide resolved
staging/src/k8s.io/apiextensions-apiserver/pkg/apis/apiextensions/types_jsonschema.go
Outdated
Show resolved
Hide resolved
staging/src/k8s.io/apiextensions-apiserver/pkg/apiserver/schema/cel/compilation.go
Outdated
Show resolved
Hide resolved
staging/src/k8s.io/apiextensions-apiserver/pkg/apiserver/schema/cel/compilation_test.go
Show resolved
Hide resolved
staging/src/k8s.io/apiextensions-apiserver/pkg/apiserver/schema/cel/compilation_test.go
Outdated
Show resolved
Hide resolved
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()) |
There was a problem hiding this comment.
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.
There was a problem hiding this comment.
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..
staging/src/k8s.io/apiextensions-apiserver/pkg/apiserver/schema/cel/validation.go
Outdated
Show resolved
Hide resolved
staging/src/k8s.io/apiextensions-apiserver/pkg/apiserver/schema/cel/validation.go
Outdated
Show resolved
Hide resolved
(force push to address #115969 (comment)) |
staging/src/k8s.io/apiextensions-apiserver/pkg/apis/apiextensions/types_jsonschema.go
Outdated
Show resolved
Hide resolved
staging/src/k8s.io/apiextensions-apiserver/pkg/apis/apiextensions/v1/types_jsonschema.go
Outdated
Show resolved
Hide resolved
staging/src/k8s.io/apiextensions-apiserver/pkg/apis/apiextensions/v1/types_jsonschema.go
Outdated
Show resolved
Hide resolved
staging/src/k8s.io/apiextensions-apiserver/pkg/apis/apiextensions/v1/types_jsonschema.go
Outdated
Show resolved
Hide resolved
staging/src/k8s.io/apiextensions-apiserver/pkg/apiserver/schema/cel/validation.go
Outdated
Show resolved
Hide resolved
Update docs to note that generating line breaks from messageExpression is not allowed.
dea1d9a
to
b711a08
Compare
0d3e2e5
to
4e26f68
Compare
@DangerOnTheRanger: The following tests failed, say
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. |
/retest |
// 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. |
There was a problem hiding this comment.
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?
There was a problem hiding this comment.
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
There was a problem hiding this comment.
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
There was a problem hiding this comment.
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:
kubernetes/staging/src/k8s.io/apiextensions-apiserver/pkg/apiserver/schema/cel/validation_test.go
Line 1762 in 90c3232
"authorizer.path('/healthz').check('get').isAllowed()": "undeclared reference to 'authorizer'", |
/lgtm |
LGTM label has been added. Git tree hash: bdaad98a95ab79fbb6590f4b1cbf99a13ae153a5
|
[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 |
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?
Additional documentation e.g., KEPs (Kubernetes Enhancement Proposals), usage docs, etc.: