Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Docker best practices for security [closed]

Most of the Dockerfile you will find on Internet build and run softwares as root ! This must scare everybody, right ? ... but it doesn't seems to be the case ...

So the pb is that running a server as root, even in a container, IS DANGEROUS, because root inside a container is quite the same as root outside the container.

One of the solution is to build a Dockerfile properly by using "USER" instruction like this example for a tor relay.

Another solution is to use the "linux user namespaces" to "map" UID/GID inside container to UID/GID outside a container. for exemple root (uid=0) inside a container can be mapped to your personal user account inside the host, so files created in a shared volume has good permissions.

So my question is :what is the best practice when it comes to security with Docker ? run code as non root (i.e. USER instruction in a Dockerfile) ? Or by using "user namespaces" ? Or eventually (or additionnally) by using selinux and/or AppArmor ?

Thanks :)

like image 387
kondor Avatar asked Dec 02 '14 14:12

kondor


Video Answer


1 Answers

Quoting Solomon Hykes

Hi all, I'm a maintainer of Docker. As others already indicated this doesn't work on 1.0. But it could have.

Please remember that at this time, we don't claim Docker out-of-the-box is suitable for containing untrusted programs with root privileges. So if you're thinking "pfew, good thing we upgraded to 1.0 or we were toast", you need to change your underlying configuration now. Add apparmor or selinux containment, map trust groups to separate machines, or ideally don't grant root access to the application.

So as far as best practices go yes to the namespaces and apparmor or selinux, if you are serious about security. That being said a lot of people don't care enough to go to the extra trouble (For better or worse) so you see a lot of people don't go to the trouble. Setting permissions for users on files inside the container (specially ones mounted as volumes) gets tricky sometimes and that is way a lot of people skip the extra overhead.

like image 77
Usman Ismail Avatar answered Sep 28 '22 20:09

Usman Ismail