From 10d87dcc77bb0b5f381414e59d0b62f084393c98 Mon Sep 17 00:00:00 2001 From: jochen Date: Tue, 17 Nov 2026 15:03:47 +0100 Subject: [PATCH] mesh-grants: a module's consumer is composed from its own subjects, not from its account's wide grant MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit 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) --- .../cmd/mesh-grants/integration_test.go | 17 ++++++++++++++--- .../internal/buscompose/buscompose_test.go | 5 +++++ .../mesh-grants/internal/buscompose/derived.go | 4 +++- 3 files changed, 22 insertions(+), 4 deletions(-) diff --git a/modules/mesh-grants/cmd/mesh-grants/integration_test.go b/modules/mesh-grants/cmd/mesh-grants/integration_test.go index 5aa60ab3..d84b24ee 100644 --- a/modules/mesh-grants/cmd/mesh-grants/integration_test.go +++ b/modules/mesh-grants/cmd/mesh-grants/integration_test.go @@ -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. diff --git a/modules/mesh-grants/internal/buscompose/buscompose_test.go b/modules/mesh-grants/internal/buscompose/buscompose_test.go index d37475b0..683972e2 100644 --- a/modules/mesh-grants/internal/buscompose/buscompose_test.go +++ b/modules/mesh-grants/internal/buscompose/buscompose_test.go @@ -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) diff --git a/modules/mesh-grants/internal/buscompose/derived.go b/modules/mesh-grants/internal/buscompose/derived.go index ddc633d8..d0772c42 100644 --- a/modules/mesh-grants/internal/buscompose/derived.go +++ b/modules/mesh-grants/internal/buscompose/derived.go @@ -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 }