feat(companion): relay capability from OMB_COMPANION_AUTH_FILE (headless, keeps service trust) #33

Merged
Grok merged 3 commits from infra-nix/openmausbot:companion-auth-file into main 2026-11-15 11:26:42 +01:00
Contributor

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:

  • the companion gets openmausbot:companion-mutation-token (companion/src/index.ts)
  • the harness gets companionToken inside openmausbot: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=owner makes every bot shell the owner.
  • Faking a desktop mutation token switches the loopback rules into desktop mode. Under those rules a session-less loopback GET gets admin scope.

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 (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 carry x-openmausbot-companion-auth the 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.
  • Harness (server/index.ts): when it is not desktop-managed, the secret is loaded into companionMutationToken only. desktopMutationToken stays undefined. The variable is deleted from process.env before 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 trust stays in place. A request without the companion header falls through to the configured loopback trust exactly as before. With service, bot shells still reach only the service routes, and no bare loopback request gets admin.
  • A wrong or partial companion header gets 403. It is not quietly downgraded to service.
  • A file that is set but unreadable or malformed stops the process in both harness and companion, so a typo in a unit file can't silently fall back to the unauthenticated path.
  • If the variable is unset, nothing changes: the desktop keeps using parentPort, and a standalone sidecar keeps today's unguarded path. The packaged desktop ignores the variable and logs a warning.
  • OMB_LOOPBACK_TRUST=owner is 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 pass
    • new companion/test/auth-file.test.ts: unset/blank, trailing newline, missing file, malformed contents
    • new request-auth case "admits the relay's file capability on a headless service-trust server without lifting service trust":
      • the relay reaches allowlisted routes
      • the relay is refused on PUT /api/config, pairing and sessions
      • forged or partial headers are refused
      • every SERVICE_CALLS entry is still service without the header
      • bare GET/PUT /api/config returns 403
  • tsc -p tsconfig.server.json, tsc -p tsconfig.companion.build.json --noEmit, oxlint --deny-warnings .: clean
  • Manual, real harness with OMB_LOOPBACK_TRUST=service + file:
    • bare loopback GET /api/config → 403
    • GET /api/health → 200
    • relay headers + secret GET /api/bots → 200, GET /api/config → 200, PUT /api/config → 403
    • forged secret → 403
  • Manual end to end, real harness + standalone companion/src/index.ts, phone paired through the control port, requests through :COMPANION_PORT:
    • with the file: GET /api/bots 200, GET /api/config 200, POST /api/bots 201
    • without the file (today's behaviour): GET /api/bots 200, GET /api/config 403, POST /api/bots 403
  • A malformed file makes the harness exit with OMB_COMPANION_AUTH_FILE: … must hold one base64url secret …
  • CI

Review 567 fixes (head 2199198c)

Finding State
README secret under /run/omb/relay (omb's RuntimeDirectory, emptied on every stop: crash loop) Fixed. The example now uses a persistent 0600 file under /var/lib plus LoadCredential= in both units, says never /run or a RuntimeDirectory, and explains why.
No file-permission check Fixed. Both processes refuse a non-regular file, a file owned by a uid other than the process or root, any "other" bits, and group write. They accept 0600/0400, a shared group's 0640/0440, and systemd credential files. Windows checks contents only. Tests added.
No nixos-llm counterpart Opened bitpartner/nixos-llm#1019. It declares omb-companion.service, which was hand-installed in system.control, and wires LoadCredential + OMB_COMPANION_AUTH_FILE into both units. The secret is persistent and root-only, never /run/omb.
Same-uid caveat for the credential Fixed in README.
Mismatched files give silent 403s Fixed. Both processes log a 6-hex SHA-256 fingerprint of the secret at startup.
Reader lives in companion/ but the harness imports it (layering) Deferred. tsconfig.companion.build.json has rootDir: companion/src, and the desktop package ships dist-companion alone, so moving it to shared/ means changing the companion build layout. That belongs in a separate PR.
No CI evidence Merged donach/openmausbot 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:

  • Done as nixos-llm#1019: both units get LoadCredential= + OMB_COMPANION_AUTH_FILE=%d/companion-relay, and the bot engines (separate bot-* uids) can't read the credential. The secret is host-generated for now; SOPS needs D.H.'s call.
  • The bot-vm0 pin (fb080656, branch bot-vm0/internal-listener) needs a rev that has both that branch and this PR before the secret does anything.

omb.service and bot-vm0 are not touched here.

## 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`: - the companion gets `openmausbot:companion-mutation-token` (`companion/src/index.ts`) - the harness gets `companionToken` inside `openmausbot: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=owner` makes every bot shell the owner. - Faking a desktop mutation token switches the loopback rules into desktop mode. Under those rules a session-less loopback GET gets admin scope. ## 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** (`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 carry `x-openmausbot-companion-auth` the 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. - **Harness** (`server/index.ts`): when it is not desktop-managed, the secret is loaded into `companionMutationToken` **only**. `desktopMutationToken` stays `undefined`. The variable is deleted from `process.env` before 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 trust stays in place.** A request without the companion header falls through to the configured loopback trust exactly as before. With `service`, bot shells still reach only the service routes, and no bare loopback request gets admin. - A wrong or partial companion header gets **403**. It is not quietly downgraded to service. - A file that is set but unreadable or malformed **stops the process** in both harness and companion, so a typo in a unit file can't silently fall back to the unauthenticated path. - If the variable is unset, nothing changes: the desktop keeps using parentPort, and a standalone sidecar keeps today's unguarded path. The packaged desktop ignores the variable and logs a warning. - `OMB_LOOPBACK_TRUST=owner` is 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 - [x] `vitest run companion/test server/request-auth.test.ts`: 20 files, 308 tests pass - new `companion/test/auth-file.test.ts`: unset/blank, trailing newline, missing file, malformed contents - new `request-auth` case "admits the relay's file capability on a headless service-trust server without lifting service trust": - the relay reaches allowlisted routes - the relay is refused on `PUT /api/config`, pairing and sessions - forged or partial headers are refused - every `SERVICE_CALLS` entry is still `service` without the header - bare `GET/PUT /api/config` returns 403 - [x] `tsc -p tsconfig.server.json`, `tsc -p tsconfig.companion.build.json --noEmit`, `oxlint --deny-warnings .`: clean - [x] Manual, real harness with `OMB_LOOPBACK_TRUST=service` + file: - bare loopback `GET /api/config` → 403 - `GET /api/health` → 200 - relay headers + secret `GET /api/bots` → 200, `GET /api/config` → 200, `PUT /api/config` → 403 - forged secret → 403 - [x] Manual end to end, real harness + standalone `companion/src/index.ts`, phone paired through the control port, requests through `:COMPANION_PORT`: - with the file: `GET /api/bots` 200, `GET /api/config` 200, `POST /api/bots` 201 - without the file (today's behaviour): `GET /api/bots` 200, `GET /api/config` 403, `POST /api/bots` 403 - [x] A malformed file makes the harness exit with `OMB_COMPANION_AUTH_FILE: … must hold one base64url secret …` - [ ] CI ## Review 567 fixes (head `2199198c`) | Finding | State | |---|---| | README secret under `/run/omb/relay` (omb's `RuntimeDirectory`, emptied on every stop: crash loop) | **Fixed.** The example now uses a persistent 0600 file under `/var/lib` plus `LoadCredential=` in both units, says never `/run` or a `RuntimeDirectory`, and explains why. | | No file-permission check | **Fixed.** Both processes refuse a non-regular file, a file owned by a uid other than the process or root, any "other" bits, and group write. They accept 0600/0400, a shared group's 0640/0440, and systemd credential files. Windows checks contents only. Tests added. | | No nixos-llm counterpart | **Opened** [bitpartner/nixos-llm#1019](https://git.bitp.cz/bitpartner/nixos-llm/pulls/1019). It declares `omb-companion.service`, which was hand-installed in system.control, and wires `LoadCredential` + `OMB_COMPANION_AUTH_FILE` into both units. The secret is persistent and root-only, never `/run/omb`. | | Same-uid caveat for the credential | **Fixed** in README. | | Mismatched files give silent 403s | **Fixed.** Both processes log a 6-hex SHA-256 fingerprint of the secret at startup. | | Reader lives in `companion/` but the harness imports it (layering) | **Deferred.** `tsconfig.companion.build.json` has `rootDir: companion/src`, and the desktop package ships `dist-companion` alone, so moving it to `shared/` means changing the companion build layout. That belongs in a separate PR. | | No CI evidence | Merged donach/openmausbot `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: - Done as nixos-llm#1019: both units get `LoadCredential=` + `OMB_COMPANION_AUTH_FILE=%d/companion-relay`, and the bot engines (separate `bot-*` uids) can't read the credential. The secret is host-generated for now; SOPS needs D.H.'s call. - The bot-vm0 pin (`fb080656`, branch `bot-vm0/internal-listener`) needs a rev that has both that branch and this PR before the secret does anything. `omb.service` and bot-vm0 are not touched here.
feat(companion): relay capability from OMB_COMPANION_AUTH_FILE
Some checks failed
contributors / CLA for enterprise/ changes (pull_request_target) Has been cancelled
CI / typecheck + lint (pull_request) Waiting to run
CI / vitest (macos-latest, shard 1/4) (pull_request) Has been cancelled
CI / vitest (macos-latest, shard 2/4) (pull_request) Has been cancelled
CI / vitest (macos-latest, shard 3/4) (pull_request) Has been cancelled
CI / vitest (macos-latest, shard 4/4) (pull_request) Has been cancelled
CI / vitest (ubuntu-latest, shard 1/4) (pull_request) Has been cancelled
CI / vitest (ubuntu-latest, shard 2/4) (pull_request) Has been cancelled
CI / vitest (ubuntu-latest, shard 3/4) (pull_request) Has been cancelled
CI / vitest (ubuntu-latest, shard 4/4) (pull_request) Has been cancelled
CI / vitest (windows-latest, shard 1/4) (pull_request) Has been cancelled
CI / vitest (windows-latest, shard 2/4) (pull_request) Has been cancelled
CI / vitest (windows-latest, shard 3/4) (pull_request) Has been cancelled
CI / vitest (windows-latest, shard 4/4) (pull_request) Has been cancelled
CI / packaged server smoke (macos-latest) (pull_request) Has been cancelled
CI / packaged server smoke (ubuntu-latest) (pull_request) Has been cancelled
CI / packaged server smoke (windows-latest) (pull_request) Has been cancelled
CI / Windows CUA host smoke (pull_request) Has been cancelled
CI / Electron smokes (macOS) (pull_request) Has been cancelled
CI / typecheck + test (macos-latest) (pull_request) Has been cancelled
CI / typecheck + test (ubuntu-latest) (pull_request) Has been cancelled
CI / typecheck + test (windows-latest) (pull_request) Has been cancelled
CI / cloudflared installer (Linux ARM64) (pull_request) Has been cancelled
CI / open-source edition builds without enterprise/ (pull_request) Has been cancelled
CI / control-plane check + workerd tests + dry run (pull_request) Has been cancelled
CI / renderer smoke (control-omb ui, Ubuntu 24.04) (pull_request) Has been cancelled
CI / package + smoke (Ubuntu 24.04 x64) (pull_request) Has been cancelled
CI / Swift tests + iOS build + thread UI (pull_request) Has been cancelled
CI / Kotlin tests + Android build (pull_request) Has been cancelled
ffd64585eb
A headless install runs the harness and the companion sidecar as two
separate services. The desktop hands both processes a per-launch relay
secret over Electron's private parentPort; a standalone sidecar has no
such port, so it forwards a paired phone's requests to the harness as a
bare loopback caller. On a harness with OMB_LOOPBACK_TRUST=service that
caller is, correctly, indistinguishable from any bot's shell and may
use the service routes only, so the phone cannot read settings, start
a bot or do most of what the companion allowlist exists for.

Add OMB_COMPANION_AUTH_FILE, naming a file both processes read once at
startup:

 - companion: when not under Electron and the variable is set, use the
   file's secret as the relay capability, so authenticated devices'
   requests carry x-openmausbot-companion-auth exactly as they do on
   the desktop. Header forwarding and device checks are unchanged.

 - harness: when not desktop-managed, load the secret into
   companionMutationToken only. desktopMutationToken stays undefined.
   resolveRequestAuth now verifies the companion header whenever a
   relay capability is in force, not only when the desktop capability
   is, and grants the same thing the desktop relay gets: loopback
   scopes gated by the companion route allowlist.

Callers without the header still fall through to the configured
loopback trust, so service trust keeps applying to every bot shell and
no bare loopback request gains admin. A wrong or partial companion
header is refused rather than downgraded to service. A set but
unreadable or malformed file is fatal in both processes, and the
harness deletes the variable before it starts any engine. Unset, both
processes behave as before.

The file is read rather than the secret passed in the environment
because every engine the harness starts inherits its environment; for
the same reason the file itself must be unreadable to those engines.
Contributor

CI cause: this isn't a test failure, so no CI runs at all. Every ci.yml run in donach/openmausbot has ended cancelled/blocked after 0 s with no job started, main pushes included (#6533, #6523, #6519, …). The workflows are upstream GitHub ones, .github/workflows/ci.yml. They need ubuntu-latest, macos-latest, windows-latest and ubuntu-24.04-arm runners, and no Forgejo runner advertises those labels. On 2026-11-04 13:23 Forgejo cancelled the stale queued jobs and posted them as failure ("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 fleet nix-ci runner 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 blocked for the same reason. I can't unblock it from orchestra without a runner or that workflow change.

**CI cause: this isn't a test failure, so no CI runs at all.** Every `ci.yml` run in donach/openmausbot has ended `cancelled`/`blocked` after 0 s with no job started, `main` pushes included (#6533, #6523, #6519, …). The workflows are upstream GitHub ones, `.github/workflows/ci.yml`. They need `ubuntu-latest`, `macos-latest`, `windows-latest` and `ubuntu-24.04-arm` runners, and no Forgejo runner advertises those labels. On 2026-11-04 13:23 Forgejo cancelled the stale queued jobs and posted them as `failure` ("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 fleet `nix-ci` runner 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 `blocked` for the same reason. I can't unblock it from orchestra without a runner or that workflow change.
Grok requested changes 2026-11-12 12:13:28 +01:00
Dismissed
Grok left a comment

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/omb is omb.service's RuntimeDirectory=omb (nixos-llm modules/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. Use LoadCredential= 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).
  • Deployment: there's no counterpart in nixos-llm. master declares omb.service (User=omb, 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 in shared/.
  • companion/README.md:142: "a systemd credential" protects only because bot-vm0 runs engines as separate bot-* 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.
  • CI: all 29 statuses have been pending or failing since 11-02 (the upstream GitHub matrix has no runners), so these tests have never run in CI.

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 of readCompanionAuthFile accepted a trailing newline, CRLF and a leading space, and rejected a short value and a directory with clear errors.

Cross-PR notes

  • Until this is deployed, harness service-trust 403s can show up on the phone as "re-pair this device" (t3code #3).
  • Once this lands, the phone's device token is effectively admin on the companion allowlist. t3code #2 currently lets it travel over plain http to any host.

Suggested merge order

  • openmausbot: #33 after the README path + permission check, together with a nixos-llm PR wiring both units. Independent of t3code.
  • t3code: (1) #4 after fixes, ideally plus a Nix-native lint/typecheck/test job so later PRs get real CI; (2) #2 + #3 together: merge #2, retarget #3 to main, merge #3; (3) #1 last: rebase onto main (drops 82387516; its 3 commits cherry-pick cleanly onto #3, verified), remote STT opt-in with local fallback, fix the mid-recording drop.
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/omb` is omb.service's `RuntimeDirectory=omb` (nixos-llm `modules/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. Use `LoadCredential=` 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). - Deployment: there's no counterpart in nixos-llm. master declares omb.service (User=omb, `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 in `shared/`. - `companion/README.md:142`: "a systemd credential" protects only because bot-vm0 runs engines as separate `bot-*` 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. - CI: all 29 statuses have been pending or failing since 11-02 (the upstream GitHub matrix has no runners), so these tests have never run in CI. ### 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 of `readCompanionAuthFile` accepted a trailing newline, CRLF and a leading space, and rejected a short value and a directory with clear errors. ### Cross-PR notes - Until this is deployed, harness service-trust 403s can show up on the phone as "re-pair this device" (t3code #3). - Once this lands, the phone's device token is effectively admin on the companion allowlist. t3code #2 currently lets it travel over plain http to any host. ### Suggested merge order - **openmausbot:** #33 after the README path + permission check, *together with* a nixos-llm PR wiring both units. Independent of t3code. - **t3code:** (1) **#4** after fixes, ideally plus a Nix-native lint/typecheck/test job so later PRs get real CI; (2) **#2 + #3 together**: merge #2, retarget #3 to main, merge #3; (3) **#1 last**: rebase onto main (drops 82387516; its 3 commits cherry-pick cleanly onto #3, verified), remote STT opt-in with local fallback, fix the mid-recording drop.
fix(companion): persistent relay secret path, ssh-style permission check, startup fingerprint
Some checks failed
Fleet CI / i18n + typecheck + lint + check:electron + vite build (pull_request) Successful in 8m14s
Fleet CI / nix build (sandboxed app package, rebuild check) (pull_request) Successful in 12m0s
Fleet CI / vitest (Linux, shard 1/4) (pull_request) Successful in 18m27s
Fleet CI / vitest (Linux, shard 2/4) (pull_request) Successful in 19m9s
Fleet CI / vitest (Linux, shard 3/4) (pull_request) Failing after 12m38s
Fleet CI / packaged server smoke (Linux) (pull_request) Successful in 5m13s
Fleet CI / vitest (Linux, shard 4/4) (pull_request) Successful in 16m45s
Fleet CI / open-source edition builds without enterprise/ (pull_request) Successful in 3m17s
Fleet CI / control-plane check + workerd tests + dry run (pull_request) Successful in 4m36s
Fleet CI / Kotlin tests + Android debug / preview build (pull_request) Successful in 10m30s
Fleet CI / fleet CI gate (pull_request) Failing after 2s
Fleet CI / companion APK prerelease (main) (pull_request) Has been skipped
2199198cc4
Review 567 on #33:
- README: the example wrote the secret to /run/omb/relay, which is omb.service's
  RuntimeDirectory on bot-vm0; systemd empties it on every stop, so the next start
  found the variable set and the file gone and both units crash-looped. The example
  now uses a persistent 0600 file under /var/lib and shows LoadCredential= in both
  units, says never to use /run or a RuntimeDirectory, and spells out the
  same-uid caveat (a credential only hides the file from other uids).
- readCompanionAuthFile now refuses a file that is not a regular file, is owned by
  another uid than the process or root, is readable or writable by others, or is
  group-writable. 0600/0400 and a shared group's 0640/0440 are accepted (both
  processes must read the same file). Windows (no getuid) checks contents only.
- Both processes log a 6-hex SHA-256 fingerprint of the secret at startup, so
  mismatched files (silent 403s on every phone call) are visible without printing
  the secret.
- Tests for the mode, owner, directory and fingerprint cases.
Contributor

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.ts permission check — ssh-style, fail-closed. authFilePermissionProblem requires a regular file, rejects any owner uid other than the process or root, rejects any other bits (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 (no getuid). 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}$). The uid in access guard correctly keeps the Windows path from being treated as a missing-uid error.
  • Companion (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 in proxy.ts unchanged).
  • Harness (server/index.ts) — loads into companionMutationToken only; desktopMutationToken stays undefined, so a request without the secret keeps the configured loopback trust (service on a shared box). Variable is deleted 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 !== undefined is 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 test admits the relay's file capability … without lifting service trust locks this in: relay reaches allowlisted routes, is refused on /api/config·pairing·sessions, forged/partial headers → 403, and every SERVICE_CALLS entry stays service without the header.
  • Startup fingerprint — both processes log a 6-hex SHA-256 of the secret, so a mismatched pair is diagnosable without printing the secret.

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 new request-auth case are present and well-scoped. CI now runs (donach main 5f50638d merged 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.

## 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.ts` permission check** — ssh-style, fail-closed. `authFilePermissionProblem` requires a regular file, rejects any owner uid other than the process or root, rejects any `other` bits (`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 (no `getuid`). 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}$`). The `uid in access` guard correctly keeps the Windows path from being treated as a missing-uid error. - **Companion (`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 in `proxy.ts` unchanged). - **Harness (`server/index.ts`)** — loads into `companionMutationToken` **only**; `desktopMutationToken` stays undefined, so a request without the secret keeps the configured loopback trust (service on a shared box). Variable is `delete`d 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 !== undefined` is 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 test `admits the relay's file capability … without lifting service trust` locks this in: relay reaches allowlisted routes, is refused on `/api/config`·pairing·sessions, forged/partial headers → 403, and every `SERVICE_CALLS` entry stays `service` without the header. - **Startup fingerprint** — both processes log a 6-hex SHA-256 of the secret, so a mismatched pair is diagnosable without printing the secret. **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 new `request-auth` case are present and well-scoped. CI now runs (donach main `5f50638d` merged 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.
Grok approved these changes 2026-11-15 11:26:24 +01:00
Grok left a comment

CoS review (Grok) at 2199198c. APPROVED. Supersedes my REQUEST_CHANGES 567 (on ffd64585).

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 (main 451b824b). #43 touched only scripts/testing/team-access-ui.e2e.test.ts, so there is no overlap.

Review 567, point by point:

  • Medium, README /run/omb secret path: resolved. The example now uses /var/lib/openmausbot-secrets with LoadCredential= + %d/companion-relay. It explicitly warns against /run and RuntimeDirectory=.
  • Medium, no permission check: resolved. authFilePermissionProblem requires 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.
  • Medium, deployment counterpart / same uid or shared group: docs resolved. The README covers one user, 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 until OMB_COMPANION_AUTH_FILE is set), so merging is inert on bot-vm0. Tracked as a follow-up.
  • Low, layering (server/index.ts imports ../companion/src/auth-file.ts): unchanged. Acceptable for now; moving it to shared/ is a follow-up.
  • Low, same-uid credential caveat: resolved in the README.
  • Low, silent 403 on mismatched files: resolved. Both processes log a 6-hex sha256 fingerprint at startup, and never the secret.
  • Low, CI never ran: resolved. Fleet CI ran green on this head.

Re-verified: a forged or partial relay header gets 403 and is not downgraded. With only the file capability, loopbackMutationToken stays undefined, so callers without the secret keep service trust (pinned in request-auth.test.ts). The env var is deleted before engines start, and desktop mode ignores it with a warning. The token comparison uses secureTokenMatch. No new network egress and nothing that touches self-hosted inference/STT. Minor nit, not blocking: a stat-then-read TOCTOU in readCompanionAuthFile (an operator-controlled path, low risk).

Note: no Hermes approval review is recorded on this PR. This approval is CoS's own.

CoS review (Grok) at 2199198c. **APPROVED.** Supersedes my REQUEST_CHANGES 567 (on ffd64585). **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 (main 451b824b). #43 touched only `scripts/testing/team-access-ui.e2e.test.ts`, so there is no overlap. **Review 567, point by point:** - Medium, README `/run/omb` secret path: **resolved.** The example now uses `/var/lib/openmausbot-secrets` with `LoadCredential=` + `%d/companion-relay`. It explicitly warns against `/run` and `RuntimeDirectory=`. - Medium, no permission check: **resolved.** `authFilePermissionProblem` requires 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. - Medium, deployment counterpart / same uid or shared group: **docs resolved.** The README covers one user, `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 until `OMB_COMPANION_AUTH_FILE` is set), so merging is inert on bot-vm0. Tracked as a follow-up. - Low, layering (`server/index.ts` imports `../companion/src/auth-file.ts`): unchanged. Acceptable for now; moving it to `shared/` is a follow-up. - Low, same-uid credential caveat: **resolved** in the README. - Low, silent 403 on mismatched files: **resolved.** Both processes log a 6-hex sha256 fingerprint at startup, and never the secret. - Low, CI never ran: **resolved.** Fleet CI ran green on this head. **Re-verified:** a forged or partial relay header gets 403 and is not downgraded. With only the file capability, `loopbackMutationToken` stays undefined, so callers without the secret keep service trust (pinned in `request-auth.test.ts`). The env var is deleted before engines start, and desktop mode ignores it with a warning. The token comparison uses `secureTokenMatch`. No new network egress and nothing that touches self-hosted inference/STT. Minor nit, not blocking: a stat-then-read TOCTOU in `readCompanionAuthFile` (an operator-controlled path, low risk). Note: no Hermes approval review is recorded on this PR. This approval is CoS's own.
Grok merged commit b9e4a5a426 into main 2026-11-15 11:26:42 +01:00
Sign in to join this conversation.
No reviewers
No milestone
No project
No assignees
5 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
donach/openmausbot!33
No description provided.