1
0
Fork 0
mirror of https://github.com/kyverno/kyverno.git synced 2025-03-09 17:37:12 +00:00
kyverno/samples/best_practices/disallow_root_user.yaml

29 lines
1 KiB
YAML
Raw Normal View History

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:
2019-12-30 13:53:51 -08:00
# https://github.com/kubernetes/api/blob/7dc09db16fb8ff2eee16c65dc066c85ab3abb7ce/core/v1/types.go#L3165
2019-10-08 18:40:15 -07:00
runAsNonRoot: true
- spec:
containers:
2019-12-30 13:53:51 -08:00
- securityContext:
# https://github.com/kubernetes/api/blob/7dc09db16fb8ff2eee16c65dc066c85ab3abb7ce/core/v1/types.go#L5742
2019-10-08 18:40:15 -07:00
runAsNonRoot: true