Kubernetes container runs in privileged mode

Disable unnecessary privileged mode in Kubernetes containers.

Description

For a Linux container, privileged = true grants broad access to devices and kernel functions. The process UID and privileged mode are separate settings.

Potential impact

A compromised container can affect the node and other workloads, depending on its devices, mounts and access.

Remediation

Set privileged = false in the security_context of application and init containers. Review capabilities, hostPath mounts and shared host namespaces. Isolate unavoidable exceptions with dedicated nodes and policies and keep their privileges narrow.

Examples

Only app-container’s privileged setting changes here. For deployment, select a maintained image and verify the service starts without privileged mode.

Before

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

  spec {
    container {
      image = "nginx:1.7.9"
      name  = "app-container"

      security_context {
        privileged = true
      }
    }
  }
}

After

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

  spec {
    container {
      image = "nginx:1.7.9"
      name  = "app-container"

      security_context {
        privileged = false
      }
    }
  }
}

References