OWASP Recommenation for Docker is not to share /var/run/docker.sock with containers #2507
Replies: 3 comments 1 reply
-
This is a very interesting question, thanks for asking it. I'm no Docker security expert but I'll try to answer as best as I can. Short answer
I completely agree. traefik is in the exact same situation and I quite like their documentation about this. And, like traefik, nginx-proxy can't work without access to the Docker daemon API in one form or in another. More detailed answerWhy does nginx-proxy (more specifically docker-gen) need access to the Docker daemon ?
As you can see all of those save one are just reading stuff, so what if we could just simply restrict permissions on the Docker daemon socket ? Well, no we can't, not simply anyway:
Creating or using Docker authorization plugins is a topic way, way outside the scope of this repository. So what could we do without taking Docker authorization plugins route ?
Regarding the second point (securing the Docker daemon socket with SSH or TLS) that OWASP insist on : it's not clear to me what difference that would make if the container that have access to the secured endpoint is compromised. AFAIK, if you gain access to this container you also gain access to the SHH or TLS credentials and then to the endpoint, exactly as if the Docker socket was directly mounted to the container. 🤔 I think that 1) and 3) are the most immediately important, followed by 2), but again I'm no Docker security expert. |
Beta Was this translation helpful? Give feedback.
-
If you need nginx and cert renewal you can use https://github.com/JonasAlfredsson/docker-nginx-certbot, it doesn't need docker.sock exposed. |
Beta Was this translation helpful? Give feedback.
-
I would argue the threat model doesn't change significantly changing from using local Unix socket to TCP based TLS/SSH locally. Given the additional complexity and not default behavior, there's not a security win there. If you were already accessing your docker API remotely, then using an encrypted transport is critical but that's not possible with UNIX sockets so changing a local API call to a different local API call buys you almost no benefit and adds a lot of complexity and opportunity to make things worse. The other notes I think are all solid: use separate containers so internet facing ones don't have docker API access and add an AuthZ plugin if you really think you need it, though is pretty advanced. For hardening some other good ones that get you pretty far are running nginx as non-root and providing read-only file systems to limit living off the land if someone does break in. Active monitoring and hardening your origin servers can also be done if you need to secure your deployment. |
Beta Was this translation helpful? Give feedback.
Uh oh!
There was an error while loading. Please reload this page.
-
I am using nginx-proxy and the acme-companion, and I really like the control and automation this solution provides.
I even wrote a blog post about it.
It was brought to my attention that sharing the /var/run/docker.sock goes against the OWASP rules for Docker security:
https://cheatsheetseries.owasp.org/cheatsheets/Docker_Security_Cheat_Sheet.html#rule-1-do-not-expose-the-docker-daemon-socket-even-to-the-containers
What do you recommend here? Is there any way around it?
Maybe it makes sense to add a discussion about the associated risks to the documentation.
Thank you.
Beta Was this translation helpful? Give feedback.
All reactions