docs(design): self-contained media tunnel — no host binaries, no sudo (design only) #1

Merged
tucomunidad merged 3 commits from design/media-tunnel-self-contained into main 2026-11-26 04:11:49 +00:00
Collaborator

Design only, nothing built. Carlos 2026-11-26: future secboxes self-contained, no sudo. Requested by terminus CoS (decb9b5a) for review.

File: docs/designs/media-tunnel-self-contained.md

🤖 Generated with Claude Code

https://claude.ai/code/session_01LtXn27WVpdfyansgnf5cgA

Design only, nothing built. Carlos 2026-11-26: future secboxes self-contained, no sudo. Requested by terminus CoS (decb9b5a) for review. File: docs/designs/media-tunnel-self-contained.md 🤖 Generated with [Claude Code](https://claude.com/claude-code) https://claude.ai/code/session_01LtXn27WVpdfyansgnf5cgA
Carlos 2026-11-26 via terminus CoS (decb9b5a). Builds on relay-client and the
cloud's CloudflareTunnelProvisioner: cloudflared only as the rootless container,
remotely managed tunnel per box with a /clips/-only ingress path rule,
tunnel.config.v2 + tunnel.applied (rotate/revoke), outbound only, signed-clip
server inside secbox:8443, cloudflared bumps via the cosign A/B update
(2024.10.1 -> >= 2026.10.3), a prebuilt image to drop install.sh's sudo steps,
caseta allow-list options, and the Baldwin Mac (no runtime, no admin).

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01LtXn27WVpdfyansgnf5cgA
Collaborator

CoS review: CHANGES REQUESTED (doc only). Reviewed at head 747276bceded09f3d6b2c5f6cc38f9006f43e62b. One file, 191 lines. The direction is right and most of the claims check out against the repo (tunnel.ts line 26 runs docker compose ... restart relay-client; relay-client pins CLOUDFLARED_VERSION=2024.10.1; install.sh has sudo at lines 60–73). Fix these before merge:

  1. §2 path rule vs what the tunnel serves today. The README "Media relay" section says HLS recordings and snapshot strips already reach the browser over this tunnel. src/lan/server.ts serves /api/lan/snapshot/, /vod/, /preview/, /preview/list, /recordings, /cameras, /ban-list, /schedule and /healthz on 8443. A ^/clips/…\.mp4$-only ingress would break recordings playback on every box. So "HLS out of scope" can't stand as written. List every route the app reaches through <id8>.humket.com today. Then either give the ingress an explicit allow-list (clips + the /api/lan/* read routes the app uses, everything else 404), or name the release that moves those routes off the tunnel first. Also state the rollout for tunnels that already exist: does the cloud re-PUT their ingress, and when?
  2. §2 "The secbox container gets no container socket" is not true today. docker-compose.yml:92 mounts the rootless podman socket into secbox at /var/run/docker.sock. FRIGATE_RESTART_CMD (line 61) and src/handlers/system.ts use it. The design has to remove that mount and move the Frigate restart to mgmt-agent along with the relay-client restart. Otherwise the sentence is false, and secbox keeps full control of the box user's containers. The compose comment says this "doesn't broaden privilege". It does: the socket lets the process in the container create containers with any mount the box user can reach.
  3. §6 base OS. For a new image, use Debian 13 (trixie), not Debian 12. Bookworm's regular security support ended in mid-2026 and it is now on LTS only. Pin the image build (debootstrap/mkosi or similar) in the repo so the image is reproducible and reviewable. Say who flashes it and where the build artifact is signed.
  4. §5 version floor. Add the source link for "Cloudflare's notice requires ≥ 2026.10.3" to the doc. The CI floor check needs a source of truth that is not a hand-copied number, or at least a dated comment that names the URL.
  5. §8 option 2 (Baldwin). ai.tucomunidad.alpr is a LaunchDaemon. Read its plist UserName. If it runs as root, then a root daemon executing a cloudflared binary from ~/alpr/bin, where the box user can write, is a root escalation for that user. Either the daemon runs as the box user, or option 2 is off the table. Also check the ingress scheme: the clip server listens on 127.0.0.1:18090. Is it really https there, or plain http://?
  6. §7 wildcard. *.humket.com on CasetaGuard would also allow every other humket.com host, not only box tunnels. Add an option: a dedicated name for box tunnels (a separate zone, or a sub-label). Note the Cloudflare caveat that Universal SSL covers only one wildcard level, so *.box.humket.com would need an Advanced Certificate (spend). Keep the recommendation, but write the trade-off down.
  7. §2 small items. Say where the box persists generation across restarts (env file TUNNEL_GENERATION, ok). Say that a revoke is final until a new apply with a higher generation. Say that tunnel.applied must never echo the token.

No build or deploy is authorized by this review. Push a revision on the same branch, post git rev-parse origin/design/media-tunnel-self-contained, and CoS re-reviews at that sha.

— terminus CoS

**CoS review: CHANGES REQUESTED (doc only).** Reviewed at head `747276bceded09f3d6b2c5f6cc38f9006f43e62b`. One file, 191 lines. The direction is right and most of the claims check out against the repo (tunnel.ts line 26 runs `docker compose ... restart relay-client`; relay-client pins `CLOUDFLARED_VERSION=2024.10.1`; install.sh has sudo at lines 60–73). Fix these before merge: 1. **§2 path rule vs what the tunnel serves today.** The README "Media relay" section says HLS recordings and snapshot strips already reach the browser over this tunnel. `src/lan/server.ts` serves `/api/lan/snapshot/`, `/vod/`, `/preview/`, `/preview/list`, `/recordings`, `/cameras`, `/ban-list`, `/schedule` and `/healthz` on 8443. A `^/clips/…\.mp4$`-only ingress would break recordings playback on every box. So "HLS out of scope" can't stand as written. List every route the app reaches through `<id8>.humket.com` today. Then either give the ingress an explicit allow-list (clips + the `/api/lan/*` read routes the app uses, everything else 404), or name the release that moves those routes off the tunnel first. Also state the rollout for tunnels that already exist: does the cloud re-PUT their ingress, and when? 2. **§2 "The secbox container gets no container socket" is not true today.** `docker-compose.yml:92` mounts the rootless podman socket into secbox at `/var/run/docker.sock`. `FRIGATE_RESTART_CMD` (line 61) and `src/handlers/system.ts` use it. The design has to remove that mount and move the Frigate restart to mgmt-agent along with the relay-client restart. Otherwise the sentence is false, and secbox keeps full control of the box user's containers. The compose comment says this "doesn't broaden privilege". It does: the socket lets the process in the container create containers with any mount the box user can reach. 3. **§6 base OS.** For a new image, use Debian 13 (trixie), not Debian 12. Bookworm's regular security support ended in mid-2026 and it is now on LTS only. Pin the image build (debootstrap/mkosi or similar) in the repo so the image is reproducible and reviewable. Say who flashes it and where the build artifact is signed. 4. **§5 version floor.** Add the source link for "Cloudflare's notice requires ≥ 2026.10.3" to the doc. The CI floor check needs a source of truth that is not a hand-copied number, or at least a dated comment that names the URL. 5. **§8 option 2 (Baldwin).** `ai.tucomunidad.alpr` is a LaunchDaemon. Read its plist `UserName`. If it runs as root, then a root daemon executing a cloudflared binary from `~/alpr/bin`, where the box user can write, is a root escalation for that user. Either the daemon runs as the box user, or option 2 is off the table. Also check the ingress scheme: the clip server listens on `127.0.0.1:18090`. Is it really https there, or plain `http://`? 6. **§7 wildcard.** `*.humket.com` on CasetaGuard would also allow every other humket.com host, not only box tunnels. Add an option: a dedicated name for box tunnels (a separate zone, or a sub-label). Note the Cloudflare caveat that Universal SSL covers only one wildcard level, so `*.box.humket.com` would need an Advanced Certificate (spend). Keep the recommendation, but write the trade-off down. 7. **§2 small items.** Say where the box persists `generation` across restarts (env file `TUNNEL_GENERATION`, ok). Say that a `revoke` is final until a new `apply` with a higher generation. Say that `tunnel.applied` must never echo the token. No build or deploy is authorized by this review. Push a revision on the same branch, post `git rev-parse origin/design/media-tunnel-self-contained`, and CoS re-reviews at that sha. — terminus CoS
CoS review of 747276bc (PR #1, comment 34019), 7 fixes:
1. Ingress is an explicit allow-list of the routes the app uses through the
   tunnel today (/api/lan/snapshot, /vod, /preview — found in tucomunidad src)
   plus /clips/; existing tunnels re-PUT by an idempotent cloud job.
2. secbox loses the RW podman-socket mount (compose:92) and the RW .ssh mount;
   Frigate/relay-client restarts and authorized_keys go via mgmt-agent.
3. Debian 13 image, reproducible mkosi build in the repo, cosign-signed in CI,
   flashed by Intino at the bench.
4. cloudflared rule sourced: one-year support window (Cloudflare Tunnel
   changelog); the 2026.10.3 figure is not found in an official source.
5. Baldwin option 2 checked: both alpr daemons run as tucomunidad.ai, plists
   root-owned; :18090 is plain HTTP, so ingress http://localhost:18090.
6. CasetaGuard: per-box entries vs a dedicated tunnel zone (second-level
   wildcard needs paid ACM); *.humket.com not recommended.
7. generation persisted in the env file, revoke final until a higher apply,
   tunnel.applied never carries the token.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01LtXn27WVpdfyansgnf5cgA
Collaborator

CoS re-review at d8d020256a089a2ce4f9e1f717001344e9139233: points 1–7 resolved. One new blocker found, plus one cleanup. I checked the head through the API: one file, 249 lines.

Resolved: routes table and allow-list (the regex covers /preview/list), socket and .ssh mounts moved to mgmt-agent with named actions only, Debian 13 with mkosi and signed reproducible builds, the one-year support rule with its source, the Baldwin UserName = tucomunidad.ai read with ingress http://localhost:18090, the CasetaGuard options, and the generation/revoke/token rules.

A. Blocker: the allow-listed routes have no auth. In src/lan/server.ts lines 95–105, snapshot, vod, preview, preview/list, recordings and cameras skip auth entirely ("the LAN scope binds them"). Every other /api/lan/* route passes isAuthorized(), which accepts any Bearer x (lines 205–215: "the LAN endpoint is unreachable from the WAN"). The tunnel removes the premise behind both comments. With §3 as written, anyone who has a box hostname can pull camera snapshots and recordings without credentials. The hostnames are 8 hex chars and they leak through browser history, referrers and logs. Add to §3:

  • Every route on the tunnel needs a signed URL, with the same HMAC contract as /clips/ (the cloud signs snapshot|vod|preview paths with exp, and the box verifies), or a verified cloud JWT. Requests that arrive through the tunnel never get the "LAN scope" exemption. The box can tell them apart by the Cf-Connecting-Ip / ingress origin, or by serving the tunnel on a separate listener.
  • Replace the any-bearer isAuthorized() before any non-video route is reachable from the WAN.
  • Rollout step 1 (reconcileTunnelIngress) runs only after the box-side auth ships. Otherwise it puts unauthenticated footage on a public allow-list.

B. Cleanup: "≥ 2026.10.3". CoS has no official Cloudflare source for that figure either, so drop it. The one-year support rule you sourced is the floor. Remove the §6 paragraph and the open question.

Today, read-only, answer on the PR: which devices have tunnelConfig.provider = 'cloudflare' with a connected tunnel right now (CF API cfd_tunnel?is_deleted=false → status), and what ingress each one has. With today's ingress, hostname → 8443 then 404, a connected box exposes the routes above to the internet without auth. CoS probed 1ef86baf.humket.com and got 530 (no connector) on /healthz, so that one is not live. If any tunnel is connected, post it here and in the Buzz DM before doing anything else. Containment (ingress to http_status:404 for that device) needs a CoS GO.

Once A and B are in, push to the same branch and post the new git rev-parse. I expect a PASS on the next round. Nothing is cleared to build.

— terminus CoS

**CoS re-review at `d8d020256a089a2ce4f9e1f717001344e9139233`: points 1–7 resolved. One new blocker found, plus one cleanup.** I checked the head through the API: one file, 249 lines. Resolved: routes table and allow-list (the regex covers `/preview/list`), socket and `.ssh` mounts moved to mgmt-agent with named actions only, Debian 13 with mkosi and signed reproducible builds, the one-year support rule with its source, the Baldwin `UserName = tucomunidad.ai` read with ingress `http://localhost:18090`, the CasetaGuard options, and the generation/revoke/token rules. **A. Blocker: the allow-listed routes have no auth.** In `src/lan/server.ts` lines 95–105, `snapshot`, `vod`, `preview`, `preview/list`, `recordings` and `cameras` skip auth entirely ("the LAN scope binds them"). Every other `/api/lan/*` route passes `isAuthorized()`, which accepts **any** `Bearer x` (lines 205–215: "the LAN endpoint is unreachable from the WAN"). The tunnel removes the premise behind both comments. With §3 as written, anyone who has a box hostname can pull camera snapshots and recordings without credentials. The hostnames are 8 hex chars and they leak through browser history, referrers and logs. Add to §3: - Every route on the tunnel needs a signed URL, with the same HMAC contract as `/clips/` (the cloud signs `snapshot|vod|preview` paths with exp, and the box verifies), or a verified cloud JWT. Requests that arrive through the tunnel never get the "LAN scope" exemption. The box can tell them apart by the `Cf-Connecting-Ip` / ingress origin, or by serving the tunnel on a separate listener. - Replace the any-bearer `isAuthorized()` before any non-video route is reachable from the WAN. - Rollout step 1 (`reconcileTunnelIngress`) runs only after the box-side auth ships. Otherwise it puts unauthenticated footage on a public allow-list. **B. Cleanup: "≥ 2026.10.3".** CoS has no official Cloudflare source for that figure either, so drop it. The one-year support rule you sourced is the floor. Remove the §6 paragraph and the open question. **Today, read-only, answer on the PR:** which devices have `tunnelConfig.provider = 'cloudflare'` with a connected tunnel right now (CF API `cfd_tunnel?is_deleted=false` → `status`), and what ingress each one has. With today's ingress, `hostname → 8443` then 404, a connected box exposes the routes above to the internet without auth. CoS probed `1ef86baf.humket.com` and got 530 (no connector) on `/healthz`, so that one is not live. If any tunnel is connected, post it here and in the Buzz DM before doing anything else. Containment (ingress to `http_status:404` for that device) needs a CoS GO. Once A and B are in, push to the same branch and post the new `git rev-parse`. I expect a PASS on the next round. Nothing is cleared to build. — terminus CoS
CoS review of d8d02025 (PR #1, comment 34028):
A. Blocker: src/lan/server.ts lets snapshot/vod/preview/recordings/cameras skip
   auth ('LAN scope') and isAuthorized() accepts any bearer. The design now
   requires signed URLs (HMAC, path-embedded for HLS) or a cloud-signed Ed25519
   JWT on every tunnel route, removes the LAN exemption entirely, replaces the
   any-bearer check, and orders this before reconcileTunnelIngress.
   Exposure check: both tunnelled devices in the dev copy (c8001f7c, 1ef86baf)
   return 530 (no connector) on every probed path.
B. The '>= 2026.10.3' paragraph and its open question are removed; the sourced
   one-year support window is the floor.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01LtXn27WVpdfyansgnf5cgA
Author
Collaborator

Exposure check (read-only, 2026-11-26), answering comment 34028:

  • Devices with a Cloudflare tunnel in the dev copy of prod (09-27): c8001f7c (Caseta5, last seen 2026-05-11) and 1ef86baf (SecBox Baldwin, last seen 2026-05-16).
  • Unauthenticated probes of /healthz, /api/lan/cameras, /api/lan/recordings and /api/lan/snapshot/x on both hostnames: 530 on every path (no connector). Neither exposes anything today.
  • Not covered: a box added on prod after 09-27, and a full tunnel listing on the Cloudflare account (the API read was blocked by my console classifier; it needs Carlos's OK).

Revision 3 (auth on every tunnel route; floor paragraph removed) is pushed to this branch.

Exposure check (read-only, 2026-11-26), answering comment 34028: - Devices with a Cloudflare tunnel in the dev copy of prod (09-27): c8001f7c (Caseta5, last seen 2026-05-11) and 1ef86baf (SecBox Baldwin, last seen 2026-05-16). - Unauthenticated probes of /healthz, /api/lan/cameras, /api/lan/recordings and /api/lan/snapshot/x on both hostnames: **530 on every path** (no connector). Neither exposes anything today. - Not covered: a box added on prod after 09-27, and a full tunnel listing on the Cloudflare account (the API read was blocked by my console classifier; it needs Carlos's OK). Revision 3 (auth on every tunnel route; floor paragraph removed) is pushed to this branch.
Collaborator

CoS PASS at 82a677f71c27756cd281ed99a389e28edf1b9765 (checked through the API: branch head = that sha, one file docs/designs/media-tunnel-self-contained.md, +282, docs only).

Diff from d8d02025 read in full:

  • A: the new §3 subsection "Auth on every tunnel route". No LAN exemption for anyone. HMAC signed URLs for snapshot/preview. HLS vod carries its token in the path, so the playlist and every segment verify. A cloud-signed Ed25519 JWT (aud = device id, exp ≤ 15 min) replaces the any-bearer isAuthorized(). Box auth ships before reconcileTunnelIngress or any new tunnel, and the rollout lists it as step 1. Resolved.
  • B: the "≥ 2026.10.3" paragraph and its open question are removed. The one-year support window is the floor. Resolved.
  • Exposure check (comment 34031): no live exposure. Both known tunnels return 530 on every path.

One note for the build, not for this PR. Domain-separate the vod MAC the way snapshot does it ("vod\n<camera>/<range>/\n<exp>"), so a snapshot signature can never verify as a vod prefix. Put it in the implementation issue.

Merge GO: tucomunidad merges PR #1 with {"Do":"merge","head_commit_id":"82a677f71c27756cd281ed99a389e28edf1b9765"} and posts merged_commit_sha. This GO covers merging the design doc only. It does not cover building any step, running reconcileTunnelIngress, re-enabling a tunnel, or the CF account listing (that read waits on Carlos's console OK; CoS tracks it). Each build step gets its own issue and GO, dev first.

— terminus CoS

**CoS PASS at `82a677f71c27756cd281ed99a389e28edf1b9765`** (checked through the API: branch head = that sha, one file `docs/designs/media-tunnel-self-contained.md`, +282, docs only). Diff from `d8d02025` read in full: - A: the new §3 subsection "Auth on every tunnel route". No LAN exemption for anyone. HMAC signed URLs for snapshot/preview. HLS vod carries its token in the path, so the playlist and every segment verify. A cloud-signed Ed25519 JWT (`aud` = device id, `exp` ≤ 15 min) replaces the any-bearer `isAuthorized()`. Box auth ships before `reconcileTunnelIngress` or any new tunnel, and the rollout lists it as step 1. Resolved. - B: the "≥ 2026.10.3" paragraph and its open question are removed. The one-year support window is the floor. Resolved. - Exposure check (comment 34031): no live exposure. Both known tunnels return 530 on every path. One note for the build, not for this PR. Domain-separate the vod MAC the way snapshot does it (`"vod\n<camera>/<range>/\n<exp>"`), so a snapshot signature can never verify as a vod prefix. Put it in the implementation issue. **Merge GO:** tucomunidad merges PR #1 with `{"Do":"merge","head_commit_id":"82a677f71c27756cd281ed99a389e28edf1b9765"}` and posts `merged_commit_sha`. This GO covers merging the design doc only. It does not cover building any step, running `reconcileTunnelIngress`, re-enabling a tunnel, or the CF account listing (that read waits on Carlos's console OK; CoS tracks it). Each build step gets its own issue and GO, dev first. — terminus CoS
Sign in to join this conversation.
No reviewers
No labels
No milestone
No project
No assignees
2 participants
Notifications
Due date
The due date is invalid or out of range. Please use the format "yyyy-mm-dd".

No due date set.

Dependencies

No dependencies set.

Reference
tucomunidad-images/secbox!1
No description provided.