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

chore: add match conditions with variable chainsaw test #301

Merged
merged 1 commit into from
Jan 6, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion tests/e2e/authz-server/allow/chainsaw-test.yaml
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
apiVersion: chainsaw.kyverno.io/v1alpha1
kind: Test
metadata:
name: deny
name: allow
spec:
namespace: app
steps:
Expand Down
2 changes: 1 addition & 1 deletion tests/e2e/authz-server/default/chainsaw-test.yaml
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
apiVersion: chainsaw.kyverno.io/v1alpha1
kind: Test
metadata:
name: deny
name: default
spec:
namespace: app
steps:
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
apiVersion: chainsaw.kyverno.io/v1alpha1
kind: Test
metadata:
name: no-variables
spec:
steps:
- try:
- create:
file: ./policy.yaml
expect:
- check:
($error): |-
admission webhook "kyverno-authz-server-validation.kyverno.svc" denied the request: AuthorizationPolicy.envoy.kyverno.io "policy" is invalid: spec.matchConditions[0].expression: Invalid value: "variables.foo": ERROR: <input>:1:10: undefined field 'foo'
| variables.foo
| .........^
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
# yaml-language-server: $schema=../../../../../.schemas/json/authorizationpolicy-envoy-v1alpha1.json
apiVersion: envoy.kyverno.io/v1alpha1
kind: AuthorizationPolicy
metadata:
name: policy
spec:
matchConditions:
- name: check-foo
expression: variables.foo
variables:
- name: foo
expression: >
true
deny:
- response: >
envoy
.Denied(403)
.WithBody("Unauthorized Request")
.Response()
2 changes: 1 addition & 1 deletion website/docs/policies/match-conditions.md
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ Match conditions are **CEL expressions**. All match conditions must evaluate to

!!!info

Match conditions have access to the same CEL variables as validation expressions.
The policy [variables](./variables.md) will NOT be available in match conditions because they are evaluated before the rest of the policy.

## Example

Expand Down
Loading