← Policy catalog
</> ValidatingAdmissionPolicy · Apache-2.0

Runs as a Windows HostProcess

container-windows-hostprocess

severityHigh resourceContainers productKubernetes bundles2

A Windows HostProcess container runs directly on the node in the host namespaces under a system account, exposing the host filesystem, registry and services and making node compromise trivial.

Rejects unless

object.spec.containers.all(c,
  !has(c.securityContext) ||
  !has(c.securityContext.windowsOptions) ||
  !has(c.securityContext.windowsOptions.hostProcess) ||
  c.securityContext.windowsOptions.hostProcess == false
)

HostProcess is not allowed for containers. Each spec.containers[*].securityContext.windowsOptions.hostProcess must be undefined or set to false.

Remediation

Remove windowsOptions.hostProcess from every container security context or set it to false. Field: spec.containers[*].securityContext.windowsOptions.hostProcess.

Applies to

  • pods · v1 · CREATE, UPDATE

Manifest

apiVersion: admissionregistration.k8s.io/v1
kind: ValidatingAdmissionPolicy
metadata:
  name: container-windows-hostprocess
  annotations:
    kubeapt.io/uuid: "6dd987f5-a988-40f2-bce8-d6eef4c6eb4d"
    security.kubeapt.io/displayName: "Runs as a Windows HostProcess"
    security.kubeapt.io/description: "A Windows HostProcess container runs 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: "Containers"
    security.kubeapt.io/severity: "High"
    security.kubeapt.io/remediation: "Remove windowsOptions.hostProcess from every container security context or set it to false. Field: spec.containers[*].securityContext.windowsOptions.hostProcess."
    security.kubeapt.io/product: "Kubernetes"
spec:
  failurePolicy: Fail
  matchConstraints:
    resourceRules:
    - apiGroups:
      - ''
      apiVersions:
      - v1
      operations:
      - CREATE
      - UPDATE
      resources:
      - pods
  validations:
  - expression: |
      object.spec.containers.all(c,
        !has(c.securityContext) ||
        !has(c.securityContext.windowsOptions) ||
        !has(c.securityContext.windowsOptions.hostProcess) ||
        c.securityContext.windowsOptions.hostProcess == false
      )
    message: |
      HostProcess is not allowed for containers. Each spec.containers[*].securityContext.windowsOptions.hostProcess must be undefined or set to false.

Save it as container-windows-hostprocess.yaml — the commands below assume that name.

Validate with kubeapt

Check a workload against this one policy, before anything is installed on a cluster.

$ kubeapt validate -p ./container-windows-hostprocess.yaml -r ./workload.yaml

Or without the file, from the published policy set — -r takes a directory too:

$ kubeapt policies download && kubeapt validate --policy-name container-windows-hostprocess -r ./manifests

Or against every namespace in the cluster your kubeconfig points at:

$ kubeapt validate --policy-name container-windows-hostprocess -A