diff --git a/docs/DEVICE-UNIQUENESS-BACKEND.md b/docs/DEVICE-UNIQUENESS-BACKEND.md index 7daf4e8..390aaac 100644 --- a/docs/DEVICE-UNIQUENESS-BACKEND.md +++ b/docs/DEVICE-UNIQUENESS-BACKEND.md @@ -262,7 +262,8 @@ And the secrets, in `scripts/dub/service.sh` rather than the TOML (see `docs/PROFILES.md`): `CHAIN_WRITER_SIGNER_SURI`, `INVITER_SIGNER_SURI`, `JWT_ED25519_SECRET` with `JWT_ED25519_PUBLIC_KEY` derived from it, and `TURN_SECRET` with `ICE_SERVERS`, which `ppn service dub-turn-env` resolves together with the eturnal config -(see [TURN.md](TURN.md)). +(see [TURN.md](TURN.md)). It also reads `TURN_PROOF_GENESIS` from People when the network +lists TURN proof products. The rest stay dormant under the dev defaults: `PAYMENT_MASTER_ACCOUNT` / `PAYMENT_AMOUNT_PLANCK` are only read when `PAYMENT_LANE_ENABLED=true` (default false, diff --git a/docs/TURN.md b/docs/TURN.md index 744b213..85d94f3 100644 --- a/docs/TURN.md +++ b/docs/TURN.md @@ -11,6 +11,21 @@ whose `turn-api` mints the short-lived credentials the relay accepts. `{ servers, username, password, ttl }`. 3. Pass `servers` as the ICE server URLs, with `username` and `password` as the credential. +A product without a DUB sign-in, such as Jollity, sends a personhood proof instead: +`POST /dub/api/v1/turn/issue-with-proof` with a ring-VRF proof made under its own product name. +turn-api serves this route only for the products the network lists in `turnProofProducts`, such +as `["dim2.testnet"]` on previewnet, and answers 404 when it lists none. Each product must be a +dotNS name under the network's TLD, since that is the name a host proves under. A deployment +replaces the list in its `PPN_NETWORK_OVERLAY` file, where `[]` turns the route off: + +```json +{ "previewnet": { "turnProofProducts": ["dim2.testnet", "vox.testnet"] } } +``` + +The proofs are checked against the network's own People chain, whose genesis hash +`ppn service dub-turn-env` reads when `dub-api` starts. `dub-api` waits for People to answer +before it starts. + Clients never configure a password themselves. The dashboard lists the same servers under **TURN / STUN**, and so does `/api/network` under `ice`. diff --git a/networks/README.md b/networks/README.md index e18ced3..c18afb8 100644 --- a/networks/README.md +++ b/networks/README.md @@ -39,8 +39,9 @@ or `PPN_NETWORK=` in the environment of the scripts. | *(para ids)* | `parachains[].paraId` is the single source: the genesis TOML, the fork TOML, `ppn generate` and `assign-cores.sh` all read it from here. `config/ports.env` deliberately holds no para ids — those belong to the network, not the machine. | | `relay.extraArgs`, `parachains[].extraArgs` | Extra node flags for that chain. A flag the shared per-key table also sets takes this value (`--rpc-max-connections=5000` replaces the table's 500), and a `-l` arg replaces the default log targets whole; the rest are appended. | | `parachains[].rpcNodes`, `parachains[].rpcNodeArgs` | Non-authoring full nodes (0..9) that serve the chain's public path instead of the collator, on the chain's port + 1, + 2, …, with nginx balancing across them. They run the collator's flags without the authoring ones, with `rpcNodeArgs` over them. | -| *(network overlay)* | `PPN_NETWORK_OVERLAY=` changes `extraArgs`, `rpcNodes` and `rpcNodeArgs` for one deployment without a release: `{ "previewnet": { "relay": { "extraArgs": [...] }, "parachains": { "people": { "rpcNodes": 2, "rpcNodeArgs": [...] } } } }`. Every command applies it, so the zombienet config, nginx routes and dashboard agree. An unknown network, chain or field is an error. | +| *(network overlay)* | `PPN_NETWORK_OVERLAY=` changes `extraArgs`, `rpcNodes`, `rpcNodeArgs` and `turnProofProducts` for one deployment without a release: `{ "previewnet": { "relay": { "extraArgs": [...] }, "parachains": { "people": { "rpcNodes": 2, "rpcNodeArgs": [...] } } } }`. Every command applies it, so the zombienet config, nginx routes and dashboard agree. An unknown network, chain or field is an error. | | `services` | Per-service switches and binaries: `false` disables a service; `{ "binary": { … } }` says what it runs. `eth-rpc` must match the revive pallet in the network's Asset Hub runtime, which is exactly why it is pinned per network rather than shared. | +| `turnProofProducts` | The dotNS products, under the network's TLD, whose personhood proofs buy TURN credentials at DUB's `/api/v1/turn/issue-with-proof`, such as `["dim2.testnet"]`. Absent leaves the route off. A deployment replaces it in `PPN_NETWORK_OVERLAY` (see `docs/TURN.md`). | | `tools` | Local tools this network needs that are neither a chain nor a service — previewnet's `chain-spec-builder`, for instance, which only a genesis network uses. | | `bite.doppelganger` | `{repo, tag}` of the bite tool. Per network, because the build has to be able to execute the runtimes of the network being bitten. | | *(bin layout)* | Only node binaries are network-versioned: previewnet's live in `bin/`, every other network's in `bin//` (plus `dg/` for bites). Shared tooling with no per-network dimension — zombie-cli, ipfs, postgres, identity, design families — lives in plain `bin/` and is pinned in `config/versions.env`. Collators run through `scripts/omni-node.sh` regardless of binary; it carries the libp2p fix and picks binary/dir from `PPN_COLLATOR_BINARY`/`PPN_BIN_DIR`. | diff --git a/networks/previewnet.json b/networks/previewnet.json index c6c69b5..06c1c81 100644 --- a/networks/previewnet.json +++ b/networks/previewnet.json @@ -162,6 +162,8 @@ } } ], + "turnProofProducts": ["dim2.testnet"], + "_turnProofProducts": "Jollity's product account, which proves as dim2. for TURN credentials (paritytech/individuality-apps packages/jollity-protocol/src/config.ts).", "services": { "eth-rpc": { "binary": { diff --git a/packages/cli/src/commands/trinity-stack.ts b/packages/cli/src/commands/trinity-stack.ts index 8f17481..025544b 100644 --- a/packages/cli/src/commands/trinity-stack.ts +++ b/packages/cli/src/commands/trinity-stack.ts @@ -13,6 +13,7 @@ import { chainKey, dashboardModel, dotnsFromContracts, + networkTld, trinityStackModel, trinityStackUrl, type ChainKey, @@ -262,7 +263,7 @@ export async function trinityStack(ctx: ServiceContext): Promise { console.log('trinity-stack: an ephemeral run has no data directory to publish from'); return; } - if (!ctx.net.stack?.tld && !ctx.net.genesisConfig?.networkSuffix) { + if (!networkTld(ctx.net)) { console.log(`trinity-stack: networks/${ctx.net.name}.json names no TLD, so there is no descriptor to write`); return; } diff --git a/packages/cli/src/commands/turn.ts b/packages/cli/src/commands/turn.ts index dd9a247..ef35b56 100644 --- a/packages/cli/src/commands/turn.ts +++ b/packages/cli/src/commands/turn.ts @@ -1,15 +1,18 @@ // `ppn service turn`: the TURN/STUN relay (eturnal) whose credentials DUB's turn-api mints. -// `ppn service dub-turn-env`: the matching secret and ICE servers, as shell exports for -// scripts/dub/service.sh. Both resolve from the same inputs, so they cannot disagree. +// `ppn service dub-turn-env`: the matching secret and ICE servers, plus the People genesis the +// proof route is bound to, as shell exports for scripts/dub/service.sh. Both resolve from the +// same inputs, so they cannot disagree. // See docs/TURN.md. import fs from 'node:fs'; import os from 'node:os'; import path from 'node:path'; import { spawn, type ChildProcess } from 'node:child_process'; -import { LOCAL_TURN_SECRET, eturnalConfig, iceServers, runsTurnRelay, turnSecret } from '@parity/ppn-network-config'; +import { LOCAL_TURN_SECRET, asHttp, eturnalConfig, iceServers, runsTurnRelay, turnSecret } from '@parity/ppn-network-config'; import type { ServiceContext } from './service-context.js'; import { secretsFile } from '../lib/secrets.js'; +import { rpc } from '../fork/rpc.js'; +import { sleep, type Sleep } from '../fork/sleep.js'; import { ETURNAL_BREW_INSTALL, eturnalCtl, eturnalDist } from '../lib/eturnal.js'; /** The host clients reach the network under; only its hostname and scheme matter here. */ @@ -35,8 +38,25 @@ export function dubTurnEnv(ctx: ServiceContext): Record { }; } +/** The chain's genesis hash, once its RPC answers; it waits as long as that takes. */ +export async function waitForGenesisHash(rpcUrl: string, wait: Sleep = sleep): Promise { + for (let attempt = 1; ; attempt++) { + try { + return await rpc(asHttp(rpcUrl), 'chain_getBlockHash', [0]); + } catch (error) { + if (attempt % 15 === 1) console.error(`dub-turn-env: waiting for ${rpcUrl}: ${(error as Error).message}`); + await wait(2000); + } + } +} + export async function printDubTurnEnv(ctx: ServiceContext): Promise { - for (const [k, v] of Object.entries(dubTurnEnv(ctx))) { + const env = dubTurnEnv(ctx); + // turn-api exits at start when the proof route is on and no genesis is set. + if (process.env.TURN_PROOF_ENABLED === 'true' && process.env.TURN_PROOF_RPC_URL) { + env.TURN_PROOF_GENESIS = await waitForGenesisHash(process.env.TURN_PROOF_RPC_URL); + } + for (const [k, v] of Object.entries(env)) { console.log(`export ${k}='${v.replace(/'/g, `'\\''`)}'`); } } diff --git a/packages/cli/tests/turn-proof.test.ts b/packages/cli/tests/turn-proof.test.ts new file mode 100644 index 0000000..0f6a59e --- /dev/null +++ b/packages/cli/tests/turn-proof.test.ts @@ -0,0 +1,39 @@ +import { describe, it } from 'node:test'; +import assert from 'node:assert/strict'; +import http from 'node:http'; +import type { AddressInfo } from 'node:net'; + +import { waitForGenesisHash } from '../src/commands/turn.js'; + +const GENESIS = `0x${'ab'.repeat(32)}`; + +/** A People RPC that fails `failures` requests before answering chain_getBlockHash(0). */ +async function startPeopleRpc(failures: number): Promise<{ url: string; close: () => void }> { + let seen = 0; + const server = http.createServer((req, res) => { + let body = ''; + req.on('data', (chunk) => (body += chunk)); + req.on('end', () => { + if (seen++ < failures) return res.destroy(); + const { method, params } = JSON.parse(body); + assert.deepEqual([method, params], ['chain_getBlockHash', [0]]); + res.setHeader('content-type', 'application/json'); + res.end(JSON.stringify({ jsonrpc: '2.0', id: 1, result: GENESIS })); + }); + }); + await new Promise((resolve) => server.listen(0, '127.0.0.1', resolve)); + return { url: `ws://127.0.0.1:${(server.address() as AddressInfo).port}`, close: () => server.close() }; +} + +describe('waitForGenesisHash', () => { + // dub-api starts beside the chains, so People may not answer yet; turn-api exits at start + // when the proof route is on and no genesis is set, and nothing restarts dub-api if it exits. + it('waits for People to answer', async () => { + const rpc = await startPeopleRpc(3); + try { + assert.equal(await waitForGenesisHash(rpc.url, async () => {}), GENESIS); + } finally { + rpc.close(); + } + }); +}); diff --git a/packages/network-config/src/dub.ts b/packages/network-config/src/dub.ts index d582245..779a823 100644 --- a/packages/network-config/src/dub.ts +++ b/packages/network-config/src/dub.ts @@ -125,7 +125,8 @@ export function peopleRpcUrl(peoplePort: number): string { export function dubServices( ports: DubPorts, attesterAccount: string = ALICE_SS58, - inviterAccount: string = BOB_SS58 + inviterAccount: string = BOB_SS58, + turnProofProducts: string[] = [] ): DubService[] { const rpc = peopleRpcUrl(ports.people); const db = (name: (typeof DUB_DATABASES)[number]) => dubDatabaseUrl(name, ports.postgres); @@ -180,6 +181,12 @@ export function dubServices( // and ICE_SERVERS depend on the host, so service.sh supplies them. TURN_PROVIDER: 'coturn', TURN_REALM, + // /api/v1/turn/issue-with-proof. service.sh adds TURN_PROOF_GENESIS, read from People. + ...(turnProofProducts.length && { + TURN_PROOF_ENABLED: 'true', + TURN_PROOF_RPC_URL: rpc, + TURN_PROOF_PRODUCTS: turnProofProducts.join(','), + }), }, }, { @@ -229,13 +236,14 @@ export function dubCustomProcesses( // fork mode writes a standalone TOML with absolute paths already resolved. scriptsDir: string = '{{SCRIPTS}}', // The TURN/STUN relay whose credentials turn-api mints (docs/TURN.md). - turn: boolean = true + turn: boolean = true, + turnProofProducts: string[] = [] ): string { const wait = `127.0.0.1:${ports.postgres}`; // zombienet validates custom_process args as CLI arguments — each must parse // as a flag or --key=value, so bare positionals are rejected outright. - const blocks = dubServices(ports, attesterAccount).map( + const blocks = dubServices(ports, attesterAccount, undefined, turnProofProducts).map( (svc) => ` [[custom_processes]] name = "${svc.name}" diff --git a/packages/network-config/src/fork-toml.ts b/packages/network-config/src/fork-toml.ts index 5535ba4..a35bba3 100644 --- a/packages/network-config/src/fork-toml.ts +++ b/packages/network-config/src/fork-toml.ts @@ -389,7 +389,8 @@ export function generateForkToml(options: GenerateForkTomlOptions): string { }, undefined, scriptsDir, - net.services['turn'] !== false + net.services['turn'] !== false, + net.turnProofProducts ) : ''; diff --git a/packages/network-config/src/networks.ts b/packages/network-config/src/networks.ts index 65e9f01..4855785 100644 --- a/packages/network-config/src/networks.ts +++ b/packages/network-config/src/networks.ts @@ -207,6 +207,11 @@ export interface NetworkDef { parachains: NetworkParachain[]; /** Per-service switches and binaries for the custom processes. */ services: Record; + /** + * The dotNS products whose personhood proofs buy TURN credentials at DUB's + * `/api/v1/turn/issue-with-proof`, such as `dim2.testnet`. Empty leaves the route off. + */ + turnProofProducts: string[]; /** Local tools this network needs that are neither a chain nor a service. */ tools: Record; /** @@ -474,6 +479,12 @@ export function loadDescriptor(name: string): NetworkDef { rpcNodeArgs: parseArgs(`parachains.${p.key}.rpcNodeArgs`, p.rpcNodeArgs, bad), })), services, + turnProofProducts: parseTurnProofProducts( + 'turnProofProducts', + raw.turnProofProducts, + networkTld({ stack, genesisConfig: raw.genesisConfig }), + bad + ), tools, dotns: raw.dotns, stack, @@ -481,6 +492,31 @@ export function loadDescriptor(name: string): NetworkDef { }; } +/** The dotNS TLD: `stack.tld`, else a genesis network's `genesisConfig.networkSuffix`. */ +export function networkTld(net: Pick): string | undefined { + return net.stack?.tld ?? net.genesisConfig?.networkSuffix; +} + +/** + * `products` as TURN proof products, or `bad` unless each is a dotNS name under the network's + * `tld`: a host proves under the product's name on this network, so any other name never matches. + * Absent or empty is none, which leaves the route off. + */ +export function parseTurnProofProducts( + at: string, + products: unknown, + tld: string | undefined, + bad: (why: string) => never +): string[] { + if (products === undefined || (Array.isArray(products) && !products.length)) return []; + if (!tld) bad(`${at}: the network has no dotNS TLD (stack.tld or genesisConfig.networkSuffix)`); + const name = new RegExp(`^[a-z0-9-]+\\.${tld}$`); + if (!Array.isArray(products) || products.some((product) => typeof product !== 'string' || !name.test(product))) { + bad(`${at} must be an array of dotNS names under .${tld}, such as "dim2.${tld}"`); + } + return products as string[]; +} + /** `args` as node flags, or `bad` when it is not a list of "--flag" strings. Absent is none. */ export function parseArgs(at: string, args: unknown, bad: (why: string) => never): string[] { if (args === undefined) return []; diff --git a/packages/network-config/src/overlay.ts b/packages/network-config/src/overlay.ts index d89c83f..fe08208 100644 --- a/packages/network-config/src/overlay.ts +++ b/packages/network-config/src/overlay.ts @@ -1,6 +1,7 @@ // A deployment's own shape for a network, without a release of the engine: RPC nodes in front of -// a chain, or different flags on its nodes. Keyed by network, so loading another network (as -// `ppn networks` does) is unaffected by a section written for this one. +// a chain, different flags on its nodes, or the products its TURN proof route accepts. Keyed by +// network, so loading another network (as `ppn networks` does) is unaffected by a section written +// for this one. // // PPN_NETWORK_OVERLAY=/etc/ppn/network-overlay.json // { "previewnet": { @@ -9,14 +10,15 @@ import fs from 'node:fs'; import { overrideArgs } from './args.js'; -import { listNetworks, parseArgs, parseRpcNodes, type NetworkDef } from './networks.js'; +import { listNetworks, networkTld, parseArgs, parseRpcNodes, parseTurnProofProducts, type NetworkDef } from './networks.js'; const RELAY_FIELDS = ['extraArgs']; const PARACHAIN_FIELDS = ['extraArgs', 'rpcNodes', 'rpcNodeArgs']; /** * `net` with the overlay file's section for it applied: its extraArgs and rpcNodeArgs override - * the descriptor's flag by flag, and rpcNodes replaces the count. Throws on an unreadable file, + * the descriptor's flag by flag, and rpcNodes and turnProofProducts replace the descriptor's. + * Throws on an unreadable file, * an unknown network, chain or field, or a value the descriptor itself would reject. */ export function applyOverlay(net: NetworkDef, file: string): NetworkDef { @@ -42,7 +44,7 @@ export function applyOverlay(net: NetworkDef, file: string): NetworkDef { if (strangers.length) bad(`unknown networks ${strangers.join(', ')} (known: ${networks.join(', ')})`); if (raw[net.name] === undefined) return net; - const section = object(net.name, raw[net.name], ['relay', 'parachains']); + const section = object(net.name, raw[net.name], ['relay', 'parachains', 'turnProofProducts']); const relay = object(`${net.name}.relay`, section.relay ?? {}, RELAY_FIELDS); const parachains = object(`${net.name}.parachains`, section.parachains ?? {}); const parachainKeys: string[] = net.parachains.map((parachain) => parachain.key); @@ -53,6 +55,10 @@ export function applyOverlay(net: NetworkDef, file: string): NetworkDef { return { ...net, + turnProofProducts: + section.turnProofProducts === undefined + ? net.turnProofProducts + : parseTurnProofProducts(`${net.name}.turnProofProducts`, section.turnProofProducts, networkTld(net), bad), relay: { ...net.relay, extraArgs: overrideArgs(net.relay.extraArgs, parseArgs(`${net.name}.relay.extraArgs`, relay.extraArgs, bad)), diff --git a/packages/network-config/src/toml-generator.ts b/packages/network-config/src/toml-generator.ts index af92339..bd34995 100644 --- a/packages/network-config/src/toml-generator.ts +++ b/packages/network-config/src/toml-generator.ts @@ -584,7 +584,7 @@ command = "{{SCRIPTS}}/grant-invites.sh" people: PORTS.people, assetHub: PORTS['asset-hub'], gateway: requiredPort('DUB_PORT'), - }, undefined, undefined, serviceEnabled('turn')) + }, undefined, undefined, serviceEnabled('turn'), genesisNet().turnProofProducts) )} ${section(serviceEnabled('patch-bootnodes'), ` [[custom_processes]] diff --git a/packages/network-config/src/trinity-stack.ts b/packages/network-config/src/trinity-stack.ts index 88c3744..9a2d733 100644 --- a/packages/network-config/src/trinity-stack.ts +++ b/packages/network-config/src/trinity-stack.ts @@ -6,7 +6,7 @@ import type { Block, Chain, Model, Service, SpecFile } from '@parity/trinity-stack'; import type { DashboardModel } from './dashboard-model.js'; -import type { ChainKey, NetworkDef } from './networks.js'; +import { networkTld, type ChainKey, type NetworkDef } from './networks.js'; import { CHAIN_ARGS } from './toml-generator.js'; /** RFC 0026 roles, plus Web3Storage, which serves tools. */ @@ -94,7 +94,7 @@ export function trinityStackUrl(baseUrl: string): string { * source publishes its own descriptor: `fork.of` is that pointer. */ export function trinityStackModel(net: NetworkDef, model: DashboardModel, facts: StackFacts): Model { - const tld = net.stack?.tld ?? net.genesisConfig?.networkSuffix; + const tld = networkTld(net); if (!tld) throw new Error(`networks/${net.name}.json has no stack.tld`); // `fork` requires `forkedAt` on every chain, so it is all or nothing. const everyForkedAt = Object.values(facts.chains).every((c) => c?.forkedAt); diff --git a/packages/network-config/tests/dub.test.ts b/packages/network-config/tests/dub.test.ts index 8006bec..1ef8da2 100644 --- a/packages/network-config/tests/dub.test.ts +++ b/packages/network-config/tests/dub.test.ts @@ -170,6 +170,22 @@ describe('dubServices', () => { }); }); +describe('TURN proof issuance', () => { + // turn-api mounts /api/v1/turn/issue-with-proof only with these set, and rejects a product + // missing from the list. Jollity fetches its relay credentials there. + it('enables the proof route on dub-api for the listed products, against local People', () => { + const [api, ...workers] = dubServices(PORTS, undefined, undefined, ['dim2.testnet', 'vox.testnet']); + assert.equal(api.env.TURN_PROOF_ENABLED, 'true'); + assert.equal(api.env.TURN_PROOF_RPC_URL, api.env.PEOPLE_RPC_URL); + assert.equal(api.env.TURN_PROOF_PRODUCTS, 'dim2.testnet,vox.testnet'); + for (const svc of workers) assert.ok(!('TURN_PROOF_ENABLED' in svc.env)); + }); + + it('leaves the route off without products', () => { + for (const svc of dubServices(PORTS)) assert.ok(!Object.keys(svc.env).some((k) => k.startsWith('TURN_PROOF_'))); + }); +}); + describe('dubCustomProcesses', () => { const toml = dubCustomProcesses(PORTS); diff --git a/packages/network-config/tests/networks.test.ts b/packages/network-config/tests/networks.test.ts index 8cf3839..bc03c5a 100644 --- a/packages/network-config/tests/networks.test.ts +++ b/packages/network-config/tests/networks.test.ts @@ -3,6 +3,9 @@ import { describe, it } from 'node:test'; import assert from 'node:assert/strict'; +import fs from 'node:fs'; +import os from 'node:os'; +import path from 'node:path'; import { listNetworks, currentNetworkName, @@ -16,6 +19,7 @@ import { DEFAULT_NETWORK, } from '../src/networks.js'; import { loadNetwork } from '../src/load.js'; +import { repoRoot } from '../src/repo-root.js'; import { pinsProducts } from '../src/fork-toml.js'; import { paraIds, VALID_PARACHAINS } from '../src/toml-generator.js'; @@ -281,3 +285,36 @@ describe('product import', () => { assert.equal(pinsProducts(loadNetwork('devnet')), false); }); }); + +describe('turnProofProducts', () => { + function loadWith(fields: Record): () => ReturnType { + return () => { + const saved = process.env.PPN_HOME; + const home = fs.mkdtempSync(path.join(os.tmpdir(), 'ppn-home-')); + fs.mkdirSync(path.join(home, 'networks')); + const raw = JSON.parse(fs.readFileSync(path.join(repoRoot(), 'networks/previewnet.json'), 'utf-8')); + fs.writeFileSync(path.join(home, 'networks', 'proof-test.json'), JSON.stringify({ ...raw, name: 'proof-test', ...fields })); + process.env.PPN_HOME = home; + try { + return loadNetwork('proof-test'); + } finally { + if (saved === undefined) delete process.env.PPN_HOME; + else process.env.PPN_HOME = saved; + fs.rmSync(home, { recursive: true, force: true }); + } + }; + } + + it('accepts Jollity on previewnet, under its TLD', () => { + assert.deepEqual(loadNetwork('previewnet').turnProofProducts, ['dim2.testnet']); + }); + + it('is empty for a network that lists none', () => { + assert.deepEqual(loadNetwork('polkadot').turnProofProducts, []); + }); + + it('rejects a product that is not a name under the network TLD', () => { + assert.throws(loadWith({ turnProofProducts: ['dim2'] }), /dotNS names under \.testnet/); + assert.throws(loadWith({ turnProofProducts: ['dim2.paseo'] }), /dotNS names under \.testnet/); + }); +}); diff --git a/packages/network-config/tests/overlay.test.ts b/packages/network-config/tests/overlay.test.ts index 4de6d86..276e008 100644 --- a/packages/network-config/tests/overlay.test.ts +++ b/packages/network-config/tests/overlay.test.ts @@ -108,6 +108,31 @@ describe('network overlay: RPC nodes in front of People', () => { }); }); +describe('network overlay: TURN proof products', () => { + const net = loadDescriptorOnly('previewnet'); + + // A deployment accepts its own products' proofs without an engine release, and dub-api is + // started with that list rather than the network file's. + it("replaces the network file's products in dub-api's environment", () => { + const overlaid = applyOverlay(net, write('turn.json', { previewnet: { turnProofProducts: ['dim2.testnet', 'vox.testnet'] } })); + assert.deepEqual(overlaid.turnProofProducts, ['dim2.testnet', 'vox.testnet']); + }); + + it('leaves the network file\'s products unchanged when the section omits them', () => { + assert.deepEqual(applyOverlay(net, write('none.json', { previewnet: {} })).turnProofProducts, ['dim2.testnet']); + }); + + it('rejects a product under another TLD, which no host on this network proves as', () => + assert.throws( + () => applyOverlay(net, write('tld.json', { previewnet: { turnProofProducts: ['dim2.paseo'] } })), + /previewnet\.turnProofProducts must be an array of dotNS names under \.testnet/ + )); + + it('turns the route off with an empty list', () => { + assert.deepEqual(applyOverlay(net, write('off.json', { previewnet: { turnProofProducts: [] } })).turnProofProducts, []); + }); +}); + describe('network overlay: a mistake fails instead of deploying defaults', () => { const net = loadDescriptorOnly('previewnet'); const rejects = (body: unknown, message: RegExp) => diff --git a/scripts/dub/service.sh b/scripts/dub/service.sh index d929ece..dcb4af2 100755 --- a/scripts/dub/service.sh +++ b/scripts/dub/service.sh @@ -113,7 +113,8 @@ export CHAIN_WRITER_SIGNER_SURI="${PPN_DUB_ATTESTER_URI:-${PPN_IDENTITY_ATTESTER export INVITER_SIGNER_SURI="${PPN_INVITER_SURI:-//Bob}" # turn-api signs credentials for the eturnal relay and returns ICE_SERVERS with them. Resolved -# by the same code that configures eturnal, so the secret and hosts match (docs/TURN.md). +# by the same code that configures eturnal, so the secret and hosts match (docs/TURN.md). When +# the network lists TURN proof products, dub-turn-env also waits for People to read its genesis. if [[ "$ROLE" == "all-in-one" ]]; then ENTRY="$PROJECT_DIR/bin/ppn.mjs" [[ -f "$ENTRY" ]] || ENTRY="$PROJECT_DIR/dist/bin.js" @@ -168,8 +169,8 @@ fi # ("pool timed out while waiting for an open connection"). custom_processes # have no ordering, so waiting here is the only sequencing available. # -# No equivalent wait for the chain: the services block on the People Chain -# connect indefinitely and pick it up whenever it appears. They do not bind +# The services themselves do not wait for the chain: they block on the People +# Chain connect indefinitely and pick it up whenever it appears. They do not bind # their HTTP port until that succeeds, so /livez and /readyz being # unreachable while the parachain starts is expected, not a fault. WAIT_HOST="${WAIT_TARGET%:*}" diff --git a/tests/scripts/test-turn.ts b/tests/scripts/test-turn.ts index d411d39..8daff14 100644 --- a/tests/scripts/test-turn.ts +++ b/tests/scripts/test-turn.ts @@ -184,6 +184,19 @@ export async function run(nodeName: string, _networkInfo: NetworkInfo, _args: st } console.log(`[TEST] ok relay allocated at ${xorAddress(relayed)}`); + // Previewnet lists TURN proof products, so turn-api serves the proof route. An empty body + // is rejected as malformed; without the route it is a 404. + const proof = await fetch(`${DUB_BASE}/api/v1/turn/issue-with-proof`, { + method: "POST", + headers: { "content-type": "application/json" }, + body: "{}", + }); + if (proof.status !== 400) { + console.error(`[TEST] FAIL turn/issue-with-proof: ${proof.status} ${await proof.text()}`); + return FAILURE; + } + console.log("[TEST] ok turn/issue-with-proof is served"); + const refused = await allocate(creds.username, `${creds.password}x`); if (errorCode(refused) !== 401) { console.error(`[TEST] FAIL a wrong password was answered ${refused.type.toString(16)}, not 401`); diff --git a/zombienet-configs/local-dev.toml b/zombienet-configs/local-dev.toml index ab4df9a..a36f075 100644 --- a/zombienet-configs/local-dev.toml +++ b/zombienet-configs/local-dev.toml @@ -201,6 +201,9 @@ env = [ { name = "BIND_ADDR", value = "127.0.0.1:8092" }, { name = "TURN_PROVIDER", value = "coturn" }, { name = "TURN_REALM", value = "previewnet.local" }, + { name = "TURN_PROOF_ENABLED", value = "true" }, + { name = "TURN_PROOF_RPC_URL", value = "ws://127.0.0.1:10010" }, + { name = "TURN_PROOF_PRODUCTS", value = "dim2.testnet" }, ] [[custom_processes]]