forked from kyverno/kyverno
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
fix: CEL policies aren't applied to deleted resources
Signed-off-by: Mariam Fahmy <[email protected]>
- Loading branch information
1 parent
b88b627
commit 8b161ac
Showing
18 changed files
with
134 additions
and
22 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -12,6 +12,9 @@ spec: | |
- resources: | ||
kinds: | ||
- Pod | ||
operations: | ||
- CREATE | ||
- UPDATE | ||
validate: | ||
cel: | ||
expressions: | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -12,6 +12,9 @@ spec: | |
- resources: | ||
kinds: | ||
- Deployment | ||
operations: | ||
- CREATE | ||
- UPDATE | ||
validate: | ||
cel: | ||
expressions: | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -12,6 +12,9 @@ spec: | |
- resources: | ||
kinds: | ||
- Deployment | ||
operations: | ||
- CREATE | ||
- UPDATE | ||
validate: | ||
cel: | ||
variables: | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -12,6 +12,9 @@ spec: | |
- resources: | ||
kinds: | ||
- StatefulSet | ||
operations: | ||
- CREATE | ||
- UPDATE | ||
validate: | ||
cel: | ||
expressions: | ||
|
11 changes: 11 additions & 0 deletions
11
test/conformance/chainsaw/validate/clusterpolicy/standard/cel/deny/README.md
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,11 @@ | ||
## Description | ||
|
||
This test creates a policy that uses CEL expressions to deny the creation/deletion/update of any pod. | ||
|
||
## Expected Behavior | ||
|
||
Any pod creation/deletion/update is blocked. | ||
|
||
## Reference Issue(s) | ||
|
||
10576 |
32 changes: 32 additions & 0 deletions
32
test/conformance/chainsaw/validate/clusterpolicy/standard/cel/deny/chainsaw-test.yaml
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,32 @@ | ||
apiVersion: chainsaw.kyverno.io/v1alpha1 | ||
kind: Test | ||
metadata: | ||
creationTimestamp: null | ||
name: deny | ||
spec: | ||
steps: | ||
- name: step-01 | ||
try: | ||
- script: | ||
content: kubectl run nginx --image=nginx | ||
- name: step-02 | ||
try: | ||
- apply: | ||
file: policy.yaml | ||
- assert: | ||
file: policy-assert.yaml | ||
- name: step-03 | ||
try: | ||
- script: | ||
content: "if kubectl run --image=busybox foo\nthen \n exit 1\nelse \n exit | ||
0\nfi\n" | ||
- name: step-04 | ||
try: | ||
- script: | ||
content: "if kubectl label pod nginx app=nginx\nthen \n exit 1\nelse \n exit | ||
0\nfi\n" | ||
- name: step-05 | ||
try: | ||
- script: | ||
content: "if kubectl delete pod nginx\nthen \n exit 1\nelse \n exit | ||
0\nfi\n" |
9 changes: 9 additions & 0 deletions
9
test/conformance/chainsaw/validate/clusterpolicy/standard/cel/deny/policy-assert.yaml
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,9 @@ | ||
apiVersion: kyverno.io/v1 | ||
kind: ClusterPolicy | ||
metadata: | ||
name: restrict-operations-on-pod | ||
status: | ||
conditions: | ||
- reason: Succeeded | ||
status: "True" | ||
type: Ready |
19 changes: 19 additions & 0 deletions
19
test/conformance/chainsaw/validate/clusterpolicy/standard/cel/deny/policy.yaml
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,19 @@ | ||
apiVersion: kyverno.io/v1 | ||
kind: ClusterPolicy | ||
metadata: | ||
name: restrict-operations-on-pod | ||
spec: | ||
validationFailureAction: Enforce | ||
background: true | ||
rules: | ||
- name: rule-1 | ||
match: | ||
any: | ||
- resources: | ||
kinds: | ||
- Pod | ||
validate: | ||
cel: | ||
expressions: | ||
- expression: "false" | ||
message: Create, update and delete on pods is not allowed |
3 changes: 2 additions & 1 deletion
3
...conformance/chainsaw/validate/clusterpolicy/standard/cel/disallow-host-port/pod-fail.yaml
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,10 +1,11 @@ | ||
apiVersion: v1 | ||
kind: Pod | ||
metadata: | ||
name: webserver | ||
name: webserver-2 | ||
spec: | ||
containers: | ||
- name: webserver | ||
image: nginx:latest | ||
ports: | ||
- hostPort: 80 | ||
containerPort: 80 |
2 changes: 1 addition & 1 deletion
2
...conformance/chainsaw/validate/clusterpolicy/standard/cel/disallow-host-port/pod-pass.yaml
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,7 +1,7 @@ | ||
apiVersion: v1 | ||
kind: Pod | ||
metadata: | ||
name: webserver | ||
name: webserver-1 | ||
spec: | ||
containers: | ||
- name: webserver | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -14,6 +14,9 @@ spec: | |
- resources: | ||
kinds: | ||
- Pod | ||
operations: | ||
- CREATE | ||
- UPDATE | ||
validate: | ||
cel: | ||
expressions: | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -12,6 +12,9 @@ spec: | |
- resources: | ||
kinds: | ||
- Namespace | ||
operations: | ||
- CREATE | ||
- UPDATE | ||
validate: | ||
cel: | ||
paramKind: | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -12,6 +12,9 @@ spec: | |
- resources: | ||
kinds: | ||
- Namespace | ||
operations: | ||
- CREATE | ||
- UPDATE | ||
validate: | ||
cel: | ||
paramKind: | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -12,6 +12,9 @@ spec: | |
- resources: | ||
kinds: | ||
- Deployment | ||
operations: | ||
- CREATE | ||
- UPDATE | ||
validate: | ||
cel: | ||
paramKind: | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -12,6 +12,9 @@ spec: | |
- resources: | ||
kinds: | ||
- StatefulSet | ||
operations: | ||
- CREATE | ||
- UPDATE | ||
validate: | ||
cel: | ||
paramKind: | ||
|