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).
feat(docker): make BACKEND_HOST and FRONTEND_HOST env-configurable
Two opt-in env vars (default 0.0.0.0, non-breaking) let host-network
deployments pin uvicorn and Next.js to a specific bind address — e.g.
127.0.0.1 to keep both off the host LAN when running network_mode: host.
Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
#582 made supervisord run as root with per-program user=deeptutor, so the
gosu privilege-drop binary is no longer invoked. Remove the gosu and
libcap2-bin apt packages and the setcap step (a setuid-capable binary that
was left unused == needless attack surface), and refresh the Dockerfile
comments.
Realign the authoritative docs that still described the old gosu model:
- CONTAINERIZATION.md: supervisord runs as root and drops each program to
deeptutor via user=; fix the verification snippet.
- compose.yaml: correct the (now wrong + dangerous) note that cap_drop ALL
is safe — root supervisord NEEDS CAP_SETUID/CAP_SETGID to setuid its
children, so cap_drop ALL would stop the backend/frontend from starting.
Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
The production image's start-backend.sh and start-frontend.sh previously
hard-coded --host 0.0.0.0 (uvicorn) and HOSTNAME (Next.js standalone
default). That's fine for bridge-mode deployments where the port
publish binds to the host, but in network_mode: host the container's
processes bind directly on the host's interfaces — exposing :8001 and
:3782 to the LAN.
This change makes both bind addresses env-configurable:
start-backend.sh: --host ${BACKEND_HOST:-0.0.0.0}
start-frontend.sh: export HOSTNAME=${FRONTEND_HOST:-0.0.0.0}
Defaults preserve the current behavior. Setting
BACKEND_HOST=127.0.0.1 and FRONTEND_HOST=127.0.0.1 in compose.yaml
under a host-mode service gives loopback-only bindings.
Note: setting BACKEND_HOST=127.0.0.1 in bridge mode breaks the
port publish (uvicorn binds inside the container's loopback). Use
this env var only with network_mode: host.
The backend was logging every request (the chatty frontend polling of
/settings, /tools, /knowledge/list, /settings/llm-options, ...) as
`::1:0 - "GET ... 200 OK"`. uvicorn's per-request access log was only disabled
in run_server.py (access_log=False); the `deeptutor start` launcher and the
Docker entrypoints invoked uvicorn directly with it still on, so the 200s
leaked.
- launcher.py + Dockerfile (production start-backend.sh and the dev supervisord
program): add `--no-access-log` so all launch paths match run_server.py.
- Funnel access logging through the existing selective_access_log middleware
(non-200 only), but log via a `deeptutor.access` logger with its own INFO
stdout handler (propagate=False). Previously it used `uvicorn.access`, which
has no handler once uvicorn's access log is off, and the root console handler
runs at WARNING — so non-200s were being silently dropped. Now 200s are quiet
and 4xx/5xx still surface.
- Rewrite the middleware test to capture on the deeptutor.access logger directly
(it no longer propagates to root).
Verified: live server with --no-access-log logs nothing for 200s and prints
`127.0.0.1 - "GET /api/v1/... HTTP/1.1" 404` for a 404. ruff + pytest (2447) green.
Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
The PR's relative-path + proxy.ts rewrite design depends on two env vars
(DEEPTUTOR_API_BASE_URL, DEEPTUTOR_AUTH_ENABLED) read server-side by the
Next.js middleware. As submitted they were only set by the Docker entrypoint,
and the auth one read a non-existent auth.json key — so auth enforcement was
silently disabled and the PyPI `deeptutor start` path was unwired.
- Export both vars from render_environment() (the single JSON-backed source of
truth), so the Docker entrypoint AND the `deeptutor start` launcher get them
consistently. DEEPTUTOR_API_BASE_URL falls back to localhost:<backend_port>.
- launcher.py: set both in common_env using the resolved backend_url, so they
track port-conflict reassignment.
- Dockerfile: drop the duplicated, buggy per-var heredocs (one read the wrong
key `auth_enabled` instead of `enabled`, leaving the proxy auth gate always
off); the export_runtime_settings_to_env eval now provides both. Add them to
the env-unset list for hygiene.
- Update the two placeholder tests to assert the new proxy-based design instead
of the removed build-time sed mechanism; add DEEPTUTOR_* coverage in
test_runtime_settings.
Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
The frontend no longer bakes the backend URL into the bundle at build
time and mutates it with sed on every container start. Instead:
* web/lib/api.ts: apiUrl and wsUrl become one-line pass-throughs, so
the browser fetches relative paths through the frontend
(:3782/api/...). All existing call sites keep working unchanged.
* web/proxy.ts: catches /api/* and /ws/* and rewrites them to
DEEPTUTOR_API_BASE_URL at request time, reading
DEEPTUTOR_AUTH_ENABLED for the auth-redirect check.
* web/lib/auth.ts: switches from NEXT_PUBLIC_AUTH_ENABLED (build-time)
to DEEPTUTOR_AUTH_ENABLED (set by the entrypoint on every start).
* Dockerfile: drops the .env.local placeholder block, the sed -i in
start-frontend.sh, and the runtime API-base fallback chain. Adds
gosu, bakes a non-root 'deeptutor' user (UID 1000), and has the
entrypoint chown /app/data and export DEEPTUTOR_API_BASE_URL and
DEEPTUTOR_AUTH_ENABLED from data/user/settings/*.json on every
start. supervisord is now invoked under 'gosu deeptutor'.
* web/tests/api-resolve-base.test.ts: deleted (its 8 tests reference
resolveBase / isApiBasePlaceholder, both gone; apiUrl/wsUrl are
now pass-throughs so the rest is meaningless). The auth-redirect
test is updated to prime DEEPTUTOR_AUTH_ENABLED instead.
Stability release after v1.3.0 covering safer RAG/KB routing, stronger
embedding validation, more reliable Docker/TutorBot restarts, Web UX
fixes, and Windows/encoding hardening. See assets/releases/ver1-3-1.md
for the full notes.
Made-with: Cursor