id: k8s-host-pid-namespace-sharing info: name: Host PID Namespace Sharing author: princechaddha severity: critical description: Checks if containers in Kubernetes pods share the host's process ID namespace, which can pose a security risk. impact: | Sharing the host's PID namespace allows processes within the pod to view all of the processes on the host, potentially leading to privilege escalation and other security vulnerabilities. remediation: | Ensure that the 'hostPID' field is set to 'false' in Kubernetes Pod specifications to prevent containers from sharing the host's PID namespace. reference: - https://kubernetes.io/docs/concepts/policy/pod-security-policy/#host-namespaces tags: cloud,devops,kubernetes,k8s,devsecops,pods,k8s-cluster-security flow: | code(1); for (let pod of template.items) { set("pod", pod) javascript(1); } self-contained: true code: - engine: - sh - bash source: kubectl get pods --all-namespaces --output=json extractors: - type: json name: items internal: true json: - '.items[]' javascript: - code: | pod = JSON.parse(template.pod); if (pod.spec.hostPID) { let result = (`Pod '${pod.metadata.name}' in namespace '${pod.metadata.namespace}' is sharing the host's PID namespace.`); Export(result); } extractors: - type: dsl dsl: - response # digest: 4b0a00483046022100b6c1a589b8b0530b22668279422d9e367506c2e5cbe53392b1e3871175a185300221008a9d26776f8f10fb9f5e02c5649df5da2f2e9b8dd61a6ff295abfba5a3d8f5b9:922c64590222798bb761d5b6d8e72950