fix(docker): say what the volume-root check leaves alone, and skip the walk for a custom fsGroup

The entrypoint comment, the Helm chart README, the wiki and the ssrfGuard
note now describe what the shipped check does.
This commit is contained in:
Maurice
2026-11-05 13:02:26 +01:00
parent 7b5a05afee
commit 402a02a302
6 changed files with 44 additions and 14 deletions
+1 -1
View File
@@ -56,5 +56,5 @@ See `values.yaml` for more options.
- `COOKIE_SECURE` is auto-derived (on when `NODE_ENV=production` or `FORCE_HTTPS=true`). Set `env.COOKIE_SECURE: "false"` only during local testing without TLS. **Not recommended for production.**
- Web Push needs no chart settings: TREK generates its key pair on first start and keeps it in the database on the data PVC. To bring your own pair, set `env.VAPID_PUBLIC_KEY` and `secretEnv.VAPID_PRIVATE_KEY` together (and optionally `env.VAPID_SUBJECT`); changing the pair later means every device has to turn push on again.
- Set `env.OIDC_DISCOVERY_URL` to override the auto-constructed OIDC discovery endpoint. Required for providers (e.g. Authentik) that expose it at a non-standard path.
- `podSecurityContext` defaults to `fsGroup: 1000` with `fsGroupChangePolicy: OnRootMismatch`, and `securityContext` (the container's) is empty. The container then starts as root, hands any file under `/app/data` and `/app/uploads` that is not owned by `node` yet to `node`, and drops to `node`. To run as `node` from the start, for example under the `restricted` Pod Security Standard, set `podSecurityContext.runAsUser: 1000` and `runAsGroup: 1000`; the image then skips that step and the privilege drop. See the example in `values.yaml`.
- `podSecurityContext` defaults to `fsGroup: 1000` with `fsGroupChangePolicy: OnRootMismatch`, and `securityContext` (the container's) is empty. The container then starts as root, hands `/app/data` and `/app/uploads` to `node` (uid 1000) if the directory or anything directly inside it is not owned by `node` yet, and drops to `node`. Deeper files are not checked. Only the owning user is changed (plus a `root` group), so a different `fsGroup` stays in place. A volume that refuses `chown` (NFS with `root_squash`) logs a warning instead; set `runAsUser: 1000` then. To run as `node` from the start, for example under the `restricted` Pod Security Standard, set `podSecurityContext.runAsUser: 1000` and `runAsGroup: 1000`; the image then skips that step and the privilege drop. See the example in `values.yaml`.
- Use `extraVolumes` and `extraVolumeMounts` to add your own volumes to the pod. To give the booking import more KItinerary extractors, mount a ConfigMap at `/usr/local/share/kitinerary/extractors`, with one `.json` and one `.js` key for each extractor; see the example in `values.yaml`.
+19 -7
View File
@@ -36,17 +36,29 @@ fi
# which on a large or network-backed one (NFS, CephFS, Longhorn) kept the
# container busy for minutes before Node printed its first line (#2918). So only
# the dir and what sits directly in it are looked at: a volume that is not
# node's yet (a fresh one, or one copied in as root) shows there, and is handed
# over once. A volume that refuses chown altogether (NFS with root_squash) is
# said once per start instead of being walked file by file; such a pod belongs
# under runAsUser 1000, see the Helm page of the wiki. Best effort either way: a
# node's yet (a fresh one, or one whose top level was copied in as root) shows
# there, and is handed over once. Files copied in as root further down, into a
# subdirectory node already owns, do not show and are left alone; the
# Troubleshooting page of the wiki has the one-off chown for that.
#
# Only the owning user has to be node, because that is what Node runs as and
# what gosu leaves it with. The group is left to whoever set it: a Kubernetes
# fsGroup other than 1000 gives every file its own gid, and taking that back
# here would make the kubelet's OnRootMismatch walk the volume again on the
# next start, and this script after it, every time. Only a root group (a fresh
# volume under plain docker) is handed to node as well.
#
# A volume that refuses chown altogether (NFS with root_squash) is said once
# per start instead of being walked file by file; such a pod belongs under
# runAsUser 1000, see the Helm page of the wiki. Best effort either way: a
# read-only host filesystem or a locked-down bind mount must keep booting.
for dir in /app/data /app/uploads; do
[ -d "$dir" ] || continue
if [ -n "$(find "$dir" -maxdepth 1 \( ! -user node -o ! -group node \) -print -quit 2>/dev/null)" ]; then
if chown node:node "$dir" 2>/dev/null; then
if [ -n "$(find "$dir" -maxdepth 1 \( ! -user node -o -group 0 \) -print -quit 2>/dev/null)" ]; then
if chown node "$dir" 2>/dev/null; then
echo "Correcting ownership of $dir for the node user..."
chown -R -h node:node "$dir" 2>/dev/null || true
chown -R -h node "$dir" 2>/dev/null || true
find "$dir" -group 0 -exec chgrp -h node {} + 2>/dev/null || true
else
echo "WARNING: $dir cannot be handed to the node user (chown refused); run the container as uid 1000 instead."
fi
+4 -3
View File
@@ -36,9 +36,10 @@ export interface SsrfResult {
* that many hosts cannot reach on port 443 while the A record would have
* answered at once. Every address the guard allows goes to the socket, where
* Node tries the addresses in turn (autoSelectFamily, the default since Node
* 20), so an unreachable family costs a quarter of a second instead of the
* caller's whole timeout. IPv4 leads because that is the family that is
* reachable from the containers and LXCs TREK usually runs in.
* 20), so an unreachable family costs at most one connect attempt per address
* (CONNECT_ATTEMPT_TIMEOUT_MS, 2 s, raised at startup in utils/connectAttempt.ts)
* instead of the caller's whole timeout. IPv4 leads because that is the family
* that is reachable from the containers and LXCs TREK usually runs in.
*/
async function resolveAll(hostname: string): Promise<{ address: string; family: number }[]> {
const result = await dns.lookup(hostname, { all: true });
+13 -2
View File
@@ -61,16 +61,27 @@ describe('entrypoint script', () => {
it('never walks the volumes on a start where they already belong to node', () => {
// Only the dir and its direct entries are looked at, never the whole tree.
expect(code).toContain('find "$dir" -maxdepth 1 \\( ! -user node -o ! -group node \\) -print -quit');
expect(code).toContain('find "$dir" -maxdepth 1 \\( ! -user node -o -group 0 \\) -print -quit');
expect(code).not.toMatch(/find "\$dir" \\\(/);
// The recursive hand-over sits behind that check and behind a chown of the dir that worked.
const check = code.indexOf('-maxdepth 1');
const dirChown = code.indexOf('if chown node:node "$dir"');
const dirChown = code.indexOf('if chown node "$dir"');
expect(dirChown).toBeGreaterThan(check);
expect(code.indexOf('chown -R')).toBeGreaterThan(dirChown);
expect(code.indexOf('find "$dir" -group 0 -exec chgrp -h node {} +')).toBeGreaterThan(code.indexOf('chown -R'));
expect(code).toContain('Correcting ownership of $dir for the node user...');
});
// A Kubernetes fsGroup other than 1000 gives every file that gid. Handing the
// group back to node would leave the kubelet's OnRootMismatch with a mismatched
// root on the next start, and the two recursive walks would undo each other on
// every start (#2918 again). So only the user is taken over, plus a root group.
it('takes over the owning user and a root group, never a foreign fsGroup', () => {
expect(code).not.toContain('-group node');
expect(code).not.toContain('node:node');
expect(code).toContain('chown -R -h node "$dir"');
});
it('says so once instead of walking a volume that refuses chown', () => {
expect(code).toContain('cannot be handed to the node user (chown refused); run the container as uid 1000 instead.');
});
+1 -1
View File
@@ -199,7 +199,7 @@ podSecurityContext:
securityContext: {}
```
With these defaults the container starts as root, hands `/app/data` and `/app/uploads` to the `node` user (uid 1000) if they are not `node`'s yet, and then drops to `node`. Only the two directories and what sits directly in them are checked, so a large uploads volume that already belongs to `node` does not slow down the start. If ownership has to be corrected, the log says `Correcting ownership of /app/uploads for the node user...` before TREK's own start-up lines. A volume that refuses `chown` (NFS with `root_squash`, for example) logs a warning instead; run TREK as uid 1000 then, as shown below.
With these defaults the container starts as root, hands `/app/data` and `/app/uploads` to the `node` user (uid 1000) if they are not `node`'s yet, and then drops to `node`. Only the two directories and what sits directly in them are checked, so a large uploads volume that already belongs to `node` does not slow down the start. Only the owning user is changed, plus a `root` group, so an `fsGroup` other than 1000 stays in place and the kubelet does not walk the volume again on the next start. If ownership has to be corrected, the log says `Correcting ownership of /app/uploads for the node user...` before TREK's own start-up lines. A volume that refuses `chown` (NFS with `root_squash`, for example) logs a warning instead; run TREK as uid 1000 then, as shown below.
To run TREK as `node` from the first process on, for example in a namespace that enforces the `restricted` Pod Security Standard, set the user in the pod security context. The image notices it is not root and starts Node directly, with no ownership step and no privilege drop:
+6
View File
@@ -179,6 +179,12 @@ Keep only `./data:/app/data` and `./uploads:/app/uploads`, then recreate the con
> ```bash
> sudo chown -R 1000:1000 ./data ./uploads
> ```
>
> The start-up step only looks at `data`, `uploads` and what sits directly in them. Files copied in as root further down, into a subdirectory that already belongs to `node` (for example a restore with `docker cp ./photos/. trek:/app/uploads/photos/` or with `sudo cp` on the bind mount), stay root-owned across restarts. Hand them over once:
>
> ```bash
> docker exec trek chown -R node:node /app/uploads /app/data
> ```
---