carlos / platform Public

system apply: the rootfs floor refuses by the box's version, with an operator override

Task 15 round 3, Paul's ruling (stopping rule 2 after two rounds in the
runtime admission family): the registry fence and the floor's registry
read are gone. A box whose installed release (onDiskBuild, the gate's
source; this build when it cannot be asked) is v0.29.0 or later refuses a
candidate below v0.29.0, or one whose version does not parse, whatever
rows it has, before anything is begun or staged; the refusal is terminal.
Boxes below the floor install as on main. carlos system update
--allow-below-rootfs-floor (carried on the signed pointer for that write)
and carlos system apply --allow-below-rootfs-floor let a deliberate
downgrade through with a logged warning. The gate's automatic rollback
restores .prev without passing the check. RFS-3-C25 is struck; C30 to C32
are pending the copy pass. P1-3's refuseRootfs marking stays.
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
claude agent, operated by paul@keymail.dev 1def2a6b1f40de68fb0ebe15fd9e6f75280d168a parent a686db8
19 files changed, +408 −778
  • approved_rootfs_copy_test.go +4 −5
  • docs/superpowers/plans/2026-10-24-rootfs-apps-copy.md +9 −5
  • internal/console/apisystemupdate.go +5 −1
  • internal/console/apisystemupdate_test.go +31 −0
  • internal/host/systemapply.go +64 −141
  • internal/host/systemapply_rootfs_test.go +186 −388
  • internal/host/systemapply_test.go +4 −10
  • internal/registry/registry.go +1 −6
  • internal/registry/registry_test.go +0 −12
  • internal/registry/remote.go +1 −1
  • internal/registry/remote_dispatch.go +0 −4
  • internal/registry/runtimefence.go +0 −76
  • internal/registry/runtimefence_test.go +0 −119
  • internal/release/layoutintent.go +28 −5
  • internal/release/layoutintent_test.go +25 −2
  • internal/release/systempointer.go +10 −1
  • internal/release/systempointer_test.go +32 −0
  • plan3_groups_test.go +3 −2
  • system.go +5 −0
