The tool runner's bus account carried the heard grants, consumer and bind word of every module it runs, and every agent session on that machine reaches the bus as that account, so any session could pull a granted module's consumer on MAIL. Per ADR 0376 §1 the controller now composes a restricted stream's consumer, grants and bind word only for a module that declares runs-as; registration refuses a consumes of a restricted stream without runs-as (§2), and a grant that composes nothing is said in doctor (D-heard) and in the controller's log on every raise and send.
67 lines
3.1 KiB
Go
67 lines
3.1 KiB
Go
package main
|
|
|
|
import (
|
|
"context"
|
|
"fmt"
|
|
"strings"
|
|
|
|
"github.com/novox/mesh-controller/internal/broker"
|
|
"github.com/novox/mesh-controller/internal/conditions"
|
|
)
|
|
|
|
// A grant of a restricted stream that composes nothing (novox/hq ADR 0376 §2).
|
|
//
|
|
// A restricted stream is heard only by a module that runs as an account of its own (`runs-as`, ADR 0259): the
|
|
// tool runner's bus account is the one every agent session on its machine reaches the bus as, so the controller
|
|
// composes no consumer, grant or bind word for a module it carries (broker.ComposedHears). Where a grant still
|
|
// names such a module, the module hears nothing it was granted, and that is said — in `doctor` and in the
|
|
// controller's log on every raise and send — naming the module, the stream and the remedy. Never silent.
|
|
|
|
const (
|
|
// probeWithheldID is the self-check's probe of it, and kindGrantComposesNothing the condition it raises.
|
|
probeWithheldID = "D-heard"
|
|
kindGrantComposesNothing = "grant-composes-nothing"
|
|
)
|
|
|
|
// probeWithheldHearing says every granted hearing of a restricted stream composed for nothing.
|
|
func probeWithheldHearing(ctx context.Context, d *doctor) ([]conditions.Observation, error) {
|
|
records, err := d.open.inventory.BusRecords(ctx)
|
|
if err != nil {
|
|
return nil, err
|
|
}
|
|
return withheldObservations(broker.WithheldOf(records)), nil
|
|
}
|
|
|
|
// withheldObservations is each withheld hearing as a condition of its module on its machine.
|
|
func withheldObservations(withheld []broker.Withheld) []conditions.Observation {
|
|
var out []conditions.Observation
|
|
for _, w := range withheld {
|
|
out = append(out, conditions.Observation{Scope: conditions.ScopeModule,
|
|
ID: w.Module + "." + strings.ToLower(w.Stream) + "." + w.Node,
|
|
Kind: kindGrantComposesNothing, Machine: w.Node, Severity: conditions.Warning,
|
|
Summary: w.Said(), Said: fmt.Sprintf("%s on %s granted %s; composed nothing", w.Module, w.Node, w.Stream)})
|
|
}
|
|
return sortedFound(out)
|
|
}
|
|
|
|
// sayWithheld puts every withheld hearing in the controller's log, once per raise or send that composes it.
|
|
func sayWithheld(records broker.Records, indent string) {
|
|
for _, w := range broker.WithheldOf(records) {
|
|
fmt.Printf("%sA GRANT COMPOSES NOTHING: %s\n", indent, w.Said())
|
|
}
|
|
}
|
|
|
|
// withheldWords are the plain words of a withheld hearing: the module, the machine and what to do.
|
|
func withheldWords(o conditions.Observation) words {
|
|
module, m := "a module", machineOr(o, "a machine")
|
|
if o.Scope == conditions.ScopeModule && idPart(o, 0) != "" {
|
|
module = idPart(o, 0)
|
|
}
|
|
return words{Headline: clip(conditions.Capital(fmt.Sprintf("%s on %s hears nothing it was granted", module, m)), 60),
|
|
Needs: fmt.Sprintf("give %s an account of its own in its manifest; the details say which stream.", module),
|
|
Explanation: fmt.Sprintf("You granted %s part of a stream that only modules running under an account of "+
|
|
"their own may hear. It runs inside the shared tool runner on %s, which every assistant session there "+
|
|
"also uses, so the mesh gives it none of that stream.", module, m),
|
|
Resolved: fmt.Sprintf("%s on %s hears what it was granted, or is no longer granted it", module, m)}
|
|
}
|