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:
@@ -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,21 @@ 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, the entries the modules not held compose, and each
|
||||
// running entry whose owner is a held module where those name no owner of 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 {
|
||||
var running map[string]string
|
||||
if body, says := ran[mcat.FilesOwnedPaths]; !says || json.Unmarshal([]byte(body), &running) != nil {
|
||||
return resolutionOwnedPaths(r)
|
||||
}
|
||||
owned := resolutionOwnedPaths(notHeld(r, held))
|
||||
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