Files
mesh-host/internal/compose/resolution/files.go
T
jschoubben 94a2e6ede0 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)
2026-11-21 22:10:50 +01:00

105 lines
4.0 KiB
Go

package resolution
import (
"encoding/json"
"fmt"
"path"
mcat "git.novox.be/novox/mesh-sdk/go/catalogue"
)
const filesAsAccount = "as the node's operator account, through sudo -n where its rights do not reach; a place a " +
"secret is kept, or a known credential file, is refused by name"
const overrideWord = "a reason, to change a path a module owns anyway (optional)"
// ownedPaths is every path a module owns on this node, as the holder is told (novox/hq ADR 0394 §5): the
// paths every seat declares (ADR 0287) with the module holding the seat here, and the paths and files each
// module's manifest places (declaredPaths). A seat's path wins where both name one.
func resolutionOwnedPaths(r mcat.Resolution) map[string]string {
owned := map[string]string{}
for _, m := range r.Modules {
for _, p := range sortedKeys(declaredPaths(m)) {
owned[p] = m.Module + " (its own tools)"
}
}
for _, s := range mcat.Seats() {
for _, sp := range s.Paths {
for _, m := range r.Modules {
if m.ClaimsSeat(s.Name) && declaresPath(m, path.Clean(sp.Path)) && !resolutionStepsBackHere(r, m, sp) {
owned[sp.Path] = m.Module + " (" + s.Name + ")"
}
}
}
}
return owned
}
// stepsBackHere says m's seat path steps back on this machine (novox/hq ADR 0287): it names a seat whose holder here
// declares the path too, so that holder owns it, as stepsBack leaves m's own rendering of it out. Without it the owner
// told was the last seat in the order of the seat table, which the controller reads sorted by name and a node in the
// order compiled (issue 1126, C3: /etc/resolv.conf, node-uplink against node-resolver).
func resolutionStepsBackHere(r mcat.Resolution, m mcat.Manifest, sp mcat.SeatPath) bool {
if sp.StepsBackFor == "" {
return false
}
for _, o := range r.Modules {
if o.Module != m.Module && holdsSeat(o, sp.StepsBackFor) && declaresPath(o, path.Clean(sp.Path)) {
return true
}
}
return false
}
// 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. 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
}
ran := h.ran(process, m.Module)
places, err := resolutionSecretPlaces(r, with, h.Held, ran)
if err != nil {
return nil, err
}
places2, err := json.Marshal(places)
if err != nil {
return nil, err
}
owned, err := json.Marshal(heldOwnedPaths(r, h.Held, ran))
if err != nil {
return nil, err
}
if words == nil {
words = map[string]string{}
}
for _, w := range []string{mcat.ReadsSecretPlaces, mcat.FilesOwnedPaths} {
if _, has := words[w]; has {
return nil, fmt.Errorf("%s gives its own %s; the node's secret places and owned paths are the mesh's to "+
"say (novox/hq ADR 0394 §5)", m.Module, w)
}
}
words[mcat.ReadsSecretPlaces] = string(places2)
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
}