Skip to content

Commit 51812cc

Browse files
authored
Merge pull request #271 from linuxserver/nonroot
2 parents 1694068 + 77c1d2d commit 51812cc

4 files changed

Lines changed: 64 additions & 5 deletions

File tree

docs/general/docker-compose.md

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -37,7 +37,6 @@ As v2 runs as a plugin instead of a standalone binary, it is invoked by `docker
3737
Here's a basic example for deploying a Linuxserver container with docker compose:
3838

3939
```yaml
40-
version: "2.1"
4140
services:
4241
heimdall:
4342
image: linuxserver/heimdall
@@ -67,7 +66,6 @@ You can have multiple services managed by a single compose yaml. Copy the conten
6766
Let's say you have the following in a yaml file named `compose.yml`:
6867

6968
```yaml
70-
version: "2.1"
7169
services:
7270
heimdall:
7371
image: linuxserver/heimdall

docs/misc/non-root.md

Lines changed: 62 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,62 @@
1+
# Running Containers As A Non-Root User
2+
3+
!!! warning
4+
Running containers as a non-root user is an advanced topic and should not be undertaken without a full understanding of everything documented below.
5+
6+
## What?
7+
8+
If you run one of our typical images in a standard Docker setup, the container itself will run as `root`. After init we then drop to an unprivileged user, `abc` to run the actual application service(s). We do this because at the time we designed our architecture the alternative - setting a fixed unprivileged user at build time - would have prevented us from offering the range of options that wanted to. While it is now possible to use the `--user` parameter to run any container as an arbitrary user, it hasn't been something we've been able to support before now.
9+
10+
The other approach is to run [Docker itself rootless](https://docs.docker.com/engine/security/rootless/). This creates a separate user and network namespace for your containers and means that even containers nominally running as `root` don't have root permissions on your host. Running a container as a non-root user and running it rootless are **not** the same, but are commonly conflated.
11+
12+
## Why?
13+
14+
Some people take the position that a container running as root *at any point in any configuration* is an unacceptable security risk. Those people typically misunderstand the attack surface of containers and where the risks actually lie. Having said that, there *are* some risks with having containers running as root, depending on the environment; generally, a better solution to running every container as an unprivileged user is to run Docker itself rootless, but that's not always desirable. In these situations, being able to run a single container as a unprivileged user has its benefits.
15+
16+
To give you some sense of the scope of potential risk, let's take our SABnzbd image, imagine you've exposed it to the internet, and for some reason allowed unauthenticated access. Now let's assume a user were to discover a Remote Code Execution vulnerability in SABnzbd, and were able to exploit it to get a shell in the container (not a simple task, but let's be generous). At this point they have a shell running as the unprivileged `abc` account, which heavily limits what they can do. There's no sudo/doas in the container so they'd likely need to chain a Privilege Escalation vulnerability (within the limited set of packages installed) to get root. Even at that point, with root access inside the container, they would then need a further Container Escape vulnerability in order to do anything meaningful to the host beyond simply deleting or modifying data in a mounted path (which they could do as a non-root user anyway). That said, some of our containers do require additional Capabilities to run, and these *could* be exploited by a user with root to affect the host in various ways.
17+
18+
## How?
19+
20+
Creating a container with `--user <uid>:<gid>` or:
21+
22+
```yaml
23+
services:
24+
somecontainer:
25+
image: someimage
26+
user: <uid>:<gid>
27+
```
28+
29+
Will run the container as that user, and that cannot then be changed without recreating it. It's never quite that simple, however.
30+
31+
Our images use s6 as a supervisor and that needs to be able to write its service files to `/run`; many applications expect to be able to write to their working directory, changing UIDs and GIDs requires writing to `/etc/passwd` & `/etc/group`, installing new packages requires writing to numerous locations, and mods need to be extracted to the container filesystem. In short, there are some heavy limitations around operation of our images with a non-root user:
32+
33+
* The PUID & PGID variables will not have any effect, the container will instead run applications with the UID & GID of the user you have specified via the `--user` parameter
34+
* You will need to manually manage the permissions of any mounted volumes or paths
35+
* Docker Mods will not be run
36+
* Custom Services will not be run
37+
* Custom Scripts will be limited in their functionality
38+
39+
For all of these reasons, we recommend you *do not* switch existing container instances to run with a non-root user without careful testing.
40+
41+
For example:
42+
43+
```yaml
44+
services:
45+
sonarr:
46+
image: lscr.io/linuxserver/radarr:latest
47+
container_name: radarr
48+
environment:
49+
- TZ=Europe/London
50+
volumes:
51+
- /path/to/radarr/data:/config
52+
- /path/to/movies:/movies
53+
- /path/to/downloadclient-downloads:/downloads
54+
ports:
55+
- 7878:7878
56+
restart: unless-stopped
57+
user: 1000:1000
58+
```
59+
60+
## Support Policy
61+
62+
Operation of our images with a non-root user is supported on a Reasonable Endeavours basis and *only* for images which we have specifically tested. These images will have their ability to be run with a non-root user noted in the readme, along with any additional caveats. Please see our [Support Policy](https://linuxserver.io/supportpolicy) for more details.

docs/misc/read-only.md

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -57,8 +57,6 @@ services:
5757
image: lscr.io/linuxserver/sonarr:latest
5858
container_name: sonarr
5959
environment:
60-
- PUID=1000
61-
- PGID=1000
6260
- TZ=Europe/London
6361
volumes:
6462
- /path/to/sonarr/data:/config

docs/misc/support-policy.md

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -57,7 +57,6 @@ The following configurations are entirely unsupported and we will not provide he
5757

5858
The following configurations are entirely unsupported and you are unlikely to be able to get them to work at all, or experience serious issues if you do:
5959

60-
* Use of the `user` directive to run containers as a custom UID/GID
6160
* Use of a custom `init` for Docker
6261
* Overriding container entrypoints
6362

@@ -67,9 +66,11 @@ The following configurations don't fit nicely into any single category because "
6766

6867
* Running our containers with a root (`0`) PUID or PGID
6968
* Running our containers with a read-only container filesystem. Please [read the docs](https://docs.linuxserver.io/misc/read-only/).
69+
* Use of the `user` directive to run containers as a custom UID/GID. Please [read the docs](https://docs.linuxserver.io/misc/non-root/).
7070

7171
## Change History
7272

73+
* 2024-12-05 - Move non-root users to Weird Exceptions
7374
* 2024-06-13 - Add read-only running
7475
* 2024-02-13 - Add Weird Exceptions section
7576
* 2024-02-05 - Add ipvlan/macvlan networks

0 commit comments

Comments
 (0)