Container shares the host PID namespace

Disable host_pid for pods that do not need access to host processes.

Description

Keep host_pid = false unless the workload needs to observe node processes. With true, a container can see processes on the node and in other workloads.

Potential impact

Process details such as command arguments can be exposed. Permission to signal or debug another process also depends on the user ID and additional privileges.

Remediation

Review the purpose and access rights of tools that need host PIDs. Run them as non-root with only the necessary capabilities. Use Pod Security Admission or a policy engine to restrict host namespace sharing for ordinary workloads.

Examples

Replace the example’s nginx:1.7.9 with a maintained image for deployment.

Before

hcl
resource "kubernetes_pod" "pod" {
  metadata {
    name = "terraform-example"
  }

  spec {
    host_pid = true

    container {
      image = "nginx:1.7.9"
      name  = "example"
    }
  }
}

After

hcl
resource "kubernetes_pod" "pod" {
  metadata {
    name = "terraform-example"
  }

  spec {
    host_pid = false

    container {
      image = "nginx:1.7.9"
      name  = "example"
    }
  }
}

The second example disables only PID sharing. Check the deployed Pod for other unnecessary host namespace or file access.

References