Docker daemon socket exposed to a container

Remove unnecessary Docker socket mounts and isolate access to the host runtime.

Description

Remove the volume and mount for /var/run/docker.sock from ordinary Pods. A process that can connect to the socket can call the Docker API even through a read-only mount.

Potential impact

The daemon’s permissions determine the impact. A rootful host daemon can give access to other containers and host files.

Remediation

If build or operational automation needs the daemon, use a dedicated builder or isolated environment and allow only the API access it needs. Test normal application behavior after removing the socket.

Examples

The first Pod needs a Docker socket on its node. The second needs an existing /data directory. Supply an accessible image and the application configuration.

Before

yaml
apiVersion: v1
kind: Pod
metadata:
  name: test-pd
spec:
  containers:
    - image: k8s.gcr.io/test-webserver
      name: test-container
      volumeMounts:
        - mountPath: /test-pd
          name: test-volume
  volumes:
    - name: test-volume
      hostPath:
        path: /var/run/docker.sock
        type: Socket

After

yaml
apiVersion: v1
kind: Pod
metadata:
  name: test-pd
spec:
  containers:
    - image: k8s.gcr.io/test-webserver
      name: test-container
      volumeMounts:
        - mountPath: /test-pd
          name: test-volume
  volumes:
    - name: test-volume
      hostPath:
        path: /data
        type: Directory

The second Pod mounts the host’s /data at /test-pd in the container. Expose only the necessary files and make the mount read-only if the app only needs to read them.

References