2019-11-13 13:56:20 -08:00
|
|
|
apiVersion: kyverno.io/v1
|
2019-10-08 18:40:15 -07:00
|
|
|
kind: ClusterPolicy
|
|
|
|
metadata:
|
2019-11-08 19:25:43 -08:00
|
|
|
name: disallow-root-user
|
2019-10-11 18:57:16 -07:00
|
|
|
annotations:
|
2019-11-08 19:25:43 -08:00
|
|
|
policies.kyverno.io/category: Security
|
2019-10-14 16:33:19 -07:00
|
|
|
policies.kyverno.io/description: By default, processes in a container run as a
|
|
|
|
root user (uid 0). To prevent potential compromise of container hosts, specify a
|
|
|
|
least privileged user ID when building the container image and require that
|
|
|
|
application containers run as non root users.
|
2019-10-08 18:40:15 -07:00
|
|
|
spec:
|
|
|
|
rules:
|
2019-11-08 19:25:43 -08:00
|
|
|
- name: validate-runAsNonRoot
|
2019-10-08 18:40:15 -07:00
|
|
|
match:
|
|
|
|
resources:
|
|
|
|
kinds:
|
|
|
|
- Pod
|
|
|
|
validate:
|
2019-11-08 19:25:43 -08:00
|
|
|
message: "Running as root user is not allowed. Set runAsNonRoot to true"
|
2019-10-08 18:40:15 -07:00
|
|
|
anyPattern:
|
|
|
|
- spec:
|
|
|
|
securityContext:
|
|
|
|
runAsNonRoot: true
|
|
|
|
- spec:
|
|
|
|
containers:
|
|
|
|
- name: "*"
|
|
|
|
securityContext:
|
|
|
|
runAsNonRoot: true
|