From 34fb3501b6acdd6fcde539baf907083598e6ae9f Mon Sep 17 00:00:00 2001 From: nanw Date: Wed, 24 Jun 2026 20:24:06 +0800 Subject: [PATCH] fix(docker): make supervisord config portable across rootful + rootless keep-id MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Removes `user=root` from the [supervisord] section in both production and development supervisord configs, and rewrites the entrypoint comment to explain why. Background: under rootless podman + userns_mode: keep-id, container PID 1 runs as the host user (UID 1000) instead of root. The previous design explicitly forced supervisord to drop privileges to root (`user=root`), which works under rootful daemons (PID 1 is root, has CAP_SETUID) but fails under rootless + keep-id — supervisord sees `user=root` in its config, tries to setuid(0), lacks CAP_SETUID, and exits with "Error: Can't drop privilege as nonroot user" (per supervisord options.py: refuses to drop privileges when not running as root). Fix: omit `user=` from the [supervisord] section so supervisord inherits PID 1's UID (root in rootful; UID 1000 in rootless + keep-id). The backend and frontend programs still drop to the unprivileged deeptutor user via per-program `user=deeptutor` — setuid(1000) works because either PID 1 is root (rootful) or PID 1 is already UID 1000 (rootless keep-id, where the setuid is a no-op). /dev/fd/1,2 ownership matches PID 1's UID in both runtimes, so supervisord's stdout/stderr writes succeed without an explicit setuid dance. Verified locally: clean heredoc indentation; supervisord config parses; both [supervisord] sections confirmed without `user=root`. Closes the rootless-podman + read-only-rootfs follow-up to PR #577 (reported by the user after #577 + #586 merged). --- Dockerfile | 30 +++++++++++++++++------------- 1 file changed, 17 insertions(+), 13 deletions(-) diff --git a/Dockerfile b/Dockerfile index aa3468d08..24021fdb6 100644 --- a/Dockerfile +++ b/Dockerfile @@ -200,7 +200,6 @@ nodaemon=true logfile=/dev/null logfile_maxbytes=0 pidfile=/var/run/supervisord.pid -user=root [program:backend] command=/bin/bash /app/start-backend.sh @@ -359,18 +358,24 @@ echo " - data/user/settings/main.yaml" echo " - data/user/settings/agents.yaml" echo "============================================" -# Run supervisord as root so it can open the container's stdout/stderr -# (/dev/fd/1,2 — root-owned pipes under a rootful daemon like Docker Desktop) -# and write its pidfile under /var/run. The backend and frontend programs are -# dropped to the unprivileged deeptutor user (UID 1000) via `user=deeptutor` -# in the supervisord config, so the app processes stay non-root. +# Run supervisord with PID 1's UID — deliberately omitting `user=` from the +# [supervisord] section so supervisord inherits whatever UID the container +# started with (root under rootful Docker/Podman; UID 1000 under rootless +# podman + userns_mode: keep-id, where PID 1 is the host user). # -# Dropping supervisord ITSELF to UID 1000 here (the previous -# `exec gosu deeptutor ...`) worked under rootless podman — where UID 1000 is -# the mapped host user that owns those FDs — but under a rootful daemon it -# could not open /dev/fd/1,2 ("making dispatchers ... EACCES") nor the pidfile, -# so neither service ever started. Per-program `user=` keeps the children -# unprivileged in both runtimes without that breakage. +# Why no `user=root`: under rootless + keep-id, PID 1 is UID 1000 and has no +# CAP_SETUID, so forcing `user=root` would make supervisord fail at startup +# with "Error: Can't drop privilege as nonroot user" (see supervisord +# options.py — it refuses to drop privileges when not running as root). The +# previous design with `user=root` worked under rootful but broke rootless. +# +# The backend and frontend programs are still dropped to the unprivileged +# deeptutor user (UID 1000) via per-program `user=deeptutor` in the +# supervisord config — that setuid works because either (a) PID 1 is root +# (rootful) and has CAP_SETUID, or (b) PID 1 is already UID 1000 (rootless +# keep-id) and the setuid is a no-op. /dev/fd/1,2 ownership matches PID 1's +# UID in both runtimes, so supervisord can write to them without an explicit +# setuid dance. exec /usr/bin/supervisord -c /etc/supervisor/conf.d/deeptutor.conf EOF @@ -440,7 +445,6 @@ nodaemon=true logfile=/dev/null logfile_maxbytes=0 pidfile=/var/run/supervisord.pid -user=root [program:backend] command=python -m uvicorn deeptutor.api.main:app --host 0.0.0.0 --port %(ENV_BACKEND_PORT)s --reload --no-access-log