mirror of
https://github.com/kyverno/kyverno.git
synced 2025-04-13 15:57:31 +00:00
67 lines
2.2 KiB
YAML
67 lines
2.2 KiB
YAML
{{- $name := "require-non-root-groups" }}
|
|
{{- if eq (include "kyverno-policies.podSecurityRestricted" (merge (dict "name" $name) .)) "true" }}
|
|
apiVersion: kyverno.io/v1
|
|
kind: ClusterPolicy
|
|
metadata:
|
|
name: {{ $name }}
|
|
annotations:
|
|
policies.kyverno.io/category: Pod Security Standards (Restricted)
|
|
{{- if .Values.podSecuritySeverity }}
|
|
policies.kyverno.io/severity: {{ .Values.podSecuritySeverity | quote }}
|
|
{{- end }}
|
|
policies.kyverno.io/description: >-
|
|
Containers should be forbidden from running with a root primary or supplementary GID.
|
|
labels: {{ include "kyverno-policies.labels" . | nindent 4 }}
|
|
app: kyverno
|
|
spec:
|
|
background: true
|
|
validationFailureAction: {{ .Values.validationFailureAction }}
|
|
rules:
|
|
- name: check-runasgroup
|
|
match:
|
|
resources:
|
|
kinds:
|
|
- Pod
|
|
validate:
|
|
message: >-
|
|
Running with root group IDs is disallowed. The fields
|
|
spec.securityContext.runAsGroup, spec.containers[*].securityContext.runAsGroup,
|
|
and spec.initContainers[*].securityContext.runAsGroup must be empty
|
|
or greater than zero.
|
|
pattern:
|
|
spec:
|
|
=(securityContext):
|
|
=(runAsGroup): ">0"
|
|
=(initContainers):
|
|
- =(securityContext):
|
|
=(runAsGroup): ">0"
|
|
containers:
|
|
- =(securityContext):
|
|
=(runAsGroup): ">0"
|
|
- name: check-supplementalGroups
|
|
match:
|
|
resources:
|
|
kinds:
|
|
- Pod
|
|
validate:
|
|
message: >-
|
|
Adding of supplemental group IDs is not allowed. The field
|
|
spec.securityContext.supplementalGroups must not be defined.
|
|
pattern:
|
|
spec:
|
|
=(securityContext):
|
|
=(supplementalGroups): ">0"
|
|
- name: check-fsGroup
|
|
match:
|
|
resources:
|
|
kinds:
|
|
- Pod
|
|
validate:
|
|
message: >-
|
|
Changing to root group ID is disallowed. The field
|
|
spec.securityContext.fsGroup must be empty or greater than zero.
|
|
pattern:
|
|
spec:
|
|
=(securityContext):
|
|
=(fsGroup): ">0"
|
|
{{- end -}}
|