A-386 runner-left-out-is-kept-and-carried: a tool runner of the list in force that the pass composes no account for is kept as it runs and written as a carrying runner
Builds: design 47 G A-386 (G-22-lead-answers-2.md) Claude-Session: https://claude.ai/code/session_01NcbgfGKaxw984XyAPfLm4h
This commit is contained in:
@@ -5666,3 +5666,76 @@ func TestAKeptRunnerCarriesAModuleKnownOnlyByItsBindings(t *testing.T) {
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// A-386 live: a runner account left out for want of a manifest (the node's runner is another module's) is written as the union of the list in
|
||||
// force and a carrying runner's grants.
|
||||
func TestARunnerLeftOutForWantOfAManifestIsComposedAsACarryingRunner(t *testing.T) {
|
||||
const runner = `{"module":"node-tools","version":"1","tool-runner":true,"own-secrets":{"broker":"/var/lib/nt/broker"}}`
|
||||
b := fixture()
|
||||
b.manifestOf("node-tools", runner)
|
||||
b.assign("a", "node-tools")
|
||||
b.assign("a", "mod-c")
|
||||
busKey, err := seal.GenerateKeyPair()
|
||||
if err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
b.put(grants.ReadHave, "a.nats", nodeengine.HaveByNodeModuleValue{V: keys.Version, Phase: nodeengineclient.PhaseRunning, Health: nodeengineclient.HealthOK,
|
||||
UserList: &nodeengine.UserListWritten{Source: grantsstate.GrantsUserListSource, Revision: 8, Wanted: "sha256:aa", Digest: "sha256:aa", Users: 5,
|
||||
Key: busKey.PublicKey, Follows: grantsstate.FollowGrants}})
|
||||
for _, u := range shadowOf(t, b) {
|
||||
b.put(grants.ReadAccounts, u.User, map[string]any{"user": u.User, "hash": "$2a$10$x", "generation": 1, "fingerprint": "sha256:1"})
|
||||
}
|
||||
p := partOn(b)
|
||||
p.Bus = grants.BusAddress{URL: "nats://a.mesh:4222", Fingerprint: "ab"}
|
||||
p.Objects = &fakeObjects{}
|
||||
binding := membership.BusBinding{Local: "records", Storage: "ledger", Template: "ledger", Stream: "mod-c_records", History: "mod-c_records",
|
||||
Subject: "mesh.ledger.mod-c.records.history", State: "mod-c_records_state", Snapshot: "mesh.ledger.mod-c.records.snapshot"}
|
||||
p.Compose() // the pass that learns the bus module is the broker
|
||||
body, _ := json.Marshal(grants.BrokerEvent{V: 1, Module: "mod-c", Local: "records", Storage: "ledger", Template: "ledger", Binding: binding})
|
||||
if _, err := p.HearBroker("mesh.seat.mesh-broker.event.created", body, p.Brokers()); err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
p.Compose()
|
||||
first, _, _ := p.Sealed()
|
||||
key := grants.SealedUserKey(first.Digest, "a.node-tools")
|
||||
var was grants.User
|
||||
if err := json.Unmarshal(b.own[grants.StateUserList][key], &was); err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
isLedger := func(s string) bool { return strings.Contains(s, "mod-c_records") }
|
||||
was.Publish = append(slices.DeleteFunc(slices.Clone(was.Publish), isLedger), "mesh.control.a.tools-alive")
|
||||
b.own[grants.StateUserList][key], _ = json.Marshal(was)
|
||||
// Its manifest is gone, and another module placed on a says it is the tool runner: no kept runner by what runs, and the account
|
||||
// of the list in force has no principal of the pass's.
|
||||
delete(b.states[grants.ReadModules], "node-tools")
|
||||
b.manifestOf("other-runner", strings.Replace(runner, "node-tools", "other-runner", 1))
|
||||
b.assign("a", "other-runner")
|
||||
b.assign("b", "mod-x")
|
||||
p.Compose()
|
||||
sealed, _, _ := p.Sealed()
|
||||
if sealed.Digest == first.Digest {
|
||||
t.Fatal("the list did not change")
|
||||
}
|
||||
var got grants.User
|
||||
if err := json.Unmarshal(b.own[grants.StateUserList][grants.SealedUserKey(sealed.Digest, "a.node-tools")], &got); err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
for _, want := range []string{
|
||||
"$JS.API.STREAM.INFO.KV_mod-c_records_state", "$JS.API.DIRECT.GET.KV_mod-c_records_state.>", "$KV.mod-c_records_state.>",
|
||||
"$JS.API.CONSUMER.CREATE.KV_mod-c_records_state.>", "$JS.API.DIRECT.GET.mod-c_records.>", "$JS.API.CONSUMER.CREATE.mod-c_records.>",
|
||||
"$JS.API.DIRECT.GET.mod-c_records_snapshot.>"} {
|
||||
if !slices.Contains(got.Publish, want) {
|
||||
t.Errorf("the runner of a lacks %s", want)
|
||||
}
|
||||
}
|
||||
for _, s := range was.Publish {
|
||||
if !slices.Contains(got.Publish, s) {
|
||||
t.Errorf("the kept runner lost %s", s)
|
||||
}
|
||||
}
|
||||
for _, no := range []string{"mesh.ledger.mod-c.records.history.>", "mesh.ledger.mod-c.records.snapshot.>"} {
|
||||
if slices.Contains(got.Publish, no) {
|
||||
t.Errorf("the runner may publish on the ledger's %s", no)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -153,3 +153,20 @@ func (p *Part) sayHeldModules(held map[string]string, kept map[string]User) {
|
||||
p.heldModulesSaid, p.heldModulesKnown = why, true
|
||||
}
|
||||
}
|
||||
|
||||
// runnersOutOfTheList are, by user, why it is kept: a user of the list in force that is a tool runner (it says its node's runner is alive,
|
||||
// buscompose.ToolsAliveSubject) and that the pass composed no account for. Pure.
|
||||
func runnersOutOfTheList(inForce map[string]User, composed []User, already map[string]string) map[string]string {
|
||||
out := map[string]string{}
|
||||
for user, u := range inForce {
|
||||
node, _, cut := strings.Cut(user, ".")
|
||||
if !cut || !slices.Contains(u.Publish, buscompose.ToolsAliveSubject(node)) {
|
||||
continue
|
||||
}
|
||||
if _, kept := already[user]; kept || slices.ContainsFunc(composed, func(c User) bool { return c.User == user }) {
|
||||
continue
|
||||
}
|
||||
out[user] = fmt.Sprintf("the pass composes no account for the tool runner of %s (its manifest is not readable), so it keeps what it runs", node)
|
||||
}
|
||||
return out
|
||||
}
|
||||
|
||||
@@ -370,6 +370,11 @@ func (p *Part) Compose() Result {
|
||||
}
|
||||
heldUsers := heldModuleUsers(in, candidates)
|
||||
runnersKept := runnerUsersKept(listRecs, inForce)
|
||||
// And a runner of the list in force that the pass composes no principal for, whatever the reason (its manifest is unreadable and another
|
||||
// module placed on its node says it is the runner): kept as it runs, and written as a carrying runner (design 47 G A-386).
|
||||
for user, why := range runnersOutOfTheList(inForce, users, runnersKept) {
|
||||
runnersKept[user] = why
|
||||
}
|
||||
for user, why := range runnersKept {
|
||||
heldUsers[user] = why
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user