← Policy catalog
</> ValidatingAdmissionPolicy · Apache-2.0

Shares the Host PID Namespace

pod-hostpid

severityHigh resourcePods productKubernetes bundles2

Sharing the host PID namespace exposes every process on the node to the container, leaking credentials from process command lines and /proc and letting it signal or trace host and other tenant workloads.

Rejects unless

!has(object.spec.hostPID) || object.spec.hostPID == false

Using hostPID is disallowed. spec.hostPID must be undefined or set to false.

Remediation

Remove spec.hostPID or set it to false. Field: spec.hostPID.

Applies to

  • pods · v1 · CREATE, UPDATE

Manifest

apiVersion: admissionregistration.k8s.io/v1
kind: ValidatingAdmissionPolicy
metadata:
  name: pod-hostpid
  annotations:
    kubeapt.io/uuid: "23ef68db-2409-43a1-854d-c46477a533a9"
    security.kubeapt.io/displayName: "Shares the Host PID Namespace"
    security.kubeapt.io/description: "Sharing the host PID namespace exposes every process on the node to the container, leaking credentials from process command lines and /proc and letting it signal or trace host and other tenant workloads."
    security.kubeapt.io/resource: "Pods"
    security.kubeapt.io/severity: "High"
    security.kubeapt.io/remediation: "Remove spec.hostPID or set it to false. Field: spec.hostPID."
    security.kubeapt.io/product: "Kubernetes"
spec:
  failurePolicy: Fail
  matchConstraints:
    resourceRules:
    - apiGroups:
      - ''
      apiVersions:
      - v1
      operations:
      - CREATE
      - UPDATE
      resources:
      - pods
  validations:
  - expression: |
      !has(object.spec.hostPID) || object.spec.hostPID == false
    message: |
      Using hostPID is disallowed. spec.hostPID must be undefined or set to false.

Save it as pod-hostpid.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 ./pod-hostpid.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 pod-hostpid -r ./manifests

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

$ kubeapt validate --policy-name pod-hostpid -A