All Policies
Disallow Capabilities
Adding capabilities beyond those listed in the policy must be disallowed.
Policy Definition
/pod-security/baseline/disallow-capabilities/disallow-capabilities.yaml
1apiVersion: kyverno.io/v1
2kind: ClusterPolicy
3metadata:
4 name: disallow-capabilities
5 annotations:
6 policies.kyverno.io/title: Disallow Capabilities
7 policies.kyverno.io/category: Pod Security Standards (Baseline)
8 policies.kyverno.io/severity: medium
9 kyverno.io/kyverno-version: 1.6.0
10 policies.kyverno.io/minversion: 1.6.0
11 kyverno.io/kubernetes-version: "1.22-1.23"
12 policies.kyverno.io/subject: Pod
13 policies.kyverno.io/description: >-
14 Adding capabilities beyond those listed in the policy must be disallowed.
15spec:
16 validationFailureAction: audit
17 background: true
18 rules:
19 - name: adding-capabilities
20 match:
21 any:
22 - resources:
23 kinds:
24 - Pod
25 preconditions:
26 all:
27 - key: "{{ request.operation || 'BACKGROUND' }}"
28 operator: NotEquals
29 value: DELETE
30 validate:
31 message: >-
32 Any capabilities added beyond the allowed list (AUDIT_WRITE, CHOWN, DAC_OVERRIDE, FOWNER,
33 FSETID, KILL, MKNOD, NET_BIND_SERVICE, SETFCAP, SETGID, SETPCAP, SETUID, SYS_CHROOT)
34 are disallowed.
35 deny:
36 conditions:
37 all:
38 - key: "{{ request.object.spec.[ephemeralContainers, initContainers, containers][].securityContext.capabilities.add[] }}"
39 operator: AnyNotIn
40 value:
41 - AUDIT_WRITE
42 - CHOWN
43 - DAC_OVERRIDE
44 - FOWNER
45 - FSETID
46 - KILL
47 - MKNOD
48 - NET_BIND_SERVICE
49 - SETFCAP
50 - SETGID
51 - SETPCAP
52 - SETUID
53 - SYS_CHROOT