coderouter: accept chatmux per-VM tokens (team-shared accounts only)

Merged
LA
2mo ago
+334-7

What

coderouter accepts per-VM tokens from chatmux (chatmux.dev) for chatmux's Freestyle VMs.

  • chatmux signs a one-hour ES256 JWT per VM with an HSM key (Azure Key Vault Premium). The Freestyle edge injects it as x-chatmux-vm-authorization: Bearer <jwt>; the VM never holds it.
  • coderouter verifies it against chatmux's JWKS: ES256 only, issuer allowlist, audience coderouter, lifetime at most one hour, required claims sub (vm:<id>), jti, team_id, owner_id, role. No database lookup.
  • When that header is present, it is the only credential considered. A bad token fails closed and never falls back to another header.
  • A chatmux machine gets a new access kind, team-machine: only accounts its Hexclave team shares (visibility = 'team'), never anyone's private account. There is no pool and no cloud_vms row. The chatmux and cmux Hexclave projects are the same, so team ids match.
  • A chatmux machine is data plane only: the account control plane (add or remove accounts) answers 403 chatmux_machine_not_allowed, and Cloud VM-only routes (VM principal, /api/vm/self, vm-usage/self, subrouter teams) answer vm_bound_token_required.

Rollout

Off until both are set in Vercel:

  • CODEROUTER_CHATMUX_JWKS_URL=https://chatmux.dev/.well-known/chatmux-vm-jwks.json
  • CODEROUTER_CHATMUX_ISSUERS=https://chatmux.dev

The chatmux side (token minting, JWKS route, edge rule) ships separately.

Tests

web/tests/coderouter-chatmux-vm-token.test.ts: valid token; wrong key, issuer, audience, lifetime, role, subject, and missing claims; off without configuration; request authentication with no lookup and no fallback; the control plane and VM principal refuse a chatmux machine; the team-machine SQL predicate; session keys per machine. Existing route-token and VM-authorization tests pass. typecheck, eslint, and lint:complexity pass.

End-to-end check (2026-09-23)

A real token, signed out of band by the production HSM key (10-minute lifetime, manual-e2e- jti), verified with this code against the live https://chatmux.dev/.well-known/chatmux-vm-jwks.json. A changed claim, a changed signature, a foreign issuer, an expired clock, and no configuration all failed.

Summary by CodeRabbit

  • New Features
    • Chatmux virtual machines can authenticate requests with signed bearer tokens. Tokens are checked for validity, issuer, audience, lifetime, and permitted role.
    • Chatmux machine access is scoped to team-visible accounts, with session keys separated by machine.
  • Bug Fixes
    • Invalid Chatmux tokens are rejected without falling back to other authentication methods.
    • Chatmux machine tokens are denied access to VM-bound and control-context endpoints.