From d0129d08ae17b7397ea31d7f6522ea6ca53e8d31 Mon Sep 17 00:00:00 2001 From: jochen Date: Sat, 21 Nov 2026 21:38:20 +0100 Subject: [PATCH] Grant the node-engine the subscription to its allowances-changed MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Review round 1 (5): the node grant's stored copy had the allowed call subjects but not the event the engine consumes, which the grants part grants every machine's as a wildcard; the subtest of allowances-changed now checks the grant covers the node's subject. Builds: design 08 control-verbs §1, §3 --- internal/nodegrant/testdata/node.json | 3 ++- internal/selfcompose/versions_test.go | 23 +++++++++++++++++++++++ 2 files changed, 25 insertions(+), 1 deletion(-) diff --git a/internal/nodegrant/testdata/node.json b/internal/nodegrant/testdata/node.json index d6b315e8..e31dcc1c 100644 --- a/internal/nodegrant/testdata/node.json +++ b/internal/nodegrant/testdata/node.json @@ -162,7 +162,8 @@ "mesh.seat.mesh-catalog.event.seat-definition-changed", "mesh.seat.mesh-catalog.event.seat-definition-removed", "mesh.seat.node-engine.call.*.NODE.*", - "mesh.seat.node-engine.tool.*.NODE" + "mesh.seat.node-engine.tool.*.NODE", + "mesh.seat.node-packet-filter.event.allowances-changed.*" ], "AllowResponses": true } diff --git a/internal/selfcompose/versions_test.go b/internal/selfcompose/versions_test.go index 76cf4bf8..9b2fa862 100644 --- a/internal/selfcompose/versions_test.go +++ b/internal/selfcompose/versions_test.go @@ -13,6 +13,7 @@ import ( "time" "github.com/novox/mesh-host/internal/agent" + "github.com/novox/mesh-host/internal/nodegrant" "git.novox.be/novox/mesh-contracts/go/seats/meshmoduleassigner" "git.novox.be/novox/mesh-delivery/modules/mesh-delivery-contracts/go/clients/meshcatalogclient" @@ -248,6 +249,14 @@ func TestAModulesClaimsAreReadFromTheEntryOfItsWantsBuild(t *testing.T) { if own == nil || other != nil { t.Fatalf("heard %v, want the own node's allowances-changed and no other's", heard) } + // And the node's grant lets it subscribe there, as the grants part grants the consume (every machine's, as `*`). + granted := false + for _, f := range nodegrant.For("n1").Subscribe { + granted = granted || subjectCovers(f, nodepacketfilter.SubjectAllowancesChanged("n1")) + } + if !granted { + t.Errorf("the node's grant does not let it subscribe to %s", nodepacketfilter.SubjectAllowancesChanged("n1")) + } select { case own <- []byte(`{"node":"n1","change":"allowed"}`): case <-time.After(10 * time.Second): @@ -359,3 +368,17 @@ type storeAway struct{} func (storeAway) Error() string { return "artifact-store answered 503 Service Unavailable" } func (storeAway) StoreAnswered() bool { return false } + +// subjectCovers says whether the subject filter f matches the subject s, by NATS's wildcards (* one token, > the rest). +func subjectCovers(f, s string) bool { + ft, st := strings.Split(f, "."), strings.Split(s, ".") + for i, t := range ft { + if t == ">" { + return i < len(st) + } + if i >= len(st) || (t != "*" && t != st[i]) { + return false + } + } + return len(ft) == len(st) +}