Skip to content

Commit

Permalink
chore: add match conditions with variable chainsaw test (#301)
Browse files Browse the repository at this point in the history
Signed-off-by: Charles-Edouard Brétéché <[email protected]>
  • Loading branch information
eddycharly authored Jan 6, 2025
1 parent 7c35858 commit c5df7b5
Show file tree
Hide file tree
Showing 5 changed files with 37 additions and 3 deletions.
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

0 comments on commit c5df7b5

Please sign in to comment.