-
Notifications
You must be signed in to change notification settings - Fork 4
/
kyverno.yaml
63 lines (63 loc) · 2.04 KB
/
kyverno.yaml
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
apiVersion: kyverno.io/v1
kind: ClusterPolicy
metadata:
name: psp-allowedcapabilities
spec:
validationFailureAction: Enforce
rules:
# Checks initContainers to ensure they don't add anything other than what is permitted.
- name: psp-allowedcapabilities-initcontainers
match:
resources:
kinds:
- Pod
preconditions:
all:
- key: "{{request.operation}}"
operator: In
value:
- CREATE
- UPDATE
# Check if initContainers even exist in the Pod
- key: "{{ request.object.spec.initContainers[] | length(@) }}"
operator: GreaterThanOrEquals
value: 1
validate:
message: The only capabilities that may be explicitly added are `something` or `somethingelse`.
foreach:
- list: "request.object.spec.initContainers[].securityContext.capabilities"
deny:
conditions:
any:
# Loop over the `add[]` array in each container and deny if anything other than the "something" or "somethingelse" capability has been added.
- key: "{{ element.add }}"
operator: AnyNotIn
value:
- something
- somethingelse
# Checks containers to ensure they don't add anything other than what is permitted.
- name: psp-allowedcapabilities-containers
match:
resources:
kinds:
- Pod
preconditions:
all:
- key: "{{request.operation}}"
operator: In
value:
- CREATE
- UPDATE
validate:
message: The only capability that may be explicitly added is `something`.
foreach:
- list: "request.object.spec.containers[].securityContext.capabilities"
deny:
conditions:
any:
# Loop over the `add[]` array in each container and deny if anything other than the "something" or "somethingelse" capability has been added.
- key: "{{ element.add }}"
operator: AnyNotIn
value:
- something
- somethingelse