feat(relay): rendezvous-relay service — 7 packages + plans (contracts/transport/agent/control-plane/e2e/auth/web)
Multi-tenant reverse-tunnel service ("ngrok for Claude Code" with E2E): a
host-agent dials OUT to an operator-run relay; external devices reach the host
THROUGH the relay, routed by per-tenant subdomain, forwarding ciphertext only
(the relay never sees plaintext). Lets a customer reach their own self-hosted
web-terminal from anywhere with zero networking setup.
Packages — all tsc-strict + vitest green (656 tests), cross-package integration verified:
- relay-contracts: frozen shared contracts (mux frame codec, data model,
capability token, E2E envelope, pairing) — the src/types.ts analog
- term-relay: native WS mux + stateless data plane (subdomain routing, ciphertext forward)
- agent: host-agent (pairing, per-host Ed25519 + mTLS dial-out, forwards to 127.0.0.1:3000)
- control-plane: accounts/hosts registry, pairing-code flow, routing table, provisioning
- relay-e2e: browser<->agent E2E (X25519 ECDH through relay, AEAD, anti-replay, recoverable replay key)
- relay-auth: Passkey/WebAuthn, capability tokens, per-host certs, deny-by-default tenant isolation
- relay-web: browser login + Web Crypto E2E + client-side preview rendering
Security invariants INV1-15 enforced; cross-tenant isolation CI tripwire live
(.github/workflows/relay-tripwire.yml). Design + implementation-level plans in
docs/PLAN_RELAY_*.md and docs/EXPLORE_RELAY_SERVICE.md.
NOTE: generated autonomously per the reviewed plans. The security-critical
packages (relay-e2e, relay-auth) REQUIRE expert security audit before any real
deployment — passing tests prove self-consistency, not resistance to attackers.
Base app (src/, public/) unchanged; concurrent desktop work left uncommitted.
This commit is contained in:
68
control-plane/test/env.test.ts
Normal file
68
control-plane/test/env.test.ts
Normal file
@@ -0,0 +1,68 @@
|
||||
import { describe, test, expect } from 'vitest'
|
||||
import { loadEnv, DEFAULT_PAIRING_TTL_SEC, DEFAULT_PAIRING_MAX_REDEEM_ATTEMPTS } from '../src/env.js'
|
||||
import { bytesToBase64 } from '../src/util/bytes.js'
|
||||
|
||||
const validPubkey = bytesToBase64(new Uint8Array(32).fill(7))
|
||||
|
||||
const base = (): NodeJS.ProcessEnv => ({
|
||||
PG_URL: 'postgres://u:p@localhost:5432/cp',
|
||||
REDIS_URL: 'redis://localhost:6379',
|
||||
CAPABILITY_SIGN_PUBKEY_B64: validPubkey,
|
||||
CA_INTERMEDIATE_KMS_KEY_REF: 'kms://key/intermediate',
|
||||
CA_INTERMEDIATE_CERT_PATH: '/etc/cp/intermediate.pem',
|
||||
NODE_MTLS_TRUST_BUNDLE_PATH: '/etc/cp/node-ca.pem',
|
||||
BASE_DOMAIN: 'term.example.com',
|
||||
})
|
||||
|
||||
describe('T1 loadEnv (INV9 fail-fast)', () => {
|
||||
test('empty env throws listing every missing required key', () => {
|
||||
let msg = ''
|
||||
try {
|
||||
loadEnv({})
|
||||
} catch (e) {
|
||||
msg = e instanceof Error ? e.message : ''
|
||||
}
|
||||
expect(msg).toContain('PG_URL')
|
||||
expect(msg).toContain('REDIS_URL')
|
||||
expect(msg).toContain('CAPABILITY_SIGN_PUBKEY_B64')
|
||||
expect(msg).toContain('CA_INTERMEDIATE_KMS_KEY_REF')
|
||||
expect(msg).toContain('BASE_DOMAIN')
|
||||
})
|
||||
|
||||
test('bad pgUrl throws', () => {
|
||||
expect(() => loadEnv({ ...base(), PG_URL: 'not a url' })).toThrow(/PG_URL/)
|
||||
})
|
||||
|
||||
test('valid map parses', () => {
|
||||
const env = loadEnv(base())
|
||||
expect(env.baseDomain).toBe('term.example.com')
|
||||
expect(env.capabilitySignPubkey.length).toBe(32)
|
||||
})
|
||||
|
||||
test('pairing ttl / max-attempts default when unset', () => {
|
||||
const env = loadEnv(base())
|
||||
expect(env.pairingTtlSec).toBe(DEFAULT_PAIRING_TTL_SEC)
|
||||
expect(env.pairingMaxRedeemAttempts).toBe(DEFAULT_PAIRING_MAX_REDEEM_ATTEMPTS)
|
||||
})
|
||||
|
||||
test('explicit pairing overrides parse', () => {
|
||||
const env = loadEnv({ ...base(), PAIRING_TTL_SEC: '900', PAIRING_MAX_REDEEM_ATTEMPTS: '3' })
|
||||
expect(env.pairingTtlSec).toBe(900)
|
||||
expect(env.pairingMaxRedeemAttempts).toBe(3)
|
||||
})
|
||||
|
||||
test('never echoes secret VALUES on failure (INV9)', () => {
|
||||
const secret = bytesToBase64(new Uint8Array(32).fill(9))
|
||||
try {
|
||||
loadEnv({ ...base(), CAPABILITY_SIGN_PUBKEY_B64: secret, PG_URL: 'bad' })
|
||||
} catch (e) {
|
||||
const msg = e instanceof Error ? e.message : ''
|
||||
expect(msg).not.toContain(secret)
|
||||
}
|
||||
})
|
||||
|
||||
test('capability pubkey wrong length rejected', () => {
|
||||
const short = bytesToBase64(new Uint8Array(16))
|
||||
expect(() => loadEnv({ ...base(), CAPABILITY_SIGN_PUBKEY_B64: short })).toThrow(/32 bytes/)
|
||||
})
|
||||
})
|
||||
Reference in New Issue
Block a user