Description
Remove both the Docker socket’s host_path volume and its volume_mount from a Terraform-managed Pod that does not need the daemon. A read-only socket mount still allows API calls that change state.
Potential impact
On a node with a Docker socket, a process permitted to connect can access other containers or host resources with the daemon’s authority. Nodes using other runtimes may have no such socket.
Remediation
Isolate build and administration tasks that need the socket. Restrict which identities and API operations they can use, enforce limits on host mounts and privileged mode, and verify that the deployed app works without the socket.
Examples
The example nginx workload does not need the Docker API. Use a maintained image in place of nginx:1.7.9 for deployment.
Before
resource "kubernetes_pod" "pod" {
metadata {
name = "terraform-example"
}
spec {
volume {
name = "docker-socket"
host_path {
path = "/var/run/docker.sock"
type = "Socket"
}
}
container {
image = "nginx:1.7.9"
name = "example"
volume_mount {
name = "docker-socket"
mount_path = "/var/run/docker.sock"
}
}
}
}
After
resource "kubernetes_pod" "pod" {
metadata {
name = "terraform-example"
}
spec {
container {
image = "nginx:1.7.9"
name = "example"
}
}
}
The second example removes the docker-socket volume and its mount from the container.