carlos / platform Public

Merge origin/main into moves-offline

claude agent, operated by paul@keymail.dev 38dfe4d7f6e1000bdb7fd9743aea8090df2a6588 parent 75ebf4fparent cd2dd6e
12 files changed, +574 −18
  • internal/console/apisystembootstrap_test.go +70 −0
  • internal/console/apisystemupdate.go +75 −9
  • internal/host/agent.go +30 −6
  • internal/host/rootunits_test.go +88 −0
  • internal/provision/plan14_root_reads_test.go +16 −0
  • internal/provision/testdata/plan14-root-reads-adopt-unit-root-pass-315.tsv +7 −0
  • internal/provision/testdata/plan14-root-reads-bootstrap-carlos-follows-316.tsv +3 −0
  • internal/release/adopt.go +48 −0
  • internal/release/rollback.go +26 −0
  • internal/release/rootunits_test.go +152 −0
  • system.go +24 −3
  • system_test.go +35 −0
diff --git a/internal/console/apisystembootstrap_test.go b/internal/console/apisystembootstrap_test.go
new file mode 100644
index 000000000..4221b8f25
--- /dev/null
+++ b/internal/console/apisystembootstrap_test.go
@@ -0,0 +1,70 @@
+package console
+
+import (
+ "context"
+ "crypto/sha256"
+ "encoding/hex"
+ "net/http"
+ "testing"
+
+ "github.com/carlosframework/platform/internal/release"
+)
+
+// Issue #316: system status compares bootstrap/carlos, the binary a new box
+// boots, with stable's signed linux-arm64 artifact.
+func TestSystemStatusReportsWhetherBootstrapIsStablesBuild(t *testing.T) {
+ fx := newConsoleFixture(t)
+ owner := cliToken(t, fx, "paul@keymail.dev", "code-sys-bootstrap")
+ seedBox(t, fx, "ie", "linux-arm64", "stable", "v0.28.0")
+ ctx := context.Background()
+ build := []byte("stable build")
+ sum := sha256.Sum256(build)
+ if _, err := release.PromoteSystem(ctx, fx.rel, release.RootSigner(fx.priv), "router", "stable", release.SystemRelease{
+ Version: "v0.28.0", Artifacts: map[string]release.SystemArtifact{"linux-arm64": {
+ Key: release.SystemArtifactKey("v0.28.0", "linux-arm64"), SHA256: hex.EncodeToString(sum[:])}},
+ }, release.SystemPromoteOptions{}); err != nil {
+ t.Fatal(err)
+ }
+ bootstrap := func() any {
+ t.Helper()
+ st, out := getJSON(t, fx.ts.URL+"/api/cli/system/status", owner)
+ if st != http.StatusOK {
+ t.Fatalf("status = %d %v", st, out)
+ }
+ v, ok := out["bootstrap"]
+ if !ok {
+ t.Fatalf("no bootstrap field in %v", out)
+ }
+ return v
+ }
+ if got := bootstrap(); got != nil {
+ t.Fatalf("absent bootstrap object: bootstrap = %v, want null", got)
+ }
+ put := func(data []byte) {
+ t.Helper()
+ _, etag, err := fx.rel.Get(ctx, bootstrapKey)
+ if err != nil {
+ etag = ""
+ }
+ if _, err := fx.rel.Put(ctx, bootstrapKey, data, etag); err != nil {
+ t.Fatal(err)
+ }
+ }
+ put([]byte("an older build"))
+ row, _ := bootstrap().(map[string]any)
+ if row["state"] != "behind" || row["version"] != "v0.28.0" || row["key"] != "bootstrap/router/v0.28.0/carlos-linux-arm64" {
+ t.Fatalf("stale bootstrap: row = %v, want behind v0.28.0 with the mirror key", row)
+ }
+ put(build)
+ if row, _ := bootstrap().(map[string]any); row["state"] != "current" {
+ t.Fatalf("matching bootstrap: row = %v, want current", row)
+ }
+ // Past its budget the comparison reads unreadable, and the status read
+ // still answers (Astra review: a slow store must not time the CLI out).
+ was := bootstrapReadBudget
+ bootstrapReadBudget = 0
+ t.Cleanup(func() { bootstrapReadBudget = was })
+ if row, _ := bootstrap().(map[string]any); row["state"] != "unreadable" || row["error"] == "" {
+ t.Fatalf("over budget: row = %v, want unreadable with the error", row)
+ }
+}
diff --git a/internal/console/apisystemupdate.go b/internal/console/apisystemupdate.go
index 80e0d3385..f3f3dd9b5 100644
--- a/internal/console/apisystemupdate.go
+++ b/internal/console/apisystemupdate.go
@@ -601,25 +601,84 @@ func (s *Server) mirrorSystemArtifact(ctx context.Context, job *systemJob, versi
// object beside it would make the peak two copies of a platform binary per
// in-flight promote, for no purpose beyond computing one sha256.
func (s *Server) systemArtifactMatches(ctx context.Context, key, sha string) (bool, error) {
- rc, _, err := release.OpenObject(ctx, s.cfg.Releases, key)
+ got, err := s.objectSHA256(ctx, key)
switch {
case errors.Is(err, os.ErrNotExist):
return false, nil
case err != nil:
return false, err
}
- h := sha256.New()
- _, err = io.Copy(h, rc)
- rc.Close()
- if err != nil {
- return false, fmt.Errorf("%s: reading the mirrored object to compare it: %w", key, err)
- }
- if hex.EncodeToString(h.Sum(nil)) == sha {
+ if got == sha {
return true, nil
}
return false, fmt.Errorf("%s exists with different bytes — versions are immutable; pick a new version", key)
}
+// objectSHA256 streams the object at key through a hasher; absent is
+// os.ErrNotExist. A ctx that ended during the read is its error, even on a
+// store that read on regardless.
+func (s *Server) objectSHA256(ctx context.Context, key string) (string, error) {
+ rc, _, err := release.OpenObject(ctx, s.cfg.Releases, key)
+ if err != nil {
+ return "", err
+ }
+ defer rc.Close()
+ h := sha256.New()
+ if _, err := io.Copy(h, rc); err != nil {
+ return "", fmt.Errorf("%s: reading the object to compare it: %w", key, err)
+ }
+ if err := ctx.Err(); err != nil {
+ return "", fmt.Errorf("%s: reading the object to compare it: %w", key, err)
+ }
+ return hex.EncodeToString(h.Sum(nil)), nil
+}
+
+// bootstrapKey is the binary a new, rebuilt or failover box downloads at
+// first boot. `carlos system update` mirrors each release under
+// bootstrap/router/ and never writes this key, so it falls behind the fleet
+// unless an operator copies stable's build over it (issue #316).
+const bootstrapKey = "bootstrap/carlos"
+
+// bootstrapPlatform is the one platform bootstrap/carlos serves.
+const bootstrapPlatform = "linux-arm64"
+
+// bootstrapReadBudget bounds the comparison. It reads the whole binary, and
+// the status read it rides (also `carlos system update`'s preview) must
+// answer inside the CLI's 30-second timeout on slow storage: past the budget
+// the row reads unreadable and the rest of the response stands.
+var bootstrapReadBudget = 10 * time.Second
+
+// bootstrapState is the status row for bootstrapKey against stable's signed
+// linux-arm64 artifact, or nil when there is nothing to compare: no verified
+// stable pointer, no linux-arm64 artifact in it, or no bootstrap object (a
+// deployment that bootstraps another way). A read failure is reported, never
+// fatal to the status read.
+func (s *Server) bootstrapState(ctx context.Context, stable *release.SystemPointer) map[string]any {
+ if stable == nil {
+ return nil
+ }
+ art, ok := stable.Current.Artifacts[bootstrapPlatform]
+ if !ok || art.SHA256 == "" {
+ return nil
+ }
+ row := map[string]any{"version": stable.Current.Version, "key": art.Key}
+ ctx, cancel := context.WithTimeout(ctx, bootstrapReadBudget)
+ defer cancel()
+ got, err := s.objectSHA256(ctx, bootstrapKey)
+ switch {
+ case errors.Is(err, os.ErrNotExist):
+ return nil
+ case err != nil:
+ log.Printf("console: api system status: %s: %v", bootstrapKey, err)
+ row["state"], row["error"] = "unreadable", err.Error()
+ case strings.EqualFold(got, art.SHA256):
+ row["state"] = "current"
+ default:
+ row["state"] = "behind"
+ }
+ return row
+}
+
func (s *Server) handleAPISystemJob(w http.ResponseWriter, r *http.Request) {
if _, _, ok := s.apiSystemRoller(w, r); !ok {
return
@@ -806,6 +865,7 @@ func (s *Server) handleAPISystemStatus(w http.ResponseWriter, r *http.Request) {
ctx := r.Context()
pointers := map[string]any{}
targets := map[string]string{}
+ var stable *release.SystemPointer
for _, ch := range []string{release.RungCanary, release.RungStable} {
p, _, err := release.GetSystemPointer(ctx, s.cfg.Releases, s.cfg.ReleasePub, release.SystemComponentRouter, ch)
switch {
@@ -824,6 +884,9 @@ func (s *Server) handleAPISystemStatus(w http.ResponseWriter, r *http.Request) {
pointers[ch] = map[string]any{"version": p.Current.Version, "promoted_at": p.PromotedAt, "spread": p.Spread, "source": p.Current.Source,
"history": len(p.History)}
targets[ch] = p.Current.Version
+ if ch == release.RungStable {
+ stable = p
+ }
}
}
boxes, partial, err := s.systemBoxes(ctx, false)
@@ -854,5 +917,8 @@ func (s *Server) handleAPISystemStatus(w http.ResponseWriter, r *http.Request) {
// could not be read. Always present, so a reader never has to tell a
// missing key from a false one, and so "no boxes on that fleet" and
// "could not ask that fleet" are different answers here.
- writeJSON(w, http.StatusOK, map[string]any{"pointers": pointers, "boxes": rows, "partial": partial})
+ //
+ // bootstrap is null when there is nothing to compare (bootstrapState).
+ writeJSON(w, http.StatusOK, map[string]any{"pointers": pointers, "boxes": rows, "partial": partial,
+ "bootstrap": s.bootstrapState(ctx, stable)})
}
diff --git a/internal/host/agent.go b/internal/host/agent.go
index 06c3f9c5e..ce93fb963 100644
--- a/internal/host/agent.go
+++ b/internal/host/agent.go
@@ -1295,14 +1295,19 @@ func adoptLoop(reg *registry.Registry, svc *activator.Service, sd *scheduleDeps,
// DO NOT add the platform self-update here either: the system leg
// lives in the fast loop and re-observes hourly on its own, so an
// hourly call here would only double the pointer read.
- if err := release.Pass(ctx, reg, store, pub, optDir, restart,
+ //
+ // agentUnitsOption hands named units to root when this process is
+ // not root (issue #315), which leaves WithStartUnit and
+ // WithRollbackRestart to an agent run as root.
+ opts := append([]release.PassOption{
release.BakeDir(dataDir()), release.OnStageBlocked(stageRequester(dataDir())),
release.RestartHibernating(restart),
release.WithStartUnit(makeStartRoute(reg, systemctlStartUnit)),
release.WithRollbackRestart(agentRollbackUnitRestart(reg, systemdUnits{}, optDir, os.Getenv)),
release.WithProofGate(agentProofGate()), release.WithHostWrites(writes),
release.WithDigestRatchet(pointerRatchet(false, optDir, dataDir(), os.Getenv)),
- updatesPassOption(dataDir(), false)); err != nil {
+ updatesPassOption(dataDir(), false)}, agentUnitsOption()...)
+ if err := release.Pass(ctx, reg, store, pub, optDir, restart, opts...); err != nil {
log.Printf("agent: adopt pass: %v", err)
}
// The schedule converge's hourly floor (schedule spec §6.2), AFTER the
@@ -1746,9 +1751,10 @@ func stageMarkerRequester(dd string) func(host, ver string, err error) {
}
// One line for every cause the marker relays (Task 12a): a build
// this process cannot stage, an install request only root
- // resolves (ErrInstallRequestNeedsRoot), and a held wake's target
- // only root installs. The throttle does not carry the cause.
- log.Printf("agent: %s needs a root pass for %s (a build only root can stage or install, or an install request only root resolves); asked for one", host, ver)
+ // resolves (ErrInstallRequestNeedsRoot), a named unit only root
+ // restarts (ErrUnitRestartNeedsRoot), and a held wake's target only
+ // root installs. The throttle does not carry the cause.
+ log.Printf("agent: %s needs a root pass for %s (a build only root can stage or install, a unit only root can restart, or an install request only root resolves); asked for one", host, ver)
})
}
@@ -2039,8 +2045,11 @@ type restartFailure struct {
// did not already need, and it cannot fire for a sleeper: only an
// ERRORED restart reaches it, and every arm that can meet a sleeping
// route swallows its failure.
+//
+// unitsOption hands named units to root when this process is not root
+// (issue #315); see agentUnitsOption.
func fastPassOpts(dd string, stageReq func(host, ver string, err error), restart, start func(string) error) []release.PassOption {
- return []release.PassOption{
+ return append([]release.PassOption{
release.BakeDir(dd),
release.OnStageBlocked(stageReq),
release.RestartHibernating(restart),
@@ -2050,7 +2059,22 @@ func fastPassOpts(dd string, stageReq func(host, ver string, err error), restart
// resolves. The book is opened per pass, not here: these options are
// built once per agent run.
updatesPassOption(dd, false),
+ }, agentUnitsOption()...)
+}
+
+// agentRunsAsRoot is the agent's euid test, a seam for tests.
+var agentRunsAsRoot = func() bool { return os.Geteuid() == 0 }
+
+// agentUnitsOption is release.RootRestartsUnits for an agent that is not
+// root (issue #315). carlos-edge.service runs as User=carlos, and systemd
+// refuses that user a restart of any unit a route names, so a named-unit
+// route goes to the root pass through the stage relay before anything moves.
+// An agent run as root restarts the unit itself, as before.
+func agentUnitsOption() []release.PassOption {
+ if agentRunsAsRoot() {
+ return nil
}
+ return []release.PassOption{release.RootRestartsUnits()}
}
// fastMembers computes the fast set for one tick — the routes with a reason
diff --git a/internal/host/rootunits_test.go b/internal/host/rootunits_test.go
new file mode 100644
index 000000000..6c2df491a
--- /dev/null
+++ b/internal/host/rootunits_test.go
@@ -0,0 +1,88 @@
+package host
+
+import (
+ "context"
+ "errors"
+ "runtime"
+ "testing"
+ "time"
+
+ "github.com/carlosframework/platform/internal/registry"
+ "github.com/carlosframework/platform/internal/release"
+)
+
+// Issue #315, through the fast loop's production options: an agent that is
+// not root hands a named-unit route to root's pass rather than repointing it
+// and failing systemd's permission check. An agent run as root keeps
+// restarting the unit itself.
+func TestFastSweepHandsANamedUnitToRoot(t *testing.T) {
+ for _, tc := range []struct {
+ name string
+ root bool
+ }{{"agent user", false}, {"root", true}} {
+ t.Run(tc.name, func(t *testing.T) {
+ was := agentRunsAsRoot
+ agentRunsAsRoot = func() bool { return tc.root }
+ t.Cleanup(func() { agentRunsAsRoot = was })
+
+ env := newFastFixture(t)
+ ctx := context.Background()
+ plat := runtime.GOOS + "-" + runtime.GOARCH
+ for _, v := range []string{"v1", "v2"} {
+ m := release.Manifest{App: "fastapp", Version: v, Kind: "binary",
+ Artifacts: map[string]release.Artifact{plat: {}}}
+ if err := release.Ship(ctx, env.store, "bab", m, map[string][]byte{plat: []byte("build " + v)}); err != nil {
+ t.Fatalf("Ship %s: %v", v, err)
+ }
+ }
+ if err := release.Promote(ctx, env.store, env.priv, "bab", "fastapp", "canary/dev", "v1"); err != nil {
+ t.Fatal(err)
+ }
+ if err := env.reg.Upsert(registry.Route{Host: "console.test", Kind: "instance", App: "fastapp",
+ Channel: "canary/dev", Status: "ready", Addr: "127.0.0.1:8090"}); err != nil {
+ t.Fatal(err)
+ }
+ if err := release.Pass(ctx, env.reg, env.store, env.pub, env.optDir, nil); err != nil {
+ t.Fatal(err)
+ }
+ if err := env.reg.SetUnit("console.test", "console.service"); err != nil {
+ t.Fatal(err)
+ }
+ if err := release.Promote(ctx, env.store, env.priv, "bab", "fastapp", "canary/dev", "v2"); err != nil {
+ t.Fatal(err)
+ }
+
+ var unitRestarts []string
+ restart := makeRestartRoute(env.reg, func(string) {},
+ unitOnly(func(u string) error { unitRestarts = append(unitRestarts, u); return nil }), nil)
+ var relayed []error
+ stageReq := func(host, ver string, err error) {
+ if host == "console.test" && ver == "v2" {
+ relayed = append(relayed, err)
+ }
+ }
+ d := env.deps(nil)
+ d.restart = restart
+ d.passOpts = fastPassOpts(env.dataDir, stageReq, restart, nil)
+
+ fastTick(ctx, d, time.Unix(1754640000, 0))
+
+ live, err := release.LiveVersion(env.optDir, "console.test")
+ if err != nil {
+ t.Fatal(err)
+ }
+ if tc.root {
+ if live != "v2" || len(unitRestarts) != 1 || len(relayed) != 0 {
+ t.Fatalf("root agent: live %q, unit restarts %v, relays %v; want v2, one restart, no relay", live, unitRestarts, relayed)
+ }
+ return
+ }
+ if live != "v1" || len(unitRestarts) != 0 {
+ t.Fatalf("agent user: live %q, unit restarts %v; want v1 untouched and no restart", live, unitRestarts)
+ }
+ if len(relayed) != 1 || !errors.Is(relayed[0], release.ErrUnitRestartNeedsRoot) {
+ t.Fatalf("relays = %v, want one ErrUnitRestartNeedsRoot", relayed)
+ }
+ })
+ }
+}
diff --git a/internal/provision/plan14_root_reads_test.go b/internal/provision/plan14_root_reads_test.go
index 8e68b7dbb..1175ecad9 100644
--- a/internal/provision/plan14_root_reads_test.go
+++ b/internal/provision/plan14_root_reads_test.go
@@ -933,6 +933,22 @@ func TestPlan14RootReadCensus(t *testing.T) {
if err = loadRootReadInventory(filepath.Join(root, "internal/provision/testdata/plan14-root-reads-claim-guard-umask.tsv"), &inv, true); err != nil {
t.Fatal(err)
}
+ // Census overlay adopt-unit-root-pass-315 (amadan #315: a non-root agent
+ // hands a named unit's routes to the root pass), loaded last. PROPOSED-315,
+ // ruling asked of the census owner on #280: adoptHost re-pinned at its
+ // class, type passConfig gains a bool, and unitServed (new) classified
+ // with processGroup, whose membership it inverts. Both envelopes
+ // re-pinned. It adds no accepted-legacy row, so the seal stands.
+ if err = loadRootReadInventory(filepath.Join(root, "internal/provision/testdata/plan14-root-reads-adopt-unit-root-pass-315.tsv"), &inv, true); err != nil {
+ t.Fatal(err)
+ }
+ // Census overlay bootstrap-carlos-follows-316 (amadan #316: system status
+ // compares bootstrap/carlos with stable's build), loaded last. Envelope
+ // only, proposed; ruling asked of the census owner on #280. The seal
+ // stands.
+ if err = loadRootReadInventory(filepath.Join(root, "internal/provision/testdata/plan14-root-reads-bootstrap-carlos-follows-316.tsv"), &inv, true); err != nil {
+ t.Fatal(err)
+ }
seal = "53b3cbb6f46d657ce32f49dad84dae79316c80da949ccf37273833eef5c5b2d7"
errs := append(compareRootReads(got, inv), checkRootReadLegacy(inv, seal)...)
errs = append(errs, checkRootReadDeclarations(got, inv)...)
diff --git a/internal/provision/testdata/plan14-root-reads-adopt-unit-root-pass-315.tsv b/internal/provision/testdata/plan14-root-reads-adopt-unit-root-pass-315.tsv
new file mode 100644
index 000000000..2844ab497
--- /dev/null
+++ b/internal/provision/testdata/plan14-root-reads-adopt-unit-root-pass-315.tsv
@@ -0,0 +1,7 @@
+# Census overlay adopt-unit-root-pass-315 (amadan #315: a non-root agent hands named-unit routes and their process group to the root pass), loaded LAST, after claim-guard-umask. Proposed; ruling asked of the census owner on #280.
+# adoptHost re-pinned at its class and task: the new hand-off precedes staging and only returns. type passConfig gains a bool. unitServed (new) reads registry routes exactly as processGroup does and classifies with it. carlos adopt (root) never sets RootRestartsUnits, so root reads are unchanged. The seal stands: no accepted-legacy row.
+@coverage internal/release 4aafab144b1b742b27cab13ded61276b5203a64eb94f12203b6b94adddd0ae83
+@coverage internal/host c589ae17ec476291bd5cd103f10909b55ddcacdc1bddff76800078133766665e
+internal/release/adopt.go adoptHost authority B3,E1,E2,E3,E4,J1 E16: root first-registration creation evidence under release exclusion; exact installation identity is required for first-program adoption and is consumed before an attempt. Installed-program history comes from the verified claim launch. Fixtures: TestPlan14FreshInstallRegistration, TestPlan14FreshInstallProgramGate, TestPlan14FreshInstallCanonicalIdentity, TestPlan14FreshInstallLaunchObservation, TestPlan14InstalledLaunchProgramEvidence, TestPlan14FreshInstallProcessCrash, TestPlan14FreshInstallVisibleSync, TestClaimControlUnitInstallers. E22: root generation pins guard existing-tree artifact and manifest writes in adoption and moves-held staging/publication. Held snapshot is read under release exclusion before the leaf held-stage lock; failures remain restrictive for writes. Claims-off source returns no root pins. Fresh wholly absent version trees retain signed staging. Fixtures: TestPlan14GenerationSiblingWrites, TestPlan14GenerationVerifiedSiblingWrites, TestPlan14GenerationHeldStage (production source assembly, both flag values without census, lock order, pin/error/fresh cases). Production completeness remains unavailable; no new completeness grant.;rev3=PROPOSED-p3;run=8;identity=carlos adopt uid 0; legacy agent pass uid carlos;basis=applies root settings to canonically resolved routes including named units while legacy settings eligibility remains unchanged;rev3=PROPOSED-p3;run=16;basis=P3-R11 approved punctuation edit only; authority and reads unchanged;rev3=PROPOSED-315;identity=legacy agent pass uid carlos (RootRestartsUnits; never set on carlos adopt);basis=a non-root agent pass hands a route its named unit serves (unitServed) to root through the stage relay before staging or repointing; root adopt reads unchanged registry:App@11360,registry:App@11520,registry:App@12549,registry:App@13475,registry:App@15054,registry:App@20213,registry:App@25689,registry:App@3144,registry:App@33448,registry:App@6758,registry:App@8059,registry:App@8253,registry:Hibernate@34309,registry:Host@10484,registry:Host@11240,registry:Host@11273,registry:Host@11373,registry:Host@11533,registry:Host@11635,registry:Host@11667,registry:Host@11732,registry:Host@12182,registry:Host@12315,registry:Host@12762,registry:Host@12871,registry:Host@13073,registry:Host@13565,registry:Host@14351,registry:Host@14826,registry:Host@15040,registry:Host@15382,registry:Host@15972,registry:Host@19703,registry:Host@19811,registry:Host@20181,registry:Host@21001,registry:Host@2105,registry:Host@21159,registry:Host@21621,registry:Host@21673,registry:Host@21820,registry:Host@21907,registry:Host@2294,registry:Host@23013,registry:Host@23257,registry:Host@2375,registry:Host@23917,registry:Host@24302,registry:Host@24443,registry:Host@25657,registry:Host@25784,registry:Host@27126,registry:Host@27776,registry:Host@31009,registry:Host@3157,registry:Host@31627,registry:Host@31952,registry:Host@32026,registry:Host@32273,registry:Host@32424,registry:Host@33620,registry:Host@33787,registry:Host@33894,registry:Host@34122,registry:Host@34265,registry:Host@35010,registry:Host@35136,registry:Host@35224,registry:Host@4469,registry:Host@4583,registry:Host@5546,registry:Host@5651,registry:Host@6870,registry:Host@6918,registry:Host@7035,registry:Host@7067,registry:Host@7945,registry:Host@8113,registry:Host@8239,registry:Host@8358,registry:Host@8836,registry:Host@9223,registry:Host@9449,registry:Host@9545,registry:Host@9636,registry:Kind@554,registry:Unit@32172,registry:Unit@579,whole:Route@10073,whole:Route@10427,whole:Route@11355,whole:Route@11515,whole:Route@12539,whole:Route@13465,whole:Route@15022,whole:Route@15587,whole:Route@15948,whole:Route@17171,whole:Route@17474,whole:Route@17630,whole:Route@19960,whole:Route@20104,whole:Route@20203,whole:Route@2206,whole:Route@22742,whole:Route@23141,whole:Route@25679,whole:Route@30580,whole:Route@3139,whole:Route@33596,whole:Route@3595,whole:Route@4347,whole:Route@6753 219694d85c22b7886a4ebc62be97888bf993af79d5c0df134b95e0480b2db992
+internal/release/adopt.go type passConfig authority E2,E3 E19: both destructive readers use the root reservation snapshot under existing release exclusion. Exact artifact and containing-tree identities are retained; missing completeness refuses destruction. Production installation/launch/kernel completeness and verified retirement remain unfinished. Fixtures: TestPlan14GenerationDeletionCannotUnpin, TestPlan14GenerationSnapshotCompleteness, TestPlan14GenerationSnapshotPermitsUnreservedRestage, TestPlan14GenerationSnapshotPinsContainingTree, TestPlan14GenerationSnapshotEmptyIsUnknown, TestPlan14GenerationConsumerMode, TestPlan14GenerationProductionModeGate, TestPlan14GenerationSnapshotPermitsFreshTree.;rev3=PROPOSED-p3;run=8;identity=carlos adopt uid 0; legacy agent pass uid carlos;basis=stores the typed census-only root update provider and per-pass resolved input authority;rev3=PROPOSED-315;identity=legacy agent pass uid carlos (RootRestartsUnits; never set on carlos adopt);basis=adds the unitsToRoot bool set by RootRestartsUnits; reads nothing 60131fde0633bcee3db957f9f898b6e9eef96f1a84f2f2f03a7ab0d9b05db6ad
+internal/release/rollback.go unitServed authority B3,E1,E3,J1 root-route;kept=B3,E1,E3;scope=protected-decision-only;rev3=PROPOSED-315;identity=legacy agent pass uid carlos (RootRestartsUnits; never set on carlos adopt);basis=processGroup membership inverted (same account, app, channel and non-empty upstream as a route naming a unit); only ever narrows the agent pass to a hand-off; a registry list failure hands off; no file read registry:App@281,registry:App@290,registry:Host@244,registry:Host@254,registry:Unit@265,registry:Unit@70,whole:Route@119,whole:Route@233,whole:Route@316,whole:Route@335,whole:Route@351,whole:Route@379,whole:Route@398 fef7b67b13241535f225f634f776d2822837a734ca6a25ea732ef37d9b7909e9
diff --git a/internal/provision/testdata/plan14-root-reads-bootstrap-carlos-follows-316.tsv b/internal/provision/testdata/plan14-root-reads-bootstrap-carlos-follows-316.tsv
new file mode 100644
index 000000000..d92e2784f
--- /dev/null
+++ b/internal/provision/testdata/plan14-root-reads-bootstrap-carlos-follows-316.tsv
@@ -0,0 +1,3 @@
+# Census overlay bootstrap-carlos-follows-316 (amadan #316: carlos system status compares bootstrap/carlos with stable's signed linux-arm64 artifact), loaded LAST. Envelope only: no root-read unit is added or changed; the console's status door gains a store read of bootstrap/carlos and the CLI prints the result. Proposed; ruling asked of the census owner on #280. The seal stands.
+@coverage internal/console f697865970fd453298b73b42dc31b7c3b4ae2fd97e27a4837522eb8bc9b604b0
+@coverage . ea902ca81c5eff7e3eb4b6b36afe1e0557101e8b27e27b6821f7b2073534c0a3
diff --git a/internal/release/adopt.go b/internal/release/adopt.go
index da914a81c..2867b8797 100644
--- a/internal/release/adopt.go
+++ b/internal/release/adopt.go
@@ -86,6 +86,11 @@ type passConfig struct {
// is consulted for them at all.
restartHibernating func(host string) error
+ // unitsToRoot hands every route that names its own unit to the root pass
+ // before anything is staged or repointed (RootRestartsUnits). false, the
+ // default and RunAdopt's, restarts the named unit in this pass.
+ unitsToRoot bool
+
// startUnit is consulted ONLY on adoptHost's restart-failure rollback
// path, after the symlink has gone back (WithStartUnit). nil — every
// call site that does not pass the option, and every existing test —
@@ -154,6 +159,40 @@ type FailedBuild func(acct, app, build, host string, served bool) bool
// this pass sees it. Never shown to members.
var ErrInstallRequestNeedsRoot = errors.New("release: an install request waits for root's pass to resolve it")
+// ErrUnitRestartNeedsRoot is what a RootRestartsUnits pass hands
+// OnStageBlocked's callback for a route that names its own unit: nothing
+// failed, and the version is the build root's pass should install. Never
+// shown to members.
+var ErrUnitRestartNeedsRoot = errors.New("release: a route's named unit is restarted by root's pass")
+
+// RootRestartsUnits is for a pass whose process cannot restart a unit an
+// operator named (issue #315): the agent's in-process loops when they do not
+// run as root. carlos-edge.service is User=carlos, and systemd refuses it
+// ("Interactive authentication required") for console.service and every
+// other route.Unit. Before this option such a pass repointed the live link,
+// failed the restart, read the refusal as a broken build, rolled back,
+// poisoned the version and tried to start the old build over a process that
+// had never stopped.
+//
+// With it, a route that names its unit, and every route in that unit's
+// process group (processGroup: same account, app, channel and upstream), is
+// handed to root before anything is staged or repointed, through
+// OnStageBlocked with ErrUnitRestartNeedsRoot, the way a build this process
+// cannot stage is. The live links keep naming the running build, so no
+// sibling is stamped with a build the unit does not run. Nothing is poisoned
+// and no refusal is recorded; root's
+// pass stages, repoints, restarts and stamps. Every hold, refusal and proof
+// check before the hand-off still applies, so root is only asked for a build
+// this pass would have installed.
+//
+// Lifecycle host writes (WithHostWrites) restart through the selected
+// receiver instead, so the option does nothing under them. Nor for a route
+// this pass would not restart (restart nil: a sleeper on a pass without
+// RestartHibernating, a sidecar).
+func RootRestartsUnits() PassOption {
+ return func(c *passConfig) { c.unitsToRoot = true }
+}
+
// NagExpiredCanaries opts a Pass/PassFilter call into spec §5's nag: one
// line per expired canary/* route the call sees, written to w.
//
@@ -1483,6 +1522,15 @@ func adoptHost(ctx context.Context, work hostwrite.Work, reg *registry.Registry,
if !admitted {
return
}
+ // A named unit this process cannot restart is root's (RootRestartsUnits),
+ // and so is every route its process serves: ask for root's pass and touch
+ // nothing. Silent on the tick; the requester logs each request it writes.
+ if cfg.unitsToRoot && restart != nil && !cfg.hostWrites.Enabled && unitServed(reg, rt) {
+ if cfg.stageBlocked != nil {
+ cfg.stageBlocked(rt.Host, ver, ErrUnitRestartNeedsRoot)
+ }
+ return
+ }
// The evidence that authorizes ver (settings spec §4.1). Only today's
// adoption of the head, and a request whose T is still the head, rest on
// the signed pointer and its digest; everything else needs a promotion
diff --git a/internal/release/rollback.go b/internal/release/rollback.go
index dcdbe3831..830a0f6cf 100644
--- a/internal/release/rollback.go
+++ b/internal/release/rollback.go
@@ -66,6 +66,32 @@ func processGroup(reg *registry.Registry, bound registry.Route) []registry.Route
return out
}
+// unitServed reports whether rt's process is a unit an operator named: rt
+// names one itself, or rt is in the processGroup of a route that does. A
+// registry that cannot be listed answers true, so a RootRestartsUnits pass
+// hands the route to root rather than stamp a build the unit may not run.
+func unitServed(reg *registry.Registry, rt registry.Route) bool {
+ if rt.Unit != "" {
+ return true
+ }
+ up := upstream(rt)
+ if up == "" {
+ return false
+ }
+ all, err := reg.List()
+ if err != nil {
+ return true
+ }
+ for _, r := range all {
+ if r.Host != rt.Host && r.Unit != "" && r.App == rt.App &&
+ RouteAccount(r) == RouteAccount(rt) && upstream(r) == up &&
+ routeChannel(r) == routeChannel(rt) {
+ return true
+ }
+ }
+ return false
+}
+
// rollbackGroup puts every group route whose link names the rejected version
// onto restored (what bound now runs), stamps it to match, and returns bound
// and every group host: the hosts writeGroupRefusals refuses. restored ""
diff --git a/internal/release/rootunits_test.go b/internal/release/rootunits_test.go
new file mode 100644
index 000000000..497e81219
--- /dev/null
+++ b/internal/release/rootunits_test.go
@@ -0,0 +1,152 @@
+package release
+
+import (
+ "context"
+ "errors"
+ "testing"
+)
+
+// Issue #315: a pass that cannot restart a named unit (the agent, User=carlos)
+// hands that route to root before it stages or repoints anything. The live
+// link keeps naming the running build, the version is not poisoned for the
+// other hosts in the pass, and root's pass then installs it normally.
+func TestRootRestartsUnitsHandsNamedUnitsToRoot(t *testing.T) {
+ ctx := context.Background()
+ s := NewDirStore(t.TempDir())
+ priv, pub := testKeys(t)
+ opt := t.TempDir()
+ reg := testRegistry(t)
+ t.Cleanup(func() { reg.Close() })
+ const consoleHost, appHost = "console.example.com", "shop.example.com"
+ for _, ver := range []string{"v1", "v2"} {
+ shipRelease(t, s, "bab", "myapp", ver, adoptPlatform, []byte(ver))
+ }
+ if err := Promote(ctx, s, priv, "bab", "myapp", "canary/x", "v1"); err != nil {
+ t.Fatal(err)
+ }
+ addRoute(t, reg, consoleHost, "myapp", "canary/x", false)
+ addRoute(t, reg, appHost, "myapp", "canary/x", false)
+ if err := Pass(ctx, reg, s, pub, opt, nil); err != nil {
+ t.Fatal(err)
+ }
+ if err := reg.SetUnit(consoleHost, "console.service"); err != nil {
+ t.Fatal(err)
+ }
+ if err := Promote(ctx, s, priv, "bab", "myapp", "canary/x", "v2"); err != nil {
+ t.Fatal(err)
+ }
+
+ var restarted []string
+ restart := func(host string) error {
+ restarted = append(restarted, host)
+ if host == consoleHost {
+ return errors.New("try-restart console.service: Interactive authentication required")
+ }
+ return nil
+ }
+ type req struct {
+ host, ver string
+ err error
+ }
+ var reqs []req
+ relay := func(host, ver string, err error) { reqs = append(reqs, req{host, ver, err}) }
+
+ if err := Pass(ctx, reg, s, pub, opt, restart, OnStageBlocked(relay), RootRestartsUnits()); err != nil {
+ t.Fatal(err)
+ }
+ if len(reqs) != 1 || reqs[0].host != consoleHost || reqs[0].ver != "v2" || !errors.Is(reqs[0].err, ErrUnitRestartNeedsRoot) {
+ t.Fatalf("relays = %+v, want one for %s v2 with ErrUnitRestartNeedsRoot", reqs, consoleHost)
+ }
+ if len(restarted) != 1 || restarted[0] != appHost {
+ t.Fatalf("restarted = %v, want only %s", restarted, appHost)
+ }
+ if ver, err := LiveVersion(opt, consoleHost); err != nil || ver != "v1" {
+ t.Fatalf("%s live = %q, %v; want v1 (untouched)", consoleHost, ver, err)
+ }
+ if rt, err := reg.Get(consoleHost); err != nil || rt == nil || rt.Version != "v1" {
+ t.Fatalf("%s route = %+v, %v; want stamped v1", consoleHost, rt, err)
+ }
+ if ver, err := LiveVersion(opt, appHost); err != nil || ver != "v2" {
+ t.Fatalf("%s live = %q, %v; want v2 (not poisoned by the hand-off)", appHost, ver, err)
+ }
+ if r, err := ReadRefusal(opt, consoleHost); err != nil || r != nil {
+ t.Fatalf("refusal for %s = %+v, %v; want none", consoleHost, r, err)
+ }
+
+ // Root's pass, without the option, installs it.
+ restarted = nil
+ rootRestart := func(host string) error { restarted = append(restarted, host); return nil }
+ if err := Pass(ctx, reg, s, pub, opt, rootRestart); err != nil {
+ t.Fatal(err)
+ }
+ if ver, err := LiveVersion(opt, consoleHost); err != nil || ver != "v2" || len(restarted) != 1 || restarted[0] != consoleHost {
+ t.Fatalf("root pass: %s live = %q, %v, restarted %v; want v2 and one restart", consoleHost, ver, err, restarted)
+ }
+}
+
+// The option hands nothing over for a route this pass would not restart, and
+// leaves routes with no unit to the pass.
+func TestRootRestartsUnitsNeedsANamedUnitAndARestart(t *testing.T) {
+ ctx := context.Background()
+ s := NewDirStore(t.TempDir())
+ priv, pub := testKeys(t)
+ opt := t.TempDir()
+ reg := testRegistry(t)
+ t.Cleanup(func() { reg.Close() })
+ const host = "console.example.com"
+ shipRelease(t, s, "bab", "myapp", "v1", adoptPlatform, []byte("v1"))
+ if err := Promote(ctx, s, priv, "bab", "myapp", "canary/x", "v1"); err != nil {
+ t.Fatal(err)
+ }
+ addRoute(t, reg, host, "myapp", "canary/x", false)
+ if err := reg.SetUnit(host, "console.service"); err != nil {
+ t.Fatal(err)
+ }
+ relays := 0
+ relay := func(string, string, error) { relays++ }
+ // restart nil: a pure repoint, which needs no unit restart.
+ if err := Pass(ctx, reg, s, pub, opt, nil, OnStageBlocked(relay), RootRestartsUnits()); err != nil {
+ t.Fatal(err)
+ }
+ if ver, err := LiveVersion(opt, host); err != nil || ver != "v1" || relays != 0 {
+ t.Fatalf("live = %q, %v, relays %d; want v1 and no relay", ver, err, relays)
+ }
+}
+
+// Astra review of #315: a route with no unit of its own whose process is a
+// named unit (same account, app, channel and upstream) is root's too. Stamped
+// by the agent it would claim a build console.service does not run.
+func TestRootRestartsUnitsHandsTheProcessGroupToRoot(t *testing.T) {
+ ctx, reg, s, pub, opt := startUnitFixture(t, "console.example.com")
+ if err := reg.SetUnit("console.example.com", ""); err != nil {
+ t.Fatal(err)
+ }
+ groupFixtureRoute(t, reg, "platform.example.com", "", "127.0.0.1:8090", "console.service")
+ if err := reg.SetUpstreams("console.example.com", "127.0.0.1:8090", "", ""); err != nil {
+ t.Fatal(err)
+ }
+ if err := PointLive(opt, "platform.example.com", "bab", "old", "console"); err != nil {
+ t.Fatal(err)
+ }
+ var relayed []string
+ relay := func(host, ver string, err error) {
+ if errors.Is(err, ErrUnitRestartNeedsRoot) {
+ relayed = append(relayed, host)
+ }
+ }
+ restart := func(host string) error {
+ t.Errorf("restart(%s): every host here is the unit's", host)
+ return nil
+ }
+ if err := Pass(ctx, reg, s, pub, opt, restart, OnStageBlocked(relay), RootRestartsUnits()); err != nil {
+ t.Fatal(err)
+ }
+ if len(relayed) != 2 {
+ t.Fatalf("relayed = %v, want both hosts", relayed)
+ }
+ for _, h := range []string{"console.example.com", "platform.example.com"} {
+ if ver, err := LiveVersion(opt, h); err != nil || ver != "old" {
+ t.Fatalf("%s live = %q, %v; want old", h, ver, err)
+ }
+ }
+}
diff --git a/system.go b/system.go
index 1828c1f5a..839a2c9c6 100644
--- a/system.go
+++ b/system.go
@@ -248,9 +248,20 @@ type systemBoxRow struct {
// list is INCOMPLETE — a fleet's heartbeats could not be read — so a short
// list is never mistaken for a small fleet.
type systemStatusResponse struct {
- Pointers map[string]*systemPointerRow `json:"pointers"`
- Boxes []systemBoxRow `json:"boxes"`
- Partial bool `json:"partial"`
+ Pointers map[string]*systemPointerRow `json:"pointers"`
+ Boxes []systemBoxRow `json:"boxes"`
+ Partial bool `json:"partial"`
+ Bootstrap *systemBootstrapRow `json:"bootstrap"`
+}
+
+// systemBootstrapRow is bootstrap/carlos, the binary a new box boots,
+// against stable's signed linux-arm64 artifact (issue #316). nil when there
+// is nothing to compare, or the console predates the field.
+type systemBootstrapRow struct {
+ Version string `json:"version"` // stable's version
+ Key string `json:"key"` // stable's mirrored linux-arm64 artifact
+ State string `json:"state"` // current, behind or unreadable
+ Error string `json:"error"`
}
// ---- carlos system update ----------------------------------------------
@@ -495,6 +506,16 @@ func printSystemStatus(w io.Writer, resp systemStatusResponse, channel string) {
fmt.Fprintln(w, strings.Join(parts, " "))
}
}
+ // What a new box would boot (issue #316): quiet unless it is not stable's
+ // build, and only where stable is shown.
+ if b := resp.Bootstrap; b != nil && (channel == "" || channel == "stable") {
+ switch b.State {
+ case "behind":
+ fmt.Fprintln(w, c.warn(fmt.Sprintf("bootstrap/carlos is not stable's build (%s), so a new box would boot a different one. Copy %s over it.", b.Version, b.Key)))
+ case "unreadable":
+ fmt.Fprintln(w, c.warn("bootstrap/carlos could not be read, so this can't say what a new box would boot: "+b.Error))
+ }
+ }
fmt.Fprintln(w)
if resp.Partial {
fmt.Fprintln(w, c.warn("fleet boxes could not all be read; rows may be missing"))
diff --git a/system_test.go b/system_test.go
index 9ae34db54..68d95bc74 100644
--- a/system_test.go
+++ b/system_test.go
@@ -297,3 +297,38 @@ func TestSystemFilesSeedCommandEntryRefusesBeforeEffects(t *testing.T) {
}
}
}
+
+// Issue #316: status says when bootstrap/carlos is not stable's build, and is
+// quiet when it is, when there is nothing to compare, and under --channel
+// canary.
+func TestPrintSystemStatusSaysWhenBootstrapLags(t *testing.T) {
+ stable := map[string]*systemPointerRow{"stable": {Version: "v0.28.0"}}
+ behind := "bootstrap/carlos is not stable's build (v0.28.0), so a new box would boot a different one. Copy bootstrap/router/v0.28.0/carlos-linux-arm64 over it."
+ for _, tc := range []struct {
+ name, channel, want string
+ row *systemBootstrapRow
+ }{
+ {"behind", "", behind, &systemBootstrapRow{Version: "v0.28.0", Key: "bootstrap/router/v0.28.0/carlos-linux-arm64", State: "behind"}},
+ {"behind, stable only", "stable", behind, &systemBootstrapRow{Version: "v0.28.0", Key: "bootstrap/router/v0.28.0/carlos-linux-arm64", State: "behind"}},
+ {"unreadable", "", "bootstrap/carlos could not be read, so this can't say what a new box would boot: access denied",
+ &systemBootstrapRow{Version: "v0.28.0", State: "unreadable", Error: "access denied"}},
+ {"current", "", "", &systemBootstrapRow{Version: "v0.28.0", State: "current"}},
+ {"nothing to compare", "", "", nil},
+ {"canary only", "canary", "", &systemBootstrapRow{Version: "v0.28.0", State: "behind"}},
+ } {
+ t.Run(tc.name, func(t *testing.T) {
+ var b strings.Builder
+ printSystemStatus(&b, systemStatusResponse{Pointers: stable, Bootstrap: tc.row}, tc.channel)
+ out := b.String()
+ if tc.want == "" {
+ if strings.Contains(out, "bootstrap/carlos") {
+ t.Fatalf("output mentions bootstrap/carlos:\n%s", out)
+ }
+ return
+ }
+ if !strings.Contains(out, tc.want) {
+ t.Fatalf("output lacks %q:\n%s", tc.want, out)
+ }
+ })
+ }
+}