Ask the packet filter's holder allowed at every compose of the filter
The node-engine stays the one renderer of the filter file: at each compose of a converged node's filter it asks the holder of node-packet-filter its verb allowed within the setting compose-ask-bound (10 s) and renders the answer. When allowed does not answer, or answers what is not its answer, no filter file is composed: the one loaded is kept as it runs, the holder's module is not held (an old holder must stay replaceable), and the part withheld is said once in the journal until an answer comes between. The node hears allowances-changed on its own node's subject and composes again. The manifest invokes seat:node-packet-filter.allowed and consumes node-packet-filter.allowances-changed. Builds: design 08 control-verbs §1, §3, §4, §5, §7, §8; ADR 0683; H-A-305, H-A-307 (1), (2), H-A-314 (3), (5), (7), H-A-315 (2), (6), H-A-321
This commit is contained in:
@@ -19,6 +19,7 @@ import (
|
||||
"strings"
|
||||
"testing"
|
||||
|
||||
"git.novox.be/novox/mesh-networking/modules/mesh-connectivity-contracts/go/seats/nodepacketfilter"
|
||||
"git.novox.be/novox/mesh-networking/modules/mesh-wireguard/go/overlay"
|
||||
"git.novox.be/novox/mesh-sdk/go/catalogue"
|
||||
"github.com/novox/mesh-host/internal/compose"
|
||||
@@ -349,6 +350,52 @@ func answerNamesEveryRefusalAndLeavesAnOldBuildToTheNode(t *testing.T) {
|
||||
if !strings.Contains(rules, "# spiegel — the site") || !strings.Contains(rules, "dport 20005 accept") || strings.Contains(rules, "dport 8080") {
|
||||
t.Errorf("the filter does not open the machine port spiegel runs at:\n%s", rules)
|
||||
}
|
||||
// Design 08 control-verbs §1, §2, §4 (H-A-321): the compose of the filter renders the allowances the holder answered;
|
||||
// where allowed did not answer it composes no filter file and keeps the one loaded, as it runs, and the rest composes.
|
||||
filterOf := func(f resolution.Filter, running []engcomp.Composed) (string, bool) {
|
||||
t.Helper()
|
||||
got, _, held, err := Compose(ctx, b, Mesh{}, Scope{Node: "n1", InOwn: []string{"spiegel"}, Running: running, Filter: f}, fps)
|
||||
if _, nftHeld := held["nft"]; err != nil || nftHeld {
|
||||
t.Fatalf("the node does not compose itself with the filter given %+v: %v, held %v", f, err, held)
|
||||
}
|
||||
for _, c := range got {
|
||||
for _, raw := range c.Resources {
|
||||
var r struct {
|
||||
ID string `json:"id"`
|
||||
Content string `json:"content"`
|
||||
}
|
||||
if json.Unmarshal(raw, &r) == nil && r.ID == "nft."+catalogue.FilteringID() {
|
||||
return r.Content, true
|
||||
}
|
||||
}
|
||||
}
|
||||
return "", false
|
||||
}
|
||||
allowance := nodepacketfilter.Allowance{Key: "allow.tcp.8000", Port: 8000, Protocol: "tcp", At: "2026-11-21T19:00:00Z"}
|
||||
if got, _ := filterOf(resolution.Filter{Allowing: resolution.Allowing{Allowances: []nodepacketfilter.Allowance{allowance}}}, running); !strings.Contains(got,
|
||||
`tcp dport 8000 accept comment "allowance allow.tcp.8000 2026-11-21T19:00:00Z"`) || !strings.Contains(got, "dport 20005 accept") {
|
||||
t.Errorf("the filter does not render the allowance beside the derived ports:\n%s", got)
|
||||
}
|
||||
kept := slices.Clone(running)
|
||||
for i, c := range kept {
|
||||
if c.Module != "nft" {
|
||||
continue
|
||||
}
|
||||
c.Resources = slices.Clone(c.Resources)
|
||||
for j, raw := range c.Resources {
|
||||
if strings.Contains(string(raw), `"nft.`+catalogue.FilteringID()+`"`) {
|
||||
c.Resources[j] = json.RawMessage(`{"id":"nft.filtering","module":"nft","type":"file","path":"/etc/nftables.conf","mode":"0600","content":"the filter loaded\n"}`)
|
||||
}
|
||||
}
|
||||
kept[i] = c
|
||||
}
|
||||
withheld := resolution.Filter{Withheld: "asked of the seat node-packet-filter's verb allowed on n1, which did not answer"}
|
||||
if got, ok := filterOf(withheld, kept); !ok || got != "the filter loaded\n" {
|
||||
t.Errorf("an unanswered allowed composes the filter %q (%v), want the one loaded kept as it runs", got, ok)
|
||||
}
|
||||
if got, ok := filterOf(withheld, nil); ok {
|
||||
t.Errorf("an unanswered allowed where no filter runs composes one:\n%s", got)
|
||||
}
|
||||
// The paths a carried module owns are its manifest's, as the controller composes them, never what runs of it (issue
|
||||
// 1126, seed-8 #542: on ace, the folded f1-circuits, snake and txt-game, whose manifests leave their directories and
|
||||
// files to ${dir:…}, owned their /var/lib paths on the node and none on the controller, shifting node-tools'
|
||||
|
||||
Reference in New Issue
Block a user