Add team-vault credential leases with local egress

Merged
LA
4mo ago
+9323-107

Summary

Replaces the shared-Mac data plane with a loopback proxy on every macOS or Linux client. cmux.com chooses a shared team account and returns a five-minute access-only lease. The local daemon sends the provider request from that client machine. Provider refresh tokens stay central.

Refresh custody

  • Upload and repair force one central refresh before success, adopting the current rotation chain.
  • Refreshes are single-flight per account.
  • Successful rotation atomically stores the next access, refresh, and ID tokens before leasing.
  • invalid_grant is terminal. Transport failures and malformed success responses are ambiguous, freeze the account, and never retry the old refresh token.
  • Stale lease generations cannot mutate a repaired credential chain.
  • Leases reject refresh tokens, ID tokens, API-key fields, and credential objects at the Go client boundary.

Local data plane and CLI

  • sr login, sr logout, sr team list|use, and sr account list|import|repair|delete.
  • sr setup, sr doctor, sr cleanup, and sr daemon start|stop|restart|status|logs.
  • sr codex and sr claude auto-start and use the loopback daemon in team-vault mode.
  • The daemon authenticates provider routes with the signed-in Stack session, which protects shared Linux hosts.
  • Cloud mode fails closed. It never uses legacy remote routing, local refresh stores, Bedrock, or personal API-key fallback.
  • Bulk import requires dry-run review plus --all --yes; rollout starts with one exact canary account.

The cmux.com API is https://github.com/manaflow-ai/cmux/pull/9099.

Deployment and canary

  • Production Worker: version 467267f5-fb1c-4d25-bacc-730a566a42ff at subrouter.cmux.dev.
  • Staging Worker: version de30e48e-aa7d-4bb1-8704-a27dcd9d2e71 at subrouter-staging.cmux.dev.
  • Durable web staging: https://cmux-staging.vercel.app
  • Real OpenAI canary returned exactly OK through this Mac's local daemon. Central status remained healthy with no refresh failure.

Verification

  • go test ./... -count=1
  • Worker bun test (50 pass)
  • Worker bun run typecheck

Summary by CodeRabbit

  • New Features
    • Added cloud sign-in, team selection, credential storage, shared account import, repair, and extended setup/doctor/cleanup workflows.
    • Added local daemon lifecycle commands (up/down/restart/status), log streaming, and OS-specific health reporting.
    • Implemented authenticated Codex/Claude local-proxy launching with secure secret inputs.
    • Added health-based failover between configured servers and the local daemon, including pin/disable/override behavior.
  • Bug Fixes
    • Hardened credential refresh classification, health probing, and proxy/failover decisions to reduce misrouting and secret leakage.
  • Documentation
    • Documented local egress credential leasing model and invariants.
  • Tests
    • Added/expanded coverage for failover, leasing, lifecycle, cloud-mode routing, and CLI usage/help output.