All Policies
Add Default securityContext
A Pod securityContext entry defines fields such as the user and group which should be used to run the Pod. Sometimes choosing default values for users rather than blocking is a better alternative to not impede such Pod definitions. This policy will mutate a Pod to set `runAsUser`, `runAsGroup`, and `fsGroup` fields within the Pod securityContext if they are not already set.
Policy Definition
/other/add-default-securitycontext.yaml
1apiVersion: kyverno.io/v1
2kind: ClusterPolicy
3metadata:
4 name: add-default-securitycontext
5 annotations:
6 policies.kyverno.io/title: Add Default securityContext
7 policies.kyverno.io/category: Sample
8 policies.kyverno.io/subject: Pod
9 policies.kyverno.io/description: >-
10 A Pod securityContext entry defines fields such as the user and group which should be used to run the Pod.
11 Sometimes choosing default values for users rather than blocking is a better alternative to not impede
12 such Pod definitions. This policy will mutate a Pod to set `runAsUser`, `runAsGroup`, and `fsGroup` fields
13 within the Pod securityContext if they are not already set.
14spec:
15 background: false
16 rules:
17 - name: add-default-securitycontext
18 match:
19 resources:
20 kinds:
21 - Pod
22 mutate:
23 patchStrategicMerge:
24 spec:
25 securityContext:
26 +(runAsUser): 1000
27 +(runAsGroup): 3000
28 +(fsGroup): 2000
29