1
0
Fork 0
mirror of https://github.com/kyverno/kyverno.git synced 2025-03-28 02:18:15 +00:00

test: add kuttl tests for ephemeral containers (#6631)

Signed-off-by: Charles-Edouard Brétéché <charles.edouard@nirmata.com>
This commit is contained in:
Charles-Edouard Brétéché 2023-03-22 11:52:02 +01:00 committed by GitHub
parent aa6400269e
commit b0243e1215
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
21 changed files with 186 additions and 0 deletions

View file

@ -0,0 +1,4 @@
apiVersion: kuttl.dev/v1beta1
kind: TestStep
apply:
- resources.yaml

View file

@ -0,0 +1,6 @@
apiVersion: kuttl.dev/v1beta1
kind: TestStep
apply:
- policies.yaml
assert:
- policies-assert.yaml

View file

@ -0,0 +1,10 @@
apiVersion: kuttl.dev/v1beta1
kind: TestStep
commands:
- script: |
if kubectl debug --image=busybox foo
then
exit 1
else
exit 0
fi

View file

@ -0,0 +1,4 @@
## Description
This test creates a policy to deny the creation of ephemeral containers.
The policy is targeting `Pod` (we implicitly add the `ephemeralcontainers` subresource) and calls `kubectl debug`, the call is expected to fail.

View file

@ -0,0 +1,9 @@
apiVersion: kyverno.io/v1
kind: ClusterPolicy
metadata:
name: block-ephemeral-containers
status:
conditions:
- reason: Succeeded
status: "True"
type: Ready

View file

@ -0,0 +1,18 @@
apiVersion: kyverno.io/v1
kind: ClusterPolicy
metadata:
name: block-ephemeral-containers
annotations:
pod-policies.kyverno.io/autogen-controllers: none
spec:
validationFailureAction: Enforce
background: false
rules:
- name: deny-debug
match:
any:
- resources:
kinds:
- Pod
validate:
deny: {}

View file

@ -0,0 +1,11 @@
apiVersion: v1
kind: Pod
metadata:
name: foo
namespace: default
spec:
containers:
- name: nginx
image: nginx:1.14.2
ports:
- containerPort: 80

View file

@ -0,0 +1,6 @@
apiVersion: kuttl.dev/v1beta1
kind: TestStep
apply:
- policies.yaml
assert:
- policies-assert.yaml

View file

@ -0,0 +1,4 @@
apiVersion: kuttl.dev/v1beta1
kind: TestStep
apply:
- resources.yaml

View file

@ -0,0 +1,10 @@
apiVersion: kuttl.dev/v1beta1
kind: TestStep
commands:
- script: |
if kubectl debug --image=busybox foo
then
exit 1
else
exit 0
fi

View file

@ -0,0 +1,4 @@
## Description
This test creates a policy to deny the creation of ephemeral containers.
The policy is targeting `Pod/ephemeralcontainers` and calls `kubectl debug`, the call is expected to fail.

View file

@ -0,0 +1,9 @@
apiVersion: kyverno.io/v1
kind: ClusterPolicy
metadata:
name: block-ephemeral-containers
status:
conditions:
- reason: Succeeded
status: "True"
type: Ready

View file

@ -0,0 +1,18 @@
apiVersion: kyverno.io/v1
kind: ClusterPolicy
metadata:
name: block-ephemeral-containers
annotations:
pod-policies.kyverno.io/autogen-controllers: none
spec:
validationFailureAction: Enforce
background: false
rules:
- name: deny-debug
match:
any:
- resources:
kinds:
- Pod/ephemeralcontainers
validate:
deny: {}

View file

@ -0,0 +1,11 @@
apiVersion: v1
kind: Pod
metadata:
name: foo
namespace: default
spec:
containers:
- name: nginx
image: nginx:1.14.2
ports:
- containerPort: 80

View file

@ -0,0 +1,6 @@
apiVersion: kuttl.dev/v1beta1
kind: TestStep
apply:
- policies.yaml
assert:
- policies-assert.yaml

View file

@ -0,0 +1,4 @@
apiVersion: kuttl.dev/v1beta1
kind: TestStep
apply:
- resources.yaml

View file

@ -0,0 +1,10 @@
apiVersion: kuttl.dev/v1beta1
kind: TestStep
commands:
- script: |
if kubectl debug --image=busybox foo
then
exit 1
else
exit 0
fi

View file

@ -0,0 +1,4 @@
## Description
This test creates a policy to deny the creation of ephemeral containers.
The policy is targeting `*/ephemeralcontainers` and calls `kubectl debug`, the call is expected to fail.

View file

@ -0,0 +1,9 @@
apiVersion: kyverno.io/v1
kind: ClusterPolicy
metadata:
name: block-ephemeral-containers
status:
conditions:
- reason: Succeeded
status: "True"
type: Ready

View file

@ -0,0 +1,18 @@
apiVersion: kyverno.io/v1
kind: ClusterPolicy
metadata:
name: block-ephemeral-containers
annotations:
pod-policies.kyverno.io/autogen-controllers: none
spec:
validationFailureAction: Enforce
background: false
rules:
- name: deny-debug
match:
any:
- resources:
kinds:
- '*/ephemeralcontainers'
validate:
deny: {}

View file

@ -0,0 +1,11 @@
apiVersion: v1
kind: Pod
metadata:
name: foo
namespace: default
spec:
containers:
- name: nginx
image: nginx:1.14.2
ports:
- containerPort: 80