Skip to content

build(agent): run API and worker containers as non-root - #8

Merged
KeentGG merged 13 commits into
mainfrom
transition/nonroot-agent
Nov 28, 2026
Merged

KeentGG merged 13 commits into
mainfrom
transition/nonroot-agent

Conversation

@KeentGG

@KeentGG KeentGG commented Nov 28, 2026

Copy link
Copy Markdown
Owner

Why

The agent API and LiveKit worker containers were the last accepted HIGH misconfiguration (DS-0002: running as root). This change removes that risk and makes both runtime stages non-root.

Changes

  • Create appuser (UID 10001) before the worker model bake.
  • Place Hugging Face and uv caches under the runtime user's home.
  • Chown runtime paths and switch to USER appuser in both api and worker stages.
  • Keep application code, Compose commands, ports, and healthchecks unchanged.
  • CI now builds and loads both agent targets, asserts UID 10001, boots the API, checks /health, and imports the worker as appuser.
  • Trivy CI now scans vuln,secret,misconfig; DS-0002 is cleared rather than ignored.

Verification

  • API and worker images build successfully.
  • Both images report UID 10001 / appuser.
  • API /health returns 200 with no permission errors.
  • Trace writes succeed as appuser.
  • Worker imports as appuser; baked model cache is appuser-owned and works offline.
  • Agent tests: 212 passed, 1 skipped.
  • Compose configs pass.
  • Trivy: 0 HIGH/CRITICAL vulnerabilities, secrets, or misconfigs.

Full evidence: WORKLOG.md.

- Record the approved plan for clearing DS-0002 (api/worker as appuser).
- Planning pass only: no Dockerfile, workflow, or app code touched.
- Create appuser (uid 10001) in the base stage and point HOME/HF_HOME/
  UV_CACHE_DIR at its home before the worker model bake, so silero and
  turn-detector weights land under the runtime user's cache.
- chown /app and /home/appuser, then USER appuser in the api and worker
  stages; CMDs and compose commands stay unchanged (`uv run` still works).
- CI docker-build: build/load both agent targets, assert uid 10001 on each,
  boot the API and poll /health, and import the worker module as appuser.
- Both agent images verified as appuser/10001; API /health, trace writes,
  worker import, and an offline weight re-bake all pass.
- Trivy misconfig HIGH/CRITICAL is 0: DS-0002 cleared. CI now covers both
  targets plus non-root, health, and worker-import checks.
- Add the misconfig scanner to the Trivy security gate now that DS-0002
  (agent image root user) is fixed; the exact gate command exits 0 with 0
  findings on every target.
- Correct the stale comment claiming the root-user misconfig is accepted.
- Worklog: record the deviation, the exact gate result, and the CI change.
- Add the misconfig-gate commit to the evidence commit list.
- The docker-build job now loads four images, including the multi-GB
  worker, while buildkit holds their layers; drop preinstalled toolchains
  the job never uses so the worker export cannot run the runner out of
  disk (the local first export hit exactly that).
- Worklog: record the mitigation and that this branch's workflow has not
  run yet.
- Create appuser and chown only the empty /app in base, then USER appuser
  before every install and the model bake; COPY --chown keeps the
  lockfiles and source appuser-owned.
- Removes the ~3.2GB chown layer duplicated in both images: worker
  6.66GB -> 3.46GB, api 2.31GB -> 1.29GB; local builds 5m04s -> 1m38s
  (worker) and 2m00s -> 1m11s (api).
- uv sync and the model bake still run clean as appuser; runtime CMDs
  unchanged.
- Worker check now runs the baked venv directly with --network none and
  HF_HUB_OFFLINE=1: imports the worker, silero and turn_detector, calls
  Plugin.download_files() for every registered plugin and silero.VAD.load(),
  and asserts uid 10001. No `uv run`.
- API smoke writes a real trace with .venv/bin/python and asserts the JSONL
  exists, contains trace_start, and is owned by uid 10001.
- Findings: duplicated recursive chown layers; worker proof via `uv run`
  without offline/baked-weight coverage; health-only API smoke.
- Fixes and re-run evidence against the final images, including image
  sizes/history, offline VAD load, and trace ownership.
- PR #8 exists; record that this round is its head and that its CI run for the new head still needs checking.
- Offline: `.venv/bin/python -m deepinterview_agent.worker --help` with
  --network none and HF_HUB_OFFLINE=1, run against the already-built worker
  image (no rebuild).
- Online: the compose/CMD path `uv run python -c "import
  deepinterview_agent.worker, livekit.plugins.silero"` with the network
  available.
- Both steps were executed verbatim locally against the final image: CLI
  exit 0 with its commands listed; uv run exit 0 after syncing dev deps.
- Final-review finding, the two new CI steps, and the verbatim local
  evidence against the existing final worker image (no rebuild).
@KeentGG
KeentGG marked this pull request as ready for review November 28, 2026 16:15
@KeentGG
KeentGG merged commit 8a713cb into main Nov 28, 2026
4 checks passed
@KeentGG
KeentGG deleted the transition/nonroot-agent branch November 28, 2026 16:15
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant