2022-02-04 01:47:36 -05:00
|
|
|
{{- $name := "require-run-as-non-root-user" }}
|
|
|
|
{{- if eq (include "kyverno-policies.podSecurityRestricted" (merge (dict "name" $name) .)) "true" }}
|
|
|
|
apiVersion: kyverno.io/v1
|
|
|
|
kind: ClusterPolicy
|
|
|
|
metadata:
|
|
|
|
name: {{ $name }}
|
|
|
|
annotations:
|
|
|
|
policies.kyverno.io/title: Require Run As Non-Root User
|
|
|
|
policies.kyverno.io/category: Pod Security Standards (Restricted)
|
|
|
|
{{- if .Values.podSecuritySeverity }}
|
|
|
|
policies.kyverno.io/severity: {{ .Values.podSecuritySeverity | quote }}
|
|
|
|
{{- end }}
|
|
|
|
policies.kyverno.io/subject: Pod
|
|
|
|
kyverno.io/kyverno-version: 1.6.0
|
|
|
|
kyverno.io/kubernetes-version: "1.22-1.23"
|
|
|
|
policies.kyverno.io/description: >-
|
|
|
|
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.
|
|
|
|
spec:
|
|
|
|
validationFailureAction: {{ .Values.validationFailureAction }}
|
2022-02-09 03:24:35 -05:00
|
|
|
{{- with concat (index .Values "validationFailureActionOverrides" "all") (default list (index .Values "validationFailureActionOverrides" $name)) }}
|
|
|
|
validationFailureActionOverrides: {{ toYaml . | nindent 4 }}
|
|
|
|
{{- end }}
|
2022-02-24 17:31:51 +01:00
|
|
|
background: {{ .Values.background }}
|
2022-08-09 17:12:27 -04:00
|
|
|
failurePolicy: {{ .Values.failurePolicy }}
|
2022-02-04 01:47:36 -05:00
|
|
|
rules:
|
|
|
|
- name: run-as-non-root-user
|
|
|
|
match:
|
|
|
|
any:
|
|
|
|
- resources:
|
|
|
|
kinds:
|
|
|
|
- Pod
|
|
|
|
{{- with index .Values "policyExclude" $name }}
|
|
|
|
exclude:
|
|
|
|
{{- toYaml . | nindent 8 }}
|
|
|
|
{{- end }}
|
2022-04-18 13:59:47 -04:00
|
|
|
{{- with index .Values "policyPreconditions" $name }}
|
|
|
|
preconditions:
|
|
|
|
{{- toYaml . | nindent 8 }}
|
|
|
|
{{- end }}
|
2022-02-04 01:47:36 -05:00
|
|
|
validate:
|
|
|
|
message: >-
|
|
|
|
Running as root is not allowed. The fields spec.securityContext.runAsUser,
|
|
|
|
spec.containers[*].securityContext.runAsUser, spec.initContainers[*].securityContext.runAsUser,
|
|
|
|
and spec.ephemeralContainers[*].securityContext.runAsUser must be unset or
|
|
|
|
set to a number greater than zero.
|
|
|
|
pattern:
|
|
|
|
spec:
|
|
|
|
=(securityContext):
|
|
|
|
=(runAsUser): ">0"
|
|
|
|
=(ephemeralContainers):
|
|
|
|
- =(securityContext):
|
|
|
|
=(runAsUser): ">0"
|
|
|
|
=(initContainers):
|
|
|
|
- =(securityContext):
|
|
|
|
=(runAsUser): ">0"
|
|
|
|
containers:
|
|
|
|
- =(securityContext):
|
|
|
|
=(runAsUser): ">0"
|
|
|
|
{{- end }}
|