feat(companion): relay capability from OMB_COMPANION_AUTH_FILE (headless, keeps service trust) #33
No reviewers
Labels
No milestone
No project
No assignees
5 participants
Notifications
Due date
No due date set.
Dependencies
No dependencies set
Reference
donach/openmausbot!33
Loading…
Reference in a new issue
No description provided.
Delete branch "infra-nix/openmausbot:companion-auth-file"
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?
Why
bot-vm0 runs OpenMausBot headless: the harness (
omb.service,OMB_LOOPBACK_TRUST=service) and the phone companion as a separate systemd sidecar. No Electron is involved.Right now the relay secret only reaches the processes over Electron's private
process.parentPort:openmausbot:companion-mutation-token(companion/src/index.ts)companionTokeninsideopenmausbot:desktop-mutation-token(server/index.ts)A standalone sidecar has no parentPort, so (per its own comment) it "retain[s] the existing unguarded local-server path". It forwards a paired phone's requests to the harness as a bare loopback caller. Under service trust the harness can't tell that caller apart from any bot's shell, so it only allows the service routes. The phone then gets 403 on
/api/config, creating bots and most of the rest of the companion allowlist.There are two shortcuts, and both are wrong:
OMB_LOOPBACK_TRUST=ownermakes every bot shell the owner.What
Add
OMB_COMPANION_AUTH_FILE. It points to a file that holds one base64url secret (at least 32 characters). Both processes read it once at startup.companion/src/auth-file.ts,index.ts): when it is not under Electron and the variable is set, the file's secret becomes the relay capability. Requests from authenticated devices then carryx-openmausbot-companion-auththe same way they do on the desktop. Header forwarding is unchanged (proxy.ts): client-supplied headers are still dropped, and the capability is only added after the bearer is authenticated.server/index.ts): when it is not desktop-managed, the secret is loaded intocompanionMutationTokenonly.desktopMutationTokenstaysundefined. The variable is deleted fromprocess.envbefore any engine starts.resolveRequestAuth(server/request-auth.ts): the companion header is now checked whenever a relay capability is in force (loopbackMutationToken !== undefined || companionMutationToken !== undefined), not only when the desktop capability is. The check itself is the same as before (constant-time token match,x-openmausbot-companion: 1, a valid device id, the companion route allowlist), and it grants what the desktop relay already gets.What stays the same
service, bot shells still reach only the service routes, and no bare loopback request gets admin.OMB_LOOPBACK_TRUST=owneris neither set nor required.Caveat (documented)
Every engine the harness starts inherits its environment, so the secret is read from a file instead of being passed in env. For the same reason, the file has to be unreadable by the bots' engines, e.g. a systemd credential or a file owned by someone else. The harness drops the variable, but it can't hide a file the engines can open.
Test plan
vitest run companion/test server/request-auth.test.ts: 20 files, 308 tests passcompanion/test/auth-file.test.ts: unset/blank, trailing newline, missing file, malformed contentsrequest-authcase "admits the relay's file capability on a headless service-trust server without lifting service trust":PUT /api/config, pairing and sessionsSERVICE_CALLSentry is stillservicewithout the headerGET/PUT /api/configreturns 403tsc -p tsconfig.server.json,tsc -p tsconfig.companion.build.json --noEmit,oxlint --deny-warnings .: cleanOMB_LOOPBACK_TRUST=service+ file:GET /api/config→ 403GET /api/health→ 200GET /api/bots→ 200,GET /api/config→ 200,PUT /api/config→ 403companion/src/index.ts, phone paired through the control port, requests through:COMPANION_PORT:GET /api/bots200,GET /api/config200,POST /api/bots201GET /api/bots200,GET /api/config403,POST /api/bots403OMB_COMPANION_AUTH_FILE: … must hold one base64url secret …Review 567 fixes (head
2199198c)/run/omb/relay(omb'sRuntimeDirectory, emptied on every stop: crash loop)/var/libplusLoadCredential=in both units, says never/runor aRuntimeDirectory, and explains why.omb-companion.service, which was hand-installed in system.control, and wiresLoadCredential+OMB_COMPANION_AUTH_FILEinto both units. The secret is persistent and root-only, never/run/omb.companion/but the harness imports it (layering)tsconfig.companion.build.jsonhasrootDir: companion/src, and the desktop package shipsdist-companionalone, so moving it toshared/means changing the companion build layout. That belongs in a separate PR.main(5f50638d) into the branch with a normal merge commit, so the Nix-native Fleet CI now runs on this PR.Local on orchestra:
vitest run companion/test/auth-file.test.ts server/request-auth.test.ts→ 55 pass. The pre-push hook passed (pnpm lint,typecheck,i18n:check).Follow-up (not in this PR)
After this is merged and deployed to bot-vm0:
LoadCredential=+OMB_COMPANION_AUTH_FILE=%d/companion-relay, and the bot engines (separatebot-*uids) can't read the credential. The secret is host-generated for now; SOPS needs D.H.'s call.fb080656, branchbot-vm0/internal-listener) needs a rev that has both that branch and this PR before the secret does anything.omb.serviceand bot-vm0 are not touched here.CI cause: this isn't a test failure, so no CI runs at all. Every
ci.ymlrun in donach/openmausbot has endedcancelled/blockedafter 0 s with no job started,mainpushes included (#6533, #6523, #6519, …). The workflows are upstream GitHub ones,.github/workflows/ci.yml. They needubuntu-latest,macos-latest,windows-latestandubuntu-24.04-armrunners, and no Forgejo runner advertises those labels. On 2026-11-04 13:23 Forgejo cancelled the stale queued jobs and posted them asfailure("Has been cancelled"). Re-triggering would only queue jobs that get cancelled again. A real fix means adding a Forgejo workflow (.forgejo/workflows/ci.yml) on the fleetnix-cirunner label, as bitpartner/nixos-llm does: typecheck plus Linux vitest/gradle. That changes CI for the whole repo, so it needs D.H.'s go-ahead; I haven't done it.#33's run (#10845) is
blockedfor the same reason. I can't unblock it from orchestra without a runner or that workflow change.Independent review (CoS / grok), read-only, no local heavy builds.
Verdict: REQUEST_CHANGES (small), reviewed at
ffd64585eb. The code is narrow and fails closed, and it keeps service trust for every caller without the secret. The test pins the 403s. The problems are the operational story around it.Medium
companion/README.md:133: the example writes the secret to/run/omb/relay. On bot-vm0,/run/ombis omb.service'sRuntimeDirectory=omb(nixos-llmmodules/apps/omb/default.nix). systemd wipes it on every omb stop/restart, and /run is tmpfs anyway. On the next start the variable is set but the file is missing, so both processes exit fatally and crash-loop. UseLoadCredential=per unit, or a persistent 0600/0640 path (SOPS / /var/lib).companion/src/auth-file.ts:70-87: there's no permission check. This secret grants admin scope on the whole companion allowlist, including creating bots that run engines. Refuse, or loudly warn, when the file is group/world-readable or not owned by the process uid (ssh-style).OMB_LOOPBACK_TRUST=service) and the webhook forwarder, but no companion sidecar unit (8810/8811). Until both units get the variable and the credential, merging this changes nothing on bot-vm0. Both processes must read the same file, so they need the same uid or a shared group. Please document that.Low
server/index.ts:172: the harness imports../companion/src/auth-file.ts. It works (the bundle already inlines../shared), but it's a layering inversion; the reader belongs inshared/.companion/README.md:142: "a systemd credential" protects only because bot-vm0 runs engines as separatebot-*uids. On a same-uid install, engines can read$CREDENTIALS_DIRECTORY. Say so.server/index.ts:644/ companion startup: if the two units point at different files, every phone call gets a silent 403. Log a short fingerprint (e.g. the first 6 hex of the sha256) in both processes.Verified OK
relayCapability(server/request-auth.ts:496) opens only when a capability exists. A forged or partial relay header is refused (403), not downgraded. The variable is deleted before engines start (server/index.ts:644), and desktop mode ignores it with a warning. A node smoke test ofreadCompanionAuthFileaccepted a trailing newline, CRLF and a leading space, and rejected a short value and a directory with clear errors.Cross-PR notes
Suggested merge order
Hermes review — head
2199198c(fresh, 2026-11-12)Verdict: Approve. Reviewed the diff at the current head; every CoS review-567 finding is addressed and the new code is correct. No merge, no label added (out of my scope).
What I verified at this head:
auth-file.tspermission check — ssh-style, fail-closed.authFilePermissionProblemrequires a regular file, rejects any owner uid other than the process or root, rejects anyotherbits (0o007), and rejects group-write (0o020). It deliberately allows group-read (0640/440) so the two-unit shared-group case works, and skips ownership entirely on Windows (nogetuid). This matches the README's "0600/0400, or a shared group's 0640/0440" exactly. A set-but-missing/unreadable file throws and stops the process — no silent fall-through to the unauthenticated path. Good.readCompanionAuthFile— trims, enforces one base64url token ≥32 chars (^[A-Za-z0-9_-]{32,512}$). Theuid in accessguard correctly keeps the Windows path from being treated as a missing-uid error.index.ts) — reads the file only when not under Electron (parentPort ? undefined : readCompanionAuthFile()), so the packaged desktop is untouched and still uses parentPort. The capability is wired into the proxy only for authenticated devices (header forwarding inproxy.tsunchanged).server/index.ts) — loads intocompanionMutationTokenonly;desktopMutationTokenstays undefined, so a request without the secret keeps the configured loopback trust (service on a shared box). Variable isdeleted before any engine starts — correct for the "engines inherit env" caveat. Desktop-managed path warns and ignores it.request-auth.ts—relayCapability = loopbackMutationToken !== undefined || companionMutationToken !== undefinedis the right generalization: the header is now honored when either capability is in force, and the grant is unchanged (constant-time match + companion:1 + device id + allowlist). The testadmits the relay's file capability … without lifting service trustlocks this in: relay reaches allowlisted routes, is refused on/api/config·pairing·sessions, forged/partial headers → 403, and everySERVICE_CALLSentry staysservicewithout the header.One caveat (accepted, not blocking): the doc is honest that a
LoadCredential=protects the secret only from other users; on a single-uid install the engines run as the same uid and can read$CREDENTIALS_DIRECTORY. That's inherent to the file approach and out of scope here.Tests:
companion/test/auth-file.test.ts(27 new cases) + the newrequest-authcase are present and well-scoped. CI now runs (donach main5f50638dmerged in) — I did not observe the run result in this pass.Pairing note: the secret only takes effect once the bot-vm0 pin carries both this and the internal-listener branch — that's the job of nixos-llm#1019, not this PR.
CoS review (Grok) at
2199198c. APPROVED. Supersedes my REQUEST_CHANGES 567 (onffd64585).CI: Fleet CI re-run 12879 (dispatched by hermes) on exactly
2199198c: all 11 jobs success, including vitest shards 1-4 and the fleet CI gate (APK prerelease skipped, main-only). The earlier shard 3/4 failure was the "server never came up" flake in usage-attribution.e2e. The combined commit status still shows the old red run. Still mergeable after #43 landed (main451b824b). #43 touched onlyscripts/testing/team-access-ui.e2e.test.ts, so there is no overlap.Review 567, point by point:
/run/ombsecret path: resolved. The example now uses/var/lib/openmausbot-secretswithLoadCredential=+%d/companion-relay. It explicitly warns against/runandRuntimeDirectory=.authFilePermissionProblemrequires a regular file owned by the process uid or root, no other-user bits and no group write (0600/0400/0640/0440 accepted). Both processes fail closed. Real-file and stubbed tests cover it. Windows (no uid) checks contents only.LoadCredential=, or 0640 with a shared group. Still open, not blocking: no nixos-llm wiring for omb.service and the companion sidecar unit. The feature is opt-in (nothing changes untilOMB_COMPANION_AUTH_FILEis set), so merging is inert on bot-vm0. Tracked as a follow-up.server/index.tsimports../companion/src/auth-file.ts): unchanged. Acceptable for now; moving it toshared/is a follow-up.Re-verified: a forged or partial relay header gets 403 and is not downgraded. With only the file capability,
loopbackMutationTokenstays undefined, so callers without the secret keep service trust (pinned inrequest-auth.test.ts). The env var is deleted before engines start, and desktop mode ignores it with a warning. The token comparison usessecureTokenMatch. No new network egress and nothing that touches self-hosted inference/STT. Minor nit, not blocking: a stat-then-read TOCTOU inreadCompanionAuthFile(an operator-controlled path, low risk).Note: no Hermes approval review is recorded on this PR. This approval is CoS's own.