Daemon Socket
Main Purpose
Main entry point and persistent process for Docker API on host OS by interfacing with underlying host kernel. UNIX socket is used by default as compared to TCP to prevent remote connection from unknown sources "hosts": ["unix:///var/run/docker.sock"]
Uses Cases
Proxy configurations if container is behind an HTTP proxy server
Interacting with other containers
Logging purposes
Attack Vectors
Privilege Escalation via Mount
Different parts of filesystem can be mounted in container with root access because docker socket runs as root. This allows escalation of privileges within the container to root privileges and potentially, enabling attackers access and modity host filesystem.
Container Escape
If container happens to run as privilege or container has improper access control, it is possible to remove all isolation from container and execute commands on actual host system.
Access control plugins can also be bypassed:
Defenses
Use SSH
If remote connection is needed, use SSH on DOCKER_HOST
to ensure only SSH remote connections are permitted and not via TCP due to security reasons. TLS with CA cert can be used as an alternative.
Ensure Socket is not Mounted
Run -v /var/run/docker.sock:/var/run/docker.sock
to ensure socket flag is not present within the container. Do not run docker run -it -v /var/run/docker.sock:/var/run/docker.sock ubuntu /bin/bash
.
Run containers as non-root users
Reduce container user privileges by running as non-root.
Additional information:
Interview Questions
What is Docker Socket used for?
What are the attack vectors using the socket?
Explain some mitigation methods to prevent socket abuse. (Can list more examples not written here)
Author
References
Last updated