mesh-grants: a module's consumer is composed from its own subjects, not from its account's wide grant

ConsumerFor drew its filters from PermissionsFor, which since every account may subscribe to every subject (e1476cfd) is ">": no filter
named an event, so no module got an account consumer on EVENTS. The scoped permissions give them again. The integration subtests that
read each account's own subjects run with the wide grant off, as the unit tests do.

Builds: design 47 G A-434 (G-22-lead-answers-2.md: every account may do everything, the mechanisms stay whole), the grants part's account consumers (ADR 0561 §6)
This commit is contained in:
2026-11-17 15:31:00 +01:00
parent 0be2b3d01a
commit 10d87dcc77
3 changed files with 22 additions and 4 deletions
@@ -35,6 +35,7 @@ import (
"git.novox.be/novox/mesh-sdk/go/seatlist"
"git.novox.be/novox/mesh-sdk/go/views"
"mesh-grants/internal/buscompose"
"mesh-grants/internal/grants"
)
@@ -651,9 +652,19 @@ func TestTheGrantsPartWhole(t *testing.T) {
})
// And what the part composes holds on a server that loads it (one integration test per module, the test budget).
t.Run("the composed grants hold on a server that loads them", theBusNodeFollowsTheSealedListUnderTheComposedGrants)
t.Run("the tool runner hears every event on a server that loads its grants", theToolRunnerHearsEveryEventOnTheBus)
t.Run("a runtime denied the marks is delivered no call on a marked subject", aRuntimeDeniedTheMarksHearsNoMarkedCall)
// These read each account's own subjects, which the part composes beneath the wide grant of every account (the unit tests'
// TestMain does the same): the mechanisms of the scoped grants are built whole all the same.
scoped := func(f func(*testing.T)) func(*testing.T) {
return func(t *testing.T) {
was := buscompose.EveryAccountMayDoEverything
buscompose.EveryAccountMayDoEverything = false
defer func() { buscompose.EveryAccountMayDoEverything = was }()
f(t)
}
}
t.Run("the composed grants hold on a server that loads them", scoped(theBusNodeFollowsTheSealedListUnderTheComposedGrants))
t.Run("the tool runner hears every event on a server that loads its grants", scoped(theToolRunnerHearsEveryEventOnTheBus))
t.Run("a runtime denied the marks is delivered no call on a marked subject", scoped(aRuntimeDeniedTheMarksHearsNoMarkedCall))
}
// lockedLog is the part's log, read by the test while the part writes it.
@@ -1698,6 +1698,11 @@ func TestEveryMeshAccountMayDoEverything(t *testing.T) {
if err != nil || !slices.Equal(m.Publish, []string{AllSubjects}) || !slices.Equal(m.Subscribe, []string{AllSubjects}) {
t.Fatalf("a module account = %v / %v (%v), want every subject both ways", m.Publish, m.Subscribe, err)
}
// The wide grant leaves a module its consumer: its filters are its own events', never the grant's ">".
if c, ok := ConsumerFor(Principal{Kind: KindModule, Node: "a", Module: "plain", Consumes: []string{"nats.done"}}); !ok || slices.Contains(c.Filters, AllSubjects) ||
!slices.Contains(c.Filters, "mesh.mod.nats.event.done") {
t.Errorf("a module's consumer under the wide grant = %v, %v, want its own event filters", c.Filters, ok)
}
e, err := PermissionsFor(Principal{Kind: KindEnrolment, Node: "new"})
if err == nil && slices.Contains(e.Publish, AllSubjects) {
t.Errorf("an enrolling node is granted every subject: %v", e.Publish)
@@ -148,7 +148,9 @@ func ConsumerFor(p Principal) (Consumer, bool) {
if p.Kind != KindModule || (len(p.Consumes) == 0 && len(p.Watches) == 0 && !hearsItsOwn && !hearsAStream) {
return Consumer{}, false
}
perms, err := PermissionsFor(p)
// The module's own subjects, never its account's grant: every account may subscribe to every subject (EveryAccountMayDoEverything),
// and a filter drawn from ">" names no event, so no consumer would be composed for any module.
perms, err := scopedPermissionsFor(p)
if err != nil {
return Consumer{}, false
}