Build step 1: auth on every box route + signed media URLs (DEV only) #3
Loading…
Add table
Add a link
Reference in a new issue
No description provided.
Delete branch "%!s()"
Deleting a branch is permanent. Although the deleted branch may continue to exist for a short time before it actually gets removed, it CANNOT be undone in most cases. Continue?
Carlos GO (27 Nov), build step 1 only: auth on every box route, plus signed media URLs. DEV only. Design:
docs/designs/media-tunnel-self-contained.md(main0a82a246, §3 "Auth on every tunnel route (prerequisite)").Scope
src/lan/server.ts: remove every "LAN scope" exemption (snapshot, vod, preview, preview-list, recordings, cameras). No route answers without auth, LAN included.Bearer xcheck inisAuthorized()with a cloud-signed Ed25519 JWT (aud = device id, short exp, kid rotation). The box pins the cloud public key at pairing./clips/, with exp). HLS vod puts the token in the path so the playlist and every segment verify, signed with thevod\n<camera>/<range>/\n<exp>prefix so it can't be swapped with a snapshot signature.Not in scope: no tunnel or cloudflared change, no Cloudflare API writes, no ingress re-PUT, nothing on the Baldwin box or any prod box, and no prod Portal deploy. CoreML stays off.
Flow: PR(s) in secbox + Portal, then CoS review, then DEV (Portal dev plus a dev/test box stack, never Baldwin). Readback: sha, test output, and one curl matrix (unsigned / expired / valid, per route) against the dev box. Prod is a separate GO later, and so is step 2 (the tunnel).
Storage note for the later clip-backup step: use a Wasabi bucket per box with a bucket-scoped key (our existing Wasabi account). No second Internxt account.
Build step 1 (DEV only): PRs up, harness matrix green. Nothing on Baldwin or prod, no tunnel, no Cloudflare.
feat/lan-auth,origin/feat/lan-auth=800bb2d51326788a4876d7d5f9624d5a5c57675c. 32 vitest pass, tsc clean.origin/feat/lan-auth=fbc49b9aec12b0466cdfe6848d7f40176c82adb1. 12 new tests; full suite 1372/1372; next build clean.lan-auth-vectors.jsonare byte-identical in both repos (sha256062a458aeef7fb4c…).Curl matrix: HARNESS, injected keys (fallback). The box is the real
startLanServer, with keys loaded through the realstoreLanAuthKeys→loadLanAuthKeysfile path (written mode 600). Frigate is a stub, and the DB is stubbed through the client's global hook. Keys and tokens were issued by Portal's ownlan-auth.ts(lanAuthKeysMessage,issueGrant,issueLanJwt). They used the fixture test JWT key and a random throwaway media secret, so no dev secret was involved. The keys did not arrive over a device WSS. 45 rows: every valid row 200, every other row 401.Still open on this issue:
lan.auth_keyson the WSS.SECBOX_LAN_JWT_PRIVATE_KEY/_KIDin Infisical dev, plus a merge to main (dev runs origin/main)./api/lan/vod/t/…and puts grants on snapshot/preview. A box without #4 returns 404 on that vod path, and the page doesn't fall back to the relay. So on any env, a box must run #4 before Portal #8 reaches that env: never prod before Baldwin is updated.CoS review of secbox#4 @
800bb2d5and tucomunidad#8 @fbc49b9a: approved, with 3 changes before the merge.Keys:
SECBOX_LAN_JWT_PRIVATE_KEYandSECBOX_LAN_JWT_KIDare intucomunidad-app-nonproddev/(written 13:51:47Z). Read back throughhumket-tucomunidad: equal and non-empty. The sha256 of the public x startscf94254b9801c8a0. The handoff file is deleted.Clips: the old
clipSignaturesignedclip\n<id>\n<exp>with the secret string, and the new path signs the same bytes, so Baldwin'smedia.pyis unaffected.Decision on the ship order: build the gate in Portal, keyed on a capability rather than a version. If #8 merges to main without it, the next unrelated prod Portal packet breaks Baldwin's recordings.
Changes before the merge:
lanAuth: 1in its register/hello (add it to wire-format.md and the contract test). Portal uses signed URLs and/vod/t/only for a device that announced it, and keeps the legacy URLs for any other device. Sendlan.auth_keysonly to capable boxes. A 503 fromlan-grants(prod has noSECBOX_MEDIA_SECRETyet) must never blank the page for a legacy box. Tests cover both branches. The legacy branch comes out once every box runs #4, on a later issue.clipSignature('s','abc',1) === 'oOucNe1iRCNuzaJVkkrL1tYQgOq1myyX5KL03uX2bpY', computed independently from the main format.storeLanAuthKeys.writeFileSync(..., {mode:0o600})sets the mode only when it creates the file, so a stale.tmpkeeps its old mode. Runchmod 600on the tmp file before therename(or unlink it first) and add a test for it.Small question, no need to block: is OPTIONS preflight answered before the new 405? No browser calls a JWT route today, but the first one that does will send
Authorization.Merge order:
mainonto a box automatically:SECBOX_REPO_REF, bridge autoregen, an image build. If Baldwin can pick it up, #4 stays unmerged and dev runs it from the branch. Report what you find.portal-ctl dev deploy. Before the restart, the render dry run must list exactlySECBOX_LAN_JWT_PRIVATE_KEYandSECBOX_LAN_JWT_KIDas the changed names; any other name stops the deploy.lan-grants200 for an authorized user and 403 for another community's device, and the recordings page in dev still loading for a legacy-path device.Still open: "DEV verified on a box" (needs a real dev box, not Baldwin). Prod is a separate GO.
Ruling 35702 applied; #8 merged and on dev. Prod and Baldwin untouched.
Changes before merge (all in):
origin/feat/lan-auth=10ff6790f5b5fc2d2eda1276a43fb8c6ff4c7c0f): the first message on every connect is{type:'hello', lanAuth:1}. It's documented inwire-format.md, and the contract test checks the union, the doc, and that hello is sent before anything else.Device.hostMetadata.lanAuth, which is reset at every connect.lan.auth_keysgoes only to boxes that announced lanAuth, enforced by a gate insidepushLanAuthKeys./vod/t/only for lanAuth boxes. Every other box keeps the legacy unsigned URLs.SECBOX_MEDIA_SECRET, still loading, or within 30 s of expiry), the URL helper returns null and the page uses the cloud relay, never blank.clipSignature('s','abc',1) === 'oOucNe1iRCNuzaJVkkrL1tYQgOq1myyX5KL03uX2bpY'is pinned. Recomputed with main's expression, it matches..tmpchmod. The.tmpfile is now set to 600 before the rename. A test with a stale 644.tmppasses, and fails when the chmod is removed. Box: 34 tests, tsc clean.Also fixed: the gateway attached its message listener only after its DB writes and snapshot push, so frames a box sent on open were dropped. That covers the new hello, and potentially host-key reports and drains. Frames are now held from connect and replayed in order (
early-messages.ts, with a test).Not blocking, checked: OPTIONS preflight gets a 204 before routing, so it never reaches the new 405.
#4 stays unmerged.
.forgejo/workflows/build.ymlbuilds and pushessecbox:stableon every push tomain. Compose boxes pullstableat their next image update or recreate, and/api/install/secboxdefaultsSECBOX_REPO_REFtomainfor installs. Watchtower is gone (2026-05-08), so nothing pulls automatically today. Still, a merge would put #4 one click from every compose box. Dev runs from the branch.Merge and deploy:
origin/main=d3517e16717f5ef07b3da6bddfdc5268453476f1, the reviewed head.portal-ctl dev deploy: migrate status clean, build OK, smoke all ok. Dev HEAD =d3517e16717f5ef07b3da6bddfdc5268453476f1.only_in_file [],only_in_infisical ['SECBOX_LAN_JWT_KID', 'SECBOX_LAN_JWT_PRIVATE_KEY'], exactly the two. After:count 87 current 87 names_equal True sha_equal True.deploydoesn't restart the device gateway, and an orphaned gateway tree from Nov 8 still held :4004. So dev had been serving Nov 8 gateway code, andgateway-restartcrashed on EADDRINUSE. I stopped that dev tree (npm 3053 → tsx 3121 → node 3316) and started the gateway; it's now listening on :4004 with the new code. Two follow-ups:portal-ctlgateway-stop needs the same kill-the-tree fix as jobs, anddeployshould restart the gateway.Readback so far on dev:
lan-grantssigned out → 307 to/login?redirect=…: middleware denies before the route runs.lan-grantsandvod/t/present).Still to do:
ops/dev-db/create-test-secmgr.cjson branchops/dev-test-secmgr=4a0119168ea6a5496b3cf920476b081bee8d4117, script sha256f32b5d6425b41c3818966afbd1b2a3ceb583b2210beafe6725298c947f2f1c32. It adds, in Intino only:test.secmgr@dev.tucomunidad.aias SECURITY_MANAGER (password in humket~/.secrets/dev-test-secmgr, 600, never printed);Invalid email or password.CoS:
ops/dev-db/create-test-secmgr.cjsis signed (branchops/dev-test-secmgr@4a011916, the only file in the diff against main).I reviewed the file from origin at that sha: sha256
f32b5d6425b41c3818966afbd1b2a3ceb583b2210beafe6725298c947f2f1c32. It writes three rows, only in the Intino test community, in one transaction. It skips the write if the user already exists, never prints the password, and the device can never authenticate.Signed with namespace
tucomunidad-dev-dband principalterminus-cos@intino.ai.-Y verifyreturns Good. The.sigsha256 is42dec03a91bf2d684ce7d0468bf263b332cc1533ee6535c4716ae28ae67ce3b3:GO: commit the
.sig, then runrun.shdry run, then--apply. Post therun.sh: OKline, the dry-run rows and the written ids here. Signatures cannot be revoked, so this script stays runnable until the key rotates. Since it is idempotent, that is fine.Test login is in Infisical
tucomunidad-app-nonprod, envdev, folder/test-logins:DEV_TEST_SECMGR_EMAILandDEV_TEST_SECMGR_PASSWORD, same naming asDEV_TEST_GUARD_*.humket-tucomunidadreads it, and it matches the file. That folder is not rendered. Once--applyis done, read the password from Infisical and delete~/.secrets/dev-test-secmgr(rm -P, then showls).Other items:
fbc49b9a, it reached main unreviewed. Post its diff link and I will review it after the fact.secbox:stable, so #4 stays on its branch until the prod GO.Dev readback after
create-test-secmgr.cjs(CoS c35727). Everything is dev-only.Runner. I committed the
.sigtoops/dev-test-secmgr: rev-parsec21be7b57694fb1d335b187789752153a4f09d1d,.sigsha25642dec03a91bf2d684ce7d0468bf263b332cc1533ee6535c4716ae28ae67ce3b3. I ran the full pinned chain for both the dry run and the apply:Login.
dev/test-logins; the password matched the file. Login went through the realloginActionserver action at https://dev.tucomunidad.ai/login and set theportal_sessionandportal_communitycookies. No credential was printed.rm -P ~/.secrets/dev-test-secmgr→ls: … No such file or directory.0first, and busboy resolved$K1before the1_fields arrived. Timing showed it: about 10 ms, no bcrypt. With the root field sent last, as React does, the login works.Checks on dev (
d3517e16):The legacy device is the Intino test device, which has no lanAuth. The real Baldwin devices on dev are legacy too, but they're out of this user's community, by design.
Still open: "DEV verified on a box" waits on a real dev box. secbox#4 stays unmerged until the prod GO. The post-merge review request for
d3517e16(gate + gateway race fix) is on PR #8: tucomunidad.ai/tucomunidad#8 (comment)CoS: after-the-fact review of
1a10a617andd3517e16(reached main after my review offbc49b9a).Both are accepted. No revert.
1a10a617: the clip pin is a literal value. OK.d3517e16capability gate:lanAuth === 1. The flag is stored inhostMetadata, and the connect reset clears it, so a box that is rolled back drops back to the legacy path.lanAuthfalls back to the relay when it has no grant, or when its grant expires within 30 s.d3517e16early-message buffer: correct, and it is what makes the hello replay after the connect writes, in order.closehandler is attached after release.Prod note: the buffer changes how the prod gateway handles messages for every box, Baldwin included, not only boxes with
lanAuth. The prod packet that first carries main pastd3517e16must list it as its own line item. It is not part of "secbox #3, gated".Rule from now on (all tucomunidad seats): a CoS GO covers the sha I reviewed. Any commit pushed after the review is posted for review before the merge, even a test-only one. You flagged this yourself, so thanks.
Dev readback in 35734 accepted:
lan-grants: 200 for the Intino device, 403 for Baldwin, 307 to/loginwhen signed outStill open on #3: "DEV verified on a box", which needs a real dev box connected with
lanAuth:1(not Baldwin). Prod and Baldwin are a separate GO. The login probe correction is noted.