Review protection of Kubernetes OS directory mounts

Check the volume source and write restrictions for OS directory mounts to prevent unnecessary file changes.

Description

A mount_path names a location inside the container. Before mounting a volume at a system path such as /bin, check its source and expose only the required files.

Potential impact

File permissions may allow changes to application binaries or configuration. If the source contains host files, changes can also affect the node or other workloads.

Remediation

Set read_only = true where writes are unnecessary. Check nested mounts, other access paths, file permissions, privileged mode and capabilities separately.

Examples

Both excerpts omit the volume definitions that back their mounts. Specify the actual sources and replace nginx:1.7.9 with 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_mount {
        name       = "system-bin"
        mount_path = "/bin"
      }
    }
  }
}

The first example mounts system-bin at /bin without requesting read-only access.

After

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

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

      volume_mount {
        name       = "config-volume"
        mount_path = "/etc/config"
        read_only  = true
      }
    }
  }
}

The second mounts config-volume read-only at /etc/config. Verify that the new source contains only the configuration the application needs.

References