From fd1e5499d01ffb39d2dc158b80d8509fa0cfe01b Mon Sep 17 00:00:00 2001 From: jochen Date: Mon, 21 Sep 2026 23:35:01 +0200 Subject: [PATCH] Retire provider-uses-mesh-credential: the grant end-to-end bed proves it against the catalogue's redis, with the mesh writing the contributions; its no-seal-key assertion moves there (issue 074) --- node_modules | 1 + .../integration/mesh-grant-end-to-end.test.ts | 7 + .../provider-uses-mesh-credential.test.ts | 236 ------------------ 3 files changed, 8 insertions(+), 236 deletions(-) create mode 120000 node_modules delete mode 100644 test/integration/provider-uses-mesh-credential.test.ts diff --git a/node_modules b/node_modules new file mode 120000 index 0000000..34fd1f4 --- /dev/null +++ b/node_modules @@ -0,0 +1 @@ +/home/jochen/projects/novox/mesh-lab/node_modules \ No newline at end of file diff --git a/test/integration/mesh-grant-end-to-end.test.ts b/test/integration/mesh-grant-end-to-end.test.ts index 509325b..496d1c2 100644 --- a/test/integration/mesh-grant-end-to-end.test.ts +++ b/test/integration/mesh-grant-end-to-end.test.ts @@ -220,4 +220,11 @@ test("the mesh grants a consumer redis's cache, and the credential it delivers a assert.doesNotMatch(authed.out, /WRONGPASS|NOPERM|no password/i, `the consumer's mesh-delivered credential did not authenticate — the two ends do not agree:\n${authed.out}`); assert.match(authed.out, /PONG/, `expected PONG authenticating as the granted consumer:\n${authed.out}`); + + // And the provider needed no seal key to do it: the password reached it as a file the host left + // after unsealing, so MESH_SEAL_KEY is set nowhere (novox/hq ADR 0048). Carried over from the + // retired provider-uses-mesh-credential bed, whose other proofs this bed makes with the mesh + // writing the contributions rather than the bed. + const runtimeEnv = await must(`docker inspect mesh-redis --format '{{json .Config.Env}}'`); + assert.doesNotMatch(runtimeEnv, /MESH_SEAL_KEY/, `a seal key was set after all — ADR 0048 is not what ran:\n${runtimeEnv}`); }); diff --git a/test/integration/provider-uses-mesh-credential.test.ts b/test/integration/provider-uses-mesh-credential.test.ts deleted file mode 100644 index 6bad589..0000000 --- a/test/integration/provider-uses-mesh-credential.test.ts +++ /dev/null @@ -1,236 +0,0 @@ -/** - * A provider creates the resource with the credential the mesh minted — novox/hq ADR 0048. - * - * The old provisioner generated its own password, sealed it with a key nothing delivered, and - * handed it back. This proves the corrected contract: redis's provisioner reads the mesh's - * contributions file and, for each consumer, the password the mesh minted and the host unsealed, and - * creates the ACL user under the login the mesh derived, with that exact password. No $MESH_SEAL_KEY - * is set anywhere. The proof is authentication: a client logging in as that consumer with the mesh's - * password gets PONG — where a provisioner that invented its own password would answer WRONGPASS. - * - * A hand-written contributions file and secret stand in for the control plane here (a full grant - * from a second module is a heavier bed); their SHAPE is exactly what mesh-controller writes — a - * `receives` doc with `as`/`secret`, and the secret file the host leaves after unsealing. - * - * MESH_LAB_HOST_BINARY=.../mesh-host MESH_LAB_BUNDLE=.../examples/foundation-first-node.lock - * scripts/build-module-runtime.sh redis builds mesh-runtime-redis:development, which - * scenarios/redis-node.yml stocks. - */ - -import { test, before, after } from "node:test"; -import assert from "node:assert/strict"; -import { existsSync, readFileSync } from "node:fs"; -import { loadScenario } from "../../src/declaration/parse.ts"; -import { raise } from "../../src/lifecycle/raise.ts"; -import { destroy, exec } from "../../src/lifecycle/operate.ts"; -import { hostBinaryPath, HOST_PATH } from "../../src/lifecycle/place.ts"; -import { labIsUsable, destroyAll, foundationBundle, onTheMachine } from "./harness.ts"; -import type { HeldImage } from "../../src/pinning.ts"; - -const capability = await labIsUsable(); -const binary = hostBinaryPath(); -const bundle = process.env["MESH_LAB_BUNDLE"] ?? ""; - -const skip = !capability.usable - ? `lab not usable: ${capability.why}` - : !binary || !existsSync(binary) - ? "MESH_LAB_HOST_BINARY is not set to a built mesh-host" - : !bundle || !existsSync(bundle) - ? "MESH_LAB_BUNDLE is not set to a foundation bundle (mesh-host examples/)" - : false; - -const SCENARIO = "redis-node"; -const MACHINE = "anchor"; - -let instanceId = ""; -let held: HeldImage[] = []; - -function quote(s: string): string { - return `'${s.replaceAll("'", `'\\''`)}'`; -} - -async function on(command: string, timeoutMs?: number): Promise<{ out: string; ok: boolean }> { - const { stdout } = await exec(instanceId, MACHINE, [ - "sh", "-c", `exec 2>&1\n${command}\necho "__exit=$?"`, - ], timeoutMs); - const marker = stdout.lastIndexOf("__exit="); - if (marker < 0) return { out: stdout, ok: false }; - return { out: stdout.slice(0, marker), ok: stdout.slice(marker + 7).trim() === "0" }; -} - -async function must(command: string, timeoutMs?: number): Promise { - const { out, ok } = await on(command, timeoutMs); - if (!ok) throw new Error(`${MACHINE}: ${command}\n${out}`); - return out; -} - -async function mesh(command: string, timeoutMs?: number): Promise { - return must(`docker exec mesh-controller /mesh-controller ${command}`, timeoutMs); -} - -/** What a manifest's image reference becomes on the machine — ours by ID, everything else as written. */ -function pinned(reference: string): string { - return onTheMachine(reference, held); -} - -function bundleFor(images: HeldImage[]): string { - return foundationBundle(bundle, images); -} - -function tokenFrom(said: string): string { - const found = said.split("\n").map((l) => l.trim()).find((l) => l.length > 100 && !l.includes(" ")); - assert.ok(found, `no token in:\n${said}`); - return found; -} - -async function settled(withinMs = 480_000): Promise { - const until = Date.now() + withinMs; - let last = ""; - while (Date.now() < until) { - const asked = await on(`docker exec mesh-controller /mesh-controller status --json`); - if (asked.ok) { - try { - const state = JSON.parse(asked.out) as { - wrong: { node: string; outcome: string }[]; - waiting: { node: string }[]; - reported: { node: string; outcome: string; current: boolean }[]; - }; - const bad = state.wrong.find((w) => w.node === MACHINE); - if (bad) throw new Error(`${MACHINE} did not apply what it was sent: ${bad.outcome}\n${asked.out}`); - const word = state.reported.find((r) => r.node === MACHINE); - if (!state.waiting.some((w) => w.node === MACHINE) && word?.outcome === "applied" && word.current) return; - last = asked.out; - } catch (err) { - if (err instanceof Error && err.message.includes("did not apply")) throw err; - last = asked.out; - } - } - await new Promise((r) => setTimeout(r, 5000)); - } - throw new Error(`${MACHINE} never caught up within ${Math.round(withinMs / 1000)}s. Last:\n${last}`); -} - -before(async () => { - if (skip) return; - - const raised = await raise(loadScenario(`scenarios/${SCENARIO}.yml`), { - onProgress: (m) => console.log(`raise: ${m}`), - }); - instanceId = raised.instanceId; - held = raised.images; - - await must(`cat > /tmp/foundation.lock <<'MESHBUNDLE'\n${bundleFor(raised.images)}\nMESHBUNDLE`); - await must(`${HOST_PATH} apply /tmp/foundation.lock`, 600_000); - const up = await must(`docker ps --format '{{.Names}}'`); - for (const c of ["mesh-store", "mesh-broker", "mesh-controller"]) { - assert.match(up, new RegExp(c), `the foundation did not raise ${c}:\n${up}`); - } - - await mesh(`node add ${MACHINE}`); - const token = tokenFrom(await mesh(`token issue --node ${MACHINE}`)); - await must(`${HOST_PATH} enrol --token ${quote(token)}`); - await must(`nohup ${HOST_PATH} run > /var/log/mesh-host.log 2>&1 & sleep 3`); -}, { timeout: 1_800_000 }); - -after(async () => { - if (instanceId) await destroy(instanceId); - await destroyAll(`${SCENARIO}-`); -}, { timeout: 600_000 }); - -test("redis creates a consumer's login with the password the mesh minted, sealing nothing", { - skip, timeout: 900_000, -}, async () => { - // redis as a provider: the server, and a broker-bound runtime that serves its tools AND runs its - // provisioner. The provisioner is pointed at the contributions file the mesh would write - // (MESH_RECEIVES). There is NO MESH_SEAL_KEY — the whole point of ADR 0048 is that a provider - // needs none. - const manifest = JSON.stringify({ - module: "a-cache", - version: "1", - emits: ["module.redis.cache.provisioned", "module.redis.cache.deprovisioned"], - consumes: ["module.redis.cache.provisioned", "module.redis.cache.deprovisioned"], - "own-secrets": { default: "/var/lib/redis-module/default.secret", broker: "/var/lib/mesh/redis/broker" }, - resources: [ - { id: "mesh-state", type: "directory", path: "/var/lib/mesh/redis", mode: "0700" }, - { id: "state", type: "directory", path: "/var/lib/redis-module", mode: "0700" }, - { id: "grants-dir", type: "directory", path: "/var/lib/redis-module/grants", mode: "0700" }, - { id: "data", type: "directory", path: "/services/redis/data", mode: "0700", owner: "999:999" }, - { - id: "server-conf", type: "file", path: "/var/lib/redis-module/redis.conf", mode: "0644", - content: "requirepass ${secret:default}\nappendonly no\ndir /data\n", - }, - { - id: "server", type: "container", name: "redis", image: pinned("redis"), network: "host", - volumes: [ - "/services/redis/data:/data", - "/var/lib/redis-module/redis.conf:/etc/redis/redis.conf:ro", - ], - args: ["/etc/redis/redis.conf"], - }, - { - id: "runtime", type: "container", name: "mesh-redis", image: pinned("mesh-runtime-redis"), - network: "host", - volumes: [ - "/var/lib/mesh/redis/broker:/run/secrets/broker:ro", - "/var/lib/redis-module/grants:/var/lib/redis-module/grants", - "/var/lib/redis-module/default.secret:/run/secrets/default:ro", - ], - env: { - MESH_BROKER_FILE: "/run/secrets/broker", - MESH_RECEIVES: "/var/lib/redis-module/grants/redis-cache.json", - MESH_PROVISION_REDIS: "127.0.0.1:6379", - MESH_PROVISION_PASSWORD_FILE: "/run/secrets/default", - }, - }, - ], - }); - await must(`printf %s ${quote(manifest)} > /tmp/a-cache.json && docker cp /tmp/a-cache.json mesh-controller:/a-cache.json`); - await mesh("module add /a-cache.json"); - await mesh(`module issue a-cache --node ${MACHINE}`); - await mesh(`assign ${MACHINE} a-cache`); - await mesh(`push ${MACHINE}`); - await settled(); - - const running = await must(`docker ps --format '{{.Names}}'`); - assert.match(running, /mesh-redis/, `redis's runtime is not running:\n${(await on(`docker logs mesh-redis 2>&1 | tail -20`)).out}`); - - // What the mesh delivers to the provider: a contributions file naming the consumer's login and - // where its password is, and the password itself as the file the host leaves after unsealing. - const password = "mesh-minted-9f3c2a"; - await must(`printf %s ${quote(password)} > /var/lib/redis-module/grants/app.secret`); - const contributions = JSON.stringify({ - contributions: 1, - requirement: "redis-cache", - generated: "by the mesh — do not edit", - given: [ - { from: "app", node: "app-node", at: "192.0.2.20:6379", as: "app-one", secret: "/var/lib/redis-module/grants/app.secret", values: {} }, - ], - }); - await must(`printf %s ${quote(contributions)} > /var/lib/redis-module/grants/redis-cache.json`); - - // Within a reconcile tick the provisioner creates the ACL user. It exists on the server. - let acl = ""; - const until = Date.now() + 60_000; - while (Date.now() < until) { - acl = (await on(`docker exec redis redis-cli -a ${quote(await must(`cat /var/lib/redis-module/default.secret`))} --no-auth-warning ACL LIST 2>/dev/null`)).out; - if (/app-one/.test(acl)) break; - await new Promise((r) => setTimeout(r, 3000)); - } - assert.match(acl, /app-one/, `the provisioner never created the consumer's login:\n${(await on(`docker logs mesh-redis 2>&1 | tail -30`)).out}\n---\n${acl}`); - - // The proof: authenticate as that consumer with the password the MESH minted. PONG means the - // provisioner created the login with exactly that password. A provisioner that invented its own - // (the old behaviour) would answer WRONGPASS here. - const authed = await on(`docker exec redis redis-cli --user app-one --pass ${quote(password)} --no-auth-warning PING 2>&1`); - assert.doesNotMatch(authed.out, /WRONGPASS/, - `the consumer could not authenticate with the mesh's password — the provider used a different one:\n${authed.out}`); - assert.match(authed.out, /PONG/, `expected PONG authenticating as the consumer:\n${authed.out}`); - - // And it needed no seal key: the runtime came up and provisioned with MESH_SEAL_KEY set nowhere. - const env = await must(`docker inspect mesh-redis --format '{{json .Config.Env}}'`); - assert.doesNotMatch(env, /MESH_SEAL_KEY/, `a seal key was set after all — ADR 0048 is not what ran:\n${env}`); - - // The provisioner emitted its lifecycle event under the bound account, and no emit was refused. - const log = (await on(`docker logs mesh-redis 2>&1`)).out; - assert.doesNotMatch(log, /emit .*failed/, `the provisioned event was refused:\n${log}`); -});