← Policy catalog
</> ValidatingAdmissionPolicy · Apache-2.0

Runs as a Windows HostProcess

initcontainer-windows-hostprocess

severityHigh resourceInitContainers productKubernetes bundles2

A Windows HostProcess init 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

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

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

Remediation

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

Applies to

  • pods · v1 · CREATE, UPDATE

Manifest

apiVersion: admissionregistration.k8s.io/v1
kind: ValidatingAdmissionPolicy
metadata:
  name: initcontainer-windows-hostprocess
  annotations:
    kubeapt.io/uuid: "40d17131-f0d2-4bde-804d-dff8036e221c"
    security.kubeapt.io/displayName: "Runs as a Windows HostProcess"
    security.kubeapt.io/description: "A Windows HostProcess init 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: "InitContainers"
    security.kubeapt.io/severity: "High"
    security.kubeapt.io/remediation: "Remove windowsOptions.hostProcess from every init container security context or set it to false. Field: spec.initContainers[*].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.initContainers) || object.spec.initContainers.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 initContainers. Each spec.initContainers[*].securityContext.windowsOptions.hostProcess must be undefined or set to false.

Save it as initcontainer-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 ./initcontainer-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 initcontainer-windows-hostprocess -r ./manifests

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

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