pod-hostpid
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.
!has(object.spec.hostPID) || object.spec.hostPID == false
Using hostPID is disallowed. spec.hostPID must be undefined or set to false.
Remove spec.hostPID or set it to false. Field: spec.hostPID.
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.
Check a workload against this one policy, before anything is installed on a cluster.
$ kubeapt validate -p ./pod-hostpid.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-hostpid -r ./manifestsOr against every namespace in the cluster your kubeconfig points at:
$ kubeapt validate --policy-name pod-hostpid -A