All Policies
Require Run As Non-Root User
Containers must be required to run as non-root users. This policy ensures `runAsUser` is either unset or set to a number greater than zero.
Policy Definition
/pod-security/restricted/require-run-as-non-root-user/require-run-as-non-root-user.yaml
1apiVersion: kyverno.io/v1
2kind: ClusterPolicy
3metadata:
4 name: require-run-as-non-root-user
5 annotations:
6 policies.kyverno.io/title: Require Run As Non-Root User
7 policies.kyverno.io/category: Pod Security Standards (Restricted)
8 policies.kyverno.io/severity: medium
9 policies.kyverno.io/subject: Pod
10 kyverno.io/kyverno-version: 1.6.0
11 kyverno.io/kubernetes-version: "1.22-1.23"
12 policies.kyverno.io/description: >-
13 Containers must be required to run as non-root users. This policy ensures
14 `runAsUser` is either unset or set to a number greater than zero.
15spec:
16 validationFailureAction: audit
17 background: true
18 rules:
19 - name: run-as-non-root-user
20 match:
21 any:
22 - resources:
23 kinds:
24 - Pod
25 validate:
26 message: >-
27 Running as root is not allowed. The fields spec.securityContext.runAsUser,
28 spec.containers[*].securityContext.runAsUser, spec.initContainers[*].securityContext.runAsUser,
29 and spec.ephemeralContainers[*].securityContext.runAsUser must be unset or
30 set to a number greater than zero.
31 pattern:
32 spec:
33 =(securityContext):
34 =(runAsUser): ">0"
35 =(ephemeralContainers):
36 - =(securityContext):
37 =(runAsUser): ">0"
38 =(initContainers):
39 - =(securityContext):
40 =(runAsUser): ">0"
41 containers:
42 - =(securityContext):
43 =(runAsUser): ">0"