Docker security
Detaching from the container without stopping Ctrl-P Ctrl-Q
Create docker user
$ sudo useradd dockeradmin
$ sudo passwd dockeradmin
$ sudo usermod -aG docker dockeradmin
- Users are not namespaced. Root in container is root on host. Create a user in Dockerfile. Change to the user via USER or su/sudo/gosu
RUN groupadd -r user && useradd -r -g user user USER user
- Set container FS to read-only
$ docker run --read-only debian touch x touch: cannot touch 'x': Read-only file system
- Set Volumes to read-only/Use Data Volume Containers
$ docker run -v $(pwd)/secrets:/secrets:ro debian touch /secrets/x touch: cannot touch '/secrets/x': Read-only file system $ docker run --volumes-from my-secret-container myimage
- Drop capabilities
$ docker run --cap-drop SETUID --cap-drop SETGID myimage $ docker run --cap-drop ALL --cap-add ...
- Set CPUSHARES
$ docker run -d myimage $ docker run -d -c 512 myimage
- Set Memory limits
$ docker run -m 512m myimage
- Defang setuid/setgid binaries
// to find them
$ docker run debian \
find / -perm +6000 -type f -exec ls -ld {} \; 2> dev/null
// to defang them
FROM debian:wheezy
RUN find / -perm +6000 -type f -exec chmod a-x {}; \; || true
Auditing (Immutable infrastructure, Audit images, not containers)
tools:
$ docker diff ...
$ scalock
$ twistlock
$ clair
Reference: https://www.youtube.com/watch?v=A32Yjizt2_s
Written on November 16, 2016