diff --git a/approved_rootfs_copy_test.go b/approved_rootfs_copy_test.go
index 943ec21eb..96c1b7dea 100644
--- a/approved_rootfs_copy_test.go
+++ b/approved_rootfs_copy_test.go
@@ -66,7 +66,7 @@ var rootfsCopyIDs = []string{
"RFS-3-C17", "RFS-3-C18", "RFS-3-C19", "RFS-3-C20",
"RFS-3-C21", "RFS-3-C22", "RFS-3-C23", "RFS-3-C24",
"RFS-3-C25", "RFS-3-C26", "RFS-3-C27", "RFS-3-C28",
- "RFS-3-C29",
+ "RFS-3-C29", "RFS-3-C30", "RFS-3-C31", "RFS-3-C32",
// Plan 4
"RFS-4-C01", "RFS-4-C02", "RFS-4-C03", "RFS-4-C04",
"RFS-4-C05", "RFS-4-C06", "RFS-4-C07", "RFS-4-C08",
@@ -137,9 +137,10 @@ var rootfsCopyIDs = []string{
// rootfsCopyStruck is every id the deck marks struck, pinned, so a row can
// neither become struck nor stop being struck without this list changing in
// the same commit. RFS-3-C13 was struck by the Plan 3 pre-flight (row 3.1,
-// claims shelved). RFS-1-C15 and RFS-3-C28 are live until Plan 5 Task 2a
+// claims shelved), RFS-3-C25 by Paul's Task 15 round 3 ruling (the floor
+// refuses by version). RFS-1-C15 and RFS-3-C28 are live until Plan 5 Task 2a
// and Plan 6 Task 16 strike them.
-var rootfsCopyStruck = []string{"RFS-3-C13"}
+var rootfsCopyStruck = []string{"RFS-3-C13", "RFS-3-C25"}
// rootfsCopyStatuses are the statuses the deck may carry. struck is the
// rootfs deck's own: a struck row is never reviewed, never built and never
@@ -190,8 +191,6 @@ var rootfsCopyBuilt = []string{
// Plan 3 Task 13: the move doors and carlos apps place refuse rootfs
// instances (internal/console/seedmove.go)
"RFS-3-C23", "RFS-3-C24",
- // Plan 3 Task 15: the rootfs rollback floor (internal/host/systemapply.go)
- "RFS-3-C25",
}
func mustParseRootfsRecord(t *testing.T) []copyRow {
diff --git a/docs/superpowers/plans/2026-10-24-rootfs-apps-copy.md b/docs/superpowers/plans/2026-10-24-rootfs-apps-copy.md
index 24ee98a7e..b48627bdb 100644
--- a/docs/superpowers/plans/2026-10-24-rootfs-apps-copy.md
+++ b/docs/superpowers/plans/2026-10-24-rootfs-apps-copy.md
@@ -192,13 +192,16 @@ From the plan: Every row goes to the deck in Task 1 and reaches code only once a
| RFS-3-C22 | internal/host/runevents.go (runRefusedWords, version) | the build is not on the box | approved |
| RFS-3-C23 | internal/console/seedmove.go (refuseRootfsMove, 409) | %s is a rootfs instance, and a rootfs instance does not move. create a new instance where you want it | approved |
| RFS-3-C24 | internal/console/seedmove.go (rootfsMoveConflict, carlos apps place) | this app's instances are rootfs instances, which do not move. create new instances where you want them | approved |
-| RFS-3-C25 | internal/host/systemapply.go (systemApplyRootfsRefusal) | %s cannot run rootfs instances, and this box still has: %s. delete those instances before installing it | approved |
+| RFS-3-C25 | internal/host/systemapply.go (systemApplyRootfsRefusal; struck 2026-10-26 by Paul's Task 15 round 3 ruling: the floor refuses by the box's version, not its rows, and RFS-3-C30 replaces it) | %s cannot run rootfs instances, and this box still has: %s. delete those instances before installing it | struck |
| RFS-3-C26 | docs/site/cli.md (carlos run, a paragraph) | --version runs another build of the app against the instance, for example the build a deploy is about to bring in. The build must already be on the instance's box. The command still gets the environment the instance serves with. | approved |
| RFS-3-C27 | docs/site/cli.md (carlos run, a paragraph) | For a rootfs app the command after -- runs inside the instance's image and is found on the image's PATH. | approved |
| RFS-3-C28 | docs/site/cli.md (carlos run, the same paragraph) (live until Plan 6 Task 16 strikes it, replaced by RFS-6-C62) | carlos run does not reach instances on a customer fleet yet. | approved |
| RFS-3-C29 | internal/rolloutwords/words.go (EventReleaseLeaseLost) | the release command of build %s was stopped because this box no longer holds the instance. it runs again on the next attempt | approved |
+| RFS-3-C30 | internal/host/systemapply.go (systemApplyRootfsFloorRefusal, a refused update's reason: the installed release, the floor, the candidate) | this box runs %s, so it installs only %s or later, the releases that run rootfs instances. %s is not one. to install it anyway, promote it with --allow-below-rootfs-floor | pending |
+| RFS-3-C31 | internal/host/systemapply.go (systemApplyRootfsFloorOverride, the log warning when the override lets a release below the floor through: the candidate, the floor, the candidate) | installing %s below %s with --allow-below-rootfs-floor: this box may have rootfs instances that %s cannot run | pending |
+| RFS-3-C32 | internal/release/layoutintent.go (RootfsFloorOverrideUsage, the --allow-below-rootfs-floor help on carlos system update and carlos system apply) | install a release below v0.29.0 on boxes running v0.29.0 or later, which may have rootfs instances that release cannot run | pending |
-From the plan: Count: 29 rows, 28 live, 1 struck (RFS-3-C13). (RFS-3-C28 is live until Plan 6 Task 16 marks it struck when runs reach fleet boxes, R7.)
+From the plan: Count: 29 rows, 28 live, 1 struck (RFS-3-C13). Since then (Task 15 round 3, 2026-10-26): 32 rows, 30 live, 2 struck (RFS-3-C13, RFS-3-C25); RFS-3-C30 to C32 are pending the copy pass. (RFS-3-C28 is live until Plan 6 Task 16 marks it struck when runs reach fleet boxes, R7.)
Plan 3's file cells were set on 2026-10-26 (Plan 3 pre-flight, row 8.3) to the one file that holds each literal, with the old where-it-appears text kept as the note, so the gate's applied-text check can read them. C05 to C07 also format through `ReleaseError.Error`, named in the note. RFS-3-C13 was struck the same day (pre-flight row 3.1): host lifecycle claims are shelved, and Plan 3 adds no reader of the claim switch. The texts are unchanged.
@@ -531,14 +534,15 @@ Checked in every plan and in the index: each full `RFS-<n>-C<nn>` id, and each b
## Counts
Live rows are `pending` (or `approved`); struck rows are kept for history.
-RFS-3-C13 was struck on 2026-10-26 by the Plan 3 pre-flight (row 3.1).
+RFS-3-C13 was struck on 2026-10-26 by the Plan 3 pre-flight (row 3.1), and
+RFS-3-C25 the same day by Paul's Task 15 round 3 ruling.
RFS-1-C15 and RFS-3-C28 are live until Plan 5 Task 2a and Plan 6 Task 16
strike them (Astra R2 finding 5).
- Plan 1: 85 live, 0 struck, 85 rows
- Plan 2: 12 live, 0 struck, 12 rows
-- Plan 3: 28 live, 1 struck, 29 rows
+- Plan 3: 30 live, 2 struck, 32 rows
- Plan 4: 138 live, 0 struck, 138 rows
- Plan 5: 44 live, 0 struck, 44 rows
- Plan 6: 64 live, 0 struck, 64 rows
-- Total: 371 live, 1 struck, 372 rows
+- Total: 373 live, 2 struck, 375 rows
diff --git a/internal/console/apisystemupdate.go b/internal/console/apisystemupdate.go
index a96b3ce5c..f5470d82f 100644
--- a/internal/console/apisystemupdate.go
+++ b/internal/console/apisystemupdate.go
@@ -335,6 +335,10 @@ type systemUpdateRequest struct {
Version string `json:"version"`
Upload string `json:"upload"`
Spread string `json:"spread"`
+ // AllowBelowRootfsFloor is `carlos system update
+ // --allow-below-rootfs-floor`, carried onto the pointer
+ // (release.SystemPointer.AllowBelowRootfsFloor).
+ AllowBelowRootfsFloor bool `json:"allow_below_rootfs_floor"`
}
// handleAPISystemUpdate starts the promote and answers with a job id. The
@@ -521,7 +525,7 @@ func (s *Server) runSystemUpdate(ctx context.Context, id string, job *systemJob,
}
}
p, err := s.promoteHostUpdate(ctx, rel, in.Component, in.Channel,
- release.SystemPromoteOptions{Actor: actor, Spread: spread})
+ release.SystemPromoteOptions{Actor: actor, Spread: spread, AllowBelowRootfsFloor: in.AllowBelowRootfsFloor})
if err != nil {
return err
}
diff --git a/internal/console/apisystemupdate_test.go b/internal/console/apisystemupdate_test.go
index 3486a7cff..d8ca0b578 100644
--- a/internal/console/apisystemupdate_test.go
+++ b/internal/console/apisystemupdate_test.go
@@ -540,3 +540,34 @@ func mustGetObject(t *testing.T, fx *consoleFixture, key string) []byte {
}
return raw
}
+
+// `carlos system update --allow-below-rootfs-floor` reaches the pointer
+// the boxes read (rootfs apps Plan 3, Task 15 round 3), and only for that
+// promote.
+func TestSystemUpdateCarriesTheRootfsFloorOverride(t *testing.T) {
+ fx := newConsoleFixture(t)
+ systemFeed(t, fx, map[string][]byte{"carlos-linux-arm64": []byte("ELF arm64")})
+ seedBox(t, fx, "ie", "linux-arm64", "canary", "v0.17.0")
+ owner := cliToken(t, fx, "paul@keymail.dev", "code-sys-floor")
+ for _, allow := range []bool{true, false} {
+ in := map[string]any{"channel": "canary", "spread": "0s"}
+ if allow {
+ in["allow_below_rootfs_floor"] = true
+ }
+ st, out := postJSON(t, fx.ts.URL+"/api/cli/system/update", in, owner)
+ if st != http.StatusOK {
+ t.Fatalf("update = %d %v", st, out)
+ }
+ if job := waitJob(t, fx, owner, str(t, out, "job")); job["error"] != "" {
+ t.Fatalf("job failed: %v", job)
+ }
+ p, _, err := release.GetSystemPointer(context.Background(), fx.rel, fx.pub, "router", "canary")
+ if err != nil {
+ t.Fatal(err)
+ }
+ if p.AllowBelowRootfsFloor != allow {
+ t.Fatalf("allow=%v: the pointer's override is %v", allow, p.AllowBelowRootfsFloor)
+ }
+ time.Sleep(1100 * time.Millisecond)
+ }
+}
diff --git a/internal/host/systemapply.go b/internal/host/systemapply.go
index 644ad3064..7757bef7c 100644
--- a/internal/host/systemapply.go
+++ b/internal/host/systemapply.go
@@ -44,9 +44,7 @@ import (
// grants no new privilege. Root's adopt, stage and restart passes already
// open the same registry, the listing and the Lstats follow no symlink
// and read no journal's contents, and all the guard can do with what it
-// finds is refuse the install. The rootfs floor (fenceRootfsAdmission)
-// opens the same registry, through the same seam: it raises the runtime
-// fence, lists the rows, and lifts the fence when the install is over.
+// finds is refuse the install.
const (
systemEdgeUnit = "carlos-edge"
@@ -115,6 +113,7 @@ type sysOps struct {
func RunSystemApply(args []string) {
fs := flag.NewFlagSet("system apply", flag.ExitOnError)
recover := fs.Bool("recover", false, "recover an interrupted apply (files only) and exit: the boot and OnFailure unit")
+ allowBelowRootfsFloor := fs.Bool(release.RootfsFloorOverrideFlag, false, release.RootfsFloorOverrideUsage)
fs.Usage = cliflag.Usage(fs, "")
_ = fs.Parse(args)
if os.Geteuid() != 0 {
@@ -132,6 +131,7 @@ func RunSystemApply(args []string) {
rootMoves: rootMovesFloorIdentity, ops: productionSysOps(), openStore: openSystemStore, channel: channel,
optDir: release.OptDir(), dataDir: dataDir(), etcDir: "/etc", build: version.Build,
platform: runtime.GOOS + "-" + runtime.GOARCH, soak: systemGateSoak,
+ allowBelowRootfsFloor: *allowBelowRootfsFloor,
}
a.readEnvironment(os.Getenv)
a.floorHook = installFloorHook // decided under the apply lock, in Run
@@ -247,18 +247,20 @@ type systemApplier struct {
// openSystemStore for why that matters at boot.
openStore func(ctx context.Context) (release.Store, ed25519.PublicKey, error)
// openRegistry is called only when the candidate predates the instance
- // layout, to see whether anything on the box is still nested, or cannot
- // run rootfs instances, to raise the runtime fence, see whether any row
- // has a runtime and lift the fence again (and by the moves floor's hold
- // check). Nil means openSystemRegistry over dataDir.
- openRegistry func() (*registry.Registry, error)
- channel string
- optDir string
- dataDir string
- etcDir string // "/etc" in production; a temp dir in tests
- build string // version.Build of THIS process
- platform string // "<goos>-<goarch>"; the caller sets it from runtime
- gateWait, soak time.Duration
+ // layout, to see whether anything on the box is still nested. Nil means
+ // openSystemRegistry over dataDir.
+ openRegistry func() (*registry.Registry, error)
+ // allowBelowRootfsFloor is `carlos system apply
+ // --allow-below-rootfs-floor`: the operator's override of the rootfs
+ // floor (rootfsFloorRefusal), as the pointer's own flag is.
+ allowBelowRootfsFloor bool
+ channel string
+ optDir string
+ dataDir string
+ etcDir string // "/etc" in production; a temp dir in tests
+ build string // version.Build of THIS process
+ platform string // "<goos>-<goarch>"; the caller sets it from runtime
+ gateWait, soak time.Duration
// claims is CARLOS_HOST_CLAIM, read with hostwrite.Enabled from the
// unit's environment (carlos-system-update.service and
// carlos-system-recover.service both load host.env). It changes only the
@@ -378,12 +380,6 @@ func (a *systemApplier) Run(ctx context.Context, recover bool) (retErr error) {
}
deferred = true
}
- // A runtime fence an earlier run raised and did not lift (it stopped
- // mid-install) comes down once no install is open: this run holds the
- // apply lock and recovery has closed the journal.
- if j, err := readSystemJournal(a.optDir); err == nil && j == nil {
- a.liftRootfsFence()
- }
if recover {
return nil
}
@@ -437,9 +433,18 @@ func (a *systemApplier) Run(ctx context.Context, recover bool) (retErr error) {
if err := writeJSONDurable(a.file("seen.json"), seen, 0o644); err != nil {
return err
}
- if req.NoOp || p.Current.Version == a.onDiskBuild(ctx) {
+ if req.NoOp {
+ return a.writeResult(req, systemOutcomeNoted, "")
+ }
+ installed := a.onDiskBuild(ctx)
+ if p.Current.Version == installed {
return a.writeResult(req, systemOutcomeNoted, "")
}
+ // The rootfs floor, before anything is begun, staged or run: a box on a
+ // release that runs rootfs instances never installs one that cannot.
+ if err := a.rootfsFloorRefusal(installed, p); err != nil {
+ return a.record(req, err)
+ }
// The claim release floor's transaction (Plan 8) first, as on main;
// then the moves activation check. Either one refusing refuses; a
// moves refusal after beginGuard leaves no journal, so Run's deferred
@@ -461,6 +466,43 @@ func (a *systemApplier) Run(ctx context.Context, recover bool) (retErr error) {
return a.install(ctx, req, p, staged)
}
+// systemApplyRootfsFloorRefusal (RFS-3-C30) takes the installed release,
+// the floor and the candidate.
+const systemApplyRootfsFloorRefusal = "this box runs %s, so it installs only %s or later, the releases that run rootfs instances. %s is not one. to install it anyway, promote it with --allow-below-rootfs-floor"
+
+// systemApplyRootfsFloorOverride (RFS-3-C31) takes the candidate, the floor
+// and the candidate again.
+const systemApplyRootfsFloorOverride = "installing %s below %s with --allow-below-rootfs-floor: this box may have rootfs instances that %s cannot run"
+
+// rootfsFloorRefusal is the rootfs floor (rootfs apps spec §5.6; Paul's
+// ruling, Task 15 round 3). A box whose installed release is at or above
+// release.RootfsLifecycleFloor refuses a candidate below it, or one whose
+// version does not parse, whatever rows it has: by the box's version
+// alone, so no registry read, fence or race stands between the check and
+// the handover. The refusal is terminal for that promote. A box below the
+// floor installs as on main. installed is onDiskBuild's answer, the source
+// the update gate reads; when it cannot be read, this process's own build
+// (the installed binary is what runs this apply) stands in. The operator's
+// override (the pointer's AllowBelowRootfsFloor, or this command's flag)
+// lets a deliberate downgrade through with a warning. The gate's automatic
+// rollback restores .prev through rollback and restoreFiles, which never
+// come here.
+func (a *systemApplier) rootfsFloorRefusal(installed string, p *release.SystemPointer) error {
+ if installed == "" {
+ installed = a.build
+ }
+ target := p.Current.Version
+ if release.RootfsFloorAllows(installed, target) {
+ return nil
+ }
+ floor := "v" + release.RootfsLifecycleFloor.String()
+ if a.allowBelowRootfsFloor || p.AllowBelowRootfsFloor {
+ a.ops.logf("system apply: "+systemApplyRootfsFloorOverride, target, floor, target)
+ return nil
+ }
+ return fmt.Errorf("%w: "+systemApplyRootfsFloorRefusal, errSystemRefused, installed, floor, target)
+}
+
// waitForLock is --recover's bounded wait for the apply lock: poll
// systemRecoverLockPoll apart for up to systemRecoverLockWait, then give up.
// It reports whether it got the lock; an unsupported platform is the one
@@ -532,32 +574,6 @@ func (a *systemApplier) install(ctx context.Context, req systemRequest, p *relea
return a.record(req, fmt.Errorf("%w: "+systemApplyLayoutRefusal, errSystemRefused, target, strings.Join(reasons, ", ")))
}
}
- // The rootfs floor has the same shape (rootfs apps spec §5.6): a box with
- // a row that has a runtime never installs a release that cannot run it,
- // refused here, before the journal. Plan 2's releases ship the rootfs
- // templates without the lifecycle, so the unit set is half the evidence
- // and release.RootfsLifecycleFloor the other half. Unlike the layout
- // floor, a version that does not parse is refused too: its unit set
- // says nothing about the lifecycle.
- //
- // The check runs under the runtime fence (fenceRootfsAdmission), which
- // stays up until this install returns: after the gate, when the
- // installed release's agent has taken over, or after the rollback. So
- // no row with a runtime is admitted between the check and the handover.
- // Rows confirmed in the way refuse the install; a registry that cannot
- // answer defers it, and the agent's backoff asks again (INV-6).
- if !rootfsLifecycleCandidate(target, newUnits) {
- hosts, err := a.fenceRootfsAdmission()
- if err != nil {
- a.liftRootfsFence()
- return a.record(req, fmt.Errorf("%w: %v", errSystemDeferred, err))
- }
- if len(hosts) > 0 {
- a.liftRootfsFence()
- return a.record(req, fmt.Errorf("%w: "+systemApplyRootfsRefusal, errSystemRefused, target, strings.Join(hosts, ", ")))
- }
- defer a.liftRootfsFence()
- }
// Only the unit set is taken from the return: a rollback picks this
// staging up as it stands, plan.json and all, rather than exec'ing the
// previous binary again on a box that is already unhealthy.
@@ -1265,99 +1281,6 @@ const layoutMountUnit = "data-instances.mount"
// systemApplyLayoutRefusal takes the release and the rows in its way.
const systemApplyLayoutRefusal = "%s predates the instance layout, and this box still has: %s. revert the layout and wait for every row to report flat before installing it"
-// rootfsInstanceUnit is the contract's rootfs instance template. Its
-// presence in a candidate's staged set is half of the evidence that the
-// candidate runs rows with a runtime; release.RootfsLifecycleFloor is the
-// other half.
-const rootfsInstanceUnit = "carlos-instance-rootfs@.service"
-
-// systemApplyRootfsRefusal (RFS-3-C25) takes the release and the rows in
-// its way.
-const systemApplyRootfsRefusal = "%s cannot run rootfs instances, and this box still has: %s. delete those instances before installing it"
-
-// rootfsRowsPresent names, once each and sorted, every host whose row has
-// a runtime: rootfs-v1, or one this build does not know. reg is the
-// *Registry the openRegistry seam returned (openSystemRegistry, the
-// service-user child, by default), never one root opened itself. A
-// registry that cannot be listed is an error, never an empty box.
-func rootfsRowsPresent(reg *registry.Registry) ([]string, error) {
- routes, err := reg.List()
- if err != nil {
- return nil, err
- }
- var hosts []string
- for _, rt := range routes {
- if rt.Runtime != "" {
- hosts = append(hosts, rt.Host)
- }
- }
- slices.Sort(hosts)
- return slices.Compact(hosts), nil
-}
-
-// rootfsLifecycleCandidate reports whether a candidate runs rows with a
-// runtime: it ships rootfsInstanceUnit and its version parses at or above
-// release.RootfsLifecycleFloor.
-func rootfsLifecycleCandidate(version string, units []string) bool {
- v, ok := release.ParseReleaseVersion(version)
- return ok && v.Compare(release.RootfsLifecycleFloor) >= 0 && slices.Contains(units, rootfsInstanceUnit)
-}
-
-// rootfsFenceMarker is root's own record that it raised the runtime fence
-// (registry.FenceRuntimeAdmission), in root's directory: written before the
-// fence goes up and removed once it is down, so a run that stopped between
-// the two lifts it at the next run's start (Run, after recovery).
-const rootfsFenceMarker = "rootfs-fence"
-
-// fenceRootfsAdmission raises the runtime fence through the openRegistry
-// seam and then names, through rootfsRowsPresent, every row with a runtime.
-// The fence is committed before the read starts, so a row with a runtime
-// is either in the answer or refused until liftRootfsFence. An error means
-// the registry could not answer; it is never read as an empty box.
-func (a *systemApplier) fenceRootfsAdmission() ([]string, error) {
- if err := writeJSONDurable(a.file(rootfsFenceMarker), a.ops.now().UTC(), 0o644); err != nil {
- return nil, err
- }
- open := a.openRegistry
- if open == nil {
- open = func() (*registry.Registry, error) { return openSystemRegistry(a.dataDir) }
- }
- reg, err := open()
- if err != nil {
- return nil, err
- }
- defer reg.Close()
- if err := reg.FenceRuntimeAdmission(); err != nil {
- return nil, err
- }
- return rootfsRowsPresent(reg)
-}
-
-// liftRootfsFence lowers the runtime fence this applier raised, then
-// removes its marker. With no marker there is nothing to lift. A lift that
-// fails keeps the marker, and the next run's start tries again.
-func (a *systemApplier) liftRootfsFence() {
- if _, err := os.Lstat(a.file(rootfsFenceMarker)); err != nil {
- return
- }
- open := a.openRegistry
- if open == nil {
- open = func() (*registry.Registry, error) { return openSystemRegistry(a.dataDir) }
- }
- reg, err := open()
- if err == nil {
- err = reg.LiftRuntimeFence()
- reg.Close()
- }
- if err != nil {
- a.ops.logf("system apply: runtime fence: %v (kept; the next run lifts it)", err)
- return
- }
- if err := os.Remove(a.file(rootfsFenceMarker)); err != nil && !errors.Is(err, os.ErrNotExist) {
- a.ops.logf("system apply: runtime fence marker: %v", err)
- }
-}
-
// layoutReversalReasons opens the registry and lists what stands in the
// way of a release before the layout. A registry that will not open cannot
// vouch that nothing is nested, so its error is itself a reason.
diff --git a/internal/host/systemapply_rootfs_test.go b/internal/host/systemapply_rootfs_test.go
index ada654290..a18f44589 100644
--- a/internal/host/systemapply_rootfs_test.go
+++ b/internal/host/systemapply_rootfs_test.go
@@ -1,440 +1,290 @@
package host
-// The rootfs rollback floor (rootfs apps Plan 3, Task 15; spec §5.6): a box
-// that has rows with a runtime never installs a platform release that
-// cannot run them. No t.Parallel(): the floor's tests share the applier's
-// seams with the layout floor's.
+// The rootfs floor (rootfs apps Plan 3, Task 15; spec §5.6; Paul's ruling,
+// round 3): a box whose installed release runs rootfs instances
+// (release.RootfsLifecycleFloor or later) never installs a release that
+// cannot, whatever rows it has, unless the operator overrides it. No
+// t.Parallel(): the floor's tests share the applier's seams with the
+// layout floor's.
import (
"context"
- "errors"
+ "crypto/sha256"
+ "encoding/hex"
+ "fmt"
"go/ast"
"go/parser"
"go/token"
"os"
"path/filepath"
- "slices"
"strconv"
"strings"
"testing"
+ "time"
- "github.com/carlosframework/platform/internal/registry"
+ "github.com/carlosframework/platform/internal/release"
)
-// runtimeRow is a nested, always-on row with a runtime, as Plan 2 mints one.
-func runtimeRow(dataDir, host, runtime string) registry.Route {
- rt := nestedRow(dataDir, host)
- rt.Runtime, rt.Hibernate = runtime, false
- return rt
+// captureLogs collects the applier's log lines.
+func (f *applyFixture) captureLogs() *[]string {
+ var lines []string
+ logf := f.a.ops.logf
+ f.a.ops.logf = func(format string, args ...any) {
+ lines = append(lines, fmt.Sprintf(format, args...))
+ logf(format, args...)
+ }
+ return &lines
}
-// withRootfsUnit gives the fixture's candidate the rootfs instance template,
-// which every release from Plan 2 on ships.
-func (f *applyFixture) withRootfsUnit() {
+// stagedNeverRan fails the test if the candidate is ever run: a refusal by
+// version comes before anything is staged.
+func (f *applyFixture) stagedNeverRan() {
staged := filepath.Join(f.a.stagingDir(), "carlos")
- f.answer["units:"+staged] += " " + rootfsInstanceUnit
-}
-
-// countOpens wraps the fixture's openRegistry seam and counts its calls.
-func (f *applyFixture) countOpens() *int {
- n := 0
- open := f.a.openRegistry
- f.a.openRegistry = func() (*registry.Registry, error) { n++; return open() }
- return &n
+ run := f.a.ops.run
+ f.a.ops.run = func(ctx context.Context, d time.Duration, name string, args ...string) (string, error) {
+ if name == staged {
+ f.t.Errorf("a refused candidate was staged and run: %s %v", name, args)
+ }
+ return run(ctx, d, name, args...)
+ }
}
-// assertUntouched is what a refusal before the journal leaves: no journal,
-// the old binary, and systemd never stopped or restarted.
-func (f *applyFixture) assertUntouched() {
+// promoteAllowing re-promotes version with the operator's override on the
+// pointer, as `carlos system update --allow-below-rootfs-floor` does, and
+// writes the agent's request for it.
+func (f *applyFixture) promoteAllowing(version string) systemRequest {
f.t.Helper()
- if j, _ := readSystemJournal(f.a.optDir); j != nil {
- f.t.Fatalf("a refused apply wrote a journal: %+v", j)
- }
- if bin, _ := os.ReadFile(systemBinaryPath(f.a.optDir)); !strings.Contains(string(bin), "carlos v1") {
- f.t.Fatal("a refused apply swapped the binary")
+ body := []byte("#!/bin/sh\necho carlos " + version + "\n")
+ sum := sha256.Sum256(body)
+ rel := release.SystemRelease{Version: version, Artifacts: map[string]release.SystemArtifact{
+ "linux-arm64": {Key: release.SystemArtifactKey(version, "linux-arm64"), SHA256: hex.EncodeToString(sum[:])}}}
+ f.store.Put(context.Background(), rel.Artifacts["linux-arm64"].Key, body, "")
+ p, err := release.PromoteSystem(context.Background(), f.store, release.RootSigner(f.priv), "router", f.a.channel, rel,
+ release.SystemPromoteOptions{AllowBelowRootfsFloor: true})
+ if err != nil {
+ f.t.Fatal(err)
}
- if f.called("systemctl stop") || f.called("systemctl restart") {
- f.t.Fatalf("a refused apply touched systemd: %v", f.calls)
+ if !p.AllowBelowRootfsFloor {
+ f.t.Fatal("the promote did not carry the override")
}
+ req := systemRequest{Version: version, PromotedAt: p.PromotedAt, SeenAt: f.now}
+ writeJSONDurable(systemRequestPath(f.a.dataDir), req, 0o644)
+ return req
}
-func rootfsRefusalFor(version, hosts string) string {
- return "refused: " + version + " cannot run rootfs instances, and this box still has: " + hosts +
- ". delete those instances before installing it"
-}
-
-// A candidate at or above the floor that does not ship the rootfs template
-// cannot run a rootfs row, so the apply refuses it before the journal and
-// names the row. The binary row beside it is not named.
-func TestApplyRefusesACandidateWithoutRootfsUnits(t *testing.T) {
- f, req := applyHappyVersion(t, "v0.29.0")
- f.postLayout()
- dd := f.a.dataDir
- f.seedRoutes(flatRow(dd, "flat.example.com"), runtimeRow(dd, "shop.example.com", registry.RuntimeRootfsV1))
- if err := f.a.Run(context.Background(), false); err != nil {
- t.Fatal(err)
- }
- r := f.result()
- if r == nil || r.Outcome != systemOutcomeRefused || !r.matches("stable", "v0.29.0", req.PromotedAt) {
- t.Fatalf("result = %+v", r)
- }
- if want := rootfsRefusalFor("v0.29.0", "shop.example.com"); r.Reason != want {
- t.Fatalf("reason = %q\nwant %q", r.Reason, want)
- }
- f.assertUntouched()
+func rootfsFloorRefusalFor(installed, candidate string) string {
+ return "refused: this box runs " + installed + ", so it installs only v0.29.0 or later, the releases that run rootfs instances. " +
+ candidate + " is not one. to install it anyway, promote it with --allow-below-rootfs-floor"
}
-// The same candidates on a box with no row that has a runtime install as
-// they do on main: no unit set, version or registry content of a binary-only
-// box is a reason.
-func TestApplyAllowsWithoutRootfsRows(t *testing.T) {
- for _, tc := range []struct {
- name, version string
- rootfsUnit bool
- }{
- {"no rootfs unit", "v0.29.0", false},
- {"Plan 2's release", "v0.28.25", true},
- {"an unparseable version", "v2", true},
- } {
- t.Run(tc.name, func(t *testing.T) {
- f, req := applyHappyVersion(t, tc.version)
- f.postLayout()
- if tc.rootfsUnit {
- f.withRootfsUnit()
- }
- dd := f.a.dataDir
- f.seedRoutes(flatRow(dd, "flat.example.com"), nestedRow(dd, "acme.example.com"))
+// A box on the floor refuses a candidate below it and one whose version
+// does not parse, before anything is begun or staged, by version alone:
+// the box has no rootfs row at all. The refusal is terminal for that
+// promote, and its reason is the log line.
+func TestApplyRefusesBelowTheRootfsFloorOnAFloorBox(t *testing.T) {
+ for _, candidate := range []string{"v0.28.25", "v0.28.99", "4f3c2a1"} {
+ t.Run(candidate, func(t *testing.T) {
+ f, req := floorFixture(t, "v0.29.0", candidate)
+ f.seedRoutes(flatRow(f.a.dataDir, "flat.example.com"))
+ f.stagedNeverRan()
+ logs := f.captureLogs()
if err := f.a.Run(context.Background(), false); err != nil {
t.Fatal(err)
}
- if r := f.result(); r == nil || r.Outcome != systemOutcomeApplied || !r.matches("stable", tc.version, req.PromotedAt) {
- t.Fatalf("result = %+v, want applied", r)
+ r := f.result()
+ if r == nil || r.Outcome != systemOutcomeRefused || !r.matches("stable", candidate, req.PromotedAt) {
+ t.Fatalf("result = %+v", r)
}
- })
- }
-}
-
-// A candidate that ships the rootfs template at or above the floor runs
-// rootfs rows, so the floor never even opens the registry for it.
-func TestApplyAllowsACandidateWithRootfsUnits(t *testing.T) {
- for _, version := range []string{"v0.29.0", "v0.30.1", "v1.0.0"} {
- t.Run(version, func(t *testing.T) {
- f, req := applyHappyVersion(t, version)
- f.postLayout()
- f.withRootfsUnit()
- f.seedRoutes(runtimeRow(f.a.dataDir, "shop.example.com", registry.RuntimeRootfsV1))
- opened := f.countOpens()
- if err := f.a.Run(context.Background(), false); err != nil {
- t.Fatal(err)
+ want := rootfsFloorRefusalFor("v0.29.0", candidate)
+ if r.Reason != want {
+ t.Fatalf("reason = %q\nwant %q", r.Reason, want)
}
- if r := f.result(); r == nil || r.Outcome != systemOutcomeApplied || !r.matches("stable", version, req.PromotedAt) {
- t.Fatalf("result = %+v, want applied", r)
+ if !r.terminal() {
+ t.Fatal("the refusal is not terminal: the agent would ask again")
}
- if *opened != 0 {
- t.Errorf("the floor opened the registry %d times for a candidate that runs rootfs rows", *opened)
+ if !slicesContainsSubstr(*logs, want) {
+ t.Errorf("no log line carries the refusal: %v", *logs)
}
- })
- }
-}
-
-// [Astra R1 10] The unit set alone cannot tell Plan 3's lifecycle from
-// Plan 2's: Plan 2's releases ship the rootfs templates without it. So a
-// candidate with the templates and a version below the floor is refused
-// while a row has a runtime, and so is one whose version does not parse (a
-// local build named by a sha), whose unit set says nothing here. A row
-// with a runtime this build does not know is named too, and every host is
-// named once, sorted.
-func TestApplyRefusesPlan2WithRootfsUnits(t *testing.T) {
- for _, tc := range []struct {
- name, version string
- rows func(dd string) []registry.Route
- hosts string
- }{
- {"Plan 2's release", "v0.28.25", func(dd string) []registry.Route {
- return []registry.Route{flatRow(dd, "flat.example.com"), runtimeRow(dd, "shop.example.com", registry.RuntimeRootfsV1)}
- }, "shop.example.com"},
- {"just below the floor", "v0.28.99", func(dd string) []registry.Route {
- return []registry.Route{runtimeRow(dd, "shop.example.com", registry.RuntimeRootfsV1)}
- }, "shop.example.com"},
- {"an unparseable version", "4f3c2a1", func(dd string) []registry.Route {
- return []registry.Route{runtimeRow(dd, "shop.example.com", registry.RuntimeRootfsV1)}
- }, "shop.example.com"},
- {"a runtime this build does not know", "v0.28.25", func(dd string) []registry.Route {
- return []registry.Route{
- runtimeRow(dd, "shop.example.com", registry.RuntimeRootfsV1),
- runtimeRow(dd, "bab.example.com", "rootfs-v9"),
- nestedRow(dd, "acme.example.com"),
- }
- }, "bab.example.com, shop.example.com"},
- } {
- t.Run(tc.name, func(t *testing.T) {
- f, req := applyHappyVersion(t, tc.version)
- f.postLayout()
- f.withRootfsUnit()
- f.seedRoutes(tc.rows(f.a.dataDir)...)
- if err := f.a.Run(context.Background(), false); err != nil {
- t.Fatal(err)
+ if f.onDisk() != "v0.29.0" {
+ t.Fatalf("on disk %q, want v0.29.0", f.onDisk())
}
- r := f.result()
- if r == nil || r.Outcome != systemOutcomeRefused || !r.matches("stable", tc.version, req.PromotedAt) {
- t.Fatalf("result = %+v", r)
+ if j, _ := readSystemJournal(f.a.optDir); j != nil {
+ t.Fatalf("a refused apply wrote a journal: %+v", j)
}
- if want := rootfsRefusalFor(tc.version, tc.hosts); r.Reason != want {
- t.Fatalf("reason = %q\nwant %q", r.Reason, want)
+ if f.called("systemctl stop") || f.called("systemctl restart") {
+ t.Fatalf("a refused apply touched systemd: %v", f.calls)
}
- f.assertUntouched()
})
}
}
-// [Task 15 R1 2, INV-6] A registry the floor cannot read cannot vouch that
-// no row has a runtime, and it is not proof that one does either: the
-// apply is deferred, never refused, so the agent's backoff asks again. On a
-// binary-only box the same promotion then applies once the registry
-// answers. Neither a failed open nor a failed list is read as an empty box.
-func TestApplyDefersWhenTheRegistryWillNotAnswer(t *testing.T) {
- for _, tc := range []struct {
- name string
- fail func(f *applyFixture) (heal func())
- }{
- {"open fails", func(f *applyFixture) func() {
- open := f.a.openRegistry
- f.a.openRegistry = func() (*registry.Registry, error) { return nil, errors.New("registry.db: disk I/O error") }
- return func() { f.a.openRegistry = open }
- }},
- {"list fails", func(f *applyFixture) func() {
- path := filepath.Join(f.a.dataDir, "registry.db")
- good, err := os.ReadFile(path)
- if err != nil {
- f.t.Fatal(err)
- }
- open := f.a.openRegistry
- f.a.openRegistry = func() (*registry.Registry, error) {
- reg, err := open()
- if err != nil {
- return nil, err
- }
- // The fence lands, then the file stops being a database
- // before the list reads it.
- if err := reg.FenceRuntimeAdmission(); err != nil {
- f.t.Fatal(err)
- }
- for _, side := range []string{path + "-wal", path + "-shm"} {
- os.Remove(side)
- }
- if err := os.WriteFile(path, []byte(strings.Repeat("not a database ", 512)), 0o600); err != nil {
- f.t.Fatal(err)
- }
- return reg, nil
+// The operator's override lets a deliberate downgrade through, with a
+// warning in the log: on the pointer (`carlos system update
+// --allow-below-rootfs-floor`) or on `carlos system apply` itself.
+func TestApplyRootfsFloorOverrideLetsADowngradeThrough(t *testing.T) {
+ for _, via := range []string{"pointer", "flag"} {
+ t.Run(via, func(t *testing.T) {
+ f, req := floorFixture(t, "v0.29.0", "v0.28.25")
+ if via == "pointer" {
+ req = f.promoteAllowing("v0.28.25")
+ } else {
+ f.a.allowBelowRootfsFloor = true
}
- return func() {
- f.a.openRegistry = open
- for _, side := range []string{path + "-wal", path + "-shm"} {
- os.Remove(side)
- }
- if err := os.WriteFile(path, good, 0o600); err != nil {
- f.t.Fatal(err)
- }
- }
- }},
- } {
- t.Run(tc.name, func(t *testing.T) {
- f, req := applyHappyVersion(t, "v0.29.0")
- f.postLayout()
- dd := f.a.dataDir
- f.seedRoutes(flatRow(dd, "flat.example.com"), nestedRow(dd, "acme.example.com"))
- heal := tc.fail(f)
+ logs := f.captureLogs()
if err := f.a.Run(context.Background(), false); err != nil {
t.Fatal(err)
}
- r := f.result()
- if r == nil || r.Outcome != systemOutcomeDeferred || !r.matches("stable", "v0.29.0", req.PromotedAt) {
- t.Fatalf("result = %+v, want deferred", r)
+ if r := f.result(); r == nil || r.Outcome != systemOutcomeApplied || !r.matches("stable", "v0.28.25", req.PromotedAt) {
+ t.Fatalf("result = %+v, want applied", r)
}
- if r.terminal() {
- t.Fatal("a deferred result is terminal: the agent would never ask again")
+ if f.onDisk() != "v0.28.25" {
+ t.Fatalf("on disk %q, want v0.28.25", f.onDisk())
}
- f.assertUntouched()
-
- heal()
- if err := f.a.Run(context.Background(), false); err != nil {
- t.Fatal(err)
+ warn := "installing v0.28.25 below v0.29.0 with --allow-below-rootfs-floor: this box may have rootfs instances that v0.28.25 cannot run"
+ if !slicesContainsSubstr(*logs, warn) {
+ t.Errorf("no warning in the log: %v", *logs)
}
- if r := f.result(); r == nil || r.Outcome != systemOutcomeApplied || !r.matches("stable", "v0.29.0", req.PromotedAt) {
- t.Fatalf("after the registry answers: result = %+v, want applied", r)
- }
- assertFenceDown(t, f)
})
}
-}
-
-// assertFenceDown checks the runtime fence is down and root's marker gone:
-// the agent mints a row with a runtime again.
-func assertFenceDown(t *testing.T, f *applyFixture) {
- t.Helper()
- if _, err := os.Lstat(f.a.file(rootfsFenceMarker)); !errors.Is(err, os.ErrNotExist) {
- t.Fatalf("the fence marker is still there: %v", err)
- }
- reg, err := registry.Open(filepath.Join(f.a.dataDir, "registry.db"))
- if err != nil {
+ // A later promote of the same version without the override is refused
+ // again: the override belongs to the one pointer write.
+ f, _ := floorFixture(t, "v0.29.0", "v0.28.25")
+ f.promoteAllowing("v0.28.25")
+ req := f.promote("v0.28.25", []byte("#!/bin/sh\necho carlos v0.28.25\n"), false)
+ if err := f.a.Run(context.Background(), false); err != nil {
t.Fatal(err)
}
- defer reg.Close()
- if err := reg.Upsert(runtimeRow(f.a.dataDir, "after.example.com", registry.RuntimeRootfsV1)); err != nil {
- t.Fatalf("a mint after the apply: %v", err)
+ if r := f.result(); r == nil || r.Outcome != systemOutcomeRefused || !r.matches("stable", "v0.28.25", req.PromotedAt) {
+ t.Fatalf("a promote after the overriding one = %+v, want refused", r)
}
}
-// [Task 15 R1 1] The agent mints the box's first row with a runtime
-// between the floor's check and the executable's replacement. The fence
-// is up from before the check to after the gate, so the mint is refused
-// and the installed release never meets a row it cannot run. Once the
-// install is over the fence is down and the same mint lands.
-func TestApplyFencesAMintBetweenTheCheckAndTheReplacement(t *testing.T) {
- f, req := applyHappyVersion(t, "v0.28.25")
- f.postLayout()
- f.withRootfsUnit()
- dd := f.a.dataDir
- f.seedRoutes(flatRow(dd, "flat.example.com"))
- var mintErr error
- minted := false
- f.a.beforeSwap = func() {
- minted = true
- reg, err := registry.Open(filepath.Join(dd, "registry.db"))
- if err != nil {
- t.Fatal(err)
- }
- defer reg.Close()
- mintErr = reg.Upsert(runtimeRow(dd, "shop.example.com", registry.RuntimeRootfsV1))
+// A box below the floor installs as on main, Plan 2's release included,
+// and so does one whose own version does not parse. A box on the floor
+// installs any release at or above it, older ones included.
+func TestApplyRootfsFloorAllowsAsOnMain(t *testing.T) {
+ for _, tc := range []struct{ installed, candidate string }{
+ {"v0.28.24", "v0.28.25"},
+ {"v0.28.26", "v0.28.25"},
+ {"v0.28.25", "4f3c2a1"},
+ {"v0.29.0", "v0.29.1"},
+ {"v0.30.0", "v0.29.0"},
+ } {
+ t.Run(tc.installed+"->"+tc.candidate, func(t *testing.T) {
+ f, req := floorFixture(t, tc.installed, tc.candidate)
+ if err := f.a.Run(context.Background(), false); err != nil {
+ t.Fatal(err)
+ }
+ if r := f.result(); r == nil || r.Outcome != systemOutcomeApplied || !r.matches("stable", tc.candidate, req.PromotedAt) {
+ t.Fatalf("result = %+v, want applied", r)
+ }
+ })
}
+ // An installed version that does not parse (a local build): as on main.
+ f, req := applyHappyVersion(t, "v0.28.25")
if err := f.a.Run(context.Background(), false); err != nil {
t.Fatal(err)
}
- if !minted {
- t.Fatal("the apply never reached the replacement")
- }
- if !errors.Is(mintErr, registry.ErrRuntimeFenced) {
- t.Fatalf("the mint between the check and the replacement = %v, want ErrRuntimeFenced", mintErr)
- }
if r := f.result(); r == nil || r.Outcome != systemOutcomeApplied || !r.matches("stable", "v0.28.25", req.PromotedAt) {
- t.Fatalf("result = %+v, want applied", r)
- }
- reg, err := registry.Open(filepath.Join(dd, "registry.db"))
- if err != nil {
- t.Fatal(err)
+ t.Fatalf("a local build installing v0.28.25 = %+v, want applied", r)
}
- if rt, err := reg.Get("shop.example.com"); err != nil || rt != nil {
- t.Fatalf("the fenced mint left a row: %+v, %v", rt, err)
- }
- reg.Close()
- assertFenceDown(t, f)
}
-// A fence a run raised and never lifted (it stopped mid-install) comes
-// down at the next run's start once no journal is open.
-func TestApplyLiftsAStaleFenceAtTheNextRun(t *testing.T) {
- f, _ := applyHappyVersion(t, "v0.29.0")
- f.withRootfsUnit()
- if err := writeJSONDurable(f.a.file(rootfsFenceMarker), f.now, 0o644); err != nil {
- t.Fatal(err)
- }
- reg, err := registry.Open(filepath.Join(f.a.dataDir, "registry.db"))
- if err != nil {
- t.Fatal(err)
- }
- if err := reg.FenceRuntimeAdmission(); err != nil {
- t.Fatal(err)
- }
- reg.Close()
+// When the installed binary cannot be asked its version, this process's
+// own build (the installed binary runs the apply) stands in, so a floor
+// box still refuses.
+func TestApplyRootfsFloorFallsBackToThisBuild(t *testing.T) {
+ f, req := floorFixture(t, "v0.29.0", "v0.28.25")
+ os.WriteFile(systemBinaryPath(f.a.optDir), []byte("#!/bin/sh\nexit 1\n"), 0o755)
+ f.a.build = "v0.29.0"
if err := f.a.Run(context.Background(), false); err != nil {
t.Fatal(err)
}
- assertFenceDown(t, f)
+ r := f.result()
+ if r == nil || r.Outcome != systemOutcomeRefused || !r.matches("stable", "v0.28.25", req.PromotedAt) ||
+ r.Reason != rootfsFloorRefusalFor("v0.29.0", "v0.28.25") {
+ t.Fatalf("result = %+v, want the floor's refusal", r)
+ }
}
-// rootfsRowsPresent names every row with any non-empty runtime, once and
-// sorted, and a registry it cannot list is an error, never an empty box.
-func TestRootfsRowsPresentNamesEveryRuntimeRow(t *testing.T) {
- dd := t.TempDir()
- reg, err := registry.Open(filepath.Join(dd, "registry.db"))
- if err != nil {
- t.Fatal(err)
- }
- for _, rt := range []registry.Route{
- flatRow(dd, "flat.example.com"),
- runtimeRow(dd, "shop.example.com", registry.RuntimeRootfsV1),
- runtimeRow(dd, "bab.example.com", "rootfs-v9"),
- nestedRow(dd, "acme.example.com"),
- } {
- if err := reg.Upsert(rt); err != nil {
- t.Fatal(err)
+// The gate's automatic rollback never meets the floor: a floor box whose
+// install fails its gate goes back to .prev, and a rollback whose .prev is
+// below the floor restores it all the same (rollback and restoreFiles do
+// not pass through rootfsFloorRefusal).
+func TestRootfsFloorLeavesTheAutomaticRollbackAlone(t *testing.T) {
+ f, req := floorFixture(t, "v0.29.0", "v0.29.1")
+ // v0.29.1 never comes up; v0.29.0 does once it is back on disk.
+ f.edgeUp = false
+ orig := f.a.ops.systemctl
+ f.a.ops.systemctl = func(args ...string) (string, error) {
+ if args[0] == "restart" {
+ if b, _ := os.ReadFile(systemBinaryPath(f.a.optDir)); strings.Contains(string(b), "carlos v0.29.0\n") {
+ f.edgeUp = true
+ }
}
+ return orig(args...)
}
- hosts, err := rootfsRowsPresent(reg)
- if err != nil || !slices.Equal(hosts, []string{"bab.example.com", "shop.example.com"}) {
- t.Fatalf("rootfsRowsPresent = %v, %v", hosts, err)
+ if err := f.a.Run(context.Background(), false); err == nil {
+ t.Fatal("a failed gate must exit non-zero")
}
- // List reads through a fresh connection on the file, so a file that is
- // no longer a database is a registry that cannot be listed.
- reg.Close()
- path := filepath.Join(dd, "registry.db")
- for _, side := range []string{path + "-wal", path + "-shm"} {
- if err := os.Remove(side); err != nil && !errors.Is(err, os.ErrNotExist) {
- t.Fatal(err)
- }
+ if r := f.result(); r == nil || r.Outcome != systemOutcomeRolledBack || !r.matches("stable", "v0.29.1", req.PromotedAt) {
+ t.Fatalf("result = %+v, want rolled back", r)
}
- if err := os.WriteFile(path, []byte(strings.Repeat("not a database ", 512)), 0o600); err != nil {
- t.Fatal(err)
+ if f.onDisk() != "v0.29.0" {
+ t.Fatalf("on disk %q after the rollback, want v0.29.0", f.onDisk())
+ }
+
+ f, req = floorFixture(t, "v0.29.0", "v0.29.1")
+ j := f.brokenBox("v0.29.1", "v0.28.25", "")
+ f.a.rollback(context.Background(), req, "gate: test", &j)
+ if r := f.result(); r == nil || r.Outcome != systemOutcomeRolledBack || f.onDisk() != "v0.28.25" {
+ t.Fatalf("rollback to a below-floor .prev: result %+v, on disk %q", r, f.onDisk())
}
- if hosts, err := rootfsRowsPresent(reg); err == nil {
- t.Fatalf("an unreadable registry listed as %v", hosts)
+}
+
+func slicesContainsSubstr(lines []string, s string) bool {
+ for _, l := range lines {
+ if strings.Contains(l, s) {
+ return true
+ }
}
+ return false
}
// [pf 4.2] Root reads SQLite only through the service-user child. The
-// census stood in for that rule; this test does now. systemapply.go names
+// census stood in for that rule; this test does now: systemapply.go names
// no registry opener of its own (registry.Open or OpenReadOnly, called or
-// passed as a value), and the one caller of rootfsRowsPresent hands it the
-// *Registry the openRegistry seam returned, whose default is
-// openSystemRegistry.
+// passed as a value, under any import name).
func TestSystemApplyOpensNoRegistryItself(t *testing.T) {
fset := token.NewFileSet()
f, err := parser.ParseFile(fset, "systemapply.go", nil, 0)
if err != nil {
t.Fatal(err)
}
- if problems := systemApplyRegistryProblems(fset, f); len(problems) > 0 {
+ if problems := registryOpeners(fset, f); len(problems) > 0 {
t.Fatalf("systemapply.go:\n%s", strings.Join(problems, "\n"))
}
- // The guard catches what it looks for.
for name, src := range map[string]string{
"a direct open": `package host
import "github.com/carlosframework/platform/internal/registry"
-func (a *systemApplier) x() { registry.Open("p") }
-func (a *systemApplier) y() { open := a.openRegistry; reg, _ := open(); rootfsRowsPresent(reg) }`,
- "a renamed import": `package host
+func x() { registry.Open("p") }`,
+ "a renamed import, as a value": `package host
import reg "github.com/carlosframework/platform/internal/registry"
-var o = reg.OpenReadOnly
-func (a *systemApplier) y() { open := a.openRegistry; r, _ := open(); rootfsRowsPresent(r) }`,
- "a registry from elsewhere": `package host
-func (a *systemApplier) y(r *registry.Registry) { rootfsRowsPresent(r) }`,
- "no caller": `package host
-func (a *systemApplier) y() {}`,
+var o = reg.OpenReadOnly`,
} {
fx, err := parser.ParseFile(fset, name+".go", src, 0)
if err != nil {
t.Fatal(err)
}
- if len(systemApplyRegistryProblems(fset, fx)) == 0 {
+ if len(registryOpeners(fset, fx)) == 0 {
t.Errorf("%s: the guard reported nothing", name)
}
}
}
-// systemApplyRegistryProblems is the guard's reading of one file.
-func systemApplyRegistryProblems(fset *token.FileSet, f *ast.File) []string {
+// registryOpeners names every registry.Open* selector in f.
+func registryOpeners(fset *token.FileSet, f *ast.File) []string {
const regPath = "github.com/carlosframework/platform/internal/registry"
- var problems []string
regName := ""
for _, imp := range f.Imports {
if p, _ := strconv.Unquote(imp.Path.Value); p == regPath {
@@ -444,6 +294,7 @@ func systemApplyRegistryProblems(fset *token.FileSet, f *ast.File) []string {
}
}
}
+ var problems []string
ast.Inspect(f, func(n ast.Node) bool {
sel, ok := n.(*ast.SelectorExpr)
if !ok {
@@ -454,58 +305,5 @@ func systemApplyRegistryProblems(fset *token.FileSet, f *ast.File) []string {
}
return true
})
- callers := 0
- for _, d := range f.Decls {
- fd, ok := d.(*ast.FuncDecl)
- if !ok || fd.Body == nil {
- continue
- }
- // Which identifiers hold the seam, and which hold what it returned.
- seam, fromSeam := map[string]bool{}, map[string]bool{}
- ast.Inspect(fd.Body, func(n ast.Node) bool {
- as, ok := n.(*ast.AssignStmt)
- if !ok || len(as.Rhs) != 1 {
- return true
- }
- switch rhs := as.Rhs[0].(type) {
- case *ast.SelectorExpr:
- if rhs.Sel.Name == "openRegistry" {
- for _, l := range as.Lhs {
- if id, ok := l.(*ast.Ident); ok {
- seam[id.Name] = true
- }
- }
- }
- case *ast.CallExpr:
- if id, ok := rhs.Fun.(*ast.Ident); ok && seam[id.Name] && len(as.Lhs) > 0 {
- if l, ok := as.Lhs[0].(*ast.Ident); ok {
- fromSeam[l.Name] = true
- }
- }
- }
- return true
- })
- ast.Inspect(fd.Body, func(n ast.Node) bool {
- call, ok := n.(*ast.CallExpr)
- if !ok {
- return true
- }
- if id, ok := call.Fun.(*ast.Ident); !ok || id.Name != "rootfsRowsPresent" {
- return true
- }
- callers++
- if len(call.Args) != 1 {
- problems = append(problems, fset.Position(call.Pos()).String()+": rootfsRowsPresent takes one argument")
- return true
- }
- if arg, ok := call.Args[0].(*ast.Ident); !ok || !fromSeam[arg.Name] {
- problems = append(problems, fset.Position(call.Pos()).String()+": rootfsRowsPresent is not handed the openRegistry seam's *Registry")
- }
- return true
- })
- }
- if callers != 1 {
- problems = append(problems, "rootfsRowsPresent has "+strconv.Itoa(callers)+" callers, want 1")
- }
return problems
}
diff --git a/internal/host/systemapply_test.go b/internal/host/systemapply_test.go
index 971606826..3df36d191 100644
--- a/internal/host/systemapply_test.go
+++ b/internal/host/systemapply_test.go
@@ -1564,13 +1564,10 @@ func TestApplyInstallsAPreLayoutCandidateOverFlatRows(t *testing.T) {
}
// A candidate that ships the mount units understands nested rows, so the
-// guard never even opens the registry for it. It also runs rootfs rows
-// (the rootfs template, at RootfsLifecycleFloor), so the rootfs floor
-// does not open it either.
+// guard never even opens the registry for it.
func TestApplyInstallsAPostLayoutCandidateOverNestedRows(t *testing.T) {
- f, req := applyHappyVersion(t, "v0.29.0")
+ f, req := applyHappy(t)
f.postLayout()
- f.withRootfsUnit()
f.seedRoutes(nestedRow(f.a.dataDir, "acme.example.com"))
opened := false
f.a.openRegistry = func() (*registry.Registry, error) {
@@ -1580,7 +1577,7 @@ func TestApplyInstallsAPostLayoutCandidateOverNestedRows(t *testing.T) {
if err := f.a.Run(context.Background(), false); err != nil {
t.Fatal(err)
}
- if r := f.result(); r == nil || r.Outcome != systemOutcomeApplied || !r.matches("stable", "v0.29.0", req.PromotedAt) {
+ if r := f.result(); r == nil || r.Outcome != systemOutcomeApplied || !r.matches("stable", "v2", req.PromotedAt) {
t.Fatalf("result = %+v", r)
}
if opened {
@@ -1718,10 +1715,7 @@ func floorFixture(t *testing.T, running, target string) (*applyFixture, systemRe
bin, staged, prev := systemBinaryPath(f.a.optDir), filepath.Join(f.a.stagingDir(), "carlos"), systemPrevPath(f.a.optDir)
f.answer["version:"+staged] = "carlos " + target + "\n"
f.answer["plan:"+staged] = f.answer["plan:"+bin]
- // The candidate is of the floor's era: it ships the layout and the rootfs
- // lifecycle (every target here is at or above RootfsLifecycleFloor), so
- // neither the layout floor nor the rootfs floor opens the registry.
- f.answer["units:"+staged] = f.answer["units:"+bin] + " " + layoutMountUnit + " " + rootfsInstanceUnit
+ f.answer["units:"+staged] = f.answer["units:"+bin] + " " + layoutMountUnit
f.answer["plan:"+prev] = f.answer["plan:"+bin]
f.answer["units:"+prev] = f.answer["units:"+bin]
// Every binary answers `version` from its own bytes from here on.
diff --git a/internal/registry/registry.go b/internal/registry/registry.go
index 18e9e2e8f..6a98d1a38 100644
--- a/internal/registry/registry.go
+++ b/internal/registry/registry.go
@@ -716,11 +716,6 @@ CREATE TABLE IF NOT EXISTS routes (
return err
}
}
- // The runtime admission fence (runtimefence.go): after the runtime
- // column, which its triggers read.
- if err := r.migrateRuntimeFence(); err != nil {
- return err
- }
// route_aliases is a derived table (a later reconcile pass owns every
// row, materializing domains.Claim records into it) — a plain CREATE
// TABLE IF NOT EXISTS, no legacy shape to carry forward.
@@ -1441,7 +1436,7 @@ WHERE routes.claim_incarnation=excluded.claim_incarnation AND routes.claim_stamp
AND routes.claim_owner=excluded.claim_owner AND routes.claim_row_id=excluded.claim_row_id`+guard,
routeArgs(normalizeRoute(t))...)
if err != nil {
- return runtimeFenced(err)
+ return err
}
n, err := res.RowsAffected()
if err == nil && n != 1 {
diff --git a/internal/registry/registry_test.go b/internal/registry/registry_test.go
index 27c1767c5..049c2ea34 100644
--- a/internal/registry/registry_test.go
+++ b/internal/registry/registry_test.go
@@ -3101,11 +3101,6 @@ func TestMigrateAddsRuntimeToTheImmediatelyPreviousSchema(t *testing.T) {
if err != nil {
t.Fatal(err)
}
- // A pre-runtime registry has no runtime fence either: its triggers
- // read the column, so they go first.
- if _, err := old.Exec(`DROP TRIGGER runtime_fence_insert; DROP TRIGGER runtime_fence_update; DROP TABLE runtime_fence`); err != nil {
- t.Fatalf("simulate a pre-runtime registry: %v", err)
- }
if _, err := old.Exec(`ALTER TABLE routes DROP COLUMN runtime`); err != nil {
t.Fatalf("simulate a pre-runtime registry: %v", err)
}
@@ -3124,13 +3119,6 @@ func TestMigrateAddsRuntimeToTheImmediatelyPreviousSchema(t *testing.T) {
if !routesHasColumn(t, reg, "runtime") {
t.Errorf("no runtime column after Open")
}
- // The fence's triggers come back with the column they read.
- if err := reg.FenceRuntimeAdmission(); err != nil {
- t.Fatal(err)
- }
- if err := reg.Upsert(Route{Host: "bab.example.com", Kind: "instance", App: "shop", Runtime: RuntimeRootfsV1}); !errors.Is(err, ErrRuntimeFenced) {
- t.Errorf("a fenced mint after migration = %v, want ErrRuntimeFenced", err)
- }
}
func routesHasColumn(t *testing.T, reg *Registry, name string) bool {
diff --git a/internal/registry/remote.go b/internal/registry/remote.go
index d80ed06cb..0273300cb 100644
--- a/internal/registry/remote.go
+++ b/internal/registry/remote.go
@@ -14,7 +14,7 @@ import (
var errRemoteMethod = errors.New("registry: unsupported remote operation")
-var remoteErrors = []error{os.ErrNotExist, os.ErrPermission, sql.ErrNoRows, ErrClaimOwnership, ErrTimerChanged, ErrTimerKind, ErrPathsChanged, ErrFleetBoxActive, context.Canceled, context.DeadlineExceeded, ErrGoodBuildChanged, ErrRuntimeFixed, ErrRootfsRow, ErrRuntimePlacement, ErrRuntimeFenced}
+var remoteErrors = []error{os.ErrNotExist, os.ErrPermission, sql.ErrNoRows, ErrClaimOwnership, ErrTimerChanged, ErrTimerKind, ErrPathsChanged, ErrFleetBoxActive, context.Canceled, context.DeadlineExceeded, ErrGoodBuildChanged, ErrRuntimeFixed, ErrRootfsRow, ErrRuntimePlacement}
func responseError(out remoteResponse) error {
if !out.Failed {
diff --git a/internal/registry/remote_dispatch.go b/internal/registry/remote_dispatch.go
index 53577f531..3a07b1c55 100644
--- a/internal/registry/remote_dispatch.go
+++ b/internal/registry/remote_dispatch.go
@@ -235,10 +235,6 @@ func (r *Registry) dispatchRemote(ctx context.Context, q remoteRequest, callback
out.Changed, err = r.DeleteIfHoldWithTimers(q.Host, q.Op)
case "HoldRows":
out.Routes, err = r.HoldRows()
- case "FenceRuntimeAdmission":
- err = r.FenceRuntimeAdmission()
- case "LiftRuntimeFence":
- err = r.LiftRuntimeFence()
case "WithHoldsFrozen":
err = r.WithHoldsFrozen(func(held []Route) error { return callback(remoteResponse{Callback: "holds", Held: held}) })
case "SetAccount":
diff --git a/internal/registry/runtimefence.go b/internal/registry/runtimefence.go
deleted file mode 100644
index f5c956f3a..000000000
--- a/internal/registry/runtimefence.go
+++ /dev/null
@@ -1,76 +0,0 @@
-package registry
-
-import (
- "errors"
- "strings"
-)
-
-// The runtime admission fence (rootfs apps Plan 3, Task 15 round 1). Root's
-// `carlos system apply` raises it before it checks whether the box has a
-// row with a runtime, and lifts it once the installed release's agent has
-// taken over or the apply has stopped. While it is up, SQLite itself
-// refuses every write that would give the routes table a row with a
-// runtime: an INSERT of one (an upsert over a row that already has that
-// runtime is not one: SQLite runs the INSERT trigger before it finds the
-// conflict), and an UPDATE that sets a row's runtime to another non-empty
-// value. The triggers are the one admission point, so
-// every writer (a reconcile mint, an import swap, a cold handover, an
-// upsert that re-tenants a host) is refused alike, and SQLite's single
-// writer orders each of them against the fence: one that committed before
-// the fence is in the check that follows it, and one that comes after is
-// refused.
-
-// runtimeFencedMessage is the triggers' abort text. It is spliced into
-// their SQL, so it holds no quote.
-const runtimeFencedMessage = "registry: a platform update is checking this box for rows with a runtime; a new one waits for it"
-
-// ErrRuntimeFenced is a write the runtime fence refused. One of
-// remoteErrors.
-var ErrRuntimeFenced = errors.New(runtimeFencedMessage)
-
-func (r *Registry) migrateRuntimeFence() error {
- _, err := r.sql.Exec(`
-CREATE TABLE IF NOT EXISTS runtime_fence (
- id INTEGER PRIMARY KEY CHECK (id = 1),
- since INTEGER NOT NULL
-);
-CREATE TRIGGER IF NOT EXISTS runtime_fence_insert BEFORE INSERT ON routes
-WHEN NEW.runtime != '' AND EXISTS (SELECT 1 FROM runtime_fence)
- AND NOT EXISTS (SELECT 1 FROM routes WHERE host = NEW.host AND runtime = NEW.runtime)
-BEGIN SELECT RAISE(ABORT, '` + runtimeFencedMessage + `'); END;
-CREATE TRIGGER IF NOT EXISTS runtime_fence_update BEFORE UPDATE OF runtime ON routes
-WHEN NEW.runtime != '' AND NEW.runtime != OLD.runtime AND EXISTS (SELECT 1 FROM runtime_fence)
-BEGIN SELECT RAISE(ABORT, '` + runtimeFencedMessage + `'); END;`)
- return err
-}
-
-// runtimeFenced maps the triggers' abort to ErrRuntimeFenced.
-func runtimeFenced(err error) error {
- if err != nil && strings.Contains(err.Error(), runtimeFencedMessage) && !errors.Is(err, ErrRuntimeFenced) {
- return errors.Join(ErrRuntimeFenced, err)
- }
- return err
-}
-
-// FenceRuntimeAdmission raises the fence. It is committed when it returns,
-// so a read that starts after it sees every row with a runtime the box
-// will have until LiftRuntimeFence.
-func (r *Registry) FenceRuntimeAdmission() error {
- if r.remote != nil {
- _, err := r.remote.call(nil, remoteRequest{Method: "FenceRuntimeAdmission"}, nil)
- return err
- }
- _, err := r.sql.Exec(`INSERT INTO runtime_fence (id, since) VALUES (1, unixepoch()) ON CONFLICT(id) DO NOTHING`)
- return err
-}
-
-// LiftRuntimeFence lowers the fence; lifting a fence that is down is not an
-// error.
-func (r *Registry) LiftRuntimeFence() error {
- if r.remote != nil {
- _, err := r.remote.call(nil, remoteRequest{Method: "LiftRuntimeFence"}, nil)
- return err
- }
- _, err := r.sql.Exec(`DELETE FROM runtime_fence`)
- return err
-}
diff --git a/internal/registry/runtimefence_test.go b/internal/registry/runtimefence_test.go
deleted file mode 100644
index d127bb56d..000000000
--- a/internal/registry/runtimefence_test.go
+++ /dev/null
@@ -1,119 +0,0 @@
-package registry
-
-import (
- "errors"
- "path/filepath"
- "testing"
-)
-
-func fenceTestRoute(host, runtime string) Route {
- return Route{Host: host, Kind: "instance", App: "shop", Status: "ready", Runtime: runtime}
-}
-
-// While the fence is up, no write gives the routes table a row with a
-// runtime: not an upsert's insert, not an upsert that re-tenants a binary
-// host onto a runtime, not a raw INSERT (the import swap's and the cold
-// handover's statements). Binary rows and a runtime row's other columns
-// still write. Lifted, the same mint lands.
-func TestRuntimeFenceRefusesEveryRuntimeAdmission(t *testing.T) {
- t.Parallel()
- reg, err := Open(filepath.Join(t.TempDir(), "registry.db"))
- if err != nil {
- t.Fatal(err)
- }
- defer reg.Close()
- if err := reg.Upsert(fenceTestRoute("old.example.com", RuntimeRootfsV1)); err != nil {
- t.Fatal(err)
- }
- if err := reg.Upsert(fenceTestRoute("bin.example.com", "")); err != nil {
- t.Fatal(err)
- }
- if err := reg.FenceRuntimeAdmission(); err != nil {
- t.Fatal(err)
- }
- if err := reg.FenceRuntimeAdmission(); err != nil {
- t.Fatalf("a second raise: %v", err)
- }
-
- if err := reg.Upsert(fenceTestRoute("shop.example.com", RuntimeRootfsV1)); !errors.Is(err, ErrRuntimeFenced) {
- t.Fatalf("a fenced mint = %v, want ErrRuntimeFenced", err)
- }
- if err := reg.Upsert(fenceTestRoute("bab.example.com", "rootfs-v9")); !errors.Is(err, ErrRuntimeFenced) {
- t.Fatalf("a fenced mint of an unknown runtime = %v, want ErrRuntimeFenced", err)
- }
- retenant := fenceTestRoute("bin.example.com", RuntimeRootfsV1)
- retenant.App = "other"
- if err := reg.Upsert(retenant); !errors.Is(err, ErrRuntimeFenced) {
- t.Fatalf("a fenced re-tenancy onto a runtime = %v, want ErrRuntimeFenced", err)
- }
- if _, err := reg.sql.Exec(`INSERT INTO routes (`+routeCols+`) VALUES (`+placeholders(routeColCount)+`)`,
- routeArgs(normalizeRoute(fenceTestRoute("raw.example.com", RuntimeRootfsV1)))...); err == nil {
- t.Fatal("a raw INSERT of a runtime row went past the fence")
- }
- // An UPDATE that gives a binary row a runtime, or a row another one.
- for _, q := range []string{
- `UPDATE routes SET runtime = 'rootfs-v1' WHERE host = 'bin.example.com'`,
- `UPDATE routes SET runtime = 'rootfs-v9' WHERE host = 'old.example.com'`,
- } {
- if _, err := reg.sql.Exec(q); err == nil {
- t.Fatalf("%s went past the fence", q)
- }
- }
- if rt, err := reg.Get("old.example.com"); err != nil || rt == nil || rt.Runtime != RuntimeRootfsV1 {
- t.Fatalf("the runtime row changed runtime under the fence: %+v, %v", rt, err)
- }
- for _, h := range []string{"shop.example.com", "bab.example.com", "raw.example.com"} {
- if rt, err := reg.Get(h); err != nil || rt != nil {
- t.Fatalf("%s: %+v, %v; want no row", h, rt, err)
- }
- }
- if rt, err := reg.Get("bin.example.com"); err != nil || rt == nil || rt.Runtime != "" || rt.App != "shop" {
- t.Fatalf("the re-tenanted host changed under the fence: %+v, %v", rt, err)
- }
-
- // Binary rows and the runtime row that was already there still write.
- if err := reg.Upsert(fenceTestRoute("new.example.com", "")); err != nil {
- t.Fatalf("a binary mint under the fence: %v", err)
- }
- same := fenceTestRoute("old.example.com", RuntimeRootfsV1)
- same.Status = "stopped"
- if err := reg.Upsert(same); err != nil {
- t.Fatalf("a runtime row's own upsert under the fence: %v", err)
- }
-
- if err := reg.LiftRuntimeFence(); err != nil {
- t.Fatal(err)
- }
- if err := reg.LiftRuntimeFence(); err != nil {
- t.Fatalf("a second lift: %v", err)
- }
- if err := reg.Upsert(fenceTestRoute("shop.example.com", RuntimeRootfsV1)); err != nil {
- t.Fatalf("the mint after the lift: %v", err)
- }
-}
-
-// Root raises and lifts the fence through the service-user child, and the
-// refusal keeps its identity across it.
-func TestRemoteRuntimeFence(t *testing.T) {
- r, path := remoteTestRegistry(t)
- if err := r.FenceRuntimeAdmission(); err != nil {
- t.Fatal(err)
- }
- if err := r.Upsert(fenceTestRoute("shop.example.com", RuntimeRootfsV1)); !errors.Is(err, ErrRuntimeFenced) {
- t.Fatalf("a fenced mint through the child = %v, want ErrRuntimeFenced", err)
- }
- local, err := Open(path)
- if err != nil {
- t.Fatal(err)
- }
- defer local.Close()
- if err := local.Upsert(fenceTestRoute("shop.example.com", RuntimeRootfsV1)); !errors.Is(err, ErrRuntimeFenced) {
- t.Fatalf("the agent's own fenced mint = %v, want ErrRuntimeFenced", err)
- }
- if err := r.LiftRuntimeFence(); err != nil {
- t.Fatal(err)
- }
- if err := local.Upsert(fenceTestRoute("shop.example.com", RuntimeRootfsV1)); err != nil {
- t.Fatalf("the mint after the lift: %v", err)
- }
-}
diff --git a/internal/release/layoutintent.go b/internal/release/layoutintent.go
index f5d15450e..8f6d79b20 100644
--- a/internal/release/layoutintent.go
+++ b/internal/release/layoutintent.go
@@ -213,18 +213,41 @@ var LayoutFloor = SemVer{Major: 0, Minor: 25, Patch: 0}
// RootfsLifecycleFloor is the first platform release that runs rootfs
// instances' lifecycle (rootfs apps Plan 3, Group A: resident rows, the
// rootfs swap, carlos run). Plan 2's releases (v0.28.17 on) already ship
-// the rootfs unit templates without it, so the unit set cannot tell the
-// two apart, as with LayoutFloor. The latest tag at the time of writing is
+// the rootfs unit templates without it, so only the version tells the
+// two apart. The latest tag at the time of writing is
// v0.28.25, and v0.28.x releases are still cut from a main without Group
// A, so this names a minor bump: the first release cut from a main that
// contains Group A MUST be v0.29.0, and no release without Group A may be
// numbered v0.29.0 or later.
//
-// The box-side guard (host/systemapply.go) refuses a candidate below this
-// floor, or whose version does not parse, while the box has a row with a
-// runtime. TestRootfsLifecycleFloorIsPinned pins it.
+// The box-side guard (host/systemapply.go): a box whose installed release
+// is at or above this floor refuses a candidate below it, or whose version
+// does not parse, whatever rows the box has (Paul's ruling, Task 15 round
+// 3), unless the operator passes RootfsFloorOverrideFlag.
+// TestRootfsLifecycleFloorIsPinned pins it.
var RootfsLifecycleFloor = SemVer{Major: 0, Minor: 29, Patch: 0}
+// RootfsFloorOverrideFlag is the override's flag name, on `carlos system
+// update` and `carlos system apply`.
+const RootfsFloorOverrideFlag = "allow-below-rootfs-floor"
+
+// RootfsFloorOverrideUsage (RFS-3-C32) is the override flag's help text,
+// shared by both commands.
+const RootfsFloorOverrideUsage = "install a release below v0.29.0 on boxes running v0.29.0 or later, which may have rootfs instances that release cannot run"
+
+// RootfsFloorAllows reports whether a box running installed may install
+// candidate under the rootfs floor without the override: always on a box
+// below the floor (or whose own version does not parse), and on one at or
+// above it only a candidate whose version parses at or above it.
+func RootfsFloorAllows(installed, candidate string) bool {
+ in, ok := ParseReleaseVersion(installed)
+ if !ok || in.Compare(RootfsLifecycleFloor) < 0 {
+ return true
+ }
+ c, ok := ParseReleaseVersion(candidate)
+ return ok && c.Compare(RootfsLifecycleFloor) >= 0
+}
+
// ParseReleaseVersion parses a release tag with or without its leading v.
func ParseReleaseVersion(version string) (SemVer, bool) {
return ParseSemVer(strings.TrimPrefix(version, "v"))
diff --git a/internal/release/layoutintent_test.go b/internal/release/layoutintent_test.go
index f8ef9ac26..6d9f7a44a 100644
--- a/internal/release/layoutintent_test.go
+++ b/internal/release/layoutintent_test.go
@@ -6,6 +6,7 @@ package release
import (
"context"
+ "strings"
"testing"
)
@@ -133,8 +134,7 @@ func TestLayoutFloorIsTheFirstReleaseWhereNestedRowsWake(t *testing.T) {
// TestRootfsLifecycleFloorIsPinned pins the first release that runs rootfs
// instances' lifecycle (rootfs apps Plan 3, Group A). Plan 2's releases
// (v0.28.17 on) already ship the rootfs unit templates, so the box-side
-// rollback floor (host/systemapply.go) needs a version as well as the unit
-// set. The latest tag at the time of writing is v0.28.25, and releases
+// floor (host/systemapply.go) judges by version alone. The latest tag at the time of writing is v0.28.25, and releases
// were still being cut from a main without Group A, so the floor is a
// minor bump: the first release cut from a main that contains Group A MUST
// be v0.29.0, and no release without Group A may be numbered v0.29.0 or
@@ -151,6 +151,29 @@ func TestRootfsLifecycleFloorIsPinned(t *testing.T) {
}
}
+// RootfsFloorAllows is the box-side rule by version alone (Task 15 round
+// 3): a box below the floor, or whose own version does not parse, installs
+// anything; one at or above it only a parseable candidate at or above it.
+func TestRootfsFloorAllows(t *testing.T) {
+ for _, c := range []struct {
+ installed, candidate string
+ want bool
+ }{
+ {"v0.28.24", "v0.28.25", true}, {"v0.28.25", "abc123", true}, {"dev", "v0.20.0", true}, {"", "v0.20.0", true},
+ {"v0.29.0", "v0.29.0", true}, {"v0.29.0", "v0.30.1", true}, {"v0.31.0", "v0.29.0", true},
+ {"v0.29.0", "v0.28.25", false}, {"v0.29.0", "v0.28.99", false}, {"v1.0.0", "v0.28.0", false},
+ {"v0.29.0", "abc123", false}, {"v0.29.0", "", false}, {"0.29.0", "v0.29", false},
+ } {
+ if got := RootfsFloorAllows(c.installed, c.candidate); got != c.want {
+ t.Errorf("RootfsFloorAllows(%q, %q) = %v, want %v", c.installed, c.candidate, got, c.want)
+ }
+ }
+ // The flag's help names the floor it overrides.
+ if !strings.Contains(RootfsFloorOverrideUsage, "v"+RootfsLifecycleFloor.String()) {
+ t.Errorf("RootfsFloorOverrideUsage %q does not name v%s", RootfsFloorOverrideUsage, RootfsLifecycleFloor)
+ }
+}
+
func TestRecordLayoutIntentAppendsWithForceAndScope(t *testing.T) {
s := NewDirStore(t.TempDir())
ctx := context.Background()
diff --git a/internal/release/systempointer.go b/internal/release/systempointer.go
index 117f5af25..116220b13 100644
--- a/internal/release/systempointer.go
+++ b/internal/release/systempointer.go
@@ -29,6 +29,12 @@ type SystemPointer struct {
Spread string `json:"spread"`
PromotedAt time.Time `json:"promoted_at"` // of THIS write; the box's replay guard reads only this
Audit []Promotion `json:"audit,omitempty"`
+ // AllowBelowRootfsFloor is the operator's override of the rootfs floor
+ // for THIS write (`carlos system update --allow-below-rootfs-floor`): a
+ // box on RootfsLifecycleFloor or later installs Current even though it
+ // is below the floor or its version does not parse. Every later write
+ // starts without it; a box before this field ignores it.
+ AllowBelowRootfsFloor bool `json:"allow_below_rootfs_floor,omitempty"`
}
// SystemRelease is everything a box needs to install one version. It travels
@@ -250,6 +256,8 @@ func GetSystemPointer(ctx context.Context, s Store, pub ed25519.PublicKey, compo
type SystemPromoteOptions struct {
Actor string
Spread time.Duration // 0 = hotfix, every box at once; unset in the CLI means the default
+ // AllowBelowRootfsFloor sets SystemPointer.AllowBelowRootfsFloor.
+ AllowBelowRootfsFloor bool
}
// PromoteSystem writes the pointer for one channel, CAS-guarded. The
@@ -281,7 +289,8 @@ func PrepareSystemPromotion(ctx context.Context, s Store, sg Signer, component,
if old != nil && old.CancellationID != "" && old.Current.Version == "" {
old = nil
}
- next := &SystemPointer{ActivationID: id, Component: component, Channel: channel, Current: rel, Spread: o.Spread.String()}
+ next := &SystemPointer{ActivationID: id, Component: component, Channel: channel, Current: rel, Spread: o.Spread.String(),
+ AllowBelowRootfsFloor: o.AllowBelowRootfsFloor}
if rel.ReleasedAt.IsZero() {
next.Current.ReleasedAt = time.Now().UTC().Truncate(time.Second)
}
diff --git a/internal/release/systempointer_test.go b/internal/release/systempointer_test.go
index bc5ee372b..42d258c26 100644
--- a/internal/release/systempointer_test.go
+++ b/internal/release/systempointer_test.go
@@ -210,3 +210,35 @@ type conflictingStore struct{ Store }
func (c conflictingStore) Put(ctx context.Context, key string, body []byte, ifMatch string) (string, error) {
return "", ErrCASConflict
}
+
+// The rootfs floor override rides one pointer write (Task 15 round 3): it
+// survives signing and verification, and the next promote, or a rollback,
+// starts without it.
+func TestSystemPointerCarriesTheRootfsFloorOverrideForOneWrite(t *testing.T) {
+ priv, pub := testKeys(t)
+ s := NewDirStore(t.TempDir())
+ ctx := context.Background()
+ if _, err := PromoteSystem(ctx, s, RootSigner(priv), SystemComponentRouter, "stable", testSystemRelease("v0.29.0"), SystemPromoteOptions{}); err != nil {
+ t.Fatal(err)
+ }
+ if _, err := PromoteSystem(ctx, s, RootSigner(priv), SystemComponentRouter, "stable", testSystemRelease("v0.28.25"),
+ SystemPromoteOptions{AllowBelowRootfsFloor: true}); err != nil {
+ t.Fatal(err)
+ }
+ got, _, err := GetSystemPointer(ctx, s, pub, SystemComponentRouter, "stable")
+ if err != nil || !got.AllowBelowRootfsFloor {
+ t.Fatalf("the verified pointer lost the override: %+v, %v", got, err)
+ }
+ if _, err := RollbackSystem(ctx, s, RootSigner(priv), SystemComponentRouter, "stable", "paul"); err != nil {
+ t.Fatal(err)
+ }
+ if got, _, err := GetSystemPointer(ctx, s, pub, SystemComponentRouter, "stable"); err != nil || got.AllowBelowRootfsFloor {
+ t.Fatalf("a rollback kept the override: %+v, %v", got, err)
+ }
+ if _, err := PromoteSystem(ctx, s, RootSigner(priv), SystemComponentRouter, "stable", testSystemRelease("v0.28.25"), SystemPromoteOptions{}); err != nil {
+ t.Fatal(err)
+ }
+ if got, _, err := GetSystemPointer(ctx, s, pub, SystemComponentRouter, "stable"); err != nil || got.AllowBelowRootfsFloor {
+ t.Fatalf("a later promote kept the override: %+v, %v", got, err)
+ }
+}
diff --git a/plan3_groups_test.go b/plan3_groups_test.go
index 2f50113c8..ef31f2f81 100644
--- a/plan3_groups_test.go
+++ b/plan3_groups_test.go
@@ -33,9 +33,10 @@ import (
// "A" to plan3GroupsLanded. Nothing else changes these lists.
// The three copy sets, pinned. RFS-3-C13 is struck (pre-flight 3.1) and
-// in no set.
+// in no set; so is RFS-3-C25 (Paul's Task 15 round 3 ruling), whose place
+// RFS-3-C30 to C32 take.
var (
- plan3CopyA = plan3IDs(11, 12, 14, 15, 16, 17, 18, 19, 20, 21, 22, 23, 24, 25, 26, 27, 28)
+ plan3CopyA = plan3IDs(11, 12, 14, 15, 16, 17, 18, 19, 20, 21, 22, 23, 24, 26, 27, 28, 30, 31, 32)
plan3CopyR = plan3IDs(1, 2, 3, 4, 5, 6, 7, 29)
plan3CopyW = plan3IDs(8, 9, 10)
)
diff --git a/system.go b/system.go
index 0c23ae20c..6533ec100 100644
--- a/system.go
+++ b/system.go
@@ -17,6 +17,7 @@ import (
"github.com/carlosframework/platform/internal/dbreads"
"github.com/carlosframework/platform/internal/host"
"github.com/carlosframework/platform/internal/hostenv"
+ "github.com/carlosframework/platform/internal/release"
)
// carlos system: what is not an app (spec §0, the console-as-an-app
@@ -291,6 +292,7 @@ func runSystemUpdate(args []string) {
platform := fs.String("platform", "linux-arm64", "with --file: the binary's <goos>-<goarch>")
spread := fs.String("spread", "5m", "boxes jitter their restarts over this; 0 for a hotfix")
yes := fs.Bool("yes", false, "do not ask")
+ allowBelowRootfsFloor := fs.Bool(release.RootfsFloorOverrideFlag, false, release.RootfsFloorOverrideUsage)
fs.Usage = flagUsage(fs, "")
fs.Parse(args)
if *file != "" && *version == "" {
@@ -342,6 +344,9 @@ func runSystemUpdate(args []string) {
}
in := map[string]any{"channel": *channel, "spread": *spread}
+ if *allowBelowRootfsFloor {
+ in["allow_below_rootfs_floor"] = true
+ }
if *version != "" {
in["version"] = *version
}