2022-02-04 01:47:36 -05:00
|
|
|
{{- $name := "disallow-selinux" }}
|
|
|
|
{{- if eq (include "kyverno-policies.podSecurityBaseline" (merge (dict "name" $name) .)) "true" }}
|
|
|
|
apiVersion: kyverno.io/v1
|
2023-11-16 04:32:38 -05:00
|
|
|
kind: {{ .Values.policyKind }}
|
2022-02-04 01:47:36 -05:00
|
|
|
metadata:
|
|
|
|
name: {{ $name }}
|
|
|
|
annotations:
|
2022-12-01 11:05:56 +01:00
|
|
|
{{- with .Values.autogenControllers }}
|
|
|
|
pod-policies.kyverno.io/autogen-controllers: {{ . }}
|
|
|
|
{{- end }}
|
2022-02-04 01:47:36 -05:00
|
|
|
policies.kyverno.io/title: Disallow SELinux
|
|
|
|
policies.kyverno.io/category: Pod Security Standards (Baseline)
|
|
|
|
{{- if .Values.podSecuritySeverity }}
|
|
|
|
policies.kyverno.io/severity: {{ .Values.podSecuritySeverity }}
|
|
|
|
{{- 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: >-
|
|
|
|
SELinux options can be used to escalate privileges and should not be allowed. This policy
|
|
|
|
ensures that the `seLinuxOptions` field is undefined.
|
2022-12-01 11:05:56 +01:00
|
|
|
labels: {{ include "kyverno-policies.labels" . | nindent 4 }}
|
2022-02-04 01:47:36 -05:00
|
|
|
spec:
|
2022-08-25 17:29:20 +02:00
|
|
|
{{- with index .Values "validationFailureActionByPolicy" $name }}
|
|
|
|
validationFailureAction: {{ toYaml . }}
|
|
|
|
{{- else }}
|
2022-02-04 01:47:36 -05:00
|
|
|
validationFailureAction: {{ .Values.validationFailureAction }}
|
2022-08-25 17:29:20 +02:00
|
|
|
{{- end }}
|
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: selinux-type
|
|
|
|
match:
|
|
|
|
any:
|
|
|
|
- resources:
|
|
|
|
kinds:
|
|
|
|
- Pod
|
|
|
|
{{- with merge (index .Values "policyExclude" "selinux-type") (index .Values "policyExclude" $name) }}
|
|
|
|
exclude:
|
|
|
|
{{- toYaml . | nindent 8 }}
|
|
|
|
{{- end }}
|
2022-04-18 13:59:47 -04:00
|
|
|
{{- with merge (index .Values "policyPreconditions" "selinux-type") (index .Values "policyPreconditions" $name) }}
|
|
|
|
preconditions:
|
|
|
|
{{- toYaml . | nindent 8 }}
|
|
|
|
{{- end }}
|
2022-02-04 01:47:36 -05:00
|
|
|
validate:
|
|
|
|
message: >-
|
|
|
|
Setting the SELinux type is restricted. The fields
|
|
|
|
spec.securityContext.seLinuxOptions.type, spec.containers[*].securityContext.seLinuxOptions.type,
|
|
|
|
, spec.initContainers[*].securityContext.seLinuxOptions, and spec.ephemeralContainers[*].securityContext.seLinuxOptions.type
|
|
|
|
must either be unset or set to one of the allowed values (container_t, container_init_t, or container_kvm_t).
|
|
|
|
pattern:
|
|
|
|
spec:
|
|
|
|
=(securityContext):
|
|
|
|
=(seLinuxOptions):
|
|
|
|
=(type): "container_t | container_init_t | container_kvm_t"
|
|
|
|
=(ephemeralContainers):
|
|
|
|
- =(securityContext):
|
|
|
|
=(seLinuxOptions):
|
|
|
|
=(type): "container_t | container_init_t | container_kvm_t"
|
|
|
|
=(initContainers):
|
|
|
|
- =(securityContext):
|
|
|
|
=(seLinuxOptions):
|
|
|
|
=(type): "container_t | container_init_t | container_kvm_t"
|
|
|
|
containers:
|
|
|
|
- =(securityContext):
|
|
|
|
=(seLinuxOptions):
|
|
|
|
=(type): "container_t | container_init_t | container_kvm_t"
|
|
|
|
- name: selinux-user-role
|
|
|
|
match:
|
|
|
|
any:
|
|
|
|
- resources:
|
|
|
|
kinds:
|
|
|
|
- Pod
|
|
|
|
{{- with merge (index .Values "policyExclude" "selinux-user-role") (index .Values "policyExclude" $name) }}
|
|
|
|
exclude:
|
|
|
|
{{- toYaml . | nindent 8 }}
|
|
|
|
{{- end }}
|
2022-04-18 13:59:47 -04:00
|
|
|
{{- with merge (index .Values "policyPreconditions" "selinux-user-role") (index .Values "policyPreconditions" $name) }}
|
|
|
|
preconditions:
|
|
|
|
{{- toYaml . | nindent 8 }}
|
|
|
|
{{- end }}
|
2022-02-04 01:47:36 -05:00
|
|
|
validate:
|
|
|
|
message: >-
|
|
|
|
Setting the SELinux user or role is forbidden. The fields
|
|
|
|
spec.securityContext.seLinuxOptions.user, spec.securityContext.seLinuxOptions.role,
|
|
|
|
spec.containers[*].securityContext.seLinuxOptions.user, spec.containers[*].securityContext.seLinuxOptions.role,
|
|
|
|
spec.initContainers[*].securityContext.seLinuxOptions.user, spec.initContainers[*].securityContext.seLinuxOptions.role,
|
|
|
|
spec.ephemeralContainers[*].securityContext.seLinuxOptions.user, and spec.ephemeralContainers[*].securityContext.seLinuxOptions.role
|
|
|
|
must be unset.
|
|
|
|
pattern:
|
|
|
|
spec:
|
|
|
|
=(securityContext):
|
|
|
|
=(seLinuxOptions):
|
|
|
|
X(user): "null"
|
|
|
|
X(role): "null"
|
|
|
|
=(ephemeralContainers):
|
|
|
|
- =(securityContext):
|
|
|
|
=(seLinuxOptions):
|
|
|
|
X(user): "null"
|
|
|
|
X(role): "null"
|
|
|
|
=(initContainers):
|
|
|
|
- =(securityContext):
|
|
|
|
=(seLinuxOptions):
|
|
|
|
X(user): "null"
|
|
|
|
X(role): "null"
|
|
|
|
containers:
|
|
|
|
- =(securityContext):
|
|
|
|
=(seLinuxOptions):
|
|
|
|
X(user): "null"
|
|
|
|
X(role): "null"
|
|
|
|
{{- end }}
|