pod-selinux-role
A custom SELinux role label applied pod-wide lets containers transition into domains outside the confined container role, weakening the mandatory access control that keeps a compromised process away from host files and devices.
!has(object.spec.securityContext) || !has(object.spec.securityContext.seLinuxOptions) || !has(object.spec.securityContext.seLinuxOptions.role) || object.spec.securityContext.seLinuxOptions.role == ""
spec.securityContext.seLinuxOptions.role must be undefined or an empty string ("").
Remove the pod-level seLinuxOptions.role setting or leave it as an empty string so the runtime assigns its default container role. Field: spec.securityContext.seLinuxOptions.role.
apiVersion: admissionregistration.k8s.io/v1
kind: ValidatingAdmissionPolicy
metadata:
name: pod-selinux-role
annotations:
kubeapt.io/uuid: "7ee786ba-34bf-43d1-8873-cb16afbe89af"
security.kubeapt.io/displayName: "Sets a Custom SELinux Role"
security.kubeapt.io/description: "A custom SELinux role label applied pod-wide lets containers transition into domains outside the confined container role, weakening the mandatory access control that keeps a compromised process away from host files and devices."
security.kubeapt.io/resource: "Pods"
security.kubeapt.io/severity: "Moderate"
security.kubeapt.io/remediation: "Remove the pod-level seLinuxOptions.role setting or leave it as an empty string so the runtime assigns its default container role. Field: spec.securityContext.seLinuxOptions.role."
security.kubeapt.io/product: "Kubernetes"
spec:
failurePolicy: Fail
matchConstraints:
resourceRules:
- apiGroups:
- ''
apiVersions:
- v1
operations:
- CREATE
- UPDATE
resources:
- pods
validations:
- expression: |
!has(object.spec.securityContext) || !has(object.spec.securityContext.seLinuxOptions) || !has(object.spec.securityContext.seLinuxOptions.role) || object.spec.securityContext.seLinuxOptions.role == ""
message: |
spec.securityContext.seLinuxOptions.role must be undefined or an empty string ("").Save it as pod-selinux-role.yaml — the commands below assume that name.
Check a workload against this one policy, before anything is installed on a cluster.
$ kubeapt validate -p ./pod-selinux-role.yaml -r ./workload.yamlOr without the file, from the published policy set — -r takes a directory too:
$ kubeapt policies download && kubeapt validate --policy-name pod-selinux-role -r ./manifestsOr against every namespace in the cluster your kubeconfig points at:
$ kubeapt validate --policy-name pod-selinux-role -A