DLV-G1, DLV-W1: the grants part and the watchman hear mesh-broker's events on the seat's subject; the keeper is granted them

The lead's ruling of 13:0x (registry milestone): mesh-broker's events are mesh.seat.mesh-broker.event.<event> on the
shared events stream like every seat's. The grants part and the watchman consume mesh-broker.<event> and no longer hear
the bus module's own stream, which is its history for its tool. The keeper's process account is composed the seat's
event subjects, and the acknowledgement of a snapshot's chunks of each entry it keeps, which ADR 0626 §1 grants and the
composition lacked; a row holds it to no subscription of a restricted stream's subjects and no consumer of one.

Claude-Session: https://claude.ai/code/session_01JG73KJNrH5EgFXMKKYSrig
This commit is contained in:
2026-11-04 13:05:27 +01:00
parent 20a4a79993
commit 8a78e00bb0
14 changed files with 105 additions and 55 deletions
@@ -1069,12 +1069,14 @@ func aLedgerIsWrittenByItsLedgerAccountAlone(t *testing.T) {
func theBusModulesProcessKeepsBusState(t *testing.T) {
r := Records{Nodes: []string{"a"}, Assigned: map[string][]Declared{"a": {
{Module: "node-tools", ToolRunner: true},
{Module: "nats", SnapshotsTheBus: true, Holds: []Seat{{Name: catalogue.BrokerSeat, Serves: BrokerVerbs()}},
{Module: "nats", SnapshotsTheBus: true, Holds: []Seat{{Name: catalogue.BrokerSeat, Serves: BrokerVerbs(),
Emits: []string{"created", "refused"}}},
Consumes: []string{"mesh-delivery-indexer.manifest-accepted"}, Uses: []Seat{{Name: "operator-channel", Accepts: []string{"condition"}, ByCaller: []string{"condition"}}},
Streams: []ModuleStream{{Module: "nats", Name: "BROKER_EVENTS", Events: []string{"created", "refused"}, MaxAgeDays: 30, MaxMiB: 256}},
Processes: []ProcessPrincipal{{Process: "keeper", State: []string{"asked"}, Keeps: true}, {Process: "other"},
{Process: "nats-tools", Tools: true, Removes: []string{catalogue.RemovesEngineActs}}}},
{Module: "mod-x", Processes: []ProcessPrincipal{{Process: "sneak", Keeps: true}}},
{Module: "mod-x", Processes: []ProcessPrincipal{{Process: "sneak", Keeps: true}},
Streams: []ModuleStream{{Module: "mod-x", Name: "SECRETS", Events: []string{"sealed"}, Restricted: true}}},
{Module: "admin-ish", Invokes: []string{"*"}},
}},
BusState: map[string][]catalogue.BusStateEntry{"mod-x": {
@@ -1132,11 +1134,39 @@ func theBusModulesProcessKeepsBusState(t *testing.T) {
t.Error("the bus module's process answers what it was asked")
}
for _, s := range []string{"$JS.API.CONSUMER.MSG.NEXT.EVENTS.a_nats_keeper", "$JS.ACK.EVENTS.a_nats_keeper.x",
"mesh.stream.nats.event.created", "mesh.seat.operator-channel.accept.condition.nats"} {
"mesh.stream.nats.event.created", "mesh.seat.operator-channel.accept.condition.nats",
// The seat's events on the seat's subjects, as every seat's (the lead's ruling, registry milestone 13:0x), and the
// acknowledgement of a snapshot's chunks of an entry it keeps (ADR 0626 §1).
"mesh.seat.mesh-broker.event.created", "mesh.seat.mesh-broker.event.refused", "$JS.SNAPSHOT.ACK.KV_mod-x_records.x.1.0"} {
if !MayPublish(keeper, s) {
t.Errorf("the bus module's process may not publish %s", s)
}
}
for _, other := range []string{"a.nats.other", "a.mod-x.sneak"} {
if MayPublish(perms[other], "mesh.seat.mesh-broker.event.created") {
t.Errorf("%s, which is no keeper of the bus, says mesh-broker's created", other)
}
}
// ADR 0626, How it is checked: no subscription to a restricted stream's subjects, nor a consumer of it or of any
// stream it keeps; a snapshot's chunks come to its own inbox alone, and only of a stream it keeps.
for _, s := range []string{"mesh.stream.mod-x.event.sealed", "mesh.stream.mod-x.event.>", "mesh.bus.mod-x.records.x"} {
if MaySubscribe(keeper, s) {
t.Errorf("the bus module's process hears %s", s)
}
}
for _, s := range []string{"$JS.API.CONSUMER.CREATE.SECRETS.x.y", "$JS.API.CONSUMER.CREATE.KV_mod-x_records.x",
"$JS.API.CONSUMER.MSG.NEXT.SECRETS.x", "$JS.API.DIRECT.GET.SECRETS", "$JS.API.STREAM.SNAPSHOT.SECRETS",
"$JS.SNAPSHOT.ACK.SECRETS.x.1.0", "$JS.API.STREAM.MSG.GET.KV_mod-x_records"} {
if MayPublish(keeper, s) {
t.Errorf("the bus module's process may publish %s", s)
}
}
for _, s := range keeper.Subscribe {
if !strings.HasPrefix(s, "_INBOX.a.nats.keeper.") && !strings.HasPrefix(s, "$JS.EVENT.ADVISORY.STREAM.CREATED.KV_nats_") &&
!strings.HasPrefix(s, "mesh.seat.operator-channel.") {
t.Errorf("the bus module's process subscribes %s, beyond its inbox, its own state's creation and its conditions' answers", s)
}
}
made := false
for _, mc := range AccountConsumers(users) {
if mc.Consumer.Stream == "EVENTS" && mc.Consumer.Name == "a_nats_keeper" &&
@@ -144,13 +144,34 @@ func BusStateNames(asked map[string][]catalogue.BusStateEntry, bound map[string]
}
// busStateKeeperGrants are what the bus module's process publishes to keep the bus state named: each stream's create,
// update, information, deletion and snapshot, and the stream list it finds orphans in.
// update, information, deletion and snapshot with the acknowledgement of the snapshot's chunks (ADR 0626 §1; the server
// waits on `$JS.SNAPSHOT.ACK.<stream>.…` past its window), and the stream list it finds orphans in. Never a consumer of
// one, nor any stream's own subjects: a snapshot carries an entry's data to the keeper's inbox alone, and the keeper
// hears no message of it (ADR 0626 §1, restricted streams included).
func busStateKeeperGrants(names []string) []string {
out := []string{"$JS.API.STREAM.NAMES", "$JS.API.STREAM.LIST"}
for _, n := range names {
for _, op := range []string{"CREATE", "UPDATE", "INFO", "DELETE", "SNAPSHOT"} {
out = append(out, "$JS.API.STREAM."+op+"."+n)
}
out = append(out, "$JS.SNAPSHOT.ACK."+n+".>")
}
return out
}
// brokerSeatEvents are the subjects of the seat mesh-broker's events, from the held seat's definition: what the bus
// module's keeper says them on, like every seat's holder (the lead's ruling, registry milestone 13:0x).
func brokerSeatEvents(holds []Seat) []string {
var out []string
for _, s := range holds {
if s.Name != catalogue.BrokerSeat {
continue
}
for _, e := range s.Emits {
if safeSubject.MatchString(e) {
out = append(out, seatSubject(s, "event", e))
}
}
}
return out
}
@@ -114,6 +114,10 @@ type Principal struct {
// §4, §5), and KeepsBusState are the streams it defines, every module's bus state by its name.
KeepsBus bool
KeepsBusState []string
// SaysSeatEvents are the subjects of the seat mesh-broker's events the bus module's keeper says them on (the lead's
// ruling, registry milestone 13:0x): `mesh.seat.mesh-broker.event.<event>` for each event the seat's definition
// names, as a holder's own account would be granted them; set on the keeper alone.
SaysSeatEvents []string
// Process is the process resource's id, for a KindProcess principal alone (novox/hq ADR 0436 §2):
// Username and inbox are <node>.<module>.<process id>.
Process string
@@ -61,6 +61,7 @@ func processGrants(p Principal) (pub, sub []string, err error) {
pub = append(pub, keeperConsumerGrants(c)...)
}
pub = append(pub, ownStreamGrants(p.Module, p.Streams)...)
pub = append(pub, p.SaysSeatEvents...)
tp, ts := seatTrafficGrants(SeatTrafficOf(p.Module, nil, p.Uses, nil))
pub, sub = append(pub, tp...), append(sub, ts...)
}
@@ -249,6 +249,7 @@ func Users(r Records) ([]Principal, error) {
k := &out[len(out)-1]
k.KeepsBus, k.KeepsBusState = true, BusStateNames(r.BusState, r.Bound)
k.Consumes, k.Streams = d.Consumes, d.Streams
k.SaysSeatEvents = brokerSeatEvents(d.Holds)
}
if d.SnapshotsTheBus && len(pr.Removes) > 0 {
out[len(out)-1].Streams = d.Streams