Disallow SELinux

SELinux options can be used to escalate privileges and should not be allowed.

Policy Definition

/pod-security/default/disallow-selinux.yaml

apiVersion: kyverno.io/v1
kind: ClusterPolicy
metadata:
  name: disallow-selinux
  annotations:
    policies.kyverno.io/title: Disallow SELinux
    policies.kyverno.io/category: Pod Security Standards (Default)
    policies.kyverno.io/description: >-
      SELinux options can be used to escalate privileges and should not be allowed.
spec:
  validationFailureAction: audit
  background: true
  rules:
  - name: seLinux
    match:
      resources:
        kinds:
        - Pod
    validate:
      message: >-
        Setting custom SELinux options is disallowed. The fields
        spec.securityContext.seLinuxOptions, spec.containers[*].securityContext.seLinuxOptions,
        and spec.initContainers[*].securityContext.seLinuxOptions must be empty.
      pattern:
        spec:
          =(securityContext):
            X(seLinuxOptions): "null"
          =(initContainers):
          - =(securityContext):
              X(seLinuxOptions): "null"
          containers:
          - =(securityContext):
              X(seLinuxOptions): "null"

Last modified January 2, 2021: fix title & sort and regen policies (fa7e171)