devops0: Our audit report says we must "enable Docker rootless mode". I have no clue what that even is...
devops1: Sounds like some another security BS. What's "rootless" supposed to do?
ItSec: Relax. Rootless mode runs the Docker daemon and containers as a regular, unprivileged user [1]. It uses a user namespace, so both the daemon and your containers live in "user space", not as root. That shrinks the blast radius if the daemon or a app in container is compromised, because a breakout wouldn't hand out root on the host.
devops1: Fine. If it's "not hard" to implement, we can consider this.
ItSec: Deal.
Note: this mode does have some limitations. You can review them in docs [2].
First, let's check which user the Docker daemon is currently running as.
ps -C dockerd -o pid,user,group,cmd --no-headers
You should see something like:
9250 root root /usr/bin/dockerd -H fd:// --containerd=/run/containerd/containerd.sock
Here's a clean, minimal path that matches the current docs. First, stop the rootful daemon.
sudo systemctl disable --now docker.service docker.socket
Then install the uid/gid mapping tools. On Ubuntu it's uidmap.
sudo apt update && sudo apt install -y uidmap
Docker provides a setup tool. If you installed official DEB/RPM packages, it's already in /usr/bin. Run it as your normal user.
dockerd-rootless-setuptool.sh install
If that command doesn't exist, install the extras package or use the official rootless script.
sudo apt-get install -y docker-ce-rootless-extras
# or, without package manager access:
curl -fsSL https://get.docker.com/rootless | sh
The tool creates a per-user systemd service, a "rootless" CLI context, and prints environment hints. You usually want your client to talk to the user-scoped socket permanently, so export DOCKER_HOST and persist it in your shell profile.
export DOCKER_HOST=unix:///run/user/$(id -u)/docker.sock
echo 'export DOCKER_HOST=unix:///run/user/$(id -u)/docker.sock' >> ~/.bashrc
Enable auto-start for your user session and let services run even after logout ("linger").
systemctl --user enable docker
sudo loginctl enable-linger $(whoami)
Point the CLI at the new context and sanity-check.
docker context use rootless
Once more, check which privileges the Docker daemon is running with:
ps -C dockerd -o pid,user,group,cmd --no-headers
Now you will see something like:
10728 ubuntu ubuntu dockerd
And pssst! Podman runs containers in "rootless" mode by default [3].
[1] https://docs.docker.com/engine/security/rootless/
[2] https://docs.docker.com/engine/security/rootless/troubleshoot/
[3] https://documentation.suse.com/en-us/smart/container/html/rootless-podman/index.html#rootless-podman-sle
For more grumpy stories visit:
1) https://infosec.exchange/@reynardsec/115093791930794699
2) https://infosec.exchange/@reynardsec/115048607028444198
3) https://infosec.exchange/@reynardsec/115014440095793678
4) https://infosec.exchange/@reynardsec/114912792051851956
5) https://infosec.exchange/@reynardsec/115133293060285123
#appsec #devops #programming #webdev #java #javascript #python #php #docker #containers #k8s #cybersecurity #infosec #cloud #hacking #sysadmin #sysops