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:
2026-11-21 22:32:36 +01:00
parent 2a29c458ce
commit dc3765bb7c
18 changed files with 486 additions and 30 deletions
+27
View File
@@ -364,6 +364,33 @@ func RunsAnyOf(runs *engcomp.Composed, module string) bool {
return false
}
// FilterRunning is the content of the packet filter's file as it runs (the resource `<module>.filtering` of the module that
// loads the filter), nil where none runs: kept as it runs when the holder's allowed does not answer (design 08
// control-verbs §4).
func FilterRunning(running []engcomp.Composed) *string {
for _, c := range running {
for _, raw := range c.Resources {
var r struct {
ID string `json:"id"`
Module string `json:"module"`
Type string `json:"type"`
Content *string `json:"content"`
}
if json.Unmarshal(raw, &r) != nil || r.Type != "file" || r.Content == nil {
continue
}
owner := r.Module
if owner == "" {
owner, _ = declaration.ModuleGuess(r.ID)
}
if owner != "" && r.ID == owner+"."+catalogue.FilteringID() {
return r.Content
}
}
}
return nil
}
// ToolsRunning is, by module, the tools bundles that run on the node (Node.RunsTools): each bundle archive a module's
// resource unpacks at its BundlePath, with what the runtime's own process loads of it and the words it hands it
// (catalogue.RuntimeToolModules, catalogue.RuntimeToolEnv, the mesh's own words left out). A bundle the runtime loads
@@ -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'
+10
View File
@@ -201,6 +201,10 @@ type Scope struct {
// keeps offering the others (what it provides, contributes and listens on), since it keeps running what it runs. False
// where nothing is read; the manifest it is composed from is its offer then. Nil: none is read.
RunningManifest func(module string) (catalogue.Manifest, bool)
// Filter is, for the node composing itself, what the compose of its packet filter is given beside the derived ports
// (compose.Node.Filter): the allowances the holder of node-packet-filter answered its verb allowed, or why it did not
// answer, and then the filter file is kept as it runs in Running (design 08 control-verbs §1, §4). Empty renders none.
Filter resolution.Filter
}
// InOwn is, of the modules p places on its node, those whose resources the node's own composition it runs
@@ -479,6 +483,12 @@ func readBase(ctx context.Context, r Reader, mesh Mesh, s Scope) (base, error) {
n.RunsRuntime = compose.RuntimeRunning(s.Running)
// And every runtime process as it runs, whose words give each held module's share of a holder's (H-A-335).
n.RunsRuntimes = compose.RuntimesRunning(s.Running)
// And its packet filter's allowances, or the filter file as it runs where allowed did not answer (design 08
// control-verbs §4).
n.Filter = s.Filter
if n.Filter.Withheld != "" {
n.Filter.Running = compose.FilterRunning(s.Running)
}
for _, module := range s.InOwn {
if n.InOwn == nil {
n.InOwn = map[string]bool{}
+5
View File
@@ -22,6 +22,7 @@ import (
"encoding/json"
"errors"
"fmt"
"github.com/novox/mesh-host/internal/compose/resolution"
engcomp "github.com/novox/mesh-host/internal/compositions"
"sort"
"strings"
@@ -283,6 +284,10 @@ type Node struct {
// (`<module>.own-runtime`); nil when none runs. A held module's share of a holder's words that every module gives a
// share of (the secret places, the owned paths) is taken from them (resolution.Holding; design 47 H, H-A-335, H-A-337).
RunsRuntimes map[string]map[string]string
// Filter is, of the node composing itself, what the compose of its packet filter is given beside the derived ports: the
// allowances the holder of node-packet-filter answered its verb allowed, or why it did not answer and the filter file as
// it runs, which is then kept (design 08 control-verbs §1, §4). Empty renders no allowance, as for every other node.
Filter resolution.Filter
}
// ComposedHow is how a node-engine composes its node from an Input (Input.ComposedHow).
+3 -3
View File
@@ -176,10 +176,10 @@ func ComposeIn(in Input, node string, mode Mode) (Declared, []string, error) {
// none (resolution.NoStoreError, whatever the shape: an image, a source, a tools bundle, a runtime program, a templates
// archive) is left out of the declaration with its words and the rest composes again; the node is never refused whole for it
// (design 47 G A-461, A-452). The rendering returned carries the modules so left out, for the filter and the rest to read.
func composeWithoutStoreFetchers(plan catalogue.Resolution, with catalogue.Rendering, holding resolution.Holding) (catalogue.Composed, catalogue.Rendering, map[string]string, error) {
func composeWithoutStoreFetchers(plan catalogue.Resolution, with catalogue.Rendering, holding resolution.Holding, filter resolution.Filter) (catalogue.Composed, catalogue.Rendering, map[string]string, error) {
var held map[string]string
for {
composed, err := resolution.ComposeHolding(plan, with, holding)
composed, err := resolution.ComposeHoldingFiltered(plan, with, holding, filter)
var none *resolution.NoStoreError
if !errors.As(err, &none) {
return composed, with, held, err
@@ -223,7 +223,7 @@ func (c *composer) declaration(nodeName string, mode Mode) (Declared, error) {
}
// A held module's share of a holder's words is what runs of each runtime process (design 47 H, H-A-335, H-A-337).
holding := resolution.Holding{Held: node.Held, Runs: node.RunsRuntimes}
composed, with, storeHeld, err := composeWithoutStoreFetchers(plan, with, holding)
composed, with, storeHeld, err := composeWithoutStoreFetchers(plan, with, holding, node.Filter)
if err != nil {
return Declared{}, err
}
+41 -9
View File
@@ -105,18 +105,40 @@ func (e *UnreadManifestError) Error() string { return e.said }
// Compose is Declaration with the owner of every resource said.
func Compose(r mcat.Resolution, with mcat.Rendering) (mcat.Composed, error) {
return ComposeHolding(r, with, Holding{})
return ComposeHoldingFiltered(r, with, Holding{}, Filter{})
}
// ComposeHolding is Compose for a node that holds modules this pass (Holding): a held module's share of a holder's words
// is what runs (design 47 H, H-A-335, H-A-337).
func ComposeHolding(r mcat.Resolution, with mcat.Rendering, h Holding) (mcat.Composed, error) {
return ComposeHoldingFiltered(r, with, h, Filter{})
}
// Filter is what a compose of the node's packet filter is given beside the derived ports (design 08 control-verbs §1, §4):
// the allowances the holder of node-packet-filter answered its verb allowed, or, when allowed did not answer, why
// (Withheld) and the filter file as it runs (Running, nil when none runs). A withheld allowed composes no filter file: the
// one loaded is kept, its content as it runs, and none is composed where none runs, never one read as "nothing opened"
// (H-A-307 (1)).
type Filter struct {
Allowing Allowing
Withheld string
Running *string
}
// ComposeFiltered is Compose with the filter's allowances, or the filter kept as it runs (Filter).
func ComposeFiltered(r mcat.Resolution, with mcat.Rendering, filter Filter) (mcat.Composed, error) {
return ComposeHoldingFiltered(r, with, Holding{}, filter)
}
// ComposeHoldingFiltered is Compose for a node that holds modules this pass (Holding) and composes its packet filter with
// the allowances or keeps it as it runs (Filter): ComposeHolding and ComposeFiltered at once.
func ComposeHoldingFiltered(r mcat.Resolution, with mcat.Rendering, h Holding, filter Filter) (mcat.Composed, error) {
owner := map[string]string{}
received := map[string]map[string][]mcat.Contribution{}
leftOut := map[string]string{}
var foreseen, unplaced, handedOnly []string
handed := &handedFiles{plans: map[string]mcat.Plan{}}
resources, err := resolutionCompose(r, with, h, owner, received, leftOut, &foreseen, &unplaced, &handedOnly, handed)
resources, err := resolutionCompose(r, with, h, filter, owner, received, leftOut, &foreseen, &unplaced, &handedOnly, handed)
if err != nil {
return mcat.Composed{}, err
}
@@ -143,7 +165,7 @@ func ComposeHolding(r mcat.Resolution, with mcat.Rendering, h Holding) (mcat.Com
// BusMembershipPath is where the host reads it — the same constant on both sides.
func BusMembershipID() string { return "bus-membership" }
func resolutionCompose(r mcat.Resolution, with mcat.Rendering, h Holding, owner map[string]string,
func resolutionCompose(r mcat.Resolution, with mcat.Rendering, h Holding, filter Filter, owner map[string]string,
received map[string]map[string][]mcat.Contribution, leftOut map[string]string,
foreseen, unplaced, handedOnly *[]string, handed *handedFiles) ([]map[string]any, error) {
// **A setting is judged where it is stored, and an impossible one costs a module, not a
@@ -284,8 +306,8 @@ func resolutionCompose(r mcat.Resolution, with mcat.Rendering, h Holding, owner
"`node show %s` says whether it has. Until then %s is not sent, and the machine "+
"keeps the filter it has", r.Node, r.Node, filters)
}
filtering := AsNftablesWithLocal(rules, with.Mesh, r.PublicDomain != "", with.Foundation,
with.OutwardLinks, with.TunnelInterface, with.LocalNetworks)
filtering := AsNftablesAllowing(rules, with.Mesh, r.PublicDomain != "", with.Foundation,
with.OutwardLinks, with.TunnelInterface, with.LocalNetworks, filter.Allowing)
// **A variable two modules set is refused whether or not anything places it** (novox/hq ADR
// 0203 §5): the account has one environment, and a machine whose holder arrives later should not
@@ -323,10 +345,20 @@ func resolutionCompose(r mcat.Resolution, with mcat.Rendering, h Holding, owner
// that does not, because what gets remembered is that it works.
var first []map[string]any
if f := m.Filtering; f != nil {
first = append(first, map[string]any{
"id": mcat.FilteringID(), "type": "file", "path": f.Into,
"content": filtering, "mode": "0600",
})
// **An unanswered allowed composes no filter file** (design 08 control-verbs §4): the one loaded is kept as it
// runs, and none is composed where none runs.
switch {
case filter.Withheld == "":
first = append(first, map[string]any{
"id": mcat.FilteringID(), "type": "file", "path": f.Into,
"content": filtering, "mode": "0600",
})
case filter.Running != nil:
first = append(first, map[string]any{
"id": mcat.FilteringID(), "type": "file", "path": f.Into,
"content": *filter.Running, "mode": "0600",
})
}
}
// The node's fail2ban jails, composed from every module it runs (novox/hq to-be 31), written
// where the intrusion-prevention holder owns them. Like the rule set above: gathered from all