Description
Use host_path for an application only if it needs the node’s files. When switching to a PVC, check whether its backing volume still points to a host path.
Potential impact
Mounting host logs or configuration can expose data or allow changes to files used by other workloads, depending on permissions. Moving the Pod to kube-system leaves those permissions unchanged.
Remediation
Move ordinary application data to suitable CSI or managed storage. For essential host mounts, expose the smallest path, make it read-only where possible and consider dedicated nodes. Restrict who can create or change the workload.
Examples
The first excerpt omits a volume name, a container and its mount. Supply these for deployment and use a maintained image in place of the second example’s older one.
Before
resource "kubernetes_pod" "app_pod" {
metadata {
name = "terraform-example"
namespace = "default"
}
spec {
volume {
host_path {
path = "/var/log"
}
}
}
}
After
resource "kubernetes_pod" "app_pod" {
metadata {
name = "terraform-example"
namespace = "default"
}
spec {
container {
image = "nginx:1.7.9"
name = "app-container"
}
}
}
The second Pod removes the declaration for the node’s /var/log. Check that other volumes or permissions do not expose the same host path.