Is Mounting the Docker Socket Without Privileges Safe?

0
0
Asked By CleverPineapple27 On

I'm curious about the security aspects of mounting the Docker socket but with all capabilities dropped. Here's a snippet of my Docker Compose service configuration:

service:
image: docker:28.3-cli
restart: always
container_name: service
volumes:
- /var/run/docker.sock:/var/run/docker.sock:ro
entrypoint: >
/bin/sh -c '
...
docker exec ...;
...
'
networks:
- internal
security_opt:
- no-new-privileges:true
cap_drop:
- ALL

I have to mount the socket here since the service needs to run Docker commands. It's on an `internal` network, which connects only to localhost and has no external internet access. Given these security measures, is it still possible for this setup to be exploited?

4 Answers

Answered By RealisticRaccoon22 On

Honestly, I'd say if your priority is security, avoid mounting the Docker socket entirely. Try connecting to the Docker TCP API instead or consider a socket proxy to limit permissions more effectively. And if you really want to be safe, think about running Docker rootless. Also, keep in mind, using ':ro' on the socket doesn’t really add security.

Answered By CuriousSparrow98 On

Just a heads up, even though it seems secure since you're on an internal network, the Docker socket can still allow you to create new networks and launch new containers, maybe even privileged ones.

Answered By InquisitiveOtter45 On

Remember that the socket itself doesn't hold privileges; it connects directly to the Docker daemon. Any software that can access this socket can control the daemon as its user, so dropping capabilities in the container really doesn't help.

Answered By ProActiveChipmunk84 On

For anyone looking for alternatives, check out this Docker socket proxy: https://github.com/11notes/docker-socket-proxy.

Related Questions

LEAVE A REPLY

Please enter your comment!
Please enter your name here

This site uses Akismet to reduce spam. Learn how your comment data is processed.