Grant the node-engine the subscription to its allowances-changed

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
This commit is contained in:
2026-11-21 22:32:36 +01:00
parent f11be5d529
commit d0129d08ae
2 changed files with 25 additions and 1 deletions
+2 -1
View File
@@ -162,7 +162,8 @@
"mesh.seat.mesh-catalog.event.seat-definition-changed", "mesh.seat.mesh-catalog.event.seat-definition-changed",
"mesh.seat.mesh-catalog.event.seat-definition-removed", "mesh.seat.mesh-catalog.event.seat-definition-removed",
"mesh.seat.node-engine.call.*.NODE.*", "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 "AllowResponses": true
} }
+23
View File
@@ -13,6 +13,7 @@ import (
"time" "time"
"github.com/novox/mesh-host/internal/agent" "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-contracts/go/seats/meshmoduleassigner"
"git.novox.be/novox/mesh-delivery/modules/mesh-delivery-contracts/go/clients/meshcatalogclient" "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 { if own == nil || other != nil {
t.Fatalf("heard %v, want the own node's allowances-changed and no other's", heard) 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 { select {
case own <- []byte(`{"node":"n1","change":"allowed"}`): case own <- []byte(`{"node":"n1","change":"allowed"}`):
case <-time.After(10 * time.Second): 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) Error() string { return "artifact-store answered 503 Service Unavailable" }
func (storeAway) StoreAnswered() bool { return false } 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)
}