Open pcrespov opened 2 years ago
Chatty feedback summary:
Granting a container access to the Docker socket is a powerful capability, essentially allowing the container to control the Docker daemon, and by extension, to manage other containers on the same host. This can introduce significant security risks, especially if the container or the application inside it becomes compromised. However, there are scenarios where such access is required for legitimate purposes. Here are several strategies to safely provide Docker socket access to a container, particularly when running the application as a non-root user:
Docker-in-Docker involves running a Docker daemon inside a Docker container. This is achieved by running the container with a Docker daemon and then binding this inner daemon to a different socket or port. This approach isolates the inner Docker environment from the host Docker daemon but introduces complexity and overhead.
A Docker socket proxy sits between your application and the Docker socket, filtering requests to the Docker API and allowing only a safe subset of actions. This approach can significantly mitigate security risks by restricting what actions can be performed through the Docker socket.
By mounting the Docker socket into the container (-v /var/run/docker.sock:/var/run/docker.sock
) and controlling access through Unix groups, you can limit which users (or containers) can interact with Docker.
This method requires careful management of group permissions and user IDs inside and outside the container.
Create a dedicated service account on the host with specific permissions to interact with Docker. Use this account exclusively for containers requiring Docker access. This strategy involves more nuanced control at the host level and may require additional tools or scripts to manage permissions and capabilities.
When using container orchestration tools like Kubernetes, you can define security contexts for your pods. These contexts allow you to manage permissions and capabilities, including Docker socket access, in a more controlled and declarative manner.
Choosing the right strategy depends on your specific use case, security requirements, and operational environment. Combining these strategies with robust security practices can help mitigate the risks associated with Docker socket access.
We should have a well defined procedure to guarantee the security of any service with access to the docker daemon.
SEE comment:
_Originally posted by @mrnicegyu11 in https://github.com/ITISFoundation/osparc-simcore/pull/3364#discussion_r987823199_