Kubernetes workload uses sensitive host directories

Restrict mounts of sensitive host directories to protect node information and files.

Description

Reserve host_path for workloads that need node files, such as log collectors. Give ordinary apps configuration through ConfigMaps or Secrets and data through suitable CSI or managed storage.

Potential impact

Read-only access can still expose sensitive host logs or configuration. Write access can affect files used by the node and other workloads.

Remediation

Limit essential mounts to the smallest required path with read-only access. Restrict who can read the files or modify the workload. If you switch to a PVC, check whether its backing volume still uses hostPath.

Examples

The first excerpt omits the volume name and the container’s volume_mount. Supply complete volume configuration and a supported image for deployment.

Before

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

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

    volume {
      host_path {
        path = "/var/log"
      }
    }
  }
}

It declares the node’s /var/log as a volume source without attaching it to app-container.

After

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

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

The second configuration removes that host volume. Check that other mounts in the deployed Pod do not expose the same files.

References