Understanding Docker Security and Best Practices
blog.docker.com
blog.docker.com
- Run with -icc=false. This should have been the default but isn't for legacy reasons I think. By default there is no firewall between containers. icc=false turns the inter-container firewall on. This is a pretty basic one, but easy for new docker users to miss.
- Host port mapping (e.g. -p 80) by default binds to 0.0.0.0:80 on the host container. This could inadvertently expose your internal services to unexpected interfaces. Specify the host IP you want to bind to explicitly (e.g. -p 127.0.0.1:49123:8080)
- Run inside containers as non-root. Most Dockerfiles you come across will run as root inside the container. In your base image, 'RUN useradd' and in your Dockerfiles add a 'USER' directive, and start the container with -u <user>.
- Set root file system as read-only inside the container. It enforces the best practice that the container should be immutable anyway.
- Instead of --restart:always, try --restart=on-failure:5 to avoid a possible DoS or excessive flapping. Not sure if I 100% agree with this, but it's an interesting suggestion.
/var/run needs to be writable. /tmp needs to be writable and so on. I gave it a shot again today:
$ docker run --read-only=true -ti ubuntu:14.10 touch /tmp/foo
touch: cannot touch '/tmp/foo': Read-only file system
How is this supposed to work? There is little to no information on how this feature works. Can you give me a pointer?
In addition, restart:on-failure appears to have issues if docker itself crashes.
E.g.:
mount -t tmpfs -o size=256M tmpfs /tmp
(I'm not sure if/how you can make Docker do this automatically. I'd imagine there's a flag or something.)[0] https://docs.docker.com/articles/networking/#between-contain...
But I would add: not just form a security perspective but also from a architecture perspective to enforce encapsulation.
Have been wondering about this too: http://stackoverflow.com/questions/29952937/why-is-inter-con...
Maybe they stopped requiring it?
Discouraging people from following security best practice would be counter-productive.
https://benchmarks.cisecurity.org/tools2/docker/CIS_Docker_1...
I don't agree with several decisions that the Docker team has made, but to so grossly oversimplify the matter at hand is unhelpful.
For an example of the opposite approach, look at Sandstorm.io. It forces apps to conform to a strict platform-defined security model where things are isolated "by default" and from there the user can use friendly UI to grant permissions as necessary. This means that currently there are only some 30 apps available on Sandstorm but they are (or will be, when Sandstorm reaches 1.0) "secure by default", or at least much more so than other platforms could claim.
(Disclosure: I'm the lead developer of Sandstorm.)