|
| 1 | +# Rootless vs Rootfull |
| 2 | + |
| 3 | +epics-containers is intended to support both docker and podman. Docker is rootfull by default but also supports rootless operation. Podman is rootless by default but also supports rootfull operation. |
| 4 | + |
| 5 | +Advantages of rootless operation include: |
| 6 | + |
| 7 | +- Security: rootless containers only have the same permissions as the user running them. |
| 8 | +- Ease of use: in an environment where users do not have root privileges, rootless containers can be run without needing to escalate privileges. This is why DLS uses rootless containers. |
| 9 | +- Host mounts: host mounts have the same permissions as the user running the container. |
| 10 | +- Developer containers: rootless containers can be 'root' inside the container, but not on the host. |
| 11 | +- Simplicity: no need to switch users in Dockerfiles - just stay as root and use psuedo-root during runtime. This maps nicely to using the same container in Kubernetes where control of the user id is up to the cluster. |
| 12 | + |
| 13 | +Advantages of rootfull operation include: |
| 14 | + |
| 15 | +- networking: you can create rootable bridge networks that can be accessed from the host |
| 16 | +- power: you can give containers privileged capabilities that the user would not normally have |
| 17 | + |
| 18 | +The advantages of rootless are ideal for developing and executing IOCs. |
| 19 | + |
| 20 | +## Current situation |
| 21 | + |
| 22 | +At present epics-containers requires slightly different configuration for docker and podman. However these differences are really because of the rootfull vs rootless distinction. Those distinctions for docker (rootful) are: |
| 23 | + |
| 24 | +- EC_REMOTE_USER: must be set so that developer containers run as the current user |
| 25 | +- Permissions on the files inside the developer container need to be set with *sudo chown* at startup |
| 26 | +- Developer containers will sometimes have issues with git repo permissions |
| 27 | +- docker compose deployed IOCs do run as root and write any generated files as root in host mounted folders (this needs fixing) |
| 28 | +- UIDGID is required to be passed to the compose file for phoebus to make sure it runs as the correct user (but would not be needed at all for rootless) |
| 29 | + |
| 30 | +## Proposed solution |
| 31 | + |
| 32 | +We should mantate the use of rootless for epics-containers. This will make the configuration simpler and more secure. |
| 33 | + |
| 34 | +A potential issue with this is that developers who use docker for other purposes may need to use rootfull as well. |
| 35 | + |
| 36 | +This would therefore be accetable if it is easy to switch between rootfull and rootless operation. The next section shows how I have done this with docker on Ubuntu 24.04, I would guess that this will work on other distros but this needs to be verified. |
| 37 | + |
| 38 | +## Configure Docker with rootless/rootfull operation |
| 39 | + |
| 40 | +Note that some fixes to epics-containers 'Current Situtation' are required if you switch to rootless operation - we can remove some of the config requirements. |
| 41 | + |
| 42 | +These instructions worked for me on Ubuntu 24.04. Assume docker default install is already done and is at version 27.2.0. |
| 43 | + |
| 44 | +1. docker install comes with a script to set up rootless operation. We use --force to tell it to run even though rootfull is already set up. |
| 45 | + |
| 46 | + ```bash |
| 47 | + sudo dockerd-rootless-setuptool.sh --force |
| 48 | + ``` |
| 49 | + |
| 50 | +1. The script may get errors and explain how to get around them. In my case it asked me to run this: |
| 51 | + ```bash |
| 52 | + sudo sh -eux <<EOF |
| 53 | + # Install newuidmap & newgidmap binaries |
| 54 | + apt-get install -y uidmap |
| 55 | + EOF |
| 56 | + ``` |
| 57 | +
|
| 58 | +1. Make sure the rootfull service is still running (may not need this step). |
| 59 | +
|
| 60 | + ```bash |
| 61 | + sudo systemctl enable --now docker.service docker.socket |
| 62 | + ``` |
| 63 | +
|
| 64 | +1. Now you can switch between both by changing the environment variable DOCKER_HOST. |
| 65 | +
|
| 66 | +1. To switch to rootless: |
| 67 | +
|
| 68 | + ```bash |
| 69 | + export DOCKER_HOST=unix://$XDG_RUNTIME_DIR/docker.sock |
| 70 | + docker ps -a |
| 71 | + ``` |
| 72 | +
|
| 73 | +1. To switch back to rootfull: |
| 74 | +
|
| 75 | + ```bash |
| 76 | + export DOCKER_HOST=unix:///var/run/docker.sock |
| 77 | + docker ps -a |
| 78 | + ``` |
| 79 | +
|
| 80 | +
|
| 81 | +
|
0 commit comments