diff --git a/modules/nftables/allowances.ts b/modules/nftables/allowances.ts index f5d5269ed..03be25278 100644 --- a/modules/nftables/allowances.ts +++ b/modules/nftables/allowances.ts @@ -56,7 +56,11 @@ export interface Changed { at: string; } -/** The node's convergence state as the node-engine seat's converged answers it (§10, H-A-316, H-A-321). */ +/** One allowance as allow kept it (§4): what it replaced, and the outward link it opens when its named interface is one + * of the outward links the node-engine's converged answered for the call (H-A-324, H-A-325). */ +export type Kept = Allowance & { outward?: string; replaced?: Allowance }; + +/** The node's convergence state as the node-engine seat's converged answers it (§10, H-A-316, H-A-321, H-A-325). */ export type Convergence = ConvergedAnswer; /** One act by hand, as the seat mesh-hand-acts' hand-act takes it (ADR 0565 §10): the SDK's views.HandAct. */ @@ -311,10 +315,14 @@ export class Allowances { /** Open a port (§2): one key per named interface, or the default set's one key; a key there already is replaced * whole and answered. */ - async allow(args: Record, by: string): Promise<{ allowances: (Allowance & { replaced?: Allowance })[]; said: boolean }> { + async allow(args: Record, by: string): Promise<{ allowances: Kept[]; said: boolean }> { this.proven("allow", by); only(args, ["port", "protocol", "interfaces", "source", "until", "why"]); - this.refuseAdopted("allow", await this.askConverged("allow")); + const convergence = await this.askConverged("allow"); + this.refuseAdopted("allow", convergence); + // The outward links as the node-engine classifies them for its render, from the converged answer of this call; the + // loaded table's shape is never read to tell one from the tunnel (§4, H-A-325). + const outward = new Set(convergence.outward); const now = this.now(); const port = portOf(args.port); const protocol = protocolOf(args.protocol); @@ -334,7 +342,7 @@ export class Allowances { const keys = interfaces.map((i) => keyOf(protocol, port, i)); await this.recorded({ what: `allowed ${keys.join(", ")} on ${this.node}${source ? ` from ${source}` : ""}${until ? ` until ${until}` : ""}`, why: `${why} (${by})`, cause: "allowance-set", verb: "allow" }); - const out: (Allowance & { replaced?: Allowance })[] = []; + const out: Kept[] = []; for (const iface of interfaces) { const key = keyOf(protocol, port, iface); const value: Value = { @@ -346,9 +354,13 @@ export class Allowances { }; const before = await this.store.get(this.stored(key)); await this.store.put(this.stored(key), value); - out.push({ ...answered(key, value), ...(before ? { replaced: answered(key, before.value) } : {}) }); + out.push({ + ...answered(key, value), + ...(iface && outward.has(iface) ? { outward: iface } : {}), + ...(before ? { replaced: answered(key, before.value) } : {}), + }); } - await this.say({ node: this.node, change: "allowed", allowances: out.map(({ replaced: _, ...a }) => a), by, why, at }); + await this.say({ node: this.node, change: "allowed", allowances: out.map(({ replaced: _, outward: __, ...a }) => a), by, why, at }); return { allowances: out, said: true }; } diff --git a/modules/nftables/test/allowances.test.ts b/modules/nftables/test/allowances.test.ts index 990f2926c..35dffcc18 100644 --- a/modules/nftables/test/allowances.test.ts +++ b/modules/nftables/test/allowances.test.ts @@ -79,6 +79,17 @@ test("allow keeps one key per interface, and with none the default set's key, wh } }); +test("allow naming an outward link answers it as outward, as converged lists them; another interface and the default set do not (H-A-325)", async () => { + const { a, asks, said } = fake(); + asks.convergence = { state: "converged", since: "2026-11-01T00:00:00Z", tunnel: "mesh0", outward: ["eth1"] }; + const named = await a.allow({ port: 8000, interfaces: ["eth1", "enp6s0"], why: "w" }, "lead@shanks"); + assert.deepEqual(named.allowances.map((x) => [x.key, x.outward]), [["allow.tcp.8000.eth1", "eth1"], ["allow.tcp.8000.enp6s0", undefined]]); + assert.equal("outward" in named.allowances[1], false, "an interface that is no outward link answers without the field"); + const none = await a.allow({ port: 8001, why: "w" }, "lead@shanks"); + assert.equal("outward" in none.allowances[0], false, "the default set opens no outward link"); + assert.equal(said.flatMap((b) => b.allowances).some((x) => "outward" in x), false, "the event's allowances carry no outward"); +}); + test("allow and disallow refuse what is not an allowance, writing nothing", async () => { const bad: [string, Record, RegExp][] = [ ["port 0", { port: 0, why: "w" }, /port: /],