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

docs: match conditions docs #287

Merged
merged 3 commits into from
Jan 3, 2025
Merged
Show file tree
Hide file tree
Changes from 1 commit
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
1 change: 1 addition & 0 deletions website/docs/policies/index.md
Original file line number Diff line number Diff line change
Expand Up @@ -55,5 +55,6 @@ CEL is an expression language that’s fast, portable, and safe to execute in pe
A Kyverno `AuthorizationPolicy` is made of:

- A [failure policy](./failure-policy.md)
- [Match conditions](./match-conditions.md) if needed
- Eventually some [variables](./variables.md)
- The [authorization rules](./authorization-rules.md)
27 changes: 27 additions & 0 deletions website/docs/policies/match-conditions.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
# Match conditions

You can define match conditions if you need fine-grained request filtering.

Match conditions are **CEL expressions**. All match conditions must evaluate to `true` for the request to be evaluated.

## Example

```yaml
apiVersion: envoy.kyverno.io/v1alpha1
kind: AuthorizationPolicy
metadata:
name: demo
spec:
failurePolicy: Fail
matchConditions:
- name: has-header
expression: has(object.attributes.request.http.headers["x-force-deny"])
deny:
- response: >
envoy.Denied(403).Response()
```

In the policy above, the `matchConditions` will be used to deny all requests having the `x-force-deny` header.

- If an incoming request doesn't have the `x-force-deny` header the condition will return `false` and the policy won't apply
eddycharly marked this conversation as resolved.
Show resolved Hide resolved
- If an incoming request has the `x-force-deny` header the condition will return `true` and the `deny` rule will deny the request with status code `403`
eddycharly marked this conversation as resolved.
Show resolved Hide resolved
1 change: 1 addition & 0 deletions website/mkdocs.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ nav:
- Policies:
- policies/index.md
- policies/failure-policy.md
- policies/match-conditions.md
- policies/variables.md
- policies/authorization-rules.md
- Reference:
Expand Down
Loading