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.
This commit is contained in:
2026-11-15 18:36:55 +01:00
parent 773f89e9de
commit 4289d5583b
4 changed files with 37 additions and 1 deletions
@@ -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)
}
}
@@ -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)
@@ -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
}
@@ -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).