Skip to content

Commit fb101e5

Browse files
authored
Merge pull request #300 from linuxserver/nonroot
2 parents a8ab7ad + a21d375 commit fb101e5

6 files changed

Lines changed: 57 additions & 34 deletions

File tree

Dockerfile

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
# syntax=docker/dockerfile:1
22

3-
FROM ghcr.io/linuxserver/unrar:latest as unrar
3+
FROM ghcr.io/linuxserver/unrar:latest AS unrar
44

55
FROM ghcr.io/linuxserver/baseimage-alpine:edge
66

Dockerfile.aarch64

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
# syntax=docker/dockerfile:1
22

3-
FROM ghcr.io/linuxserver/unrar:arm64v8-latest as unrar
3+
FROM ghcr.io/linuxserver/unrar:arm64v8-latest AS unrar
44

55
FROM ghcr.io/linuxserver/baseimage-alpine:arm64v8-edge
66

README.md

Lines changed: 14 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -83,6 +83,14 @@ Use `HOST_WHITELIST` to enable an list of dns names as host-whitelist. This enab
8383

8484
Use `PEERPORT` to specify the port(s) Transmission should listen on. This disables random port selection. This should be the same as the port mapped in your docker configuration.
8585

86+
## Read-Only Operation
87+
88+
This image can be run with a read-only container filesystem. For details please [read the docs](https://docs.linuxserver.io/misc/read-only/).
89+
90+
## Non-Root Operation
91+
92+
This image can be run with a non-root user. For details please [read the docs](https://docs.linuxserver.io/misc/non-root/).
93+
8694
## Usage
8795

8896
To help you get started creating a container from this image you can either use docker-compose or the docker cli.
@@ -110,8 +118,8 @@ services:
110118
- HOST_WHITELIST= #optional
111119
volumes:
112120
- /path/to/transmission/data:/config
113-
- /path/to/downloads:/downloads
114-
- /path/to/watch/folder:/watch
121+
- /path/to/downloads:/downloads #optional
122+
- /path/to/watch/folder:/watch #optional
115123
ports:
116124
- 9091:9091
117125
- 51413:51413
@@ -137,8 +145,8 @@ docker run -d \
137145
-p 51413:51413 \
138146
-p 51413:51413/udp \
139147
-v /path/to/transmission/data:/config \
140-
-v /path/to/downloads:/downloads \
141-
-v /path/to/watch/folder:/watch \
148+
-v /path/to/downloads:/downloads `#optional` \
149+
-v /path/to/watch/folder:/watch `#optional` \
142150
--restart unless-stopped \
143151
lscr.io/linuxserver/transmission:latest
144152
```
@@ -164,6 +172,8 @@ Containers are configured using parameters passed at runtime (such as those abov
164172
| `-v /config` | Where transmission should store config files and logs. |
165173
| `-v /downloads` | Local path for downloads. |
166174
| `-v /watch` | Watch folder for torrent files. |
175+
| `--read-only=true` | Run container with a read-only filesystem. Please [read the docs](https://docs.linuxserver.io/misc/read-only/). |
176+
| `--user=1000:1000` | Run container with a non-root user. Please [read the docs](https://docs.linuxserver.io/misc/non-root/). |
167177

168178
## Environment variables from files (Docker secrets)
169179

readme-vars.yml

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,8 @@ param_container_name: "{{ project_name }}"
1616
param_usage_include_vols: true
1717
param_volumes:
1818
- {vol_path: "/config", vol_host_path: "/path/to/{{ project_name }}/data", desc: "Where transmission should store config files and logs."}
19+
opt_param_usage_include_vols: true
20+
opt_param_volumes:
1921
- {vol_path: "/downloads", vol_host_path: "/path/to/downloads", desc: "Local path for downloads."}
2022
- {vol_path: "/watch", vol_host_path: "/path/to/watch/folder", desc: "Watch folder for torrent files."}
2123
param_usage_include_ports: true
@@ -32,6 +34,8 @@ opt_param_env_vars:
3234
- {env_var: "WHITELIST", env_value: "", desc: "Specify an optional list of comma separated ip whitelist. Fills rpc-whitelist setting."}
3335
- {env_var: "PEERPORT", env_value: "", desc: "Specify an optional port for torrent TCP/UDP connections. Fills peer-port setting."}
3436
- {env_var: "HOST_WHITELIST", env_value: "", desc: "Specify an optional list of comma separated dns name whitelist. Fills rpc-host-whitelist setting."}
37+
readonly_supported: true
38+
nonroot_supported: true
3539
# application setup block
3640
app_setup_block_enabled: true
3741
app_setup_block: |
Lines changed: 28 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -1,36 +1,32 @@
11
#!/usr/bin/with-contenv bash
22
# shellcheck shell=bash
33

4-
# make folders
5-
mkdir -p \
6-
/downloads/{complete,incomplete} /watch
7-
84
# copy config
95
if [[ ! -f /config/settings.json ]]; then
106
cp /defaults/settings.json /config/settings.json
117
fi
128

139
if [[ -n "${USER}" ]] && [[ -n "${PASS}" ]]; then
1410
echo -E "$(jq -r '.["rpc-authentication-required"] = true' /config/settings.json)" >/config/settings.json
11+
echo -E "$(jq -r --arg user "${USER}" '.["rpc-username"] = $user' /config/settings.json)" >/config/settings.json
12+
echo -E "$(jq -r --arg pass "${PASS}" '.["rpc-password"] = $pass' /config/settings.json)" >/config/settings.json
1513
else
1614
echo -E "$(jq -r '.["rpc-authentication-required"] = false' /config/settings.json)" >/config/settings.json
1715
fi
18-
echo -E "$(jq -r --arg user "${USER}" '.["rpc-username"] = $user' /config/settings.json)" >/config/settings.json
19-
echo -E "$(jq -r --arg pass "${PASS}" '.["rpc-password"] = $pass' /config/settings.json)" >/config/settings.json
2016

2117
if [[ -n "${WHITELIST}" ]]; then
2218
echo -E "$(jq -r '.["rpc-whitelist-enabled"] = true' /config/settings.json)" >/config/settings.json
19+
echo -E "$(jq -r --arg whitelist "${WHITELIST}" '.["rpc-whitelist"] = $whitelist' /config/settings.json)" >/config/settings.json
2320
else
2421
echo -E "$(jq -r '.["rpc-whitelist-enabled"] = false' /config/settings.json)" >/config/settings.json
2522
fi
26-
echo -E "$(jq -r --arg whitelist "${WHITELIST}" '.["rpc-whitelist"] = $whitelist' /config/settings.json)" >/config/settings.json
2723

2824
if [[ -n "${HOST_WHITELIST}" ]]; then
2925
echo -E "$(jq -r '.["rpc-host-whitelist-enabled"] = true' /config/settings.json)" >/config/settings.json
26+
echo -E "$(jq -r --arg host_whitelist "${HOST_WHITELIST}" '.["rpc-host-whitelist"] = $host_whitelist' /config/settings.json)" >/config/settings.json
3027
else
3128
echo -E "$(jq -r '.["rpc-host-whitelist-enabled"] = false' /config/settings.json)" >/config/settings.json
3229
fi
33-
echo -E "$(jq -r --arg host_whitelist "${HOST_WHITELIST}" '.["rpc-host-whitelist"] = $host_whitelist' /config/settings.json)" >/config/settings.json
3430

3531
if [[ -n "${PEERPORT}" ]]; then
3632
echo -E "$(jq -r --argjson peerport "${PEERPORT}" '.["peer-port"] = $peerport' /config/settings.json)" >/config/settings.json
@@ -41,26 +37,33 @@ if [[ -n "${UMASK}" ]]; then
4137
echo -E "$(jq -r --arg umask "${UMASK}" '.["umask"] = $umask' /config/settings.json)" >/config/settings.json
4238
fi
4339

44-
# Handle old theme locations
45-
mkdir -p {/transmissionic,/combustion-release,/flood-for-transmission,/kettu,/transmission-web-control}
46-
echo /transmissionic /combustion-release /flood-for-transmission /kettu /transmission-web-control | xargs -n1 ln -s /defaults/index.html
40+
if [[ -z ${LSIO_NON_ROOT_USER} ]] && [[ -z ${LSIO_READ_ONLY_FS} ]]; then
41+
# Handle old theme locations
42+
mkdir -p {/transmissionic,/combustion-release,/flood-for-transmission,/kettu,/transmission-web-control}
43+
echo /transmissionic /combustion-release /flood-for-transmission /kettu /transmission-web-control | xargs -n1 ln -s /defaults/index.html
44+
fi
4745

48-
# permissions
49-
lsiown abc:abc \
50-
/config/settings.json
46+
if [[ -z ${LSIO_NON_ROOT_USER} ]]; then
47+
lsiown -R abc:abc \
48+
/config
5149

52-
if [[ "$(stat -c '%U' /downloads)" != "abc" ]]; then
53-
lsiown abc:abc /downloads
54-
fi
50+
if grep -qe ' /downloads ' /proc/mounts; then
51+
if [[ "$(stat -c '%U' /downloads)" != "abc" ]]; then
52+
lsiown abc:abc /downloads
53+
fi
5554

56-
if [[ "$(stat -c '%U' /downloads/complete)" != "abc" ]]; then
57-
lsiown abc:abc /downloads/complete
58-
fi
55+
if [[ "$(stat -c '%U' /downloads/complete)" != "abc" ]]; then
56+
lsiown abc:abc /downloads/complete
57+
fi
5958

60-
if [[ "$(stat -c '%U' /downloads/incomplete)" != "abc" ]]; then
61-
lsiown abc:abc /downloads/incomplete
62-
fi
59+
if [[ "$(stat -c '%U' /downloads/incomplete)" != "abc" ]]; then
60+
lsiown abc:abc /downloads/incomplete
61+
fi
62+
fi
6363

64-
if [[ "$(stat -c '%U' /watch)" != "abc" ]]; then
65-
lsiown abc:abc /watch
64+
if grep -qe ' /watch ' /proc/mounts; then
65+
if [[ "$(stat -c '%U' /watch)" != "abc" ]]; then
66+
lsiown abc:abc /watch
67+
fi
68+
fi
6669
fi

root/etc/s6-overlay/s6-rc.d/svc-transmission/run

Lines changed: 9 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,12 @@
33

44
PORT=$(jq '.["rpc-port"]' /config/settings.json)
55

6-
s6-notifyoncheck -d -n 300 -w 1000 -c "nc -z localhost ${PORT:-9091}" \
7-
s6-setuidgid abc /usr/bin/transmission-daemon \
8-
-g /config -f
6+
if [[ -z ${LSIO_NON_ROOT_USER} ]]; then
7+
s6-notifyoncheck -d -n 300 -w 1000 -c "nc -z localhost ${PORT:-9091}" \
8+
s6-setuidgid abc /usr/bin/transmission-daemon \
9+
-g /config -f
10+
else
11+
s6-notifyoncheck -d -n 300 -w 1000 -c "nc -z localhost ${PORT:-9091}" \
12+
/usr/bin/transmission-daemon \
13+
-g /config -f
14+
fi

0 commit comments

Comments
 (0)