Add the authenticated Iroh trust broker and relay minter
Summary
- add challenge-signed Iroh endpoint registration, same-account discovery, exact endpoint pair grants, offline endpoint attestations, relay-token brokerage, revocation, and retention
- add account-deletion fencing, transactional quotas, replay protection, globally unique active EndpointIDs, bounded cleanup, and indexed cascade paths
- isolate the Iroh Services project secret in a Rust relay minter authenticated by rotating HMAC keys
- document the offline pairing contract and production secret boundaries
Security properties
- path hints never authorize peers and pair grants bind both device IDs, EndpointIDs, generations, ALPN, scope, and expiry
- registration challenges are one-use and endpoint-signed
- authorization, revocation, deletion, grant issuance, relay reservations, and retention are transactionally linearized
- the TypeScript web service never receives the Iroh Services project secret
Verification
bun test tests/iroh-model-crypto.test.ts tests/iroh-trust-broker.test.ts tests/iroh-route-handler.test.ts tests/client-config-env.test.ts: 72 passedbun run db:test: migrations applied twice and 141 database behavior tests passedbun run typecheck: passedcargo fmt --check: passedcargo clippy --all-targets --locked -- -D warnings: passedcargo test --locked: 10 passed./scripts/reload.sh --tag irhbk1: tagged macOS build passed
Deployment is intentionally separate. The planning credential must be rotated before production, then migrations, minter secrets, and web secrets can be applied in order.
Need help on this PR? Tag /codesmith with what you need. Autofix is disabled.
[!NOTE]
High Risk
New auth, pairing, grant signing, and relay minting paths with many secrets and DB invariants; misconfiguration or broker/minter bugs could affect device trust and relay access.
Overview
Introduces personal-account Iroh end-to-end: a TypeScript trust broker on the web app, an isolated Rust relay-token minter, schema/migrations, and a v1 offline same-account pairing spec.
The broker adds authenticated routes under /api/devices/iroh (discovery, challenge/register, pair grants, endpoint attestations, relay-token brokerage, revocation) plus cron-gated /api/internal/iroh/retention. It persists bindings, challenges, grant/relay issuance audit rows, and account security state; account deletion now cascades those tables. Route publication for devices is tightened so server-stored Iroh presence keeps only approved relay hints (legacy non-Iroh routes unchanged). Env gains required broker secrets (LAN discovery, account subject, Ed25519 grant signing/verification, rate-limit id) and optional minter URL/HMAC; the Iroh Services API key is explicitly not on the web project.
services/iroh-relay-minter is a new Vercel Rust function: POST /api/relay-token with HMAC-SHA256 over method/path/timestamp/body hash, 30s clock skew, optional previous HMAC during rotation, and mints 24h relay:use RCANs via iroh-services. CI (.github/workflows/iroh-relay-minter.yml) runs fmt/clippy/test/release build. Migrations add indexes, path-hint expiry, relay reservation expired status, and a one-time wipe of legacy server-held Iroh path hints / device Iroh routes before relay-only publication.
Reviewed by Cursor Bugbot for commit ac4decb85be546f3e655f3ccc743daf3d84660b2. Bugbot is set up for automated code reviews on this repo. Configure here.
Summary by cubic
Adds an authenticated Iroh trust broker and an optional Rust relay‑token minter for same‑account offline pairing and managed relay access using our 7 self‑hosted relay.cmux.dev relays. Enforces server and presence route privacy by storing/publishing only EndpointID + an approved relay URL; the legacy hosted minter is no longer required.
-
New Features
- API routes:
challenge,register,discover,revoke,endpoint_attestation,pair_grant,relay_token. - Trust model: challenge‑signed registration; pair grants bind device IDs, EndpointIDs, identity generation,
ALPN, scope, expiry; replay protection; linearized auth/revocation/deletion; serialized LAN discovery; globally unique active EndpointIDs. - Route privacy: registry and presence strip direct/private Iroh hints and keep only EndpointID + an allow‑listed managed relay URL; legacy non‑Iroh routes pass through unchanged.
- Relay access: 24h
relay:useRCAN via an isolated Rust minter (services/iroh-relay-minter) with bounded HMAC rotation, dev‑only insecure loopback opt‑in, and CI at.github/workflows/iroh-relay-minter.yml; broker/worker enforce the 7 self‑hostedrelay.cmux.devURLs. - Ops/hardening: quotas and cron cleanup at
/api/internal/iroh/retention(abandoned reservations auto‑expire asexpired); canonical errors;@vercel/firewallrate‑limit integration with in‑flight caps, timeout recovery, and public‑host fallback; accepts JSON media type parameters; stricter env parsing and DB indexes; deferred reservation constraint validation.
- API routes:
-
Migration
- Apply DB migrations and clear legacy server‑held Iroh path hints; hosts will republish EndpointID + managed relay URL on the next heartbeat.
- Optional: deploy the Rust minter as a separate Vercel project and set
IROH_SERVICES_API_SECRET,CMUX_IROH_MINT_HMAC_SECRET_B64(and optionalCMUX_IROH_MINT_HMAC_PREVIOUS_SECRET_B64during rotation). - Configure web env for the broker:
CMUX_IROH_LAN_DISCOVERY_SECRET_B64,CMUX_IROH_ACCOUNT_SUBJECT_SECRET_B64,CMUX_IROH_GRANT_SIGNING_KEY_P8,CMUX_IROH_GRANT_SIGNING_KID,CMUX_IROH_GRANT_VERIFICATION_KEYS_JSON, and (only if minting via the hosted service)CMUX_IROH_MINT_URL,CMUX_IROH_MINT_HMAC_SECRET_B64, plusCMUX_IROH_RATE_LIMIT_ID. - Optional for local dev: set
CMUX_IROH_DEV_ALLOW_INSECURE_LOOPBACK_MINTER=1and run the loopback minter (examples/loopback.rs, portCMUX_IROH_MINT_DEV_PORT); keep HTTPS in all deployments.
Summary by CodeRabbit
- New Features
- Added Iroh trust-broker API endpoints for discovery, challenges, registration, pair grants, endpoint attestations, revocation, and relay-token minting.
- Introduced a relay-token minter with strict validation and support for bounded HMAC secret rotation.
- Added cron-protected Iroh state retention to prune expired/revoked data.
- Added database-backed tracking for Iroh security state, bindings, challenges, and relay/pair grant issuance auditing (including schema/index hardening).
- Documentation
- Added the Iroh offline same-account pairing v1 specification and relay-token minter guide.
- Bug Fixes
- Improved account-deletion cleanup to also remove related Iroh records.
- Tests
- Added extensive crypto, routing, quota/concurrency, and retention integration test coverage.