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.
66 lines
3.1 KiB
TypeScript
66 lines
3.1 KiB
TypeScript
import { describe, test, expect } from 'vitest'
|
|
import { createMemoryStores } from '../src/store/memory.js'
|
|
import { createHostRegistry } from '../src/registry/hosts.js'
|
|
import { createRoutingTable } from '../src/routing/table.js'
|
|
import { createInMemoryRevocationBus } from '../src/routing/bus.js'
|
|
import { createRevoker, createInMemoryRevokedTokenStore } from '../src/revoke/revoke.js'
|
|
import { fingerprint } from '../src/ca/fingerprint.js'
|
|
import { generateEd25519 } from '../src/util/crypto.js'
|
|
import type { KillSignal } from 'relay-contracts'
|
|
import type { NodeIdentity } from '../src/node-auth/identity.js'
|
|
|
|
const node: NodeIdentity = { nodeId: 'spiffe://relay/node-a' }
|
|
const ACCOUNT = '11111111-1111-4111-8111-111111111111'
|
|
|
|
async function harness() {
|
|
const stores = createMemoryStores()
|
|
const hosts = createHostRegistry({ hosts: stores.hosts })
|
|
const routing = createRoutingTable({ routes: stores.routes })
|
|
const bus = createInMemoryRevocationBus()
|
|
const tokens = createInMemoryRevokedTokenStore()
|
|
const revoker = createRevoker({ hosts, routing, bus, tokens })
|
|
const { publicKeyRaw } = generateEd25519()
|
|
const host = await hosts.bindHost({ accountId: ACCOUNT, subdomain: 'alice', agentPubkey: publicKeyRaw, enrollFpr: fingerprint(publicKeyRaw) })
|
|
await routing.upsertRoute(node, host.hostId, { relayNodeId: node.nodeId, updatedAt: new Date().toISOString() }, 60)
|
|
return { stores, hosts, routing, bus, tokens, revoker, host }
|
|
}
|
|
|
|
describe('T13 revocation (INV12/INV8/INV10)', () => {
|
|
test('revokeHost: route dropped + host revoked + KillSignal on relay:revocations, zero payload', async () => {
|
|
const h = await harness()
|
|
const received: KillSignal[] = []
|
|
h.bus.subscribe((s) => received.push(s))
|
|
await h.revoker.revokeHost(h.host.hostId)
|
|
expect(await h.routing.resolveRoute(h.host.hostId)).toBeNull()
|
|
expect((await h.hosts.getHost(h.host.hostId))?.status).toBe('revoked')
|
|
expect(received.length).toBe(1)
|
|
expect(received[0]?.scope).toEqual({ kind: 'host', hostId: h.host.hostId })
|
|
// zero-payload: reason is short metadata, contains no terminal bytes
|
|
expect(received[0]?.reason).toBe('revoked')
|
|
})
|
|
|
|
test('revokeHost is idempotent', async () => {
|
|
const h = await harness()
|
|
await h.revoker.revokeHost(h.host.hostId)
|
|
await expect(h.revoker.revokeHost(h.host.hostId)).resolves.toBeUndefined()
|
|
})
|
|
|
|
test('revokeAccount publishes ONE account-scoped signal + cascades to hosts', async () => {
|
|
const h = await harness()
|
|
const received: KillSignal[] = []
|
|
h.bus.subscribe((s) => received.push(s))
|
|
await h.revoker.revokeAccount(ACCOUNT)
|
|
expect((await h.hosts.getHost(h.host.hostId))?.status).toBe('revoked')
|
|
const accountSignals = received.filter((s) => s.scope.kind === 'account')
|
|
expect(accountSignals.length).toBe(1)
|
|
})
|
|
|
|
test('revokeToken → isTokenRevoked true, stops validating', async () => {
|
|
const h = await harness()
|
|
const jti = 'jti-123'
|
|
expect(await h.revoker.isTokenRevoked(jti)).toBe(false)
|
|
await h.revoker.revokeToken(jti, Math.floor(Date.now() / 1000) + 3600)
|
|
expect(await h.revoker.isTokenRevoked(jti)).toBe(true)
|
|
})
|
|
})
|