pod-selinux-user
A custom SELinux user label at pod level replaces the confined context the runtime assigns to every container, granting a policy domain with transitions and file access the sandbox was never meant to allow.
!has(object.spec.securityContext) || !has(object.spec.securityContext.seLinuxOptions) || !has(object.spec.securityContext.seLinuxOptions.user) || object.spec.securityContext.seLinuxOptions.user == ""
spec.securityContext.seLinuxOptions.user must be undefined or an empty string ("").
Remove the pod-level seLinuxOptions.user setting or leave it as an empty string so the runtime assigns its default SELinux user. Field: spec.securityContext.seLinuxOptions.user.
apiVersion: admissionregistration.k8s.io/v1
kind: ValidatingAdmissionPolicy
metadata:
name: pod-selinux-user
annotations:
kubeapt.io/uuid: "2d1a986b-a524-422b-83b0-aafe9cd95f55"
security.kubeapt.io/displayName: "Sets a Custom SELinux User"
security.kubeapt.io/description: "A custom SELinux user label at pod level replaces the confined context the runtime assigns to every container, granting a policy domain with transitions and file access the sandbox was never meant to allow."
security.kubeapt.io/resource: "Pods"
security.kubeapt.io/severity: "Moderate"
security.kubeapt.io/remediation: "Remove the pod-level seLinuxOptions.user setting or leave it as an empty string so the runtime assigns its default SELinux user. Field: spec.securityContext.seLinuxOptions.user."
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.user) || object.spec.securityContext.seLinuxOptions.user == ""
message: |
spec.securityContext.seLinuxOptions.user must be undefined or an empty string ("").Save it as pod-selinux-user.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-user.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-user -r ./manifestsOr against every namespace in the cluster your kubeconfig points at:
$ kubeapt validate --policy-name pod-selinux-user -A