Merge pull request 'A held module's share of the holders' merged words comes from what runs (H-A-335, H-A-337)' (#245) from fix/47-H1-engine-held-slices into main
This commit was merged in pull request #245.
This commit is contained in:
@@ -457,6 +457,39 @@ func RuntimeRunning(running []engcomp.Composed) map[string]string {
|
||||
return nil
|
||||
}
|
||||
|
||||
// RuntimesRunning is the environment of each runtime process as the node runs it, by its id: the tool runner's
|
||||
// (`<its module>.runtime`) and each runtime of a module of its own account (`<module>.own-runtime`), or nil when running
|
||||
// holds none (Node.RunsRuntimes).
|
||||
func RuntimesRunning(running []engcomp.Composed) map[string]map[string]string {
|
||||
var out map[string]map[string]string
|
||||
for _, c := range running {
|
||||
for _, raw := range c.Resources {
|
||||
var r struct {
|
||||
ID string `json:"id"`
|
||||
Module string `json:"module"`
|
||||
Type string `json:"type"`
|
||||
Env map[string]string `json:"env"`
|
||||
}
|
||||
if json.Unmarshal(raw, &r) != nil || r.Env == nil {
|
||||
continue
|
||||
}
|
||||
owner := r.Module
|
||||
if owner == "" {
|
||||
owner, _ = declaration.ModuleGuess(r.ID)
|
||||
}
|
||||
if runtimeOwner(r.ID, r.Module, r.Type) == "" && (r.Type != "process" || owner == "" ||
|
||||
r.ID != owner+"."+catalogue.OwnRuntimeID()) {
|
||||
continue
|
||||
}
|
||||
if out == nil {
|
||||
out = map[string]map[string]string{}
|
||||
}
|
||||
out[r.ID] = r.Env
|
||||
}
|
||||
}
|
||||
return out
|
||||
}
|
||||
|
||||
// runtimeOwner is the module of the tool runner's process a resource is (`<its module>.runtime`), or "" when it is none.
|
||||
func runtimeOwner(id, module, kind string) string {
|
||||
if kind != "process" {
|
||||
|
||||
@@ -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,149 @@ 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"]`
|
||||
// The resolver, held, and the uplink: by the rules between modules the resolver's file is the resolver's (it steps
|
||||
// back for node-resolver here), the uplink's only without the resolver (the review of 94a2e6ed).
|
||||
resolver := catalogue.Manifest{Module: "resolver", Version: "1", Claims: []catalogue.Claim{{Name: catalogue.ResolverSeat}},
|
||||
Resources: []map[string]any{{"id": "stub", "type": "file", "path": catalogue.ResolverFile, "content": "nameserver 127.0.0.53\n"}}}
|
||||
uplink := catalogue.Manifest{Module: "uplink", Version: "1", Claims: []catalogue.Claim{{Name: "node-uplink"}},
|
||||
Resources: []map[string]any{{"id": "resolv", "type": "file", "path": catalogue.ResolverFile, "content": "nameserver 192.0.2.1\n"}}}
|
||||
resolverOwns := `"` + catalogue.ResolverFile + `":"resolver (` + catalogue.ResolverSeat + `)"`
|
||||
ranOwned := `{"/var/lib/lamp-old":"lamp (its own tools)",` + resolverOwns + `}`
|
||||
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
|
||||
resolvers bool // the resolver held and the uplink beside lamp
|
||||
}{
|
||||
{"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", false},
|
||||
{"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", false},
|
||||
{"held, a path another module owns only without it", true, []catalogue.Manifest{Stub(newLamp), Stub(newLamp)},
|
||||
"/var/lib/lamp/old", "/var/lib/lamp/new", "/var/lib/lamp-old", "/var/lib/lamp-new", true},
|
||||
} {
|
||||
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}
|
||||
}
|
||||
if row.resolvers {
|
||||
in.Catalogue["resolver"], in.Catalogue["uplink"] = resolver, uplink
|
||||
anchor.Assigned = append(anchor.Assigned, "resolver", "uplink")
|
||||
anchor.Held["resolver"] = 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'), "resolver": fpFor('9'), "uplink": fpFor('b')}
|
||||
digests := map[string][]string{}
|
||||
said := map[string]string{}
|
||||
for _, stub := range row.stubs {
|
||||
anchor.Kept = map[string]catalogue.Manifest{"lamp": stub}
|
||||
if row.resolvers {
|
||||
anchor.Kept["resolver"] = Stub(resolver)
|
||||
}
|
||||
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 owned := said["node-tools.runtime owned"]; row.resolvers && !strings.Contains(owned, resolverOwns) {
|
||||
t.Errorf("%s: the owned paths are %s, want %s among them", row.name, owned, resolverOwns)
|
||||
}
|
||||
if len(said) != 3 {
|
||||
t.Errorf("%s: the holders are told %v", row.name, said)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -477,6 +477,8 @@ func readBase(ctx context.Context, r Reader, mesh Mesh, s Scope) (base, error) {
|
||||
n.RunsTools = compose.ToolsRunning(s.Running)
|
||||
// And the runtime's process as it runs, whose slice of each held module is kept verbatim (H-A-306).
|
||||
n.RunsRuntime = compose.RuntimeRunning(s.Running)
|
||||
// And every runtime process as it runs, whose words give each held module's share of a holder's (H-A-335).
|
||||
n.RunsRuntimes = compose.RuntimesRunning(s.Running)
|
||||
for _, module := range s.InOwn {
|
||||
if n.InOwn == nil {
|
||||
n.InOwn = map[string]bool{}
|
||||
|
||||
@@ -278,6 +278,11 @@ type Node struct {
|
||||
// in catalogue.RuntimeToolEnv, its fingerprint among them) is copied from it verbatim, so a pass that holds a module
|
||||
// for a part withheld composes the runtime as it runs (design 47 H, H-A-303, H-A-306).
|
||||
RunsRuntime map[string]string
|
||||
// RunsRuntimes is the environment of each runtime process as it runs, by its id (RuntimesRunning of what the node
|
||||
// runs): the tool runner's (`<module>.runtime`) and each runtime of a module of its own account
|
||||
// (`<module>.own-runtime`); nil when none runs. A held module's share of a holder's words that every module gives a
|
||||
// share of (the secret places, the owned paths) is taken from them (resolution.Holding; design 47 H, H-A-335, H-A-337).
|
||||
RunsRuntimes map[string]map[string]string
|
||||
}
|
||||
|
||||
// ComposedHow is how a node-engine composes its node from an Input (Input.ComposedHow).
|
||||
|
||||
@@ -176,10 +176,10 @@ func ComposeIn(in Input, node string, mode Mode) (Declared, []string, error) {
|
||||
// none (resolution.NoStoreError, whatever the shape: an image, a source, a tools bundle, a runtime program, a templates
|
||||
// archive) is left out of the declaration with its words and the rest composes again; the node is never refused whole for it
|
||||
// (design 47 G A-461, A-452). The rendering returned carries the modules so left out, for the filter and the rest to read.
|
||||
func composeWithoutStoreFetchers(plan catalogue.Resolution, with catalogue.Rendering) (catalogue.Composed, catalogue.Rendering, map[string]string, error) {
|
||||
func composeWithoutStoreFetchers(plan catalogue.Resolution, with catalogue.Rendering, holding resolution.Holding) (catalogue.Composed, catalogue.Rendering, map[string]string, error) {
|
||||
var held map[string]string
|
||||
for {
|
||||
composed, err := resolution.Compose(plan, with)
|
||||
composed, err := resolution.ComposeHolding(plan, with, holding)
|
||||
var none *resolution.NoStoreError
|
||||
if !errors.As(err, &none) {
|
||||
return composed, with, held, err
|
||||
@@ -217,7 +217,13 @@ func (c *composer) declaration(nodeName string, mode Mode) (Declared, error) {
|
||||
with := rendered.Rendering
|
||||
with.Generators = gens
|
||||
plan := resolved.Plan
|
||||
composed, with, storeHeld, err := composeWithoutStoreFetchers(plan, with)
|
||||
node, err := c.in.node(nodeName)
|
||||
if err != nil {
|
||||
return Declared{}, err
|
||||
}
|
||||
// A held module's share of a holder's words is what runs of each runtime process (design 47 H, H-A-335, H-A-337).
|
||||
holding := resolution.Holding{Held: node.Held, Runs: node.RunsRuntimes}
|
||||
composed, with, storeHeld, err := composeWithoutStoreFetchers(plan, with, holding)
|
||||
if err != nil {
|
||||
return Declared{}, err
|
||||
}
|
||||
@@ -227,10 +233,6 @@ func (c *composer) declaration(nodeName string, mode Mode) (Declared, error) {
|
||||
if err != nil {
|
||||
return Declared{}, err
|
||||
}
|
||||
node, err := c.in.node(nodeName)
|
||||
if err != nil {
|
||||
return Declared{}, err
|
||||
}
|
||||
// A module that fetches from a store no node reaches is held with its words, as a module whose claim cannot be held is: it
|
||||
// stays on the build it runs, its composition kept (A-452, A-461).
|
||||
held := resolved.Held
|
||||
|
||||
@@ -105,12 +105,18 @@ func (e *UnreadManifestError) Error() string { return e.said }
|
||||
|
||||
// Compose is Declaration with the owner of every resource said.
|
||||
func Compose(r mcat.Resolution, with mcat.Rendering) (mcat.Composed, error) {
|
||||
return ComposeHolding(r, with, Holding{})
|
||||
}
|
||||
|
||||
// ComposeHolding is Compose for a node that holds modules this pass (Holding): a held module's share of a holder's words
|
||||
// is what runs (design 47 H, H-A-335, H-A-337).
|
||||
func ComposeHolding(r mcat.Resolution, with mcat.Rendering, h Holding) (mcat.Composed, error) {
|
||||
owner := map[string]string{}
|
||||
received := map[string]map[string][]mcat.Contribution{}
|
||||
leftOut := map[string]string{}
|
||||
var foreseen, unplaced, handedOnly []string
|
||||
handed := &handedFiles{plans: map[string]mcat.Plan{}}
|
||||
resources, err := resolutionCompose(r, with, owner, received, leftOut, &foreseen, &unplaced, &handedOnly, handed)
|
||||
resources, err := resolutionCompose(r, with, h, owner, received, leftOut, &foreseen, &unplaced, &handedOnly, handed)
|
||||
if err != nil {
|
||||
return mcat.Composed{}, err
|
||||
}
|
||||
@@ -137,7 +143,7 @@ func Compose(r mcat.Resolution, with mcat.Rendering) (mcat.Composed, error) {
|
||||
// BusMembershipPath is where the host reads it — the same constant on both sides.
|
||||
func BusMembershipID() string { return "bus-membership" }
|
||||
|
||||
func resolutionCompose(r mcat.Resolution, with mcat.Rendering, owner map[string]string,
|
||||
func resolutionCompose(r mcat.Resolution, with mcat.Rendering, h Holding, owner map[string]string,
|
||||
received map[string]map[string][]mcat.Contribution, leftOut map[string]string,
|
||||
foreseen, unplaced, handedOnly *[]string, handed *handedFiles) ([]map[string]any, error) {
|
||||
// **A setting is judged where it is stored, and an impossible one costs a module, not a
|
||||
@@ -1065,7 +1071,7 @@ func resolutionCompose(r mcat.Resolution, with mcat.Rendering, owner map[string]
|
||||
// bundle delivered above and holding the credential sealed above, so both exist before it starts
|
||||
// — the order written here is the order the machine applies.
|
||||
if resolutionRuntimeHere(r) {
|
||||
process, err := resolutionRuntimeProcess(r, with)
|
||||
process, err := resolutionRuntimeProcess(r, with, h)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
@@ -1074,7 +1080,7 @@ func resolutionCompose(r mcat.Resolution, with mcat.Rendering, owner map[string]
|
||||
out = append(out, process)
|
||||
}
|
||||
// And a runtime of its own for each module of its own account, after it (novox/hq ADR 0259 §8).
|
||||
owns, err := resolutionOwnRuntimes(r, with)
|
||||
owns, err := resolutionOwnRuntimes(r, with, h)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
|
||||
@@ -52,12 +52,14 @@ func resolutionStepsBackHere(r mcat.Resolution, m mcat.Manifest, sp mcat.SeatPat
|
||||
}
|
||||
|
||||
// filesWords is what the holder of node-files is given beside its own words: the node's secret places and the
|
||||
// paths modules own here.
|
||||
func resolutionFilesWords(r mcat.Resolution, m mcat.Manifest, words map[string]string, with mcat.Rendering) (map[string]string, error) {
|
||||
// paths modules own here. A held module's share of each is what runs of the process (the id process) that serves m
|
||||
// (Holding, resolutionSecretPlaces, heldOwnedPaths).
|
||||
func resolutionFilesWords(r mcat.Resolution, m mcat.Manifest, words map[string]string, with mcat.Rendering, h Holding, process string) (map[string]string, error) {
|
||||
if !m.ClaimsSeat(mcat.FilesSeat) {
|
||||
return words, nil
|
||||
}
|
||||
places, err := resolutionSecretPlaces(r, with)
|
||||
ran := h.ran(process, m.Module)
|
||||
places, err := resolutionSecretPlaces(r, with, h.Held, ran)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
@@ -65,7 +67,7 @@ func resolutionFilesWords(r mcat.Resolution, m mcat.Manifest, words map[string]s
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
owned, err := json.Marshal(resolutionOwnedPaths(r))
|
||||
owned, err := json.Marshal(heldOwnedPaths(r, h.Held, ran))
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
@@ -82,3 +84,27 @@ func resolutionFilesWords(r mcat.Resolution, m mcat.Manifest, words map[string]s
|
||||
words[mcat.FilesOwnedPaths] = string(owned)
|
||||
return words, nil
|
||||
}
|
||||
|
||||
// heldOwnedPaths is ownedPaths with a held module's entries as they run (design 47 H, H-A-335, H-A-337): while any module
|
||||
// is held and the holder's words as it runs (ran) say the owned paths, ownedPaths over the whole resolution, so the rules
|
||||
// between modules (a seat path over a module's own tools, a seat path stepping back) read every module as before, less
|
||||
// each entry a held module owns, and each running entry whose owner is a held module where no entry left names its path
|
||||
// (a module that answered applies, H-A-306 (3)). Else ownedPaths.
|
||||
func heldOwnedPaths(r mcat.Resolution, held map[string]bool, ran map[string]string) map[string]string {
|
||||
owned := resolutionOwnedPaths(r)
|
||||
var running map[string]string
|
||||
if body, says := ran[mcat.FilesOwnedPaths]; !says || json.Unmarshal([]byte(body), &running) != nil {
|
||||
return owned
|
||||
}
|
||||
for p, entry := range owned {
|
||||
if held[ownerOf(entry)] {
|
||||
delete(owned, p)
|
||||
}
|
||||
}
|
||||
for p, entry := range running {
|
||||
if _, composed := owned[p]; !composed && held[ownerOf(entry)] {
|
||||
owned[p] = entry
|
||||
}
|
||||
}
|
||||
return owned
|
||||
}
|
||||
|
||||
@@ -18,7 +18,7 @@ func TestTheHolderOfNodeFilesIsToldSecretPlacesAndOwnedPaths(t *testing.T) {
|
||||
app := mcat.Manifest{Module: "app", Version: "1",
|
||||
Resources: []map[string]any{{"id": "conf", "type": "file", "path": "/etc/app/app.conf"}}}
|
||||
r := mcat.Resolution{Node: "anchor", Modules: []mcat.Manifest{files, host, app}}
|
||||
words, err := resolutionFilesWords(r, files, nil, mcat.Rendering{})
|
||||
words, err := resolutionFilesWords(r, files, nil, mcat.Rendering{}, Holding{}, "")
|
||||
if err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
@@ -51,7 +51,7 @@ func TestTheHolderOfNodeFilesIsToldSecretPlacesAndOwnedPaths(t *testing.T) {
|
||||
mcat.UseSeats(reversed)
|
||||
}
|
||||
both := mcat.Resolution{Node: "anchor", Modules: []mcat.Manifest{files, uplink, resolver}}
|
||||
w, err := resolutionFilesWords(both, files, nil, mcat.Rendering{})
|
||||
w, err := resolutionFilesWords(both, files, nil, mcat.Rendering{}, Holding{}, "")
|
||||
if err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
@@ -65,12 +65,12 @@ func TestTheHolderOfNodeFilesIsToldSecretPlacesAndOwnedPaths(t *testing.T) {
|
||||
// the controller tells them, and not the paths its running resources are at (a directory the mesh placed).
|
||||
carried := mcat.Manifest{Module: "de-spiegel", Version: "1", OwnsPaths: []string{"/var/lib/de-spiegel/server.env"},
|
||||
Resources: []map[string]any{{"id": "state", "type": "directory", "path": "/var/lib/de-spiegel"}}}
|
||||
w, err := resolutionFilesWords(mcat.Resolution{Node: "anchor", Modules: []mcat.Manifest{files, carried}}, files, nil, mcat.Rendering{})
|
||||
w, err := resolutionFilesWords(mcat.Resolution{Node: "anchor", Modules: []mcat.Manifest{files, carried}}, files, nil, mcat.Rendering{}, Holding{}, "")
|
||||
if err != nil || !strings.Contains(w[mcat.FilesOwnedPaths], `"/var/lib/de-spiegel/server.env":"de-spiegel (its own tools)"`) ||
|
||||
strings.Contains(w[mcat.FilesOwnedPaths], `"/var/lib/de-spiegel":`) {
|
||||
t.Errorf("a carried module does not own its manifest's paths alone: %v %v", w[mcat.FilesOwnedPaths], err)
|
||||
}
|
||||
if w, _ := resolutionFilesWords(r, app, nil, mcat.Rendering{}); w[mcat.FilesOwnedPaths] != "" {
|
||||
if w, _ := resolutionFilesWords(r, app, nil, mcat.Rendering{}, Holding{}, ""); w[mcat.FilesOwnedPaths] != "" {
|
||||
t.Error("a module not holding node-files is told the owned paths")
|
||||
}
|
||||
}
|
||||
|
||||
@@ -0,0 +1,59 @@
|
||||
package resolution
|
||||
|
||||
import (
|
||||
"encoding/json"
|
||||
"strings"
|
||||
|
||||
mcat "git.novox.be/novox/mesh-sdk/go/catalogue"
|
||||
)
|
||||
|
||||
// Holding is what a node holds while it composes itself (design 47 H, H-A-306, H-A-335, H-A-337): the modules held this
|
||||
// pass, each composed as its stub, and each runtime process as it runs. A holder's words that every module gives a share
|
||||
// of (the secret places, the owned paths) take a held module's share from what runs, never from its stub, so two passes
|
||||
// with the same held set compose every runtime process the same. The zero Holding holds nothing: everything is composed
|
||||
// from the manifests, as before.
|
||||
type Holding struct {
|
||||
// Held is each module held on this node this pass (compose.Node.Held).
|
||||
Held map[string]bool
|
||||
// Runs is the environment of each runtime process as it runs, by its id: the tool runner's (`<module>.runtime`) and
|
||||
// each runtime of a module of its own account (`<module>.own-runtime`).
|
||||
Runs map[string]map[string]string
|
||||
}
|
||||
|
||||
// ran is module's words in process's mcat.RuntimeToolEnv as it runs, or nil when nothing is held, the process does not
|
||||
// run, or it gives module no words.
|
||||
func (h Holding) ran(process, module string) map[string]string {
|
||||
if len(h.Held) == 0 {
|
||||
return nil
|
||||
}
|
||||
env, runs := h.Runs[process]
|
||||
if !runs {
|
||||
return nil
|
||||
}
|
||||
var words map[string]map[string]string
|
||||
if json.Unmarshal([]byte(env[mcat.RuntimeToolEnv]), &words) != nil {
|
||||
return nil
|
||||
}
|
||||
return words[module]
|
||||
}
|
||||
|
||||
// notHeld is r with only the modules not in held, or r itself when none is held.
|
||||
func notHeld(r mcat.Resolution, held map[string]bool) mcat.Resolution {
|
||||
if len(held) == 0 {
|
||||
return r
|
||||
}
|
||||
modules := make([]mcat.Manifest, 0, len(r.Modules))
|
||||
for _, m := range r.Modules {
|
||||
if !held[m.Module] {
|
||||
modules = append(modules, m)
|
||||
}
|
||||
}
|
||||
r.Modules = modules
|
||||
return r
|
||||
}
|
||||
|
||||
// ownerOf is the module an owned path's entry names (resolutionOwnedPaths: `<module> (<why>)`).
|
||||
func ownerOf(entry string) string {
|
||||
module, _, _ := strings.Cut(entry, " (")
|
||||
return module
|
||||
}
|
||||
@@ -19,7 +19,13 @@ import (
|
||||
//
|
||||
// **Failure is loud.** A place still holding a placeholder, or not absolute, fails the composition with the
|
||||
// module named: a list that silently shrank would be a refusal the decision promises and nothing does.
|
||||
func resolutionSecretPlaces(r mcat.Resolution, with mcat.Rendering) ([]string, error) {
|
||||
//
|
||||
// **A held module's share is what runs** (design 47 H, H-A-335, H-A-337): the list says no module per place, so while
|
||||
// any module is held and the holder's words as it runs (ran) say the places, the places are those the modules not held
|
||||
// compose, merged with every place in what runs, then reduced as above. A pass with the same held set gives the same
|
||||
// list, a module that answered still adds its new places, and a place a module dropped stays refused until no module
|
||||
// is held: the list refuses more, never less.
|
||||
func resolutionSecretPlaces(r mcat.Resolution, with mcat.Rendering, held map[string]bool, ran map[string]string) ([]string, error) {
|
||||
seen := map[string]bool{}
|
||||
var problems []string
|
||||
add := func(module, what, path string) {
|
||||
@@ -38,6 +44,13 @@ func resolutionSecretPlaces(r mcat.Resolution, with mcat.Rendering) ([]string, e
|
||||
}
|
||||
seen[path] = true
|
||||
}
|
||||
var running []string
|
||||
if body, says := ran[mcat.ReadsSecretPlaces]; says && json.Unmarshal([]byte(body), &running) == nil {
|
||||
r = notHeld(r, held)
|
||||
for _, p := range running {
|
||||
add("what runs", "secret place", p)
|
||||
}
|
||||
}
|
||||
for _, m := range r.Modules {
|
||||
for name, own := range m.OwnSecrets {
|
||||
add(m.Module, "own secret "+name, own.Path)
|
||||
@@ -91,11 +104,12 @@ func providesSecret(m mcat.Manifest) bool {
|
||||
}
|
||||
|
||||
// readsWords is what the holder of node-reads is given beside its own words: the node's secret places.
|
||||
func resolutionReadsWords(r mcat.Resolution, m mcat.Manifest, words map[string]string, with mcat.Rendering) (map[string]string, error) {
|
||||
// A held module's share of them is what runs of the process (the id process) that serves m (Holding).
|
||||
func resolutionReadsWords(r mcat.Resolution, m mcat.Manifest, words map[string]string, with mcat.Rendering, h Holding, process string) (map[string]string, error) {
|
||||
if !m.ClaimsSeat(mcat.ReadsSeat) {
|
||||
return words, nil
|
||||
}
|
||||
places, err := resolutionSecretPlaces(r, with)
|
||||
places, err := resolutionSecretPlaces(r, with, h.Held, h.ran(process, m.Module))
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
|
||||
@@ -39,7 +39,7 @@ func TestTheHolderOfNodeReadsIsToldWhereItsNodeKeepsASecret(t *testing.T) {
|
||||
app := mcat.Manifest{Module: "app", Version: "1", Secrets: map[string]string{"postgres-database": "/etc/app/db.secret"},
|
||||
OwnSecrets: mcat.OwnSecrets{"token": {Path: "/home/ops/.config/app/token"}}}
|
||||
r := mcat.Resolution{Node: "anchor", Account: "ops", Modules: []mcat.Manifest{reads, desk, vault, app, goRuntime}}
|
||||
owns, err := resolutionOwnRuntimes(r, with)
|
||||
owns, err := resolutionOwnRuntimes(r, with, Holding{})
|
||||
if err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
@@ -71,11 +71,11 @@ func TestASecretPlaceThatCannotBeResolvedFailsTheComposition(t *testing.T) {
|
||||
r := mcat.Resolution{Node: "anchor", Modules: []mcat.Manifest{
|
||||
{Module: "app", Version: "1", Keeps: "${dir:keep}/sealed"},
|
||||
}}
|
||||
if _, err := resolutionSecretPlaces(r, mcat.Rendering{}); err == nil || !strings.Contains(err.Error(), "app") {
|
||||
if _, err := resolutionSecretPlaces(r, mcat.Rendering{}, nil, nil); err == nil || !strings.Contains(err.Error(), "app") {
|
||||
t.Errorf("an unresolved place was dropped: %v", err)
|
||||
}
|
||||
r.Modules[0].Keeps = "relative/place"
|
||||
if _, err := resolutionSecretPlaces(r, mcat.Rendering{}); err == nil {
|
||||
if _, err := resolutionSecretPlaces(r, mcat.Rendering{}, nil, nil); err == nil {
|
||||
t.Error("a relative place was dropped")
|
||||
}
|
||||
}
|
||||
|
||||
@@ -73,7 +73,7 @@ func interpreterFor(module, language string) (string, error) {
|
||||
// runtime runs as the operator's account when the machine has one, which is what lets a tool that
|
||||
// needs root escalate as the operator would (ADR 0175 §4); on a machine with no account it runs as
|
||||
// root, and the two operator words are not set.
|
||||
func resolutionRuntimeProcess(r mcat.Resolution, with mcat.Rendering) (map[string]any, error) {
|
||||
func resolutionRuntimeProcess(r mcat.Resolution, with mcat.Rendering, h Holding) (map[string]any, error) {
|
||||
var runtime *mcat.Manifest
|
||||
for i := range r.Modules {
|
||||
if mcat.IsToolRunner(r.Modules[i]) {
|
||||
@@ -137,7 +137,7 @@ func resolutionRuntimeProcess(r mcat.Resolution, with mcat.Rendering) (map[strin
|
||||
return nil, err
|
||||
}
|
||||
// The holder of node-files is told the same, and the paths modules own here (novox/hq ADR 0394 §4).
|
||||
if words, err = resolutionFilesWords(r, m, words, with); err != nil {
|
||||
if words, err = resolutionFilesWords(r, m, words, with, h, runtime.Module+"."+RuntimeProcessID()); err != nil {
|
||||
return nil, err
|
||||
}
|
||||
if len(words) > 0 {
|
||||
@@ -209,7 +209,7 @@ func (e *NoRuntimeToRunError) Error() string { return e.said }
|
||||
// the machine's runtime program — the same build, run from the same source — serving that one module alone,
|
||||
// as the module's own account, on the module's own bus credential. Never the machine's runtime, which runs
|
||||
// as the operator's account and carries every module on the machine.
|
||||
func resolutionOwnRuntimes(r mcat.Resolution, with mcat.Rendering) ([]map[string]any, error) {
|
||||
func resolutionOwnRuntimes(r mcat.Resolution, with mcat.Rendering, h Holding) ([]map[string]any, error) {
|
||||
var own []mcat.Manifest
|
||||
for _, m := range r.Modules {
|
||||
// A held module's stand-in (Stubbed) has no runtime of its own composed, and so none of this function's rules
|
||||
@@ -275,7 +275,7 @@ func resolutionOwnRuntimes(r mcat.Resolution, with mcat.Rendering) ([]map[string
|
||||
return nil, err
|
||||
}
|
||||
// The holder of node-reads is told where this node keeps its secrets (novox/hq ADR 0310 §5).
|
||||
if words, err = resolutionReadsWords(r, m, words, with); err != nil {
|
||||
if words, err = resolutionReadsWords(r, m, words, with, h, m.Module+"."+mcat.OwnRuntimeID()); err != nil {
|
||||
return nil, err
|
||||
}
|
||||
// A build seat's holder gives way on its node, and its steps are told their part of the node's share
|
||||
|
||||
@@ -328,7 +328,7 @@ func TestAModuleOfItsOwnAccountIsServedByARuntimeOfItsOwn(t *testing.T) {
|
||||
if c.noEngine {
|
||||
modules = modules[:4]
|
||||
}
|
||||
runtimes, err := resolutionOwnRuntimes(mcat.Resolution{Node: "anchor", Modules: modules}, with)
|
||||
runtimes, err := resolutionOwnRuntimes(mcat.Resolution{Node: "anchor", Modules: modules}, with, Holding{})
|
||||
if err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
@@ -354,7 +354,7 @@ func TestAModuleOfItsOwnAccountIsServedByARuntimeOfItsOwn(t *testing.T) {
|
||||
}
|
||||
with.Settings = nil
|
||||
// Without the machine's runtime to run it from, it is refused in words.
|
||||
if _, err := resolutionOwnRuntimes((mcat.Resolution{Node: "anchor", Modules: []mcat.Manifest{telegram}}), with); err == nil {
|
||||
if _, err := resolutionOwnRuntimes((mcat.Resolution{Node: "anchor", Modules: []mcat.Manifest{telegram}}), with, Holding{}); err == nil {
|
||||
t.Error("a module of its own account composed without a runtime program")
|
||||
}
|
||||
}
|
||||
@@ -378,7 +378,7 @@ func TestAModuleOfItsOwnAccountIsRefusedTheOperatorsAndTheAgentsAccount(t *testi
|
||||
telegram.RunsAs, telegram.SecretsOwner = account, account
|
||||
telegram.OwnSecrets = mcat.OwnSecrets{"broker": {Path: "/var/lib/telegram/broker"}}
|
||||
_, err := resolutionOwnRuntimes(mcat.Resolution{Node: "anchor", Account: "ops", AgentAccount: "agent",
|
||||
Modules: []mcat.Manifest{telegram, goRuntime}}, with)
|
||||
Modules: []mcat.Manifest{telegram, goRuntime}}, with, Holding{})
|
||||
if err == nil || !strings.Contains(err.Error(), account) {
|
||||
t.Errorf("telegram running as %s was composed: %v", account, err)
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user