nftables: allow names the outward link a kept allowance opens
An allowance with no interface never opens an outward link; one named in interfaces does, and allow now says so: a kept allowance whose interface is in the outward links of the converged answer asked for the call answers with outward, that link. The holder reads no shape of the loaded table to tell an outward link from the tunnel; the event carries no outward. Builds: design 33 control-verbs §4, §14; design 47 H H-A-324, H-A-325
This commit is contained in:
@@ -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<string, unknown>, by: string): Promise<{ allowances: (Allowance & { replaced?: Allowance })[]; said: boolean }> {
|
||||
async allow(args: Record<string, unknown>, 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 };
|
||||
}
|
||||
|
||||
|
||||
@@ -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<string, unknown>, RegExp][] = [
|
||||
["port 0", { port: 0, why: "w" }, /port: /],
|
||||
|
||||
Reference in New Issue
Block a user