Add catalogue-small co-residence bed (four modules, one push)
Raises the first-node substrate and assigns postgres, minio, redis and plex to one anchor in a single push, proving they resolve and come up together on one node. postgres and minio each get a consumer that connects with a real granted credential. redis follows the corrected provider contract (ADR 0048, issue 032): its runtime reconciles the contributions the mesh delivers at MESH_RECEIVES and creates each consumer's ACL user with the mesh-minted password, sealing nothing — no MESH_SEAL_KEY, no *.grant.json/*.credential path. The provisioning proof authenticates as the consumer with the mesh's password (PONG), matching the green provider-uses-mesh-credential bed. Claude-Session: https://claude.ai/code/session_01LrgweAeERJYBg88c5cKDzF
This commit is contained in:
@@ -0,0 +1,50 @@
|
||||
# One machine that becomes a mesh and is then assigned FOUR modules at once — the first bed that
|
||||
# proves multi-module co-residence (the migration-rehearsal shape, novox/hq 04-ISSUES/012 context).
|
||||
#
|
||||
# The per-backend beds each assign one module: postgres (a database provider), minio (an object-store
|
||||
# provider), redis (a cache provider + tools), plex (a tools module). This raises the same first-node
|
||||
# substrate and then assigns all four to the one anchor in a single push, so the proof is that they
|
||||
# resolve and come up TOGETHER on one node — nothing new about any single module, everything new about
|
||||
# their co-residence.
|
||||
#
|
||||
# The four are chosen because none of them share a directory, so the shared-workspace refusal
|
||||
# (novox/hq 04-ISSUES/012 — the media stack) does not bite here; that class stays for a later bed.
|
||||
#
|
||||
# MESH_LAB_HOST_BINARY=.../mesh-host MESH_LAB_BUNDLE=.../examples/substrate-first-node.lock
|
||||
# scripts/build-module-runtime.sh {postgres,redis,minio,plex} build the four runtime images into the
|
||||
# local daemon (postgres carries psql, minio carries mc), which this scenario stocks and serves by
|
||||
# digest from its own registry. The service images must be in the local daemon to be stocked.
|
||||
scenario: catalogue-small
|
||||
|
||||
segments:
|
||||
hosting:
|
||||
kind: public
|
||||
cidr: [192.0.2.0/24]
|
||||
|
||||
machines:
|
||||
anchor:
|
||||
at: { segment: hosting, address: [192.0.2.10] }
|
||||
inbound: allow
|
||||
# Sized up: this anchor runs the substrate (store, broker, control) plus four modules — three of
|
||||
# which are a server container and a runtime container each — so a dozen containers at once. The
|
||||
# single-module beds run at 3GiB; co-residence needs the headroom.
|
||||
memory: 6GiB
|
||||
cpus: 4
|
||||
|
||||
images:
|
||||
# The first-node substrate: store, broker, control.
|
||||
- postgres:17-alpine
|
||||
- cloudamqp/lavinmq:latest
|
||||
- mesh-control:development
|
||||
# The module server images.
|
||||
- redis:7-alpine
|
||||
- minio/minio:latest
|
||||
# The four per-module runtimes, built by scripts/build-module-runtime.sh and stocked here. plex
|
||||
# needs no server image in the lab — its runtime serves tools with no Plex to reach.
|
||||
- mesh-runtime-postgres:development
|
||||
- mesh-runtime-redis:development
|
||||
- mesh-runtime-minio:development
|
||||
- mesh-runtime-plex:development
|
||||
|
||||
place:
|
||||
all: [host, runtime]
|
||||
@@ -0,0 +1,496 @@
|
||||
/**
|
||||
* The mesh assigns FOUR modules to one node in a single push, and they resolve and come up together —
|
||||
* the first bed for multi-module co-residence (the migration-rehearsal shape).
|
||||
*
|
||||
* The per-backend beds each prove one module in isolation: postgres (a database provider whose runtime
|
||||
* carries psql), minio (an object-store provider whose runtime carries mc), redis (a cache provider
|
||||
* that runs its provisioner AND its tools as one broker-bound process), plex (a tools module). Each is
|
||||
* already proven on its own (novox/hq ADR 0052/0053). This proves nothing new about any single module
|
||||
* and everything about their co-residence: all four are assigned to the one anchor, pushed ONCE, and
|
||||
* the node converges ONCE with every one of them up.
|
||||
*
|
||||
* The four share no directory, so the shared-workspace refusal (novox/hq 04-ISSUES/012, the media
|
||||
* stack) does not bite; that class of co-resolution is left for a later bed.
|
||||
*
|
||||
* The two providers that grant per-consumer credentials (postgres, minio) each get a consumer, so the
|
||||
* proof their provisioner ran under co-residence is a real credential the consumer connects with.
|
||||
* redis proves its provisioner the same way: a contribution the mesh delivers at its MESH_RECEIVES
|
||||
* path is fulfilled by creating the consumer's login with the mesh-minted password — it seals nothing
|
||||
* and needs no seal key (novox/hq ADR 0048, issue 032-provider-runtime-has-no-seal-key).
|
||||
*
|
||||
* MESH_LAB_HOST_BINARY=.../mesh-host MESH_LAB_BUNDLE=.../examples/substrate-first-node.lock
|
||||
* scripts/build-module-runtime.sh {postgres,redis,minio,plex} build the four runtime images into the
|
||||
* local daemon; scenarios/catalogue-small.yml stocks them. postgres:17-alpine, redis:7-alpine and
|
||||
* minio/minio:latest must be in the local daemon to be stocked.
|
||||
*/
|
||||
|
||||
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 } from "./harness.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 substrate bundle (mesh-host examples/)"
|
||||
: false;
|
||||
|
||||
const SCENARIO = "catalogue-small";
|
||||
const MACHINE = "anchor";
|
||||
|
||||
let instanceId = "";
|
||||
/** What the scenario's registry serves, by digest. */
|
||||
let stocked: string[] = [];
|
||||
|
||||
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<string> {
|
||||
const { out, ok } = await on(command, timeoutMs);
|
||||
if (!ok) throw new Error(`${MACHINE}: ${command}\n${out}`);
|
||||
return out;
|
||||
}
|
||||
|
||||
/** The control plane, a container on the node. */
|
||||
async function mesh(command: string, timeoutMs?: number): Promise<string> {
|
||||
return must(`docker exec mesh-control /mesh-control ${command}`, timeoutMs);
|
||||
}
|
||||
|
||||
/** The pinned reference for one of the scenario's images, by repository. */
|
||||
function pinned(repository: string): string {
|
||||
const found = stocked.find((r) => r.slice(r.indexOf("/") + 1, r.indexOf("@")) === repository);
|
||||
assert.ok(found, `the scenario stocks no ${repository}; it serves ${stocked.join(", ")}`);
|
||||
return found;
|
||||
}
|
||||
|
||||
/** The substrate bundle, its image references pointed at this scenario's own registry. */
|
||||
function bundleFor(images: string[]): string {
|
||||
let text = readFileSync(bundle, "utf8");
|
||||
for (const ref of images) {
|
||||
const repository = ref.slice(ref.indexOf("/") + 1, ref.indexOf("@"));
|
||||
const escaped = repository.replaceAll("/", "\\/").replaceAll(".", "\\.");
|
||||
text = text.replaceAll(new RegExp(`[A-Za-z0-9_.:-]+\\/${escaped}@sha256:[0-9a-f]+`, "g"), ref);
|
||||
}
|
||||
return text;
|
||||
}
|
||||
|
||||
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;
|
||||
}
|
||||
|
||||
/** Same rule minio's client uses to name a bucket for a consumer — recomputed so the test knows it. */
|
||||
function bucketFor(as: string): string {
|
||||
const name = as.toLowerCase().replace(/[^a-z0-9-]+/g, "-").replace(/^-+|-+$/g, "").slice(0, 63);
|
||||
return name.length >= 3 ? name : `mesh-${name}`;
|
||||
}
|
||||
|
||||
async function settled(withinMs = 600_000): Promise<void> {
|
||||
const until = Date.now() + withinMs;
|
||||
let last = "";
|
||||
while (Date.now() < until) {
|
||||
const asked = await on(`docker exec mesh-control /mesh-control 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;
|
||||
stocked = raised.images;
|
||||
|
||||
// Raise the substrate — store, broker, control — from the bundle.
|
||||
await must(`cat > /tmp/substrate.lock <<'MESHBUNDLE'\n${bundleFor(raised.images)}\nMESHBUNDLE`);
|
||||
await must(`${HOST_PATH} apply /tmp/substrate.lock`, 600_000);
|
||||
const up = await must(`docker ps --format '{{.Names}}'`);
|
||||
for (const c of ["mesh-store", "mesh-broker", "mesh-control"]) {
|
||||
assert.match(up, new RegExp(c), `the substrate did not raise ${c}:\n${up}`);
|
||||
}
|
||||
|
||||
// The node joins its own mesh, so it is a node the mesh can assign to, and start the host so it
|
||||
// applies what it is pushed.
|
||||
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("the mesh assigns postgres, redis, minio and plex to one node in one push, and all four come up", {
|
||||
skip, timeout: 1_500_000,
|
||||
}, async () => {
|
||||
// --- the four modules, each in its committed shape (copied from the per-backend beds) --------------
|
||||
|
||||
// postgres: a database provider — server and a broker-bound runtime (carrying psql) on the private
|
||||
// postgres network, the runtime running the provisioner.
|
||||
const postgresManifest = JSON.stringify({
|
||||
module: "postgres",
|
||||
version: "1",
|
||||
provides: [{ name: "postgres-database", scope: "mesh" }],
|
||||
serves: { "postgres-database": {} },
|
||||
emits: ["module.postgres.database.provisioned", "module.postgres.database.deprovisioned"],
|
||||
consumes: ["module.postgres.database.provisioned", "module.postgres.database.deprovisioned"],
|
||||
receives: { "postgres-database": "/var/lib/postgres/grants/mesh.json" },
|
||||
grants: { "postgres-database": "/var/lib/postgres/grants" },
|
||||
"own-secrets": { superuser: "/var/lib/postgres/superuser.secret", broker: "/var/lib/mesh/postgres/broker" },
|
||||
resources: [
|
||||
{ id: "mesh-state", type: "directory", path: "/var/lib/mesh/postgres", mode: "0700" },
|
||||
{ id: "state", type: "directory", path: "/var/lib/postgres", mode: "0700" },
|
||||
{ id: "grants", type: "directory", path: "/var/lib/postgres/grants", mode: "0700" },
|
||||
{ id: "superuser-env", type: "file", path: "/var/lib/postgres/superuser.env", mode: "0600", content: "POSTGRES_PASSWORD=${secret:superuser}\n" },
|
||||
{ id: "data", type: "directory", path: "/services/postgres/db-data", mode: "0700" },
|
||||
{ id: "net", type: "network", name: "postgres" },
|
||||
{
|
||||
id: "server", type: "container", name: "postgres", image: pinned("postgres"), network: "postgres",
|
||||
env: { POSTGRES_USER: "postgres", POSTGRES_DB: "postgres" },
|
||||
"env-file": ["/var/lib/postgres/superuser.env"],
|
||||
volumes: ["/services/postgres/db-data:/var/lib/postgresql/data"],
|
||||
},
|
||||
{
|
||||
id: "runtime", type: "container", name: "mesh-postgres", image: pinned("mesh-runtime-postgres"),
|
||||
network: "postgres",
|
||||
volumes: [
|
||||
"/var/lib/mesh/postgres/broker:/run/secrets/broker:ro",
|
||||
"/var/lib/postgres/grants:/var/lib/postgres/grants:ro",
|
||||
"/var/lib/postgres/superuser.secret:/run/secrets/superuser:ro",
|
||||
],
|
||||
env: {
|
||||
MESH_BROKER_FILE: "/run/secrets/broker",
|
||||
MESH_RECEIVES: "/var/lib/postgres/grants/mesh.json",
|
||||
MESH_PROVISION_POSTGRES: "postgres://postgres@postgres:5432/postgres?sslmode=disable",
|
||||
MESH_PROVISION_PASSWORD_FILE: "/run/secrets/superuser",
|
||||
},
|
||||
},
|
||||
],
|
||||
});
|
||||
const dbuserManifest = JSON.stringify({
|
||||
module: "dbuser",
|
||||
version: "1",
|
||||
requires: ["postgres-database"],
|
||||
contributes: { "postgres-database": { name: "dbuser" } },
|
||||
binds: { "postgres-database": "/var/lib/dbuser/db.json" },
|
||||
secrets: { "postgres-database": "/var/lib/dbuser/db.secret" },
|
||||
resources: [{ id: "state", type: "directory", path: "/var/lib/dbuser", mode: "0700" }],
|
||||
});
|
||||
|
||||
// minio: an object-store provider — server and a broker-bound runtime (carrying mc) on the private
|
||||
// minio network, the runtime running the provisioner.
|
||||
const minioManifest = JSON.stringify({
|
||||
module: "minio",
|
||||
version: "1",
|
||||
provides: [{ name: "s3-bucket", scope: "mesh" }],
|
||||
serves: { "s3-bucket": { scheme: "http", region: "us-east-1" } },
|
||||
emits: ["module.minio.bucket.created", "module.minio.bucket.removed"],
|
||||
receives: { "s3-bucket": "/var/lib/minio/grants/mesh.json" },
|
||||
grants: { "s3-bucket": "/var/lib/minio/grants" },
|
||||
"own-secrets": { root: "/var/lib/minio/root.secret", broker: "/var/lib/mesh/minio/broker" },
|
||||
resources: [
|
||||
{ id: "mesh-state", type: "directory", path: "/var/lib/mesh/minio", mode: "0700" },
|
||||
{ id: "state", type: "directory", path: "/var/lib/minio", mode: "0700" },
|
||||
{ id: "grants", type: "directory", path: "/var/lib/minio/grants", mode: "0700" },
|
||||
{ id: "root-env", type: "file", path: "/var/lib/minio/root.env", mode: "0600", content: "MINIO_ROOT_USER=meshroot\nMINIO_ROOT_PASSWORD=${secret:root}\n" },
|
||||
{ id: "data", type: "directory", path: "/services/minio/data/data1-1", mode: "0700" },
|
||||
{ id: "net", type: "network", name: "minio" },
|
||||
{
|
||||
id: "server", type: "container", name: "minio", image: pinned("minio/minio"), network: "minio",
|
||||
args: ["server", "/data", "--console-address", ":9001"],
|
||||
"env-file": ["/var/lib/minio/root.env"],
|
||||
volumes: ["/services/minio/data/data1-1:/data"],
|
||||
},
|
||||
{
|
||||
id: "runtime", type: "container", name: "mesh-minio", image: pinned("mesh-runtime-minio"),
|
||||
network: "minio",
|
||||
volumes: [
|
||||
"/var/lib/mesh/minio/broker:/run/secrets/broker:ro",
|
||||
"/var/lib/minio/grants:/var/lib/minio/grants:ro",
|
||||
"/var/lib/minio/root.secret:/run/secrets/root:ro",
|
||||
],
|
||||
env: {
|
||||
MESH_MINIO_ENDPOINT: "http://minio:9000",
|
||||
MESH_MINIO_ROOT_USER: "meshroot",
|
||||
MESH_MINIO_ROOT_PASSWORD_FILE: "/run/secrets/root",
|
||||
MESH_BROKER_FILE: "/run/secrets/broker",
|
||||
MESH_RECEIVES: "/var/lib/minio/grants/mesh.json",
|
||||
},
|
||||
},
|
||||
],
|
||||
});
|
||||
const bucketuserManifest = JSON.stringify({
|
||||
module: "bucketuser",
|
||||
version: "1",
|
||||
slug: "bkt",
|
||||
requires: ["s3-bucket"],
|
||||
contributes: { "s3-bucket": { name: "bucketuser" } },
|
||||
binds: { "s3-bucket": "/var/lib/bucketuser/s3.json" },
|
||||
secrets: { "s3-bucket": "/var/lib/bucketuser/s3.secret" },
|
||||
resources: [{ id: "state", type: "directory", path: "/var/lib/bucketuser", mode: "0700" }],
|
||||
});
|
||||
|
||||
// redis: a cache provider whose runtime serves tools AND runs the provisioner as one broker-bound
|
||||
// process. The provisioner reconciles the contributions the mesh writes at MESH_RECEIVES and
|
||||
// creates each consumer's login with the mesh-minted password — it seals nothing and needs no seal
|
||||
// key (novox/hq ADR 0048, issue 032).
|
||||
const redisManifest = JSON.stringify({
|
||||
module: "redis",
|
||||
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",
|
||||
},
|
||||
},
|
||||
],
|
||||
});
|
||||
|
||||
// plex: a tools module. Its runtime serves tools with no Plex server to reach in the lab.
|
||||
const plexManifest = JSON.stringify({
|
||||
module: "plex",
|
||||
version: "1",
|
||||
emits: [
|
||||
"module.plex.playback.started",
|
||||
"module.plex.playback.stopped",
|
||||
"module.plex.item.added",
|
||||
],
|
||||
consumes: ["module.*.download.completed"],
|
||||
"own-secrets": { broker: "/var/lib/mesh/plex/broker" },
|
||||
resources: [
|
||||
{ id: "mesh-state", type: "directory", path: "/var/lib/mesh/plex", mode: "0700" },
|
||||
{
|
||||
id: "runtime", type: "container", name: "mesh-plex", image: pinned("mesh-runtime-plex"),
|
||||
network: "host",
|
||||
volumes: ["/var/lib/mesh/plex/broker:/run/secrets/broker:ro"],
|
||||
env: {
|
||||
MESH_BROKER_FILE: "/run/secrets/broker",
|
||||
MESH_PLEX_URL: "http://127.0.0.1:32400",
|
||||
MESH_PLEX_TOKEN: "lab-token",
|
||||
},
|
||||
},
|
||||
],
|
||||
});
|
||||
|
||||
// --- add, issue (the four that serve/emit), assign, then ONE push -------------------------------
|
||||
async function add(name: string, manifest: string): Promise<void> {
|
||||
await must(`printf %s ${quote(manifest)} > /tmp/${name}.json && docker cp /tmp/${name}.json mesh-control:/${name}.json`);
|
||||
await mesh(`module add /${name}.json`);
|
||||
}
|
||||
|
||||
await add("postgres", postgresManifest);
|
||||
await mesh(`module issue postgres --node ${MACHINE}`);
|
||||
await mesh(`assign ${MACHINE} postgres`);
|
||||
|
||||
await add("minio", minioManifest);
|
||||
await mesh(`module issue minio --node ${MACHINE}`);
|
||||
await mesh(`assign ${MACHINE} minio`);
|
||||
|
||||
await add("redis", redisManifest);
|
||||
const redisIssued = await mesh(`module issue redis --node ${MACHINE}`);
|
||||
assert.match(redisIssued, /scoped to what it emits and consumes/, redisIssued);
|
||||
await mesh(`assign ${MACHINE} redis`);
|
||||
|
||||
await add("plex", plexManifest);
|
||||
const plexIssued = await mesh(`module issue plex --node ${MACHINE}`);
|
||||
assert.match(plexIssued, /scoped to what it emits and consumes/, plexIssued);
|
||||
await mesh(`assign ${MACHINE} plex`);
|
||||
|
||||
// The consumers: added and assigned, not issued (they serve nothing).
|
||||
await add("dbuser", dbuserManifest);
|
||||
await mesh(`assign ${MACHINE} dbuser`);
|
||||
await add("bucketuser", bucketuserManifest);
|
||||
await mesh(`assign ${MACHINE} bucketuser`);
|
||||
|
||||
// ONE push, ONE convergence — the whole point: six modules resolved and applied together.
|
||||
await mesh(`push ${MACHINE}`);
|
||||
await settled();
|
||||
|
||||
// --- THE co-residence proof: every module's containers are up on the one node --------------------
|
||||
const running = await must(`docker ps --format '{{.Names}}'`);
|
||||
for (const name of ["mesh-postgres", "postgres", "mesh-minio", "minio", "mesh-redis", "redis", "mesh-plex"]) {
|
||||
assert.match(running, new RegExp(`(^|\\n)${name}(\\n|$)`),
|
||||
`${name} is not running after a co-resident push:\n${running}\n---host log---\n${(await on(`tail -40 /var/log/mesh-host.log`)).out}`);
|
||||
}
|
||||
|
||||
// Each provider/tools module got its own scoped broker account — the mesh issued four distinct ones.
|
||||
const users = await must(`docker exec mesh-broker lavinmqctl list_users 2>&1`);
|
||||
for (const acct of ["anchor-postgres", "anchor-minio", "anchor-redis", "anchor-plex"]) {
|
||||
assert.match(users, new RegExp(acct), `the scoped account ${acct} is not on the broker:\n${users}`);
|
||||
}
|
||||
|
||||
// --- postgres provisioned: the consumer got a credential that connects ---------------------------
|
||||
let dbBoundRaw = "";
|
||||
const untilDbBound = Date.now() + 90_000;
|
||||
while (Date.now() < untilDbBound) {
|
||||
const got = await on(`cat /var/lib/dbuser/db.json 2>/dev/null`);
|
||||
if (got.ok && /"as"/.test(got.out)) { dbBoundRaw = got.out; break; }
|
||||
await new Promise((r) => setTimeout(r, 3000));
|
||||
}
|
||||
assert.match(dbBoundRaw, /"as"/, `postgres never granted the consumer its database:\n${dbBoundRaw}`);
|
||||
const dbBound = JSON.parse(dbBoundRaw) as { as: string; provision: string };
|
||||
assert.equal(dbBound.provision, "postgres-database");
|
||||
const dbAs = dbBound.as;
|
||||
const dbPassword = (await must(`cat /var/lib/dbuser/db.secret`)).trim();
|
||||
assert.ok(dbAs && dbPassword, `the consumer's login or password was empty (as=${dbAs})`);
|
||||
const conn = `postgresql://${dbAs}:${encodeURIComponent(dbPassword)}@postgres:5432/${dbAs}?sslmode=disable`;
|
||||
let pg = { out: "", ok: false };
|
||||
const untilConn = Date.now() + 90_000;
|
||||
while (Date.now() < untilConn) {
|
||||
pg = await on(`docker exec mesh-postgres psql ${quote(conn)} -tAc 'select 1' 2>&1`);
|
||||
if (pg.ok && /^1$/m.test(pg.out)) break;
|
||||
if (/authentication failed/i.test(pg.out)) break;
|
||||
await new Promise((r) => setTimeout(r, 3000));
|
||||
}
|
||||
assert.doesNotMatch(pg.out, /authentication failed/i, `postgres delivered a password that does not authenticate:\n${pg.out}`);
|
||||
assert.match(pg.out, /^1$/m, `the consumer could not connect to its granted database as ${dbAs}:\n${pg.out}`);
|
||||
|
||||
// --- minio provisioned: the consumer reaches its bucket with the delivered key -------------------
|
||||
let s3BoundRaw = "";
|
||||
const untilS3Bound = Date.now() + 90_000;
|
||||
while (Date.now() < untilS3Bound) {
|
||||
const got = await on(`cat /var/lib/bucketuser/s3.json 2>/dev/null`);
|
||||
if (got.ok && /"as"/.test(got.out)) { s3BoundRaw = got.out; break; }
|
||||
await new Promise((r) => setTimeout(r, 3000));
|
||||
}
|
||||
assert.match(s3BoundRaw, /"as"/, `minio never granted the consumer its bucket:\n${s3BoundRaw}`);
|
||||
const s3Bound = JSON.parse(s3BoundRaw) as { as: string; provision: string };
|
||||
assert.equal(s3Bound.provision, "s3-bucket");
|
||||
const accessKey = s3Bound.as;
|
||||
const secretKey = (await must(`cat /var/lib/bucketuser/s3.secret`)).trim();
|
||||
assert.ok(accessKey && secretKey, `the consumer's access key or secret was empty (as=${accessKey})`);
|
||||
const bucket = bucketFor(accessKey);
|
||||
const probe =
|
||||
`mc alias set probe http://minio:9000 ${quote(accessKey)} ${quote(secretKey)} >/dev/null 2>&1 && ` +
|
||||
`mc ls probe/${quote(bucket)}/`;
|
||||
let mc = { out: "", ok: false };
|
||||
const untilReach = Date.now() + 90_000;
|
||||
while (Date.now() < untilReach) {
|
||||
mc = await on(`docker exec mesh-minio sh -c ${quote(probe)} 2>&1`);
|
||||
if (mc.ok) break;
|
||||
if (/denied/i.test(mc.out)) break;
|
||||
await new Promise((r) => setTimeout(r, 3000));
|
||||
}
|
||||
assert.doesNotMatch(mc.out, /denied/i, `minio delivered a secret that is denied:\n${mc.out}`);
|
||||
assert.ok(mc.ok, `the consumer could not list its granted bucket ${bucket} as ${accessKey}:\n${mc.out}`);
|
||||
|
||||
// --- redis provisioned: it serves its tools and fulfils a contribution the mesh delivered --------
|
||||
let served = "";
|
||||
const untilServing = Date.now() + 60_000;
|
||||
while (Date.now() < untilServing) {
|
||||
served = await must(`docker exec mesh-broker lavinmqctl list_queues name 2>&1 || true`);
|
||||
if (/serve\.redis\.redis_ping/.test(served) && /serve\.plex\.plex_reachable/.test(served)) break;
|
||||
await new Promise((r) => setTimeout(r, 3000));
|
||||
}
|
||||
assert.match(served, /serve\.redis\.redis_ping/, `redis's runtime never bound its serve queue:\n${served}`);
|
||||
assert.match(served, /serve\.plex\.plex_reachable/, `plex's runtime never bound its serve queue:\n${served}`);
|
||||
|
||||
// redis's provisioner reconciles the contributions file the mesh writes at MESH_RECEIVES (ADR 0048,
|
||||
// issue 032): for each consumer it reads the login the mesh derived and the mesh-minted password the
|
||||
// host unsealed, and creates the ACL user under exactly that login and password — sealing nothing
|
||||
// and writing no credential file. A hand-written contributions file and secret stand in for the
|
||||
// control plane's write; their SHAPE is what mesh-control produces. The proof is authentication as
|
||||
// the consumer with the mesh's password (PONG) — a provisioner that invented its own would answer
|
||||
// WRONGPASS.
|
||||
const redisPassword = "mesh-minted-9f3c2a";
|
||||
await must(`printf %s ${quote(redisPassword)} > /var/lib/redis-module/grants/app.secret`);
|
||||
const redisContributions = 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(redisContributions)} > /var/lib/redis-module/grants/redis-cache.json`);
|
||||
|
||||
const redisAdmin = (await must(`cat /var/lib/redis-module/default.secret`)).trim();
|
||||
let redisAcl = "";
|
||||
const untilRedis = Date.now() + 60_000;
|
||||
while (Date.now() < untilRedis) {
|
||||
redisAcl = (await on(`docker exec redis redis-cli -a ${quote(redisAdmin)} --no-auth-warning ACL LIST 2>/dev/null`)).out;
|
||||
if (/app-one/.test(redisAcl)) break;
|
||||
await new Promise((r) => setTimeout(r, 3000));
|
||||
}
|
||||
assert.match(redisAcl, /app-one/,
|
||||
`redis's provisioner never created the consumer's login from the contributions the mesh delivered:\n${(await on(`docker logs mesh-redis 2>&1 | tail -30`)).out}\n---\n${redisAcl}`);
|
||||
|
||||
// The proof: authenticate as that consumer with the password the MESH minted. PONG means the
|
||||
// provisioner created the login with exactly that password, not one it invented.
|
||||
const redisAuthed = await on(`docker exec redis redis-cli --user app-one --pass ${quote(redisPassword)} --no-auth-warning PING 2>&1`);
|
||||
assert.doesNotMatch(redisAuthed.out, /WRONGPASS/,
|
||||
`redis created the consumer's login with a different password than the mesh minted:\n${redisAuthed.out}`);
|
||||
assert.match(redisAuthed.out, /PONG/, `expected PONG authenticating as the consumer app-one:\n${redisAuthed.out}`);
|
||||
});
|
||||
Reference in New Issue
Block a user