H-A-335: a held module's share of a holder's words is what runs
The reads runtime on ace restarted twice in two minutes because its MESH_SECRET_PLACES changed: the holders of node-reads and node-files were told the node's secret places and owned paths from held modules' stubs, which differ pass by pass while a part is withheld. While a module is held, the resolution now takes its share from each runtime process as it runs: the secret places are those the modules not held compose merged with every place that runs, and the owned paths keep each running entry a held module owns. Two passes with the same held set compose every runtime process the same; a module that answered and changed is still composed from its build. Builds: design 47 H H-A-335, H-A-337, H-A-306 (2), (3)
This commit is contained in:
@@ -22,6 +22,7 @@ func fpFor(c byte) string { return meshcatalogclient.SourcePrefix2 + strings.Rep
|
||||
// it; a module given no fingerprint is named as skipped and composed nowhere.
|
||||
func TestCompositionsAreTheDeclarationSplitByModule(t *testing.T) {
|
||||
t.Run("a held tool runner keeps its program for the modules of their own account", aHeldToolRunnerKeepsItsProgramForTheModulesOfTheirOwnAccount)
|
||||
t.Run("a held module's share of the holders' words is what runs", aHeldModulesShareOfTheHoldersWordsIsWhatRuns)
|
||||
in := aSmallMesh(t)
|
||||
d, _, err := Compose(in, "laptop")
|
||||
if err != nil {
|
||||
@@ -292,3 +293,128 @@ func aHeldToolRunnerKeepsItsProgramForTheModulesOfTheirOwnAccount(t *testing.T)
|
||||
t.Errorf("mesh-self-check is not run by the program node-tools runs: %v", out)
|
||||
}
|
||||
}
|
||||
|
||||
// H-A-335, H-A-337, H-A-306: the holder of node-reads (a runtime of its own) and the holder of node-files (in the tool
|
||||
// runner's) are told the node's secret places and owned paths, to which every module gives a share. While a module is
|
||||
// held its share is what runs, never its stub's, so two passes with the same held set compose both runtimes the same
|
||||
// whatever its stub says (ace, 2026-11-21 21:54: the reads runtime restarted twice in two minutes for MESH_SECRET_PLACES);
|
||||
// a module that answered and changed is composed from its build.
|
||||
func aHeldModulesShareOfTheHoldersWordsIsWhatRuns(t *testing.T) {
|
||||
dg := func(c byte) string { return "sha256:" + strings.Repeat(string(c), 64) }
|
||||
runtime := catalogue.Manifest{Module: "node-tools", Version: "1", ToolRunner: true,
|
||||
OwnSecrets: catalogue.OwnSecrets{"broker": {Path: "/var/lib/mesh/node-tools/broker"}},
|
||||
Bundles: []catalogue.Bundle{{Name: "runtime", Source: catalogue.ArtifactStoreScheme + "node-tools/runtime/blobs/" + dg('a'),
|
||||
Digest: dg('a'), Language: "go", Binary: "node-tools"}}}
|
||||
tools := func(module string) []catalogue.Bundle {
|
||||
return []catalogue.Bundle{{Name: "tools", Source: catalogue.ArtifactStoreScheme + module + "/tools/blobs/" + dg('d'),
|
||||
Digest: dg('d'), Language: "go", Loads: []string{module + "-tools"}}}
|
||||
}
|
||||
reads := catalogue.Manifest{Module: "mesh-reads", Version: "1", RunsAs: "mesh-reads", SecretsOwner: "mesh-reads",
|
||||
Claims: []catalogue.Claim{{Name: catalogue.ReadsSeat}},
|
||||
OwnSecrets: catalogue.OwnSecrets{"broker": {Path: "/var/lib/mesh-reads/broker", Taken: catalogue.TakenAtStart}},
|
||||
Bundles: tools("mesh-reads")}
|
||||
files := catalogue.Manifest{Module: "files", Version: "1", Claims: []catalogue.Claim{{Name: catalogue.FilesSeat}},
|
||||
Bundles: tools("files")}
|
||||
store := catalogue.Manifest{Module: "artifacts", Version: "1",
|
||||
Claims: []catalogue.Claim{{Name: "container-image-registry", Scope: catalogue.ScopeMesh}},
|
||||
Listens: []catalogue.Listening{{Name: "registry", Port: 5100, From: catalogue.FromMesh}}}
|
||||
// lamp as it ran (its secret under /var/lib/lamp/old, its state at /var/lib/lamp-old), and its new build.
|
||||
lampAt := func(secret, state string) catalogue.Manifest {
|
||||
return catalogue.Manifest{Module: "lamp", Version: "1",
|
||||
OwnSecrets: catalogue.OwnSecrets{"token": {Path: secret}},
|
||||
Resources: []map[string]any{{"id": "state", "type": "directory", "path": state, "mode": "0700"}}}
|
||||
}
|
||||
oldLamp, newLamp := lampAt("/var/lib/lamp/old/token", "/var/lib/lamp-old"), lampAt("/var/lib/lamp/new/token", "/var/lib/lamp-new")
|
||||
ranPlaces := `["/var/lib/lamp/old","/var/lib/mesh-reads","/var/lib/mesh/node-tools"]`
|
||||
ranOwned := `{"/var/lib/lamp-old":"lamp (its own tools)"}`
|
||||
process := func(id, module string, words map[string]map[string]string) json.RawMessage {
|
||||
body, _ := json.Marshal(words)
|
||||
env, _ := json.Marshal(map[string]string{catalogue.RuntimeToolEnv: string(body)})
|
||||
return json.RawMessage(`{"id":"` + id + `","module":"` + module + `","type":"process","env":` + string(env) + `}`)
|
||||
}
|
||||
ran := []engcomp.Composed{
|
||||
{Node: "anchor", Module: "node-tools", Resources: []json.RawMessage{process("node-tools.runtime", "node-tools",
|
||||
map[string]map[string]string{"files": {catalogue.ReadsSecretPlaces: ranPlaces, catalogue.FilesOwnedPaths: ranOwned}})}},
|
||||
{Node: "anchor", Module: "mesh-reads", Resources: []json.RawMessage{process("mesh-reads."+catalogue.OwnRuntimeID(), "mesh-reads",
|
||||
map[string]map[string]string{"mesh-reads": {catalogue.ReadsSecretPlaces: ranPlaces}})}},
|
||||
}
|
||||
for _, row := range []struct {
|
||||
name string
|
||||
held bool
|
||||
// The stub lamp is held as at each of two passes: what a withheld part gives it differs pass by pass.
|
||||
stubs []catalogue.Manifest
|
||||
// What lamp gives of the places and owned paths, and what it no longer gives.
|
||||
wantPlace, gonePlace, wantOwned, goneOwned string
|
||||
}{
|
||||
{"held, its stub differing pass by pass", true, []catalogue.Manifest{Stub(newLamp), Stub(catalogue.Manifest{Module: "lamp", Version: "1"})},
|
||||
"/var/lib/lamp/old", "/var/lib/lamp/new", "/var/lib/lamp-old", "/var/lib/lamp-new"},
|
||||
{"answered, its build changed", false, []catalogue.Manifest{newLamp, newLamp},
|
||||
"/var/lib/lamp/new", "/var/lib/lamp/old", "/var/lib/lamp-new", "/var/lib/lamp-old"},
|
||||
} {
|
||||
in := aMesh(t)
|
||||
in.Catalogue["node-tools"], in.Catalogue["artifacts"], in.Catalogue["mesh-reads"] = runtime, store, reads
|
||||
in.Catalogue["files"], in.Catalogue["lamp"] = files, oldLamp
|
||||
anchor := nodeOf(t, &in, "anchor")
|
||||
anchor.Assigned = append(anchor.Assigned, "artifacts", "node-tools", "mesh-reads", "files", "lamp")
|
||||
in.BusMinted = []string{"anchor.node-tools", "anchor.mesh-reads"}
|
||||
anchor.SealingKey = keyOf(t, "anchor")
|
||||
if row.held {
|
||||
anchor.Held = map[string]bool{"lamp": true}
|
||||
}
|
||||
anchor.RunsRuntime, anchor.RunsRuntimes = RuntimeRunning(ran), RuntimesRunning(ran)
|
||||
fps := map[string]string{overlay.Name: fpFor('a'), "artifacts": fpFor('5'), "node-tools": fpFor('e'),
|
||||
"mesh-reads": fpFor('6'), "files": fpFor('7'), "lamp": fpFor('8')}
|
||||
digests := map[string][]string{}
|
||||
said := map[string]string{}
|
||||
for _, stub := range row.stubs {
|
||||
anchor.Kept = map[string]catalogue.Manifest{"lamp": stub}
|
||||
out, _, _, err := CompositionsIn(in, "anchor", fps, Foreseeing)
|
||||
if err != nil {
|
||||
t.Fatalf("%s: %v", row.name, err)
|
||||
}
|
||||
for _, c := range out {
|
||||
for _, raw := range c.Resources {
|
||||
var r struct {
|
||||
ID string `json:"id"`
|
||||
Env map[string]string `json:"env"`
|
||||
}
|
||||
if json.Unmarshal(raw, &r) != nil {
|
||||
continue
|
||||
}
|
||||
holder := map[string]string{"node-tools.runtime": "files", "mesh-reads." + catalogue.OwnRuntimeID(): "mesh-reads"}[r.ID]
|
||||
if holder == "" {
|
||||
continue
|
||||
}
|
||||
dig, err := engcomp.DigestOf(c)
|
||||
if err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
digests[r.ID] = append(digests[r.ID], dig)
|
||||
var words map[string]map[string]string
|
||||
_ = json.Unmarshal([]byte(r.Env[catalogue.RuntimeToolEnv]), &words)
|
||||
said[r.ID+" places"] = words[holder][catalogue.ReadsSecretPlaces]
|
||||
if holder == "files" {
|
||||
said[r.ID+" owned"] = words[holder][catalogue.FilesOwnedPaths]
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
for _, id := range []string{"node-tools.runtime", "mesh-reads." + catalogue.OwnRuntimeID()} {
|
||||
if d := digests[id]; len(d) != 2 || d[0] != d[1] {
|
||||
t.Errorf("%s: two passes composed %s at %v", row.name, id, d)
|
||||
}
|
||||
}
|
||||
for what, words := range said {
|
||||
want, gone := row.wantPlace, row.gonePlace
|
||||
if strings.HasSuffix(what, " owned") {
|
||||
want, gone = row.wantOwned, row.goneOwned
|
||||
}
|
||||
if !strings.Contains(words, `"`+want+`"`) || strings.Contains(words, `"`+gone+`"`) {
|
||||
t.Errorf("%s: %s are %s, want %s among them and not %s", row.name, what, words, want, gone)
|
||||
}
|
||||
}
|
||||
if len(said) != 3 {
|
||||
t.Errorf("%s: the holders are told %v", row.name, said)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user