From 4289d5583b5a8fb3a0c1810cabf39209d1b6606b Mon Sep 17 00:00:00 2001 From: jochen Date: Sun, 15 Nov 2026 18:36:55 +0100 Subject: [PATCH] grants: the part's account may create the seats' ask streams it makes The bus refused SEAT_MESH_BUILDS's and SEAT_MESH_WANTS's create: the part's account is granted each stream it creates by name, and the ask streams were not named. They join the declared streams, as the kept-event streams do. --- .../internal/buscompose/askstreams_test.go | 22 +++++++++++++++++++ .../mesh-grants/internal/buscompose/users.go | 5 +++++ modules/mesh-grants/internal/grants/kept.go | 9 ++++++++ .../mesh-grants/internal/grants/records.go | 2 +- 4 files changed, 37 insertions(+), 1 deletion(-) create mode 100644 modules/mesh-grants/internal/buscompose/askstreams_test.go diff --git a/modules/mesh-grants/internal/buscompose/askstreams_test.go b/modules/mesh-grants/internal/buscompose/askstreams_test.go new file mode 100644 index 00000000..a9239286 --- /dev/null +++ b/modules/mesh-grants/internal/buscompose/askstreams_test.go @@ -0,0 +1,22 @@ +package buscompose + +import ( + "slices" + "testing" +) + +// The grants part may create each seat's ask stream it makes (AskStreamsOf), by its name alone (lead-47, 2026-11-15: the bus +// refused SEAT_MESH_BUILDS's create because the part's account named no such stream). +func TestTheGrantsPartMayCreateTheSeatsAskStreams(t *testing.T) { + got := declaredStreamsOf(Records{AskStreams: []string{"SEAT_MESH_BUILDS"}}) + if !slices.Contains(got, "SEAT_MESH_BUILDS") { + t.Fatalf("declared streams %v lack the builds seat's ask stream", got) + } + perms, err := PermissionsFor(Principal{Kind: KindModule, Node: "one", Module: GrantsModule, CreatesStreams: got}) + if err != nil { + t.Fatal(err) + } + if !MayPublish(perms, "$JS.API.STREAM.CREATE.SEAT_MESH_BUILDS") || MayPublish(perms, "$JS.API.STREAM.CREATE.SEAT_OTHER") { + t.Errorf("the grants part's creates: %v", perms.Publish) + } +} diff --git a/modules/mesh-grants/internal/buscompose/users.go b/modules/mesh-grants/internal/buscompose/users.go index 3cca1178..7da32139 100644 --- a/modules/mesh-grants/internal/buscompose/users.go +++ b/modules/mesh-grants/internal/buscompose/users.go @@ -176,6 +176,8 @@ type Records struct { // Kept is every seat event kept in a stream of its own (kept.go): the grants part makes each stream, so its principal is // granted the create of each by name. Kept []KeptEvent + // AskStreams are the seats' ask streams the grants part makes where the bus lacks them (AskStreamsOf), each its to create. + AskStreams []string // Chunked is every verb the seat definitions say sends chunks (chunks.go, design 47 G §681): their subjects are granted to the // principal that answers the verb and to an account naming it in `invokes`. Chunked []ChunkVerb @@ -641,6 +643,9 @@ func declaredStreamsOf(r Records) []string { for _, k := range r.Kept { seen[k.Stream] = true } + for _, a := range r.AskStreams { + seen[a] = true + } placed := [][]Declared{} for _, mods := range r.Assigned { placed = append(placed, mods) diff --git a/modules/mesh-grants/internal/grants/kept.go b/modules/mesh-grants/internal/grants/kept.go index 3d7f7886..05832155 100644 --- a/modules/mesh-grants/internal/grants/kept.go +++ b/modules/mesh-grants/internal/grants/kept.go @@ -213,3 +213,12 @@ func createAskStreams(c Creator, done *creations, asks []jetstream.StreamConfig, } return made, notMade } + +// askStreamNames are the names of the seats' ask streams, which the grants part's own account is granted to create. +func askStreamNames(asks []jetstream.StreamConfig) []string { + out := make([]string, 0, len(asks)) + for _, a := range asks { + out = append(out, a.Name) + } + return out +} diff --git a/modules/mesh-grants/internal/grants/records.go b/modules/mesh-grants/internal/grants/records.go index 5f9da5e3..44691e97 100644 --- a/modules/mesh-grants/internal/grants/records.go +++ b/modules/mesh-grants/internal/grants/records.go @@ -46,7 +46,7 @@ func records(in Inputs, union bool) (buscompose.Records, []Gap) { out := buscompose.Records{Assigned: map[string][]buscompose.Declared{}, People: map[string][]string{}, Interchangeable: map[string]bool{}, Enrolling: slices.Clone(in.Enrolling), // And each node's logins (ADR 0583 §1): both while it rotates. - NodeLogins: in.NodeLogins, Kept: in.Kept, Chunked: in.Chunked, EngineEvents: in.EventSubjects[buscompose.EngineSeat], + NodeLogins: in.NodeLogins, Kept: in.Kept, AskStreams: askStreamNames(in.AskStreams), Chunked: in.Chunked, EngineEvents: in.EventSubjects[buscompose.EngineSeat], // What the bus module's process may define: every manifest's bus state, and what it said it created (DLV-G2). BusState: map[string][]catalogue.BusStateEntry{}, Bound: in.Bound, // Each node's capability reading and what each node-engine said running (design 46 approval mark §6).