Skip to content

Commit e7921f9

Browse files
authored
Merge pull request #56 from linuxserver/3.21
rebase to 3.21, add support for non-root and read-only
2 parents ce60d2d + fbb5908 commit e7921f9

File tree

9 files changed

+50
-26
lines changed

9 files changed

+50
-26
lines changed

Dockerfile

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

3-
FROM ghcr.io/linuxserver/baseimage-alpine:3.20
3+
FROM ghcr.io/linuxserver/baseimage-alpine:3.21
44

55
# set version label
66
ARG BUILD_DATE
@@ -13,8 +13,6 @@ RUN \
1313
echo "**** install build packages ****" && \
1414
apk add --no-cache --virtual=build-dependencies \
1515
build-base \
16-
cargo \
17-
libffi-dev \
1816
openldap-dev \
1917
python3-dev && \
2018
echo "**** install runtime packages ****" && \
@@ -29,7 +27,7 @@ RUN \
2927
pip install -U --no-cache-dir \
3028
pip \
3129
wheel && \
32-
pip install -U --no-cache-dir --find-links https://wheel-index.linuxserver.io/alpine-3.20/ \
30+
pip install -U --no-cache-dir --find-links https://wheel-index.linuxserver.io/alpine-3.21/ \
3331
cryptography \
3432
python-ldap=="${LDAP_VERSION}" && \
3533
printf "Linuxserver.io version: ${VERSION}\nBuild-date: ${BUILD_DATE}" > /build_version && \
@@ -38,8 +36,7 @@ RUN \
3836
build-dependencies && \
3937
rm -rf \
4038
/tmp/* \
41-
$HOME/.cache \
42-
$HOME/.cargo
39+
$HOME/.cache
4340

4441
# copy local files
4542
COPY root/ /

Dockerfile.aarch64

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

3-
FROM ghcr.io/linuxserver/baseimage-alpine:arm64v8-3.20
3+
FROM ghcr.io/linuxserver/baseimage-alpine:arm64v8-3.21
44

55
# set version label
66
ARG BUILD_DATE
@@ -13,8 +13,6 @@ RUN \
1313
echo "**** install build packages ****" && \
1414
apk add --no-cache --virtual=build-dependencies \
1515
build-base \
16-
cargo \
17-
libffi-dev \
1816
openldap-dev \
1917
python3-dev && \
2018
echo "**** install runtime packages ****" && \
@@ -29,7 +27,7 @@ RUN \
2927
pip install -U --no-cache-dir \
3028
pip \
3129
wheel && \
32-
pip install -U --no-cache-dir --find-links https://wheel-index.linuxserver.io/alpine-3.20/ \
30+
pip install -U --no-cache-dir --find-links https://wheel-index.linuxserver.io/alpine-3.21/ \
3331
cryptography \
3432
python-ldap=="${LDAP_VERSION}" && \
3533
printf "Linuxserver.io version: ${VERSION}\nBuild-date: ${BUILD_DATE}" > /build_version && \
@@ -38,8 +36,7 @@ RUN \
3836
build-dependencies && \
3937
rm -rf \
4038
/tmp/* \
41-
$HOME/.cache \
42-
$HOME/.cargo
39+
$HOME/.cache
4340

4441
# copy local files
4542
COPY root/ /

README.md

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -64,6 +64,14 @@ The architectures supported by this image are:
6464
- Unlike the upstream project, this image encodes the cookie information with fernet, using a randomly generated key during container creation (or optionally user defined).
6565
- Also unlike the upstream project, this image serves the login page at `/ldaplogin` (as well as `/login`) to prevent clashes with reverse proxied apps that may also use `/login` for their internal auth.
6666

67+
## Read-Only Operation
68+
69+
This image can be run with a read-only container filesystem. For details please [read the docs](https://docs.linuxserver.io/misc/read-only/).
70+
71+
## Non-Root Operation
72+
73+
This image can be run with a non-root user. For details please [read the docs](https://docs.linuxserver.io/misc/non-root/).
74+
6775
## Usage
6876

6977
To help you get started creating a container from this image you can either use docker-compose or the docker cli.
@@ -123,6 +131,8 @@ Containers are configured using parameters passed at runtime (such as those abov
123131
| `-e FERNETKEY=` | Optionally define a custom valid fernet key (only needed if container is frequently recreated, or if using multi-node setups, invalidating previous authentications) |
124132
| `-e CERTFILE=` | Optionally point this to a certificate file to enable HTTP over SSL (HTTPS) for the ldap auth daemon |
125133
| `-e KEYFILE=` | Optionally point this to the private key file, matching the certificate file referred to in CERTFILE |
134+
| `--read-only=true` | Run container with a read-only filesystem. Please [read the docs](https://docs.linuxserver.io/misc/read-only/). |
135+
| `--user=1000:1000` | Run container with a non-root user. Please [read the docs](https://docs.linuxserver.io/misc/non-root/). |
126136

127137
## Environment variables from files (Docker secrets)
128138

@@ -286,6 +296,7 @@ Once registered you can define the dockerfile to use with `-f Dockerfile.aarch64
286296

287297
## Versions
288298

299+
* **22.12.24:** - Rebase to Alpine 3.21. Add support for read-only and non-root.
289300
* **30.06.24:** - Rebase to Alpine 3.20.
290301
* **23.12.23:** - Rebase to Alpine 3.19.
291302
* **20.06.23:** - Sync upstream changes, including the ability to disable referrals with `X-Ldap-DisableReferrals`.

readme-vars.yml

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,8 @@ opt_param_env_vars:
2222
- {env_var: "FERNETKEY", env_value: "", desc: "Optionally define a custom valid fernet key (only needed if container is frequently recreated, or if using multi-node setups, invalidating previous authentications)"}
2323
- {env_var: "CERTFILE", env_value: "", desc: "Optionally point this to a certificate file to enable HTTP over SSL (HTTPS) for the ldap auth daemon"}
2424
- {env_var: "KEYFILE", env_value: "", desc: "Optionally point this to the private key file, matching the certificate file referred to in CERTFILE"}
25+
readonly_supported: true
26+
nonroot_supported: true
2527
# application setup block
2628
app_setup_block_enabled: true
2729
app_setup_block: |
@@ -76,6 +78,7 @@ init_diagram: |
7678
"ldap-auth:latest" <- Base Images
7779
# changelog
7880
changelogs:
81+
- {date: "22.12.24:", desc: "Rebase to Alpine 3.21. Add support for read-only and non-root."}
7982
- {date: "30.06.24:", desc: "Rebase to Alpine 3.20."}
8083
- {date: "23.12.23:", desc: "Rebase to Alpine 3.19."}
8184
- {date: "20.06.23:", desc: "Sync upstream changes, including the ability to disable referrals with `X-Ldap-DisableReferrals`."}

root/app/ldap-backend-app.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -137,7 +137,7 @@ def do_POST(self):
137137

138138
self.send_response(302)
139139

140-
cipher_suite = Fernet(REPLACEWITHFERNETKEY)
140+
cipher_suite = Fernet(os.getenv("FERNET_KEY"))
141141
enc = cipher_suite.encrypt(ensure_bytes(user + ':' + passwd))
142142
enc = enc.decode()
143143
self.send_header('Set-Cookie', 'nginxauth=' + enc + '; httponly')

root/app/nginx-ldap-auth-daemon.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -85,7 +85,7 @@ def do_GET(self):
8585
ctx['action'] = 'decoding credentials'
8686

8787
try:
88-
cipher_suite = Fernet(REPLACEWITHFERNETKEY)
88+
cipher_suite = Fernet(os.getenv("FERNET_KEY"))
8989
self.log_message('Trying to dechipher credentials...')
9090
auth_decoded = auth_header[6:].encode()
9191
auth_decoded = cipher_suite.decrypt(auth_decoded)

root/etc/s6-overlay/s6-rc.d/init-ldap-config/run

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22
# shellcheck shell=bash
33

44
# generate fernet key for ldap if it doesn't exist
5-
if grep -q 'REPLACEWITHFERNETKEY' /app/ldap-backend-app.py; then
5+
if [[ ! -f "/run/.fernetkey" ]]; then
66
if [[ -z "${FERNETKEY}" ]]; then
77
KEY=$(python3 /app/fernet-key.py)
88
echo "generated fernet key"
@@ -14,7 +14,5 @@ if grep -q 'REPLACEWITHFERNETKEY' /app/ldap-backend-app.py; then
1414
KEY="b'${FERNETKEY}'"
1515
echo "using FERNETKEY from env variable"
1616
fi
17-
18-
sed -i "s/REPLACEWITHFERNETKEY/${KEY}/" /app/ldap-backend-app.py
19-
sed -i "s/REPLACEWITHFERNETKEY/${KEY}/" /app/nginx-ldap-auth-daemon.py
17+
echo "${KEY}" > /run/.fernetkey
2018
fi
Lines changed: 13 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,16 @@
11
#!/usr/bin/with-contenv bash
22
# shellcheck shell=bash
33

4-
exec \
5-
s6-notifyoncheck -d -n 300 -w 1000 -c "nc -z localhost 9000" \
6-
s6-setuidgid abc python3 /app/ldap-backend-app.py \
7-
--host 0.0.0.0 --port 9000
4+
export FERNET_KEY=$(cat /run/.fernetkey)
5+
6+
if [[ -z ${LSIO_NON_ROOT_USER} ]]; then
7+
exec \
8+
s6-notifyoncheck -d -n 300 -w 1000 -c "nc -z localhost 9000" \
9+
s6-setuidgid abc python3 /app/ldap-backend-app.py \
10+
--host 0.0.0.0 --port 9000
11+
else
12+
exec \
13+
s6-notifyoncheck -d -n 300 -w 1000 -c "nc -z localhost 9000" \
14+
python3 /app/ldap-backend-app.py \
15+
--host 0.0.0.0 --port 9000
16+
fi
Lines changed: 13 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,16 @@
11
#!/usr/bin/with-contenv bash
22
# shellcheck shell=bash
33

4-
exec \
5-
s6-notifyoncheck -d -n 300 -w 1000 -c "nc -z localhost 8888" \
6-
s6-setuidgid abc python3 /app/nginx-ldap-auth-daemon.py \
7-
--host 0.0.0.0 --port 8888
4+
export FERNET_KEY=$(cat /run/.fernetkey)
5+
6+
if [[ -z ${LSIO_NON_ROOT_USER} ]]; then
7+
exec \
8+
s6-notifyoncheck -d -n 300 -w 1000 -c "nc -z localhost 8888" \
9+
s6-setuidgid abc python3 /app/nginx-ldap-auth-daemon.py \
10+
--host 0.0.0.0 --port 8888
11+
else
12+
exec \
13+
s6-notifyoncheck -d -n 300 -w 1000 -c "nc -z localhost 8888" \
14+
python3 /app/nginx-ldap-auth-daemon.py \
15+
--host 0.0.0.0 --port 8888
16+
fi

0 commit comments

Comments
 (0)