Skip to content

Pin what the build fetches, poll a share once not twice, and boot lighter - #17

Merged
antoine-debroye merged 1 commit into
mainfrom
ad/audit-tier5-infra
Oct 9, 2026
Merged

antoine-debroye merged 1 commit into
mainfrom
ad/audit-tier5-infra

Conversation

@antoine-debroye

Copy link
Copy Markdown
Collaborator

Why

Tier 5 of the October audit (doc/audit-2026-10-09.md): the infrastructure items X6, X8, P7 and P8. Stacked on #16.

What changed

  • X6 — nothing the build fetches is taken on trust. Every GitHub Action is pinned to a commit SHA (version in a trailing comment), the node:22-alpine and nvidia/cuda base images by index digest, and whisper.cpp by commit 371b5a7 (fetched with git fetch --depth 1 <sha>, since clone --branch only takes names). Top-level permissions: contents: read; the three publish jobs keep packages: write. Each pin carries a comment saying how to bump it.
  • X8 — TRUST_PROXY. Default true keeps today's behaviour; false or a comma-separated list of IPs, CIDRs or proxy-addr range names narrows it. A bad entry is dropped with a warning naming it; a list with nothing usable trusts nobody and says so, never silently falls back to everyone. Documented in the README table and spec §9. Applied to the degraded-mode server as well as the main one.
  • P7 — lighter boot and runtime. sharp and qrcode load on first use (new src/lib/lazy-sharp.js; limitInputPixels passed exactly as before). The entrypoint only chown -Rs node_modules when its owner is actually wrong (checked on the directory and a file deep inside it, so an interrupted chown is finished, not skipped), and a failed chown is logged rather than swallowed. In polling mode the watcher now polls at the full rescan interval instead of every 60 s, so a share is stat'ed once per interval, not twice; the status line and health notice say so.
  • P8 — smaller image. WHISPER_MODELS build arg (default both, so the published image is unchanged; small alone is 717 MB and refuses to build if the default model is not among those baked in). docker/trim-node-modules.mjs removes better-sqlite3/deps and the seven other platforms' prebuilds, keeping the one the package itself loads, and fails the build loudly if that layout ever changes. 868 MB → 833 MB.

How it was verified

  • npm test: 1405 pass, 0 fail (stacked on Finish the statistics: DST-safe midnights, history that outlives an episode, a fair comparison, and a whole-page show filter #16). New tests: TRUST_PROXY parsing for every form including the fail-safe, then the parsed value handed to a real Fastify instance (forged headers honoured only from the trusted range) and through buildApp (a Secure cookie only from the proxy address); watcher polling at the rescan interval with an injectable watch.
  • ./test/acceptance/run.sh selfpod:tier5-infra: 63 passed, 0 failed against the stacked image.
  • Entrypoint and Dockerfile behaviours proven by building and running: no chown line at default ids, one line at PUID=1001; WHISPER_MODELS=small alone refused with the reason; WHISPER_MODELS=small WHISPER_DEFAULT_MODEL=small builds and smoke-tests.
  • Boot on an M-series Mac: 812 ms cold → 535 ms.

Known: the whisper probe at boot was deliberately left in place (the pass auto-triggers after the first scan anyway, and deferring it would delay the "recogniser cannot run" banner). src/services/watcher.js is treated as binary by git because of a pre-existing NUL in a string literal; use git diff --text to read it.

🤖 Generated with Claude Code

…hter (audit tier 5, X6/X8/P7/P8)

X6 — supply chain. Every GitHub Action is pinned to a commit with the release in a
comment; the workflow token is read-only except for the publish jobs. Both Dockerfiles
pin node:22-alpine and the two nvidia/cuda images by digest, and fetch whisper.cpp by
the commit b4938 pointed at rather than the tag. Each pin says how to bump it.

X8 — TRUST_PROXY. `true` (the default, as before), `false`, or a list of addresses
and CIDR ranges passed to Fastify's trustProxy, so an operator whose port 8080 is
reachable from the LAN can stop a client there setting X-Forwarded-* itself. A list
with a bad entry drops it and warns; a list with nothing usable trusts nobody and
warns, never silently everybody. Unit tests prove the parsing and what Fastify does
with each value; an integration test proves it reaches the real app through the
Secure flag on the session cookie.

P7 — boot and runtime. sharp and qrcode are loaded on first use (a shared loader for
sharp, so the two services load it once); the entrypoint chowns node_modules only
when its owner is wrong, and the image ships it owned by the default ids, so a default
run never walks the 4,500 files; in polling mode the watcher polls at the rescan
interval instead of min(rescan, 60 s) on top of the rescan, and says so in the log
and status. The whisper probe at boot is left as it was. Boot to "listening" on this
Mac: 812/236/230 ms before, 535/223/221 ms after; the covers module import went from
~26 ms to 5 ms and qr.js from 9 ms to 0.

P8 — image size. WHISPER_MODELS chooses which models are baked in (default both, so
the published image is unchanged) and WHISPER_DEFAULT_MODEL must be one of them or
the build refuses with a plain sentence; the smoke test proves every binary with the
smallest model shipped. better-sqlite3's SQLite source and the seven other platforms'
prebuilt binaries are removed before the native-module check, which now proves the
module loads with only what is kept. 868 MB → 833 MB (717 MB with one model).

npm test: 1388 pass. Acceptance (selfpod:tier5-infra on port 8299): 63 passed, 0 failed.

Co-Authored-By: Claude Fable 5.1 <noreply@anthropic.com>
@antoine-debroye
antoine-debroye changed the base branch from ad/audit-tier5-statistics to main October 9, 2026 22:38
@antoine-debroye
antoine-debroye merged commit 77ecb9f into main Oct 9, 2026
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