Kubernetes PodSecurityPolicy permits privileged execution

Prohibit privileged execution for ordinary workloads through admission policy.

Description

In a Terraform-managed PSP, spec.privileged = true allows workloads to request privileged containers. The workload settings determine which containers actually run in that mode.

Potential impact

A container running in privileged mode gains broad access to node resources.

Remediation

Set spec.privileged = false in the legacy policy. Check other policies the workload can use. Prefer the specific capabilities a task needs, isolate unavoidable exceptions with separate policies and nodes, and restrict privilege escalation and host namespace sharing.

Examples

These excerpts require a Terraform provider and cluster that support PSP. Kubernetes deprecated PSP in 1.21 and removed it in 1.25. On newer clusters, enforce the restriction with Pod Security Admission or a policy engine and check that a privileged Pod request is rejected.

Before

hcl
resource "kubernetes_pod_security_policy" "policy" {
  metadata {
    name = "terraform-example"
  }

  spec {
    privileged = true
  }
}

After

hcl
resource "kubernetes_pod_security_policy" "policy" {
  metadata {
    name = "terraform-example"
  }

  spec {
    privileged = false
  }
}

References