pod-windows-hostprocess
A Windows HostProcess pod runs its containers directly on the node in the host namespaces under a system account, exposing the host filesystem, registry and services and making node compromise trivial.
!has(object.spec.securityContext) || !has(object.spec.securityContext.windowsOptions) || !has(object.spec.securityContext.windowsOptions.hostProcess) || object.spec.securityContext.windowsOptions.hostProcess == false
HostProcess is not allowed. spec.securityContext.windowsOptions.hostProcess must be undefined or set to false.
Remove windowsOptions.hostProcess from the pod security context or set it to false. Field: spec.securityContext.windowsOptions.hostProcess.
apiVersion: admissionregistration.k8s.io/v1
kind: ValidatingAdmissionPolicy
metadata:
name: pod-windows-hostprocess
annotations:
kubeapt.io/uuid: "042cc512-57cb-4fcb-8936-d302caf7012a"
security.kubeapt.io/displayName: "Runs as a Windows HostProcess"
security.kubeapt.io/description: "A Windows HostProcess pod runs its containers directly on the node in the host namespaces under a system account, exposing the host filesystem, registry and services and making node compromise trivial."
security.kubeapt.io/resource: "Pods"
security.kubeapt.io/severity: "High"
security.kubeapt.io/remediation: "Remove windowsOptions.hostProcess from the pod security context or set it to false. Field: spec.securityContext.windowsOptions.hostProcess."
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.windowsOptions) || !has(object.spec.securityContext.windowsOptions.hostProcess) || object.spec.securityContext.windowsOptions.hostProcess == false
message: |
HostProcess is not allowed. spec.securityContext.windowsOptions.hostProcess must be undefined or set to false.Save it as pod-windows-hostprocess.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-windows-hostprocess.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-windows-hostprocess -r ./manifestsOr against every namespace in the cluster your kubeconfig points at:
$ kubeapt validate --policy-name pod-windows-hostprocess -A