feat(companion): T3 Code QR pairing + omb pair under service trust (no loopback widening) #44
No reviewers
Labels
No milestone
No project
No assignees
2 participants
Notifications
Due date
No due date set.
Dependencies
No dependencies set
Reference
donach/openmausbot!44
Loading…
Reference in a new issue
No description provided.
Delete branch "feat/service-trust-pairing-qr"
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?
Pair the T3 Code app with the companion by QR, and make
omb pairwork on a service-trust server (bot-vm0) without widening loopback rights. Brief: D.H., handoff ho-944b9e2fe979.What I found first: the pair page is not what request-auth refuses
I reproduced bot-vm0's setup on an isolated fixture: harness with
OMB_LOOPBACK_TRUST=serviceand noOMB_COMPANION_AUTH_FILE, plus a standalone companion. Results:POST/DELETE 127.0.0.1:8811/pairingDeviceRegistry)POST :8810/api/paircompanion/src/proxy.ts)GET :8810/api/bots→ harnessPOST :8810/api/bots/:id/messages→ harnessrequest-auth.ts:524openmausbot pair/omb pairPOST :8799/api/auth/pairingSERVICE_TRUST_HELP)Opening, closing and redeeming a companion pairing window already work under service trust because they never reach the harness. The two 403s are (a) a paired phone's ordinary chat, which is the
OMB_COMPANION_AUTH_FILEgap (below), and (b) the CLI asking the harness for a pairing code. So this PR makes norequest-auth.tschange and adds no service-trust exception.omb pairgoes through the same companion path as the pair page.How the pair page and
omb pairare told apart from any other loopback callerSERVICE_ALLOW.POST/GET /api/auth/pairing, sessions, config, settings, people and access routes all stay 403, including with a forgedx-openmausbot-cli-ownerheader or a relay header when no relay secret is configured (tested). The only existing secrets that open harness routes are unchanged:cliOwnerToken: per launch, passed over stdin to the server thatopenmausbot servestarts.OMB_COMPANION_AUTH_FILE, or from Electron's private port.127.0.0.1only. It refuses a non-loopbackHost(DNS rebinding) and anyOriginother than its own (CSRF from a browser page). That separates the page from a browser, but not from a local process. On bot-vm0, what keeps bots' shells off it is the existing host rule in nixos-llmmodules/apps/omb/companion.nix: nftablesmeta skuid 3000-3999 tcp dport {8810, 8811} reject.omb pairuses exactly that port and the samePOST /pairing, so it has the page's rights and no more. I did not add a new secret, as instructed.127.0.0.1:8811can open a window, read its code and pair itself. The bot-uid nftables rule is the guard. That is how the sidecar was designed ("running it is the opt-in") and this PR does not change it.omb-companionis down or restarting, a bot process could bind 8811 and answer/state. Both the page andomb pairwould then show that process's QR. The CLI's identity check (the shape of/state) does not stop this. Closing it would take systemd socket activation for the port, or a uid check on the listener. That belongs in the nixos-llm unit, not here.QR: what it carries
omb pairprints a terminal QR.t3 pairprints it:<address>/pair#token=<credential>.addressis the companion's hosted HTTPS endpoint, or else its tailnet MagicDNS endpoint. The T3 Code app dials plain http only on the tailnet, so a LAN-only machine shows the six-digit code with no QR, andomb pairsays why.credentialis the window's one-timeomb_pair_…pairing credential, whichDeviceRegistry.redeemaccepts in place of the six-digit code.POST /api/pair, and it appears only in that response. The credential dies on first use, on the next "Start pairing", and after 2 minutes. It sits in the URL fragment, so a browser that opens the link never sends it to a server.packages/shared/src/qrCode.ts), copied tocompanion/src/qr-code.ts. The sidecar runs from source with nonode_modules(bot-vm0's unit and Electron both do this), so it cannot take an npm dependency. A generated QR decodes withzbarimgto the expected link.omb_pair_credential pair as Settings → Agents server instead.omb pairombis already theopenmausbotCLI wrapper innix/package.nix.openmausbot pair --companion, and plainpairwhenever the harness refuses as a service-trust server, opens the window onOMB_CONTROL_PORT(default 8811)./stateshape) before opening a window.SERVICE_TRUST_HELP. It says when--label,--client,--public-urlor--phonedon't apply to a companion window.OMB_CONTROL_PORTis validated forpaironly.pairsends exactly the same requests as before.ombon PATH on bot-vm0 is not in this PR. That is a separate nixos-llm change.⚠️ A paired phone still reaches only the service routes
Until
OMB_COMPANION_AUTH_FILEis provisioned for bothomb.serviceandomb-companion.service, the harness cannot tell a paired phone's forwarded requests from a bot's shell. Pairing succeeds and the persona list loads, but sending a message gets 403 (row 4 above, pinned by a test). This PR does not create that secret.Tests
companion/test/service-trust-pairing.test.ts(new) wires the real control server, proxy andDeviceRegistryto a harness running the realresolveRequestAuthon service trust:/api/auth/pairing, sessions,/api/config, custom-domain andPOST /api/botsstay 403 to a session-less loopback caller, including with forged CLI-owner or relay headers.GET /api/bots200 andPOST …/messages403.companion/test/control.test.ts: link shape; a LAN-only machine gets no QR; QR SVG shape; page copy; the device token is in neither the link nor the QR.server/cli-pair.test.ts: the TTY and scripted fallbacks go to the control port; a hosted-workspace refusal does not.server/cli.test.ts:--companionparsing; the output block;runCompanionPairagainst a real control server (the window it opens is the one printed); a clear failure when nothing listens.server/cli-service-trust.e2e.test.ts: the real CLI on a real service-trust server still refusespairwith the explanation when no companion runs. The test now pinsOMB_CONTROL_PORTso it can never open a window on a real companion on the test machine.Ran locally:
pnpm lint,pnpm typecheck,pnpm i18n:checkandpnpm build:companionpass.vitest run companion/test server/request-auth.test.ts(21 files, 317 tests) andvitest run server/cli-pair.test.ts server/cli.test.ts server/cli-service-trust.e2e.test.ts companion/test/control.test.ts companion/test/service-trust-pairing.test.ts(5 files, 76 tests) all pass.omb pairon service trust printed address, code, expiry and QR. Redeeming the QR's credential at:8810/api/pairreturned a device.🤖 Generated with Claude Code
omb pairunder service trust 8add78317fpairfallbackReviewed at
54154015. CI: all Fleet CI contexts green (APK prerelease skipped as main-only).Approve. Checked:
<addr>/pair#token=omb_pair_<32B base64url>; credential in fragment, one-time, 2-min, dies on next Start/Cancel. Device token never in link/QR (asserted in tests).pairunder service trust goes to the companion control port (127.0.0.1) and never mints from the harness; hosted-workspace refusals still throw. service-trust-pairing.test pins harness admin/pairing routes still 403 and no harness exception.pair; e2e uses a private port so it never opens a real window.Nit (non-blocking): in server/cli.ts the refusedAsService doc comment now sits above SharedServerRefusal instead of its function.