carlos / platform Public

Fleet public routes Task 8: the fleet forward floor on every system channel move

release.FleetForwardFloor (v0.32.0), FleetForwardFloorAllows, the
--allow-below-fleet-forward-floor flag (FPR-C05 as its help, the floor
written in) and SystemPointer/SystemPromoteOptions.AllowBelowFleetForwardFloor
(signed, omitempty, copied by both Prepare functions).

The console judges the floor while ListFleets is non-empty: in
systemFloorSnapshot, the not-found branch included (a first publication
below the floor is refused, FPR-C03), on rollback's snapshot, and again
under fleetFloorMu in fleetFloorPublish, taken before regionalMu, so a
fleet created after the up-front judgment refuses the write. A crossing
is refused with FPR-C02; the override passes and logs FPR-C04; a listing
error refuses, override or not; the fleets are listed only when the move
does not pass on the version alone. The override is part of the
activation request's identity (omitempty, so existing ids are unchanged)
and of a held rollback's comparison. Both doors map the refusal to 409.
FPR-C02..C05 join fleetRoutesCopyBuilt; spec §7 records the census.
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Paul Campbell pushed by claude agent, operated by paul@keymail.dev 3895bf1b46feb850f3317a8b25c0a5bb38e8bb05 parent 675b636
14 files changed, +1,192 −63
  • approved_fleet_routes_copy_test.go +19 −1
  • docs/superpowers/specs/2026-10-29-fleet-public-routes-design.md +14 −0
  • internal/console/apisystemupdate.go +16 −7
  • internal/console/fleetfloor.go +117 −0
  • internal/console/fleetfloor_test.go +665 −0
  • internal/console/hostactivation.go +65 −39
  • internal/console/rootfsfloor.go +18 −10
  • internal/console/server.go +6 −0
  • internal/release/layoutintent.go +41 −0
  • internal/release/layoutintent_test.go +44 −0
  • internal/release/systempointer.go +22 −6
  • internal/release/systempointer_test.go +72 −0
  • system.go +8 −0
  • system_fleetfloor_test.go +85 −0

CI failed — run details

Intent

Human

<cross-session-message from="uds:/run/user/1001/cc-socks/276368.sock" from-name="platform-61" from-mode="bypass"> Before I roll v0.31.1 to flagship: does anything of yours on flagship block it, or need me to wait? From platform-61. Paul has OK'd the roll. v0.31.1 is the bfc668c8 tag, already on dev since 10:56Z with every check passing. It contains static _headers, rootfs exit and process reporting, logs process= and fleet HEALTH, ship --check data volume, the console purchase success screen (billing stays off on flagship), and region HA P1b-2 forwarding (dormant). Order: flagship boxes (adi, annie, barbara, iris) on stable, then the flagship console on annie (the ~21 s start against the 13 s hold is known, #434). Main's newer commits (analytics pages, billing usage, a67f377 backoff) are NOT in it. Please reply "go" or "hold: <reason>". If I hear nothing within ~10 minutes I'll take it as no objection. </cross-session-message>

Attributed to this commit: 26.7 g CO₂e (3,429,921 tokens). This is an attribution, not a measurement — usage counted from this commit's own marker forward to the next one on design-fleet-public-routes, never backward from it. A turn that produced more than one commit books all of its tokens to the last one, and a concurrent session on this branch can add to the same figure. Some of it was priced using the shared default rate, because no model-specific factor row exists yet for at least one model involved. The Carbon view has the repo total, which is never derived from this attribution.

diff --git a/approved_fleet_routes_copy_test.go b/approved_fleet_routes_copy_test.go
index ca5f36206..24c7c971a 100644
--- a/approved_fleet_routes_copy_test.go
+++ b/approved_fleet_routes_copy_test.go
@@ -6,6 +6,8 @@ import (
"regexp"
"strings"
"testing"
+
+ "github.com/carlosframework/platform/internal/release"
)
// The copy gate of the fleet public routes feature (plan
@@ -42,7 +44,7 @@ var fleetRoutesCopyStatuses = []string{"pending", "approved", "struck"}
// row is approved. Task 3 builds the CLI refusal (FPR-C01); Task 8 the floor
// rows (FPR-C02 to FPR-C05); Task 9 the fleet-create barrier (FPR-C06,
// FPR-C07); Task 11 the REASON cell (FPR-C08).
-var fleetRoutesCopyBuilt = []string{"FPR-C01"}
+var fleetRoutesCopyBuilt = []string{"FPR-C01", "FPR-C02", "FPR-C03", "FPR-C04", "FPR-C05"}
func mustParseFleetRoutesRecord(t *testing.T) []copyRow {
t.Helper()
@@ -101,10 +103,26 @@ func TestFleetRoutesCopyAppliedTextUnescapes(t *testing.T) {
}
}
+// fleetRoutesConstFloorRows are the rows whose text is a const with the
+// floor written in where the row has its %s (FPR-C05, the flag help: a const
+// cannot format), as RD-32 writes v0.31.0. The gate fills the %s with
+// "v"+release.FleetForwardFloor.String() before it looks for the text, so a
+// re-pinned floor that the const does not follow fails here.
+var fleetRoutesConstFloorRows = map[string]bool{"FPR-C05": true}
+
func TestFleetRoutesCopyBuiltIsApplied(t *testing.T) {
rows := builtRows(mustParseFleetRoutesRecord(t), fleetRoutesCopyBuilt)
for i := range rows {
rows[i].Text = fleetRoutesAppliedText(rows[i].Text)
+ if fleetRoutesConstFloorRows[rows[i].ID] {
+ if strings.Count(rows[i].Text, "%s") != 1 {
+ t.Errorf("%s: want exactly one %%s for the floor in %q", rows[i].ID, rows[i].Text)
+ }
+ rows[i].Text = strings.ReplaceAll(rows[i].Text, "%s", "v"+release.FleetForwardFloor.String())
+ if rows[i].Text != release.FleetForwardFloorOverrideUsage {
+ t.Errorf("%s: release.FleetForwardFloorOverrideUsage = %q, want %q", rows[i].ID, release.FleetForwardFloorOverrideUsage, rows[i].Text)
+ }
+ }
}
reportAll(t, checkRunApplied(rows, "."))
}
diff --git a/docs/superpowers/specs/2026-10-29-fleet-public-routes-design.md b/docs/superpowers/specs/2026-10-29-fleet-public-routes-design.md
index 4c8088203..2f53e8fdc 100644
--- a/docs/superpowers/specs/2026-10-29-fleet-public-routes-design.md
+++ b/docs/superpowers/specs/2026-10-29-fleet-public-routes-design.md
@@ -1200,6 +1200,20 @@ Units, by file (N = new, R = removed, otherwise a changed body or sites):
forward row, first; Task 3's card, above, adds the three `cli.go`
helpers).
+ Task 8's card, reconciled with the three entries above: none of their
+ declarations is a unit. `SystemPointer`, `SystemPromoteOptions`,
+ `PrepareSystemPromotion`, `PrepareSystemRollback` and the four new
+ `layoutintent.go` declarations have no read site (the new field is a
+ plain bool copied from the options), and `runSystemUpdate` and
+ `runSystemRollback` gain a flag and a request key, no read site. So
+ each moves only its envelope, `internal/release` or `.`, both already
+ re-pinned by earlier tasks. Difference from rev 4's list, recorded
+ here: those entries name declarations the change touches, not units
+ the card shows. The console side (`fleetfloor.go`, `fleetFloorMu`, the
+ doors in `apisystemupdate.go`, `hostactivation.go` and
+ `rootfsfloor.go`) is outside the root scope and no 9B8 unit
+ (`TestPlan9B8RecordWriteCensus` passes unchanged).
+
Root's own row readers (adopt, capability, named units, restart, stage,
rootfs, `layoutReversalIncomplete`) change no code and select by
`Kind == "instance"`, `IsSidecar()`, `Unit`, `Runtime`, `Backing`,
diff --git a/internal/console/apisystemupdate.go b/internal/console/apisystemupdate.go
index 98414c2aa..db69d4d21 100644
--- a/internal/console/apisystemupdate.go
+++ b/internal/console/apisystemupdate.go
@@ -361,6 +361,10 @@ type systemUpdateRequest struct {
// --allow-below-regional-floor`: the regional floor's override
// (regionalfloor.go, #447 W7), part of the request's identity too.
AllowBelowRegionalFloor bool `json:"allow_below_regional_floor"`
+ // AllowBelowFleetForwardFloor is `carlos system update
+ // --allow-below-fleet-forward-floor`: the fleet forward floor's override
+ // (fleetfloor.go), part of the request's identity too.
+ AllowBelowFleetForwardFloor bool `json:"allow_below_fleet_forward_floor"`
}
// handleAPISystemUpdate starts the promote and answers with a job id. The
@@ -421,11 +425,12 @@ func (s *Server) handleAPISystemUpdate(w http.ResponseWriter, r *http.Request) {
return
}
}
- // The rootfs and regional floors, the same way, for a named release:
- // the job asks again before it reserves or writes (promoteHostUpdate),
- // which also covers the latest release and an upload.
+ // The rootfs, regional and fleet forward floors, the same way, for a
+ // named release: the job asks again before it reserves or writes
+ // (promoteHostUpdate), which also covers the latest release and an
+ // upload.
if in.Version != "" {
- if _, err := s.systemFloorGate(r.Context(), in.Component, in.Channel, in.Version, in.AllowBelowRootfsFloor, in.AllowBelowRegionalFloor, false); errors.Is(err, errRootfsFloorPromotion) || errors.Is(err, errRegionalFloorPromotion) {
+ if _, err := s.systemFloorGate(r.Context(), in.Component, in.Channel, in.Version, in.AllowBelowRootfsFloor, in.AllowBelowRegionalFloor, in.AllowBelowFleetForwardFloor); errors.Is(err, errRootfsFloorPromotion) || errors.Is(err, errRegionalFloorPromotion) || errors.Is(err, errFleetFloorPromotion) {
jsonError(w, http.StatusConflict, err.Error())
return
}
@@ -556,7 +561,8 @@ 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, AllowBelowRootfsFloor: in.AllowBelowRootfsFloor, AllowBelowRegionalFloor: in.AllowBelowRegionalFloor})
+ release.SystemPromoteOptions{Actor: actor, Spread: spread, AllowBelowRootfsFloor: in.AllowBelowRootfsFloor, AllowBelowRegionalFloor: in.AllowBelowRegionalFloor,
+ AllowBelowFleetForwardFloor: in.AllowBelowFleetForwardFloor})
if err != nil {
return err
}
@@ -921,6 +927,9 @@ func (s *Server) handleAPISystemRollback(w http.ResponseWriter, r *http.Request)
// AllowBelowRegionalFloor is `carlos system rollback
// --allow-below-regional-floor` (regionalfloor.go).
AllowBelowRegionalFloor bool `json:"allow_below_regional_floor"`
+ // AllowBelowFleetForwardFloor is `carlos system rollback
+ // --allow-below-fleet-forward-floor` (fleetfloor.go).
+ AllowBelowFleetForwardFloor bool `json:"allow_below_fleet_forward_floor"`
}
if !readJSONStrictLimit(w, r, &in, 1<<10) {
return
@@ -950,10 +959,10 @@ func (s *Server) handleAPISystemRollback(w http.ResponseWriter, r *http.Request)
return
}
}
- p, err := s.rollbackHostUpdate(r.Context(), in.Component, in.Channel, addr, in.AllowBelowRootfsFloor, in.AllowBelowRegionalFloor, false)
+ p, err := s.rollbackHostUpdate(r.Context(), in.Component, in.Channel, addr, in.AllowBelowRootfsFloor, in.AllowBelowRegionalFloor, in.AllowBelowFleetForwardFloor)
var held activationHeldError
switch {
- case errors.Is(err, errRootfsFloorPromotion), errors.Is(err, errRegionalFloorPromotion):
+ case errors.Is(err, errRootfsFloorPromotion), errors.Is(err, errRegionalFloorPromotion), errors.Is(err, errFleetFloorPromotion):
jsonError(w, http.StatusConflict, err.Error())
return
case errors.Is(err, release.ErrCASConflict):
diff --git a/internal/console/fleetfloor.go b/internal/console/fleetfloor.go
new file mode 100644
index 000000000..ee5eb66dd
--- /dev/null
+++ b/internal/console/fleetfloor.go
@@ -0,0 +1,117 @@
+package console
+
+import (
+ "context"
+ "errors"
+ "fmt"
+ "log"
+
+ "github.com/carlosframework/platform/internal/release"
+)
+
+// The fleet forward floor at the console (fleet public routes spec §9):
+// while any fleet exists, a system channel whose current pointer names
+// release.FleetForwardFloor or later is never moved to a release below it,
+// or to one whose version does not parse, and a channel with no pointer
+// yet never gets a first release below it, unless the operator passes
+// --allow-below-fleet-forward-floor. A hub below the floor serves a
+// forward row (its fleet arm keys on placement) and cannot retire it, so
+// after such a move a deleted or reassigned host would keep pointing at
+// the old fleet.
+//
+// It sits at every door the other two floors sit on: the update door's
+// preflight and promoteHostUpdate through systemFloorGate, and
+// rollbackHostUpdate on the snapshot its target came from. Unlike them it
+// judges a channel with no pointer (spec §9, R2-2): absence is not a pass.
+// A rollback always has a pointer, so only update and promote can be first
+// publications.
+//
+// The judgment that no fleet exists is not bound by the pointer's ETag: a
+// fleet can be created while the pointer stands still. So it is made again
+// under s.fleetFloorMu with the pointer write (fleetFloorPublish), as the
+// regional floor's is under regionalMu; fleetFloorMu is taken first.
+
+// consoleFleetFloorRefusal (FPR-C02) takes the channel, its current
+// release, the floor and the target.
+const consoleFleetFloorRefusal = "%s runs %s. this deployment has a customer fleet, so it must run %s or later. %s is not one. to move the channel there anyway, pass --allow-below-fleet-forward-floor"
+
+// consoleFleetFloorFirstRefusal (FPR-C03) takes the channel, the floor and
+// the target.
+const consoleFleetFloorFirstRefusal = "%s has no release yet. this deployment has a customer fleet, so its first release must be %s or later. %s is not one. to publish it anyway, pass --allow-below-fleet-forward-floor"
+
+// consoleFleetFloorOverride (FPR-C04) takes the target, the floor and the
+// channel.
+const consoleFleetFloorOverride = "moving to %s below %s on %s with --allow-below-fleet-forward-floor: the hub keeps serving fleet apps it can no longer retire. remove their routes first"
+
+// errFleetFloorPromotion is a promotion the fleet forward floor refused.
+var errFleetFloorPromotion = errors.New("fleet forward floor")
+
+type fleetFloorError struct{ msg string }
+
+func (e fleetFloorError) Error() string { return e.msg }
+func (e fleetFloorError) Unwrap() error { return errFleetFloorPromotion }
+
+// fleetForwardFloorJudge refuses moving channel from cur (nil: the channel
+// has no pointer, and this is its first publication) to target while a
+// fleet exists, unless allow, the operator's override, which is logged
+// when it overrides. Three cases (spec §9):
+//
+// - a pointer exists: release.FleetForwardFloorAllows decides on the
+// version alone first;
+// - no pointer: a target that parses at or above the floor passes on the
+// version alone;
+// - anything else is refused while a fleet exists.
+//
+// The fleets are listed only when the move does not pass on the version
+// alone, from the console's own registry (no bucket read). A listing error
+// refuses, override or not: the console cannot tell whether the move
+// strands a forward row.
+func (s *Server) fleetForwardFloorJudge(ctx context.Context, channel string, cur *release.SystemPointer, target string, allow bool) error {
+ if cur != nil {
+ if release.FleetForwardFloorAllows(cur.Current.Version, target) {
+ return nil
+ }
+ } else if v, ok := release.ParseReleaseVersion(target); ok && v.Compare(release.FleetForwardFloor) >= 0 {
+ return nil
+ }
+ _, fleets, err := s.systemFleets()
+ if err != nil {
+ return fmt.Errorf("fleet forward floor: cannot list fleets: %w", err)
+ }
+ if len(fleets) == 0 {
+ return nil
+ }
+ floor := "v" + release.FleetForwardFloor.String()
+ if allow {
+ log.Printf("console: system: "+consoleFleetFloorOverride, target, floor, channel)
+ return nil
+ }
+ if cur == nil {
+ return fleetFloorError{msg: fmt.Sprintf(consoleFleetFloorFirstRefusal, channel, floor, target)}
+ }
+ return fleetFloorError{msg: fmt.Sprintf(consoleFleetFloorRefusal, channel, cur.Current.Version, floor, target)}
+}
+
+// fleetFloorPublish runs publish, the conditional write of channel's
+// pointer, under s.fleetFloorMu, after judging the fleet forward floor
+// again on the pointer current returns (the one the write replaces; nil
+// for none, a first publication, which is judged and never skipped)
+// moving to target. An earlier judgment (systemFloorGate, before any
+// reservation) refuses early; this one is the one that binds. With allow
+// nothing a new fleet does changes the answer, so current is not called.
+// Callers pass their regionalFloorPublish call as publish, so fleetFloorMu
+// is held before regionalMu.
+func (s *Server) fleetFloorPublish(ctx context.Context, channel string, current func() (*release.SystemPointer, error), target string, allow bool, publish func() (*release.SystemPointer, error)) (*release.SystemPointer, error) {
+ s.fleetFloorMu.Lock()
+ defer s.fleetFloorMu.Unlock()
+ if !allow {
+ cur, err := current()
+ if err != nil {
+ return nil, err
+ }
+ if err := s.fleetForwardFloorJudge(ctx, channel, cur, target, false); err != nil {
+ return nil, err
+ }
+ }
+ return publish()
+}
diff --git a/internal/console/fleetfloor_test.go b/internal/console/fleetfloor_test.go
new file mode 100644
index 000000000..7801b68f6
--- /dev/null
+++ b/internal/console/fleetfloor_test.go
@@ -0,0 +1,665 @@
+package console
+
+import (
+ "context"
+ "crypto/sha256"
+ "encoding/hex"
+ "encoding/json"
+ "errors"
+ "fmt"
+ "net/http"
+ "os"
+ "path/filepath"
+ "strings"
+ "sync"
+ "testing"
+ "time"
+
+ "github.com/carlosframework/platform/internal/hostfloor"
+ "github.com/carlosframework/platform/internal/registry"
+ "github.com/carlosframework/platform/internal/release"
+)
+
+// The fleet forward floor (fleet public routes spec §9, §8 test 11) mirrors
+// the regional floor's tests (regionalfloor_test.go), with a fleet in the
+// console's registry instead of a regional claim, and adds a channel's
+// first publication, which this floor judges and the other two do not.
+// Every channel here is above the rootfs and regional floors and holds no
+// regional claim, so only the fleet judge can refuse unless a test says so.
+
+// fpFloorWant is FPR-C02 for channel at from, moving to target.
+func fpFloorWant(channel, from, target string) string {
+ return fmt.Sprintf(consoleFleetFloorRefusal, channel, from, "v"+release.FleetForwardFloor.String(), target)
+}
+
+// fpFirstWant is FPR-C03 for channel's first publication of target.
+func fpFirstWant(channel, target string) string {
+ return fmt.Sprintf(consoleFleetFloorFirstRefusal, channel, "v"+release.FleetForwardFloor.String(), target)
+}
+
+// fpOverrideLog is the console's log line (FPR-C04) for moving channel to
+// target below the floor on the override.
+func fpOverrideLog(channel, target string) string {
+ return "console: system: " + fmt.Sprintf(consoleFleetFloorOverride, target, "v"+release.FleetForwardFloor.String(), channel)
+}
+
+// fpRegistry gives s a route registry of its own, and returns its path.
+func fpRegistry(t *testing.T, s *Server) string {
+ t.Helper()
+ path := filepath.Join(t.TempDir(), "routes.db")
+ reg, err := registry.Open(path)
+ if err != nil {
+ t.Fatal(err)
+ }
+ reg.Close()
+ s.cfg.Registry = path
+ return path
+}
+
+// fpCreateFleet creates fleet name for account bab in the registry at path,
+// through its own handle, as the fleet-create door would.
+func fpCreateFleet(t *testing.T, path, name string) {
+ t.Helper()
+ reg, err := registry.Open(path)
+ if err != nil {
+ t.Fatal(err)
+ }
+ defer reg.Close()
+ if created, err := reg.CreateFleet(registry.Fleet{Name: name, Account: "bab", Bucket: name + "-data"}); err != nil || !created {
+ t.Fatalf("create fleet %s: %v, %v", name, created, err)
+ }
+}
+
+// fpRelease is target renamed to version v (its artifact unchanged).
+func fpRelease(target release.SystemRelease, v string) release.SystemRelease {
+ r := target
+ r.Version, r.ReleaseTag, r.Source = v, v, "release:"+v
+ r.Artifacts = map[string]release.SystemArtifact{"linux-amd64": {Key: release.SystemArtifactKey(v, "linux-amd64"), SHA256: target.Artifacts["linux-amd64"].SHA256}}
+ return r
+}
+
+// fpNoPointer fails the test if channel has a pointer.
+func fpNoPointer(t *testing.T, s *Server, channel string) {
+ t.Helper()
+ if p, _, err := release.GetSystemPointer(t.Context(), s.cfg.Releases, release.RootSigner(s.cfg.Key).RootPublicKey(), "router", channel); !errors.Is(err, os.ErrNotExist) {
+ t.Fatalf("%s has a pointer: %+v, %v", channel, p, err)
+ }
+}
+
+// [§9] A channel at the floor is never promoted or rolled back below it,
+// or to a release whose version does not parse, while a fleet exists,
+// without the override; the refusal (FPR-C02) comes before any activation
+// reservation exists, and the other two overrides do not stand in for it.
+// With no fleet the same moves go through. With the override the move
+// goes through, the pointer records it and the console logs FPR-C04.
+func TestFleetFloorRefusesACrossingWhileAFleetExists(t *testing.T) {
+ s, d, target := activationFixtureAt(t, "v0.32.0", "v0.31.0", "v0.28.0")
+ fpCreateFleet(t, fpRegistry(t, s), "home")
+ want := fpFloorWant("stable", "v0.32.0", "v0.31.0")
+ for _, o := range []release.SystemPromoteOptions{{}, {AllowBelowRootfsFloor: true, AllowBelowRegionalFloor: true}} {
+ if _, err := s.promoteHostUpdate(t.Context(), target, "router", "stable", o); !errors.Is(err, errFleetFloorPromotion) || err.Error() != want {
+ t.Fatalf("promote below the floor (%+v) = %v\nwant %q", o, err, want)
+ }
+ }
+ noActivations(t, d)
+ for _, other := range []bool{false, true} {
+ if _, err := s.rollbackHostUpdate(t.Context(), "router", "stable", "operator", other, other, false); !errors.Is(err, errFleetFloorPromotion) || err.Error() != want {
+ t.Fatalf("rollback below the floor (other overrides %v) = %v\nwant %q", other, err, want)
+ }
+ }
+ noActivations(t, d)
+ if v := currentVersion(t, s, d); v != "v0.32.0" {
+ t.Fatalf("the pointer moved to %s", v)
+ }
+ // An unparseable target meets the rootfs floor first; with the other
+ // two overrides the fleet floor refuses it too.
+ for target, refused := range map[string]bool{"4f3c2a1": true, "": true, "v0.31.9": true, "v0.32.0": false, "v0.33.1": false} {
+ _, err := s.systemFloorGate(t.Context(), "router", "stable", target, true, true, false)
+ if errors.Is(err, errFleetFloorPromotion) != refused {
+ t.Errorf("systemFloorGate(%q) = %v, refused want %v", target, err, refused)
+ }
+ }
+
+ // With the override the promotion reserves and publishes, the pointer
+ // records it (and neither other override), and the console says what
+ // it costs.
+ logs := captureLog(t)
+ p, err := s.promoteHostUpdate(t.Context(), target, "router", "stable", release.SystemPromoteOptions{AllowBelowFleetForwardFloor: true})
+ if err != nil {
+ t.Fatal(err)
+ }
+ if p.Current.Version != "v0.31.0" || !p.AllowBelowFleetForwardFloor || p.AllowBelowRegionalFloor || p.AllowBelowRootfsFloor {
+ t.Fatalf("the override's promotion = %+v", p)
+ }
+ if !strings.Contains(logs.String(), fpOverrideLog("stable", "v0.31.0")) {
+ t.Fatalf("the override was not logged as FPR-C04:\n%s", logs)
+ }
+}
+
+// With no fleet, in a registry or without one, a channel at the floor
+// moves below it as before, and the pointer carries no override.
+func TestFleetFloorLeavesAChannelAloneWithoutAFleet(t *testing.T) {
+ for _, withRegistry := range []bool{false, true} {
+ for _, mode := range []string{"promote", "rollback"} {
+ t.Run(fmt.Sprintf("%s/registry=%v", mode, withRegistry), func(t *testing.T) {
+ s, _, target := activationFixtureAt(t, "v0.32.0", "v0.31.0", "v0.28.0")
+ if withRegistry {
+ fpRegistry(t, s)
+ }
+ var p *release.SystemPointer
+ var err error
+ if mode == "rollback" {
+ p, err = s.rollbackHostUpdate(t.Context(), "router", "stable", "operator", false, false, false)
+ } else {
+ p, err = s.promoteHostUpdate(t.Context(), target, "router", "stable", release.SystemPromoteOptions{})
+ }
+ if err != nil || p.Current.Version != "v0.31.0" || p.AllowBelowFleetForwardFloor {
+ t.Fatalf("%s below the floor with no fleet = %+v, %v", mode, p, err)
+ }
+ })
+ }
+ }
+}
+
+// [§9, R2-2] A channel with no pointer is judged: while a fleet exists its
+// first release must parse at or above the floor (FPR-C03), at the
+// up-front gate and again in fleetFloorPublish with a nil current pointer,
+// where publish is never called. At or above the floor, with the override,
+// or with no fleet, it publishes.
+func TestFleetFloorJudgesAFirstPublication(t *testing.T) {
+ s, d, target := activationFixtureAt(t, "v0.32.0", "v0.31.0", "v0.28.0")
+ regPath := fpRegistry(t, s)
+ fpNoPointer(t, s, "canary")
+ // No fleet yet: a first publication below the floor passes the gate.
+ if _, err := s.systemFloorGate(t.Context(), "router", "canary", "v0.31.0", false, false, false); err != nil {
+ t.Fatalf("a first publication with no fleet = %v", err)
+ }
+ fpCreateFleet(t, regPath, "home")
+ for v, refused := range map[string]bool{"v0.31.0": true, "v0.31.9": true, "4f3c2a1": true, "": true, "v0.32.0": false, "v0.33.1": false} {
+ _, err := s.systemFloorGate(t.Context(), "router", "canary", v, false, false, false)
+ if errors.Is(err, errFleetFloorPromotion) != refused {
+ t.Errorf("systemFloorGate(canary, %q) = %v, refused want %v", v, err, refused)
+ }
+ if refused && (err == nil || err.Error() != fpFirstWant("canary", v)) {
+ t.Errorf("systemFloorGate(canary, %q) = %v\nwant %q", v, err, fpFirstWant("canary", v))
+ }
+ }
+ want := fpFirstWant("canary", "v0.31.0")
+ if _, err := s.promoteHostUpdate(t.Context(), target, "router", "canary", release.SystemPromoteOptions{}); !errors.Is(err, errFleetFloorPromotion) || err.Error() != want {
+ t.Fatalf("a first promotion below the floor = %v\nwant %q", err, want)
+ }
+ fpNoPointer(t, s, "canary")
+
+ // The binding judgment, called directly with no pointer.
+ none := func() (*release.SystemPointer, error) { return nil, nil }
+ published := 0
+ publish := func() (*release.SystemPointer, error) { published++; return &release.SystemPointer{}, nil }
+ if _, err := s.fleetFloorPublish(t.Context(), "canary", none, "v0.31.0", false, publish); !errors.Is(err, errFleetFloorPromotion) || err.Error() != want {
+ t.Fatalf("fleetFloorPublish of a first release below the floor = %v\nwant %q", err, want)
+ }
+ if published != 0 {
+ t.Fatal("fleetFloorPublish published a refused first release")
+ }
+ if _, err := s.fleetFloorPublish(t.Context(), "canary", none, "v0.32.0", false, publish); err != nil || published != 1 {
+ t.Fatalf("fleetFloorPublish of a first release at the floor = %v (published %d)", err, published)
+ }
+ unread := func() (*release.SystemPointer, error) {
+ t.Error("the override read the pointer")
+ return nil, nil
+ }
+ if _, err := s.fleetFloorPublish(t.Context(), "canary", unread, "v0.31.0", true, publish); err != nil || published != 2 {
+ t.Fatalf("fleetFloorPublish with the override = %v (published %d)", err, published)
+ }
+
+ // At the floor the first promotion publishes (unreserved: v0.32.0 has
+ // no release identity in the fixture).
+ unreserved(t, d)
+ if p, err := s.promoteHostUpdate(t.Context(), fpRelease(target, "v0.32.0"), "router", "canary", release.SystemPromoteOptions{}); err != nil || p.Current.Version != "v0.32.0" || p.AllowBelowFleetForwardFloor {
+ t.Fatalf("a first promotion at the floor = %+v, %v", p, err)
+ }
+ // Below it with the override, on another channel with no pointer: it
+ // publishes, signed with the override, and FPR-C04 is logged.
+ s2, _, target2 := activationFixtureAt(t, "v0.32.0", "v0.31.0", "v0.28.0")
+ s2.cfg.Registry = regPath
+ logs := captureLog(t)
+ p, err := s2.promoteHostUpdate(t.Context(), target2, "router", "canary", release.SystemPromoteOptions{AllowBelowFleetForwardFloor: true})
+ if err != nil || p.Current.Version != "v0.31.0" || !p.AllowBelowFleetForwardFloor {
+ t.Fatalf("a first promotion below the floor with the override = %+v, %v", p, err)
+ }
+ if !strings.Contains(logs.String(), fpOverrideLog("canary", "v0.31.0")) {
+ t.Fatalf("the override was not logged as FPR-C04:\n%s", logs)
+ }
+ // With no fleet, below it and without the override: it publishes.
+ s3, _, target3 := activationFixtureAt(t, "v0.32.0", "v0.31.0", "v0.28.0")
+ fpRegistry(t, s3)
+ if p, err := s3.promoteHostUpdate(t.Context(), target3, "router", "canary", release.SystemPromoteOptions{}); err != nil || p.Current.Version != "v0.31.0" || p.AllowBelowFleetForwardFloor {
+ t.Fatalf("a first promotion below the floor with no fleet = %+v, %v", p, err)
+ }
+}
+
+// fpReadHook runs between once, just before read number at of key: a read
+// the promotion makes after its up-front floor judgment and before the
+// binding one in fleetFloorPublish. Reserved, that is the preparation's
+// second read of the channel's pointer (reserveHostUpdate); unreserved,
+// reserveHostUpdate's read of the host floor, which finds none (the first
+// such read on a promote, the second on a rollback, whose own read of it
+// comes first).
+type fpReadHook struct {
+ release.Store
+ key string
+ at int
+ reads int
+ between func()
+}
+
+func (s *fpReadHook) Get(ctx context.Context, key string) ([]byte, string, error) {
+ if key == s.key {
+ s.reads++
+ if s.reads == s.at && s.between != nil {
+ s.between()
+ }
+ }
+ return s.Store.Get(ctx, key)
+}
+
+// [§8 test 11 (a)] The judgment that no fleet exists holds through the
+// pointer write. A fleet created after the up-front judgment (and,
+// reserved, after the reservation) and before the publication refuses the
+// move: the floor is judged again under fleetFloorMu with the write. A
+// first publication (no pointer) included, which is the case Task 9's
+// fleet-create barrier lets through. No pointer is written.
+func TestFleetFloorJudgesAgainAtPublication(t *testing.T) {
+ pointer := func(channel string) string { return release.SystemPointerKey("router", channel) }
+ cases := []struct {
+ name, mode, channel string
+ reserved bool
+ key string
+ at int
+ }{
+ {"promote/reserved", "promote", "stable", true, pointer("stable"), 2},
+ {"promote/unreserved", "promote", "stable", false, hostfloor.Key, 1},
+ {"rollback/reserved", "rollback", "stable", true, pointer("stable"), 2},
+ {"rollback/unreserved", "rollback", "stable", false, hostfloor.Key, 2},
+ // No box follows canary, so its reservation finds nothing to
+ // reserve and the publication goes unreserved, after the
+ // preparation's read.
+ {"first-publication", "promote", "canary", true, pointer("canary"), 2},
+ }
+ for _, c := range cases {
+ t.Run(c.name, func(t *testing.T) {
+ s, d, target := activationFixtureAt(t, "v0.32.0", "v0.31.0", "v0.28.0")
+ regPath := fpRegistry(t, s)
+ if !c.reserved {
+ unreserved(t, d)
+ }
+ ran := false
+ s.cfg.Releases = &fpReadHook{Store: d.Store, key: c.key, at: c.at, between: func() {
+ ran = true
+ fpCreateFleet(t, regPath, "home")
+ }}
+ var err error
+ if c.mode == "rollback" {
+ _, err = s.rollbackHostUpdate(t.Context(), "router", c.channel, "operator", false, false, false)
+ } else {
+ _, err = s.promoteHostUpdate(t.Context(), target, "router", c.channel, release.SystemPromoteOptions{})
+ }
+ if !ran {
+ t.Fatal("the hook never ran: nothing sat between the judgment and the publication")
+ }
+ want := fpFloorWant(c.channel, "v0.32.0", "v0.31.0")
+ if c.channel == "canary" {
+ want = fpFirstWant(c.channel, "v0.31.0")
+ }
+ if !errors.Is(err, errFleetFloorPromotion) || err.Error() != want {
+ t.Fatalf("%s with a fleet created before the publication = %v\nwant %q", c.name, err, want)
+ }
+ if c.channel == "canary" {
+ fpNoPointer(t, s, "canary")
+ } else if v := currentVersion(t, s, d); v != "v0.32.0" {
+ t.Fatalf("the downgrade published: the pointer is at %s", v)
+ }
+ })
+ }
+}
+
+// fpHeld reports whether mu is held (by anyone).
+func fpHeld(mu *sync.Mutex) bool {
+ if mu.TryLock() {
+ mu.Unlock()
+ return false
+ }
+ return true
+}
+
+// [§9] The publication holds fleetFloorMu through the regional floor's
+// critical section, and takes it before regionalMu: in regionalFloorPublish's
+// beforeLock hook fleetFloorMu is held and regionalMu is not; in its locked
+// hook both are.
+func TestFleetFloorPublicationHoldsFleetFloorMuBeforeRegionalMu(t *testing.T) {
+ for _, mode := range []string{"promote", "rollback"} {
+ t.Run(mode, func(t *testing.T) {
+ s, _, target := activationFixtureAt(t, "v0.32.0", "v0.31.0", "v0.28.0")
+ var before, locked bool
+ s.regionalFloorHooks.beforeLock = func() {
+ before = true
+ if !fpHeld(&s.fleetFloorMu) || fpHeld(&s.regionalMu) {
+ t.Error("before regionalMu: fleetFloorMu is not held, or regionalMu already is")
+ }
+ }
+ s.regionalFloorHooks.locked = func() {
+ locked = true
+ if !fpHeld(&s.fleetFloorMu) || !fpHeld(&s.regionalMu) {
+ t.Error("at the publication: fleetFloorMu and regionalMu are not both held")
+ }
+ }
+ var err error
+ if mode == "rollback" {
+ _, err = s.rollbackHostUpdate(t.Context(), "router", "stable", "operator", false, false, false)
+ } else {
+ _, err = s.promoteHostUpdate(t.Context(), target, "router", "stable", release.SystemPromoteOptions{})
+ }
+ if err != nil || !before || !locked {
+ t.Fatalf("%s = %v (hooks ran: %v, %v)", mode, err, before, locked)
+ }
+ if !s.fleetFloorMu.TryLock() {
+ t.Fatal("fleetFloorMu is still held after the publication")
+ }
+ s.fleetFloorMu.Unlock()
+ })
+ }
+}
+
+// [§9] A rollback below the floor is refused while a fleet exists; the
+// override is part of the reservation's request, so a retry whose override
+// differs from a held reservation is refused, never handed its pointer;
+// a held rollback (or promote) reserved before a fleet existed is judged
+// again when it is retried, while one that had landed keeps its idempotent
+// answer; an unreserved rollback signs the override.
+func TestFleetFloorRollback(t *testing.T) {
+ for _, mode := range []string{"promote", "rollback"} {
+ t.Run(mode+"/override-is-part-of-the-request", func(t *testing.T) {
+ s, d, target := activationFixtureAt(t, "v0.32.0", "v0.31.0", "v0.28.0")
+ fpCreateFleet(t, fpRegistry(t, s), "home")
+ move := func(s *Server, allow bool) (*release.SystemPointer, error) {
+ if mode == "rollback" {
+ return s.rollbackHostUpdate(t.Context(), "router", "stable", "operator", false, false, allow)
+ }
+ return s.promoteHostUpdate(t.Context(), target, "router", "stable", release.SystemPromoteOptions{AllowBelowFleetForwardFloor: allow})
+ }
+ // With the override the first request reserves, and its
+ // publication fails.
+ s.cfg.Releases = &activationFaultStore{Store: d.Store, fail: true}
+ if _, err := move(s, true); err == nil {
+ t.Fatal("the failed publication succeeded")
+ }
+ o, err := d.Read(t.Context())
+ if err != nil || len(o.Roster.Activations) != 1 {
+ t.Fatalf("after the failed publication: %v, %v", o.Roster.Activations, err)
+ }
+ // A restarted console, without the override: refused, by the
+ // held reservation (rollback) or the floor (promote, whose
+ // up-front judgment comes first); never published.
+ restarted := &Server{cfg: s.cfg}
+ restarted.cfg.Releases = d.Store
+ var heldErr activationHeldError
+ _, err = move(restarted, false)
+ if mode == "rollback" && !errors.As(err, &heldErr) {
+ t.Fatalf("a retry without the override = %v, want the held reservation's refusal", err)
+ }
+ if mode == "promote" && !errors.Is(err, errFleetFloorPromotion) {
+ t.Fatalf("a retry without the override = %v, want the floor's refusal", err)
+ }
+ if v := currentVersion(t, restarted, d); v != "v0.32.0" {
+ t.Fatalf("the refused retry published: the pointer is at %s", v)
+ }
+ // The same override publishes the held reservation, as signed.
+ p, err := move(restarted, true)
+ if err != nil || p.Current.Version != "v0.31.0" || !p.AllowBelowFleetForwardFloor {
+ t.Fatalf("the held reservation published %+v, %v; want v0.31.0 with the override", p, err)
+ }
+ })
+ }
+ // With no fleet a reservation made without the override is held; a
+ // retry with it is another request.
+ for _, mode := range []string{"promote", "rollback"} {
+ t.Run(mode+"/a-different-override-meets-the-held-reservation", func(t *testing.T) {
+ s, d, target := activationFixtureAt(t, "v0.32.0", "v0.31.0", "v0.28.0")
+ fpRegistry(t, s)
+ move := func(s *Server, allow bool) (*release.SystemPointer, error) {
+ if mode == "rollback" {
+ return s.rollbackHostUpdate(t.Context(), "router", "stable", "operator", false, false, allow)
+ }
+ return s.promoteHostUpdate(t.Context(), target, "router", "stable", release.SystemPromoteOptions{AllowBelowFleetForwardFloor: allow})
+ }
+ s.cfg.Releases = &activationFaultStore{Store: d.Store, fail: true}
+ if _, err := move(s, false); err == nil {
+ t.Fatal("the failed publication succeeded")
+ }
+ restarted := &Server{cfg: s.cfg}
+ restarted.cfg.Releases = d.Store
+ var heldErr activationHeldError
+ if _, err := move(restarted, true); !errors.As(err, &heldErr) {
+ t.Fatalf("a retry with the override after a held one without = %v, want the held reservation's refusal", err)
+ }
+ if v := currentVersion(t, restarted, d); v != "v0.32.0" {
+ t.Fatalf("the refused retry published: the pointer is at %s", v)
+ }
+ })
+ }
+ for _, mode := range []string{"rollback", "promote"} {
+ for _, landed := range []bool{false, true} {
+ name := mode + "/held-then-a-fleet/unpublished"
+ if landed {
+ name = mode + "/held-then-a-fleet/landed"
+ }
+ t.Run(name, func(t *testing.T) {
+ s, d, target := activationFixtureAt(t, "v0.32.0", "v0.31.0", "v0.28.0")
+ regPath := fpRegistry(t, s)
+ move := func(s *Server) (*release.SystemPointer, error) {
+ if mode == "rollback" {
+ return s.rollbackHostUpdate(t.Context(), "router", "stable", "operator", false, false, false)
+ }
+ return s.promoteHostUpdate(t.Context(), target, "router", "stable", release.SystemPromoteOptions{})
+ }
+ s.cfg.Releases = &activationFaultStore{Store: d.Store, fail: true, commit: landed, hide: landed}
+ if _, err := move(s); err == nil {
+ t.Fatal("the failed publication succeeded")
+ }
+ fpCreateFleet(t, regPath, "home")
+ restarted := &Server{cfg: s.cfg}
+ restarted.cfg.Releases = d.Store
+ p, err := move(restarted)
+ if landed {
+ if err != nil || p.Current.Version != "v0.31.0" {
+ t.Fatalf("the retry of a landed %s = %+v, %v; want its idempotent answer", mode, p, err)
+ }
+ return
+ }
+ if want := fpFloorWant("stable", "v0.32.0", "v0.31.0"); !errors.Is(err, errFleetFloorPromotion) || err.Error() != want {
+ t.Fatalf("the retry of a held %s after a fleet = %v\nwant %q", mode, err, want)
+ }
+ if v := currentVersion(t, restarted, d); v != "v0.32.0" {
+ t.Fatalf("the held %s published: the pointer is at %s", mode, v)
+ }
+ })
+ }
+ }
+ t.Run("unreserved-rollback-keeps-the-override", func(t *testing.T) {
+ s, d, _ := activationFixtureAt(t, "v0.32.0", "v0.31.0", "v0.28.0")
+ fpCreateFleet(t, fpRegistry(t, s), "home")
+ unreserved(t, d)
+ if _, err := s.rollbackHostUpdate(t.Context(), "router", "stable", "operator", false, false, false); !errors.Is(err, errFleetFloorPromotion) {
+ t.Fatalf("the unreserved rollback without the override = %v", err)
+ }
+ p, err := s.rollbackHostUpdate(t.Context(), "router", "stable", "operator", false, false, true)
+ if err != nil || p.Current.Version != "v0.31.0" || !p.AllowBelowFleetForwardFloor {
+ t.Fatalf("the unreserved rollback published %+v, %v; want v0.31.0 with the override", p, err)
+ }
+ signed, _, err := release.GetSystemPointer(t.Context(), d.Store, d.PublicKey, "router", "stable")
+ if err != nil || !signed.AllowBelowFleetForwardFloor {
+ t.Fatalf("the signed pointer lost the override: %+v, %v", signed, err)
+ }
+ })
+}
+
+// [§9] The fleets are listed only when the move does not pass on the
+// version alone, and a listing that fails refuses, override or not, with
+// the listing's error (not the floor's), before any reservation. A move
+// that passes on the version alone never lists, so it goes through over a
+// registry that cannot be read.
+func TestFleetFloorListErrorRefuses(t *testing.T) {
+ s, d, target := activationFixtureAt(t, "v0.32.0", "v0.31.0", "v0.28.0")
+ // A registry path that exists and cannot be opened as one.
+ s.cfg.Registry = t.TempDir()
+ for _, allow := range []bool{false, true} {
+ if _, err := s.promoteHostUpdate(t.Context(), target, "router", "stable", release.SystemPromoteOptions{AllowBelowFleetForwardFloor: allow}); err == nil || errors.Is(err, errFleetFloorPromotion) {
+ t.Fatalf("promote (override %v) over a failed fleets listing = %v, want the listing's error", allow, err)
+ }
+ if _, err := s.rollbackHostUpdate(t.Context(), "router", "stable", "operator", false, false, allow); err == nil || errors.Is(err, errFleetFloorPromotion) {
+ t.Fatalf("rollback (override %v) over a failed fleets listing = %v, want the listing's error", allow, err)
+ }
+ if _, err := s.systemFloorGate(t.Context(), "router", "canary", "v0.31.0", false, false, allow); err == nil || errors.Is(err, errFleetFloorPromotion) {
+ t.Fatalf("a first publication (override %v) over a failed fleets listing = %v, want the listing's error", allow, err)
+ }
+ }
+ noActivations(t, d)
+ if v := currentVersion(t, s, d); v != "v0.32.0" {
+ t.Fatalf("the pointer moved to %s", v)
+ }
+ // Moves that pass on the version alone read no fleets.
+ if _, err := s.systemFloorGate(t.Context(), "router", "canary", "v0.32.0", false, false, false); err != nil {
+ t.Fatalf("a first publication at the floor = %v", err)
+ }
+ unreserved(t, d)
+ if p, err := s.promoteHostUpdate(t.Context(), fpRelease(target, "v0.33.0"), "router", "stable", release.SystemPromoteOptions{}); err != nil || p.Current.Version != "v0.33.0" {
+ t.Fatalf("a promotion above the floor = %+v, %v", p, err)
+ }
+}
+
+// The override leaves the activation request's identity alone when it is
+// false: the digest is the one the request had before the field existed,
+// so a reservation held across a console upgrade still meets its retry.
+func TestFleetFloorOverrideLeavesTheActivationIdentityAlone(t *testing.T) {
+ s, d, target := activationFixtureAt(t, "v0.32.0", "v0.33.0", "v0.28.0")
+ id, err := s.reserveHostUpdate(t.Context(), &target, "stable", "promote", release.SystemPromoteOptions{Spread: time.Minute})
+ if err != nil || id == "" {
+ t.Fatal(id, err)
+ }
+ o, err := d.Read(t.Context())
+ if err != nil {
+ t.Fatal(err)
+ }
+ rel := target
+ rel.ReleasedAt = time.Time{}
+ // The request's shape before this field (hostactivation.go).
+ before, err := json.Marshal(struct {
+ Channel string
+ Mode string
+ Release release.SystemRelease
+ Spread time.Duration
+ AllowBelowRootfsFloor bool
+ AllowBelowRegionalFloor bool `json:",omitempty"`
+ }{"stable", "promote", rel, time.Minute, false, false})
+ if err != nil {
+ t.Fatal(err)
+ }
+ digest := sha256.Sum256(before)
+ if got, want := o.Roster.Activations[id].RequestSHA256, hex.EncodeToString(digest[:]); got != want {
+ t.Fatalf("the request digest = %s, want %s (the pre-field shape %s)", got, want, before)
+ }
+}
+
+// [§9] Through the HTTP doors: `carlos system update` and `rollback`
+// refuse to move a channel at the floor below it while a fleet exists,
+// without --allow-below-fleet-forward-floor: a named version at the door,
+// the latest release inside the job, both before anything is reserved or
+// written, 409 with FPR-C02; a first publication below the floor is 409
+// with FPR-C03; the override goes through and is signed onto that pointer
+// only.
+func TestSystemDoorsRefuseBelowTheFleetForwardFloor(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.32.0")
+ owner := cliToken(t, fx, "paul@keymail.dev", "code-sys-fleet-floor")
+ ctx := context.Background()
+ sg := release.RootSigner(fx.priv)
+ rel := func(v string) release.SystemRelease {
+ return release.SystemRelease{Version: v, Artifacts: map[string]release.SystemArtifact{"linux-arm64": {Key: release.SystemArtifactKey(v, "linux-arm64"), SHA256: strings.Repeat("a", 64)}}}
+ }
+ for _, v := range []string{"v0.31.0", "v0.32.0"} {
+ if _, err := release.PromoteSystem(ctx, fx.rel, sg, "router", "canary", rel(v), release.SystemPromoteOptions{}); err != nil {
+ t.Fatal(err)
+ }
+ time.Sleep(1100 * time.Millisecond)
+ }
+ sizeFleet(t, fx, "home", "bab")
+ want := "canary runs v0.32.0. this deployment has a customer fleet, so it must run v0.32.0 or later. %s is not one. to move the channel there anyway, pass --allow-below-fleet-forward-floor"
+ pointer := func(channel string) *release.SystemPointer {
+ p, _, err := release.GetSystemPointer(ctx, fx.rel, fx.pub, "router", channel)
+ if err != nil {
+ t.Fatal(err)
+ }
+ return p
+ }
+
+ st, out := postJSON(t, fx.ts.URL+"/api/cli/system/update", map[string]any{"channel": "canary", "version": "v0.31.0"}, owner)
+ if st != http.StatusConflict || str(t, out, "error") != fmt.Sprintf(want, "v0.31.0") {
+ t.Fatalf("update to a named v0.31.0 = %d %v", st, out)
+ }
+ for _, other := range []map[string]any{{"channel": "canary"}, {"channel": "canary", "allow_below_rootfs_floor": true, "allow_below_regional_floor": true}} {
+ st, out = postJSON(t, fx.ts.URL+"/api/cli/system/rollback", other, owner)
+ if st != http.StatusConflict || str(t, out, "error") != fmt.Sprintf(want, "v0.31.0") {
+ t.Fatalf("rollback to v0.31.0 (%v) = %d %v", other, st, out)
+ }
+ }
+ // The latest public release (v0.18.0) is below the rootfs floor too: the
+ // rootfs override clears that floor and meets this one.
+ st, out = postJSON(t, fx.ts.URL+"/api/cli/system/update", map[string]any{"channel": "canary", "spread": "0s", "allow_below_rootfs_floor": true}, owner)
+ if st != http.StatusOK {
+ t.Fatalf("update to the latest = %d %v", st, out)
+ }
+ if job := waitJob(t, fx, owner, str(t, out, "job")); job["error"] != fmt.Sprintf(want, "v0.18.0") {
+ t.Fatalf("the latest (v0.18.0) job = %v", job)
+ }
+ if p := pointer("canary"); p.Current.Version != "v0.32.0" {
+ t.Fatalf("a refused promotion moved the pointer to %s", p.Current.Version)
+ }
+
+ // A first publication below the floor, named, on a channel with no
+ // pointer: FPR-C03 at the door.
+ if _, _, err := release.GetSystemPointer(ctx, fx.rel, fx.pub, "router", "stable"); !errors.Is(err, os.ErrNotExist) {
+ t.Fatalf("the fixture's stable channel has a pointer: %v", err)
+ }
+ st, out = postJSON(t, fx.ts.URL+"/api/cli/system/update", map[string]any{"channel": "stable", "version": "v0.31.0"}, owner)
+ if st != http.StatusConflict || str(t, out, "error") != fpFirstWant("stable", "v0.31.0") {
+ t.Fatalf("a first publication of a named v0.31.0 = %d %v", st, out)
+ }
+
+ st, out = postJSON(t, fx.ts.URL+"/api/cli/system/update", map[string]any{"channel": "canary", "spread": "0s", "allow_below_rootfs_floor": true, "allow_below_fleet_forward_floor": true}, owner)
+ if st != http.StatusOK {
+ t.Fatalf("update with both overrides = %d %v", st, out)
+ }
+ if job := waitJob(t, fx, owner, str(t, out, "job")); job["error"] != "" {
+ t.Fatalf("the overrides' job failed: %v", job)
+ }
+ if p := pointer("canary"); p.Current.Version != "v0.18.0" || !p.AllowBelowFleetForwardFloor || !p.AllowBelowRootfsFloor || p.AllowBelowRegionalFloor {
+ t.Fatalf("the overrides' pointer = %+v", p)
+ }
+ time.Sleep(1100 * time.Millisecond)
+ // Below the floor now: a rollback to v0.32.0 needs no override, and the
+ // pointer it writes carries none.
+ if st, out := postJSON(t, fx.ts.URL+"/api/cli/system/rollback", map[string]any{"channel": "canary"}, owner); st != http.StatusOK {
+ t.Fatalf("rollback to v0.32.0 = %d %v", st, out)
+ }
+ if p := pointer("canary"); p.Current.Version != "v0.32.0" || p.AllowBelowFleetForwardFloor {
+ t.Fatalf("the rollback's pointer = %+v", p)
+ }
+ time.Sleep(1100 * time.Millisecond)
+ st, out = postJSON(t, fx.ts.URL+"/api/cli/system/rollback", map[string]any{"channel": "canary", "allow_below_fleet_forward_floor": true}, owner)
+ if st != http.StatusOK || str(t, out, "version") != "v0.31.0" {
+ t.Fatalf("rollback below the floor with the override = %d %v", st, out)
+ }
+ if p := pointer("canary"); !p.AllowBelowFleetForwardFloor {
+ t.Fatalf("the override's rollback pointer = %+v", p)
+ }
+}
diff --git a/internal/console/hostactivation.go b/internal/console/hostactivation.go
index d440b1e24..74be50d30 100644
--- a/internal/console/hostactivation.go
+++ b/internal/console/hostactivation.go
@@ -112,17 +112,19 @@ func (s *Server) reserveHostUpdate(ctx context.Context, rel *release.SystemRelea
// The rootfs floor override is part of the request (Task 15 round 4): a
// retry that asks with a different override is another request, so it
// meets the held reservation and is refused, never handed its pointer.
- // So is the regional floor override (#447 W7). omitempty keeps a
- // request without it at the digest it had before the field existed, so
- // a reservation held across a console upgrade still meets its retry.
+ // So is the regional floor override (#447 W7), and the fleet forward
+ // floor override (fleet public routes spec §9). omitempty keeps a
+ // request without them at the digest it had before the fields existed,
+ // so a reservation held across a console upgrade still meets its retry.
request, err := json.Marshal(struct {
- Channel string
- Mode string
- Release release.SystemRelease
- Spread time.Duration
- AllowBelowRootfsFloor bool
- AllowBelowRegionalFloor bool `json:",omitempty"`
- }{channel, mode, requestRelease, options.Spread, options.AllowBelowRootfsFloor, options.AllowBelowRegionalFloor})
+ Channel string
+ Mode string
+ Release release.SystemRelease
+ Spread time.Duration
+ AllowBelowRootfsFloor bool
+ AllowBelowRegionalFloor bool `json:",omitempty"`
+ AllowBelowFleetForwardFloor bool `json:",omitempty"`
+ }{channel, mode, requestRelease, options.Spread, options.AllowBelowRootfsFloor, options.AllowBelowRegionalFloor, options.AllowBelowFleetForwardFloor})
if err != nil {
return "", err
}
@@ -205,7 +207,7 @@ func (s *Server) reserveHostUpdate(ctx context.Context, rel *release.SystemRelea
func (s *Server) promoteHostUpdate(ctx context.Context, rel release.SystemRelease, component, channel string, options release.SystemPromoteOptions) (*release.SystemPointer, error) {
// The floor decision binds the snapshot it judged: preparation, here
// or in the unreserved fallback, refuses a pointer that moved since.
- cur, etag, err := s.systemFloorSnapshot(ctx, component, channel, rel.Version, options.AllowBelowRootfsFloor, options.AllowBelowRegionalFloor, false)
+ cur, etag, err := s.systemFloorSnapshot(ctx, component, channel, rel.Version, options.AllowBelowRootfsFloor, options.AllowBelowRegionalFloor, options.AllowBelowFleetForwardFloor)
if err != nil {
return nil, err
}
@@ -213,17 +215,22 @@ func (s *Server) promoteHostUpdate(ctx context.Context, rel release.SystemReleas
if err != nil {
return nil, err
}
- // The regional floor is judged again on the same snapshot under
- // regionalMu, with the write (#447 T10 R1 P1). A reservation held from
- // an earlier attempt binds the same snapshot through its expected ETag,
- // and one already published judged here as its own target, which never
- // crosses, so it keeps its idempotent answer.
+ // The fleet forward floor and the regional floor are judged again on
+ // the same snapshot, under fleetFloorMu and then regionalMu, with the
+ // write (#447 T10 R1 P1; fleet public routes spec §9). A reservation
+ // held from an earlier attempt binds the same snapshot through its
+ // expected ETag, and one already published judged here as its own
+ // target, which never crosses, so it keeps its idempotent answer. A
+ // snapshot with no pointer is a first publication: the fleet floor
+ // judges it too, the regional floor does not.
d := hostactors.Directory{Store: s.cfg.Releases, PublicKey: release.RootSigner(s.cfg.Key).RootPublicKey(), Bucket: s.cfg.Bucket}
- return s.regionalFloorPublish(ctx, channel, judgedPointer(cur), rel.Version, options.AllowBelowRegionalFloor, func() (*release.SystemPointer, error) {
- if id == "" {
- return release.PromoteSystem(ctx, s.cfg.Releases, release.RootSigner(s.cfg.Key), component, channel, rel, options, etag)
- }
- return d.PublishActivation(ctx, id)
+ return s.fleetFloorPublish(ctx, channel, judgedPointer(cur), rel.Version, options.AllowBelowFleetForwardFloor, func() (*release.SystemPointer, error) {
+ return s.regionalFloorPublish(ctx, channel, judgedPointer(cur), rel.Version, options.AllowBelowRegionalFloor, func() (*release.SystemPointer, error) {
+ if id == "" {
+ return release.PromoteSystem(ctx, s.cfg.Releases, release.RootSigner(s.cfg.Key), component, channel, rel, options, etag)
+ }
+ return d.PublishActivation(ctx, id)
+ })
})
}
@@ -243,13 +250,15 @@ func (s *Server) rollbackHostUpdate(ctx context.Context, component, channel, act
if h.UpdateMode != "rollback" || h.FloorSHA256 != floor.Digest {
return nil, activationHeldError{id: id, component: component, channel: channel}
}
- // A retry with another rootfs or regional floor override is
- // another request: refused, never handed the held pointer.
+ // A retry with another rootfs, regional or fleet forward floor
+ // override is another request: refused, never handed the held
+ // pointer.
held, err := h.Publication.Verify(d.PublicKey)
if err != nil {
return nil, err
}
- if held.AllowBelowRootfsFloor != allowBelowRootfsFloor || held.AllowBelowRegionalFloor != allowBelowRegionalFloor {
+ if held.AllowBelowRootfsFloor != allowBelowRootfsFloor || held.AllowBelowRegionalFloor != allowBelowRegionalFloor ||
+ held.AllowBelowFleetForwardFloor != allowBelowFleetForwardFloor {
return nil, activationHeldError{id: id, component: component, channel: channel}
}
// An unpublished rollback is judged again under regionalMu
@@ -260,16 +269,27 @@ func (s *Server) rollbackHostUpdate(ctx context.Context, component, channel, act
// committed keeps its idempotent answer. Any other pointer fails
// the publication's CAS whatever the judgment. The rootfs floor
// needs no second look: it depends on the pointer alone, which
- // the CAS binds.
+ // the CAS binds. The fleet forward floor does, for the same
+ // reason as the regional one (a fleet may have been created
+ // since), first, under fleetFloorMu; both judge the one read,
+ // since the CAS binds the publication to the pointer anyway.
+ var standingRead bool
+ var standingPointer *release.SystemPointer
+ var standingErr error
standing := func() (*release.SystemPointer, error) {
- p, _, err := release.GetSystemPointer(ctx, s.cfg.Releases, d.PublicKey, component, channel)
- if errors.Is(err, os.ErrNotExist) {
- return nil, nil
+ if !standingRead {
+ standingRead = true
+ standingPointer, _, standingErr = release.GetSystemPointer(ctx, s.cfg.Releases, d.PublicKey, component, channel)
+ if errors.Is(standingErr, os.ErrNotExist) {
+ standingPointer, standingErr = nil, nil
+ }
}
- return p, err
+ return standingPointer, standingErr
}
- return s.regionalFloorPublish(ctx, channel, standing, held.Current.Version, allowBelowRegionalFloor, func() (*release.SystemPointer, error) {
- return d.PublishActivation(ctx, id)
+ return s.fleetFloorPublish(ctx, channel, standing, held.Current.Version, allowBelowFleetForwardFloor, func() (*release.SystemPointer, error) {
+ return s.regionalFloorPublish(ctx, channel, standing, held.Current.Version, allowBelowRegionalFloor, func() (*release.SystemPointer, error) {
+ return d.PublishActivation(ctx, id)
+ })
})
}
} else if !errors.Is(err, os.ErrNotExist) {
@@ -283,25 +303,31 @@ func (s *Server) rollbackHostUpdate(ctx context.Context, component, channel, act
return nil, release.ErrNoSystemHistory
}
target := current.History[0]
- // Both floors judge the snapshot the target came from, and both
+ // Every floor judges the snapshot the target came from, and both
// publication paths carry its ETag and the full options (P1-3, P2-4;
- // #447 W7).
+ // #447 W7; fleet public routes spec §9).
if err := rootfsFloorJudge(channel, current, target.Version, allowBelowRootfsFloor); err != nil {
return nil, err
}
if err := s.regionalFloorJudge(ctx, channel, current, target.Version, allowBelowRegionalFloor); err != nil {
return nil, err
}
- options := release.SystemPromoteOptions{Actor: actor, AllowBelowRootfsFloor: allowBelowRootfsFloor, AllowBelowRegionalFloor: allowBelowRegionalFloor}
+ if err := s.fleetForwardFloorJudge(ctx, channel, current, target.Version, allowBelowFleetForwardFloor); err != nil {
+ return nil, err
+ }
+ options := release.SystemPromoteOptions{Actor: actor, AllowBelowRootfsFloor: allowBelowRootfsFloor, AllowBelowRegionalFloor: allowBelowRegionalFloor,
+ AllowBelowFleetForwardFloor: allowBelowFleetForwardFloor}
id, err := s.reserveHostUpdate(ctx, &target, channel, "rollback", options, etag)
if err != nil {
return nil, err
}
- return s.regionalFloorPublish(ctx, channel, judgedPointer(current), target.Version, allowBelowRegionalFloor, func() (*release.SystemPointer, error) {
- if id == "" {
- return release.RollbackSystem(ctx, s.cfg.Releases, release.RootSigner(s.cfg.Key), component, channel, options, etag)
- }
- return d.PublishActivation(ctx, id)
+ return s.fleetFloorPublish(ctx, channel, judgedPointer(current), target.Version, allowBelowFleetForwardFloor, func() (*release.SystemPointer, error) {
+ return s.regionalFloorPublish(ctx, channel, judgedPointer(current), target.Version, allowBelowRegionalFloor, func() (*release.SystemPointer, error) {
+ if id == "" {
+ return release.RollbackSystem(ctx, s.cfg.Releases, release.RootSigner(s.cfg.Key), component, channel, options, etag)
+ }
+ return d.PublishActivation(ctx, id)
+ })
})
}
diff --git a/internal/console/rootfsfloor.go b/internal/console/rootfsfloor.go
index 380ee8347..264a70572 100644
--- a/internal/console/rootfsfloor.go
+++ b/internal/console/rootfsfloor.go
@@ -36,13 +36,15 @@ type rootfsFloorError struct{ msg string }
func (e rootfsFloorError) Error() string { return e.msg }
func (e rootfsFloorError) Unwrap() error { return errRootfsFloorPromotion }
-// systemFloorGate refuses moving component/channel to target where either
+// systemFloorGate refuses moving component/channel to target where any
// floor refuses it: the rootfs floor (rootfsFloorJudge, allowRootfs its
-// override) and the regional floor (regionalFloorJudge, allowRegional),
-// both judged on the ONE pointer read, so the ETag it returns covers
-// exactly the state both decided on. A channel with no pointer yet has
-// nothing to protect. A pointer that cannot be read refuses: the promotion
-// cannot tell what it would replace.
+// override), the regional floor (regionalFloorJudge, allowRegional) and
+// the fleet forward floor (fleetForwardFloorJudge, allowFleet), all judged
+// on the ONE pointer read, so the ETag it returns covers exactly the state
+// they decided on. A channel with no pointer yet has nothing for the
+// rootfs and regional floors to protect; the fleet forward floor judges
+// its first publication all the same (fleetfloor.go). A pointer that
+// cannot be read refuses: the promotion cannot tell what it would replace.
//
// It returns the ETag of the pointer snapshot it judged ("" for none). A
// caller that goes on to publish passes it as the preparation's expected
@@ -55,12 +57,15 @@ func (s *Server) systemFloorGate(ctx context.Context, component, channel, target
}
// systemFloorSnapshot is systemFloorGate returning the judged pointer too
-// (nil for none): promoteHostUpdate judges the regional floor on it again
-// under regionalMu just before it publishes (regionalFloorPublish).
+// (nil for none): promoteHostUpdate judges the fleet forward and regional
+// floors on it again under fleetFloorMu and regionalMu just before it
+// publishes (fleetFloorPublish, regionalFloorPublish).
func (s *Server) systemFloorSnapshot(ctx context.Context, component, channel, target string, allowRootfs, allowRegional, allowFleet bool) (*release.SystemPointer, string, error) {
cur, etag, err := release.GetSystemPointer(ctx, s.cfg.Releases, release.RootSigner(s.cfg.Key).RootPublicKey(), component, channel)
if errors.Is(err, os.ErrNotExist) {
- return nil, etag, nil
+ // A first publication: the rootfs and regional floors have nothing
+ // to protect, the fleet forward floor still judges it (spec §9).
+ return nil, etag, s.fleetForwardFloorJudge(ctx, channel, nil, target, allowFleet)
}
if err != nil {
return nil, "", err
@@ -68,7 +73,10 @@ func (s *Server) systemFloorSnapshot(ctx context.Context, component, channel, ta
if err := rootfsFloorJudge(channel, cur, target, allowRootfs); err != nil {
return cur, etag, err
}
- return cur, etag, s.regionalFloorJudge(ctx, channel, cur, target, allowRegional)
+ if err := s.regionalFloorJudge(ctx, channel, cur, target, allowRegional); err != nil {
+ return cur, etag, err
+ }
+ return cur, etag, s.fleetForwardFloorJudge(ctx, channel, cur, target, allowFleet)
}
// rootfsFloorJudge is the rootfs half of systemFloorGate's decision, on a
diff --git a/internal/console/server.go b/internal/console/server.go
index a1833e415..29c14ebca 100644
--- a/internal/console/server.go
+++ b/internal/console/server.go
@@ -1385,6 +1385,12 @@ type Server struct {
// regionalFloorHooks are test seams around regionalFloorPublish's
// critical section; nil in production.
regionalFloorHooks regionalFloorHooks
+ // fleetFloorMu is the fleet forward floor's mutex (fleet public routes
+ // spec §9): every system pointer publication holds it from its last
+ // fleet floor judgment to its pointer write (fleetFloorPublish). It is
+ // taken before regionalMu, and nothing that holds regionalMu takes it.
+ // The zero value is ready.
+ fleetFloorMu sync.Mutex
// The trash sweep's clock (lifetimes_purge.go) and the box floor
// watch's memory (lifetimes_floor.go).
trashSweepState
diff --git a/internal/release/layoutintent.go b/internal/release/layoutintent.go
index 1e40aa652..403178f30 100644
--- a/internal/release/layoutintent.go
+++ b/internal/release/layoutintent.go
@@ -311,6 +311,47 @@ func RegionalFloorAllows(installed, candidate string) bool {
return ok && c.Compare(RegionalDomainsFloor) >= 0
}
+// FleetForwardFloor is the first release whose hub retires a forward row
+// (fleet public routes spec §9). An older hub serves a forward row (its
+// fleet arm keys on placement) and never retires it, so a hub rolled back
+// below this floor would keep sending a deleted or reassigned host to the
+// old fleet. While any fleet exists the console does not move a system
+// channel below it, or publish a channel's first release below it, without
+// the override (console/fleetfloor.go). Numbered at the cut: the latest
+// tag at the time of writing is v0.31.1, so this names the next minor, and
+// the first release cut from a main that carries forward rows MUST be
+// v0.32.0 (re-pinned here if the cut differs). TestFleetForwardFloorIsPinned
+// pins it.
+var FleetForwardFloor = SemVer{Major: 0, Minor: 32, Patch: 0}
+
+// FleetForwardFloorOverrideFlag is the fleet forward floor override's flag
+// name, on `carlos system update` and `carlos system rollback`. Boxes have
+// no counterpart: the floor binds the console's promotion alone.
+const FleetForwardFloorOverrideFlag = "allow-below-fleet-forward-floor"
+
+// FleetForwardFloorOverrideUsage (FPR-C05) is the override flag's help
+// text, shared by the two commands. A const cannot format, so the floor is
+// written into the text (the deck's row keeps its %s), as RD-32 writes
+// v0.31.0 above; TestFleetForwardFloorIsPinned and the copy gate hold it
+// to "v"+FleetForwardFloor.String().
+const FleetForwardFloorOverrideUsage = "allow a release below v0.32.0 while customer fleets exist. a hub on that release keeps serving fleet apps it can no longer retire"
+
+// FleetForwardFloorAllows is RegionalFloorAllows against FleetForwardFloor:
+// a channel running installed may move to candidate without the override
+// when installed is below the floor or does not parse, and when it is at
+// or above it only to a candidate whose version parses at or above it.
+// The console asks it first and lists the fleets only when it says no:
+// the floor binds only while a fleet exists. A channel with no pointer at
+// all is not installed anywhere; the console judges that case itself.
+func FleetForwardFloorAllows(installed, candidate string) bool {
+ in, ok := ParseReleaseVersion(installed)
+ if !ok || in.Compare(FleetForwardFloor) < 0 {
+ return true
+ }
+ c, ok := ParseReleaseVersion(candidate)
+ return ok && c.Compare(FleetForwardFloor) >= 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 11b380655..f437f102e 100644
--- a/internal/release/layoutintent_test.go
+++ b/internal/release/layoutintent_test.go
@@ -255,3 +255,47 @@ func TestRegionalDomainsFloorIsPinned(t *testing.T) {
t.Errorf("RegionalFloorOverrideUsage %q does not name v%s", RegionalFloorOverrideUsage, RegionalDomainsFloor)
}
}
+
+// TestFleetForwardFloorIsPinned pins the first release whose hub retires a
+// forward row (fleet public routes spec §9), numbered at the cut, and the
+// override's flag name and help text, which writes the floor in.
+func TestFleetForwardFloorIsPinned(t *testing.T) {
+ if FleetForwardFloor != (SemVer{Major: 0, Minor: 32, Patch: 0}) {
+ t.Fatalf("FleetForwardFloor = %+v, want v0.32.0 (the first release carrying forward rows)", FleetForwardFloor)
+ }
+ if FleetForwardFloor.Compare(RegionalDomainsFloor) <= 0 {
+ t.Fatal("FleetForwardFloor is not above RegionalDomainsFloor")
+ }
+ for v, below := range map[string]bool{"v0.31.0": true, "v0.31.9": true, "v0.32.0": false, "v0.32.1": false, "v1.0.0": false, "dev": false} {
+ if got := BelowFloor(v, FleetForwardFloor); got != below {
+ t.Errorf("BelowFloor(%q, FleetForwardFloor) = %v, want %v", v, got, below)
+ }
+ }
+ if FleetForwardFloorOverrideFlag != "allow-below-fleet-forward-floor" {
+ t.Errorf("FleetForwardFloorOverrideFlag = %q", FleetForwardFloorOverrideFlag)
+ }
+ // FPR-C05 with its %s filled by the floor: the const cannot format.
+ want := strings.ReplaceAll("allow a release below %s while customer fleets exist. a hub on that release keeps serving fleet apps it can no longer retire", "%s", "v"+FleetForwardFloor.String())
+ if FleetForwardFloorOverrideUsage != want {
+ t.Errorf("FleetForwardFloorOverrideUsage = %q\nwant %q", FleetForwardFloorOverrideUsage, want)
+ }
+}
+
+func TestFleetForwardFloorAllows(t *testing.T) {
+ for _, c := range []struct {
+ installed, candidate string
+ want bool
+ }{
+ // Below the floor, or unparseable: anything goes.
+ {"v0.31.0", "v0.30.0", true}, {"v0.31.0", "v0.32.1", true}, {"v0.31.0", "junk", true}, {"v0.31.0", "", true},
+ {"dev", "v0.20.0", true}, {"", "v0.20.0", true},
+ // At or above it: only to a parseable release at or above it.
+ {"v0.32.0", "v0.32.0", true}, {"v0.32.0", "v0.32.1", true}, {"v0.33.0", "v0.32.0", true},
+ {"v0.32.0", "v0.31.9", false}, {"v0.32.0", "v0.31.0", false}, {"v1.0.0", "v0.31.0", false},
+ {"v0.32.0", "junk", false}, {"v0.32.0", "", false}, {"v0.32.0", "v0.32", false},
+ } {
+ if got := FleetForwardFloorAllows(c.installed, c.candidate); got != c.want {
+ t.Errorf("FleetForwardFloorAllows(%q, %q) = %v, want %v", c.installed, c.candidate, got, c.want)
+ }
+ }
+}
diff --git a/internal/release/systempointer.go b/internal/release/systempointer.go
index be53507aa..4d53086d2 100644
--- a/internal/release/systempointer.go
+++ b/internal/release/systempointer.go
@@ -44,6 +44,16 @@ type SystemPointer struct {
// override can be compared with a retry's, never read by boxes, and
// absent from every later write.
AllowBelowRegionalFloor bool `json:"allow_below_regional_floor,omitempty"`
+ // AllowBelowFleetForwardFloor records that THIS write moved the channel
+ // below FleetForwardFloor, or published its first release below it,
+ // while a fleet existed, on the operator's override (`carlos system
+ // update` or `rollback` --allow-below-fleet-forward-floor; fleet public
+ // routes spec §9), the same way again: judged by the console
+ // (console/fleetfloor.go), signed so a held activation's override can be
+ // compared with a retry's, never read by boxes, and absent from every
+ // later write. omitempty keeps a pointer without it byte-identical to
+ // one written before the field existed.
+ AllowBelowFleetForwardFloor bool `json:"allow_below_fleet_forward_floor,omitempty"`
}
// SystemRelease is everything a box needs to install one version. It travels
@@ -272,6 +282,10 @@ type SystemPromoteOptions struct {
// AllowBelowRegionalFloor is the operator's regional floor override,
// carried the same way (SystemPointer.AllowBelowRegionalFloor).
AllowBelowRegionalFloor bool
+ // AllowBelowFleetForwardFloor is the operator's fleet forward floor
+ // override, carried the same way
+ // (SystemPointer.AllowBelowFleetForwardFloor).
+ AllowBelowFleetForwardFloor bool
}
// PromoteSystem writes the pointer for one channel, CAS-guarded. The
@@ -316,7 +330,8 @@ func PrepareSystemPromotion(ctx context.Context, s Store, sg Signer, component,
old = nil
}
next := &SystemPointer{ActivationID: id, Component: component, Channel: channel, Current: rel, Spread: o.Spread.String(),
- AllowBelowRootfsFloor: o.AllowBelowRootfsFloor, AllowBelowRegionalFloor: o.AllowBelowRegionalFloor}
+ AllowBelowRootfsFloor: o.AllowBelowRootfsFloor, AllowBelowRegionalFloor: o.AllowBelowRegionalFloor,
+ AllowBelowFleetForwardFloor: o.AllowBelowFleetForwardFloor}
if rel.ReleasedAt.IsZero() {
next.Current.ReleasedAt = time.Now().UTC().Truncate(time.Second)
}
@@ -354,8 +369,8 @@ func RollbackSystem(ctx context.Context, s Store, sg Signer, component, channel
return PublishSystemPublication(ctx, s, sg.verifyPub(), prepared)
}
-// PrepareSystemRollback takes the actor and the rootfs and regional floor
-// overrides from o; the rollback keeps the old pointer's spread.
+// PrepareSystemRollback takes the actor and the rootfs, regional and fleet
+// forward floor overrides from o; the rollback keeps the old pointer's spread.
func PrepareSystemRollback(ctx context.Context, s Store, sg Signer, component, channel string, o SystemPromoteOptions, id string, expectedETag ...string) (SystemPublication, error) {
key := SystemPointerKey(component, channel)
body, etag, err := s.Get(ctx, key)
@@ -375,9 +390,10 @@ func PrepareSystemRollback(ctx context.Context, s Store, sg Signer, component, c
next := &SystemPointer{ActivationID: id,
Component: component, Channel: channel,
Current: old.History[0], History: old.History[1:], Spread: old.Spread,
- Audit: prependCapped(Promotion{Version: old.History[0].Version, From: old.Current.Version, To: channel, Actor: o.Actor, At: time.Now().UTC()}, old.Audit, auditMax),
- AllowBelowRootfsFloor: o.AllowBelowRootfsFloor,
- AllowBelowRegionalFloor: o.AllowBelowRegionalFloor,
+ Audit: prependCapped(Promotion{Version: old.History[0].Version, From: old.Current.Version, To: channel, Actor: o.Actor, At: time.Now().UTC()}, old.Audit, auditMax),
+ AllowBelowRootfsFloor: o.AllowBelowRootfsFloor,
+ AllowBelowRegionalFloor: o.AllowBelowRegionalFloor,
+ AllowBelowFleetForwardFloor: o.AllowBelowFleetForwardFloor,
}
wrapper, err := signSystemPointer(sg, next)
if err != nil {
diff --git a/internal/release/systempointer_test.go b/internal/release/systempointer_test.go
index 4f903add6..eae5f2d5a 100644
--- a/internal/release/systempointer_test.go
+++ b/internal/release/systempointer_test.go
@@ -2,6 +2,7 @@ package release
import (
"context"
+ "encoding/base64"
"encoding/json"
"errors"
"os"
@@ -311,3 +312,74 @@ func TestSystemPointerCarriesTheRegionalFloorOverrideForOneWrite(t *testing.T) {
t.Fatalf("the signed rollback lost the override: %+v, %v", got, err)
}
}
+
+// The fleet forward floor override (fleet public routes spec §9) rides one
+// pointer write as the other two do: both Prepare functions sign it from the
+// options, it verifies, and the next write without it drops it. A pointer
+// written without it carries no key for it at all (omitempty), so it is
+// byte-identical to one written before the field existed, and verifies.
+func TestPrepareCarriesTheFleetFloorOverride(t *testing.T) {
+ priv, pub := testKeys(t)
+ s := NewDirStore(t.TempDir())
+ ctx := context.Background()
+ sg := RootSigner(priv)
+ key := SystemPointerKey(SystemComponentRouter, "stable")
+ payloadOf := func() string {
+ t.Helper()
+ raw, _, err := s.Get(ctx, key)
+ if err != nil {
+ t.Fatal(err)
+ }
+ var sw signedWrapper
+ if err := json.Unmarshal(raw, &sw); err != nil {
+ t.Fatal(err)
+ }
+ payload, err := base64.StdEncoding.DecodeString(sw.Payload)
+ if err != nil {
+ t.Fatal(err)
+ }
+ return string(payload)
+ }
+ publish := func(p SystemPublication, err error) *SystemPointer {
+ t.Helper()
+ if err != nil {
+ t.Fatal(err)
+ }
+ got, err := PublishSystemPublication(ctx, s, pub, p)
+ if err != nil {
+ t.Fatal(err)
+ }
+ return got
+ }
+ for _, v := range []string{"v0.31.0", "v0.32.0"} {
+ publish(PrepareSystemPromotion(ctx, s, sg, SystemComponentRouter, "stable", testSystemRelease(v), SystemPromoteOptions{}, ""))
+ if strings.Contains(payloadOf(), "allow_below_fleet_forward_floor") {
+ t.Fatalf("a pointer written without the override names it: %s", payloadOf())
+ }
+ if got, _, err := GetSystemPointer(ctx, s, pub, SystemComponentRouter, "stable"); err != nil || got.AllowBelowFleetForwardFloor {
+ t.Fatalf("a pointer without the override = %+v, %v", got, err)
+ }
+ }
+
+ publish(PrepareSystemPromotion(ctx, s, sg, SystemComponentRouter, "stable", testSystemRelease("v0.31.5"), SystemPromoteOptions{AllowBelowFleetForwardFloor: true}, "id-1"))
+ got, _, err := GetSystemPointer(ctx, s, pub, SystemComponentRouter, "stable")
+ if err != nil || !got.AllowBelowFleetForwardFloor || got.AllowBelowRegionalFloor || got.AllowBelowRootfsFloor {
+ t.Fatalf("the promotion's verified pointer = %+v, %v; want the fleet override alone", got, err)
+ }
+ var signed map[string]any
+ if err := json.Unmarshal([]byte(payloadOf()), &signed); err != nil || signed["allow_below_fleet_forward_floor"] != true {
+ t.Fatalf("the signed payload lacks the override: %s", payloadOf())
+ }
+
+ publish(PrepareSystemRollback(ctx, s, sg, SystemComponentRouter, "stable", SystemPromoteOptions{Actor: "paul"}, "id-2"))
+ if got, _, err := GetSystemPointer(ctx, s, pub, SystemComponentRouter, "stable"); err != nil || got.AllowBelowFleetForwardFloor || got.Current.Version != "v0.32.0" {
+ t.Fatalf("a rollback without the override = %+v, %v", got, err)
+ }
+ p := publish(PrepareSystemRollback(ctx, s, sg, SystemComponentRouter, "stable", SystemPromoteOptions{Actor: "paul", AllowBelowFleetForwardFloor: true}, "id-3"))
+ if p.Current.Version != "v0.31.0" || !p.AllowBelowFleetForwardFloor {
+ t.Fatalf("the rollback with the override = %+v", p)
+ }
+ if got, _, err := GetSystemPointer(ctx, s, pub, SystemComponentRouter, "stable"); err != nil || !got.AllowBelowFleetForwardFloor {
+ t.Fatalf("the signed rollback lost the override: %+v, %v", got, err)
+ }
+}
diff --git a/system.go b/system.go
index 85d69a85e..5fa5241e0 100644
--- a/system.go
+++ b/system.go
@@ -297,6 +297,7 @@ func runSystemUpdate(args []string) {
yes := fs.Bool("yes", false, "do not ask")
allowBelowRootfsFloor := fs.Bool(release.RootfsFloorOverrideFlag, false, release.RootfsFloorOverrideUsage)
allowBelowRegionalFloor := fs.Bool(release.RegionalFloorOverrideFlag, false, release.RegionalFloorOverrideUsage)
+ allowBelowFleetForwardFloor := fs.Bool(release.FleetForwardFloorOverrideFlag, false, release.FleetForwardFloorOverrideUsage)
fs.Usage = flagUsage(fs, "")
fs.Parse(args)
if *file != "" && *version == "" {
@@ -354,6 +355,9 @@ func runSystemUpdate(args []string) {
if *allowBelowRegionalFloor {
in["allow_below_regional_floor"] = true
}
+ if *allowBelowFleetForwardFloor {
+ in["allow_below_fleet_forward_floor"] = true
+ }
if *version != "" {
in["version"] = *version
}
@@ -582,6 +586,7 @@ func runSystemRollback(args []string) {
yes := fs.Bool("yes", false, "do not ask")
allowBelowRootfsFloor := fs.Bool(release.RootfsFloorOverrideFlag, false, release.RootfsFloorOverrideUsage)
allowBelowRegionalFloor := fs.Bool(release.RegionalFloorOverrideFlag, false, release.RegionalFloorOverrideUsage)
+ allowBelowFleetForwardFloor := fs.Bool(release.FleetForwardFloorOverrideFlag, false, release.FleetForwardFloorOverrideUsage)
fs.Usage = flagUsage(fs, "")
fs.Parse(args)
if *channel == "" {
@@ -603,6 +608,9 @@ func runSystemRollback(args []string) {
if *allowBelowRegionalFloor {
in["allow_below_regional_floor"] = true
}
+ if *allowBelowFleetForwardFloor {
+ in["allow_below_fleet_forward_floor"] = true
+ }
st, body, err := sess.postJSON(context.Background(), "/api/cli/system/rollback", in)
if err != nil {
log.Fatalf("carlos system rollback: %v", err)
diff --git a/system_fleetfloor_test.go b/system_fleetfloor_test.go
new file mode 100644
index 000000000..a3c22ca41
--- /dev/null
+++ b/system_fleetfloor_test.go
@@ -0,0 +1,85 @@
+package main
+
+import (
+ "encoding/json"
+ "net/http"
+ "net/http/httptest"
+ "path/filepath"
+ "testing"
+
+ "github.com/carlosframework/platform/internal/release"
+)
+
+// systemFloorCLIFixture is a fake console for `carlos system update` and
+// `rollback`: it answers the status read, records each request body the two
+// doors receive and answers as a finished job, with a credential pointed at
+// it (doorKeysCLIFixture's shortcut).
+func systemFloorCLIFixture(t *testing.T) map[string][]map[string]any {
+ t.Helper()
+ home := t.TempDir()
+ t.Setenv("HOME", home)
+ t.Setenv("CARLOS_CONSOLE", "")
+ t.Setenv("CARLOS_DEPLOYMENT_BUCKET", "")
+ t.Setenv("CARLOS_DEPLOYMENT_DIR", "")
+ t.Chdir(t.TempDir())
+ creds := filepath.Join(home, "carlos-credentials")
+ t.Setenv("CARLOS_CREDENTIALS", creds)
+ bodies := map[string][]map[string]any{}
+ record := func(door string, r *http.Request) {
+ var in map[string]any
+ if err := json.NewDecoder(r.Body).Decode(&in); err != nil {
+ t.Errorf("%s: %v", door, err)
+ }
+ bodies[door] = append(bodies[door], in)
+ }
+ mux := http.NewServeMux()
+ mux.HandleFunc("GET /api/cli/system/status", func(w http.ResponseWriter, r *http.Request) {
+ json.NewEncoder(w).Encode(map[string]any{})
+ })
+ mux.HandleFunc("POST /api/cli/system/update", func(w http.ResponseWriter, r *http.Request) {
+ record("update", r)
+ json.NewEncoder(w).Encode(map[string]any{"job": "j1"})
+ })
+ mux.HandleFunc("GET /api/cli/system/jobs/j1", func(w http.ResponseWriter, r *http.Request) {
+ json.NewEncoder(w).Encode(map[string]any{"done": true})
+ })
+ mux.HandleFunc("POST /api/cli/system/rollback", func(w http.ResponseWriter, r *http.Request) {
+ record("rollback", r)
+ json.NewEncoder(w).Encode(map[string]any{"channel": "canary", "version": "v0.31.0"})
+ })
+ ts := httptest.NewServer(mux)
+ t.Cleanup(ts.Close)
+ writeTestCredential(t, creds, ts.URL)
+ return bodies
+}
+
+// `carlos system update` and `carlos system rollback` send
+// allow_below_fleet_forward_floor: true with
+// --allow-below-fleet-forward-floor, and leave the key out without it, so a
+// request without the flag is the request it was before the flag existed.
+func TestSystemUpdateSendsTheFleetFloorOverride(t *testing.T) {
+ bodies := systemFloorCLIFixture(t)
+ captureStdout(t)
+ flag := "--" + release.FleetForwardFloorOverrideFlag
+ runSystemUpdate([]string{"--channel", "canary", "--version", "v0.31.0", "--yes", flag})
+ runSystemUpdate([]string{"--channel", "canary", "--version", "v0.31.0", "--yes"})
+ runSystemRollback([]string{"--channel", "canary", "--yes", flag})
+ runSystemRollback([]string{"--channel", "canary", "--yes"})
+ for _, door := range []string{"update", "rollback"} {
+ got := bodies[door]
+ if len(got) != 2 {
+ t.Fatalf("%s: %d requests, want 2", door, len(got))
+ }
+ if got[0]["allow_below_fleet_forward_floor"] != true {
+ t.Errorf("%s with %s sent %v", door, flag, got[0])
+ }
+ if _, ok := got[1]["allow_below_fleet_forward_floor"]; ok {
+ t.Errorf("%s without %s sent %v", door, flag, got[1])
+ }
+ for _, other := range []string{"allow_below_rootfs_floor", "allow_below_regional_floor"} {
+ if _, ok := got[0][other]; ok {
+ t.Errorf("%s with %s alone also sent %s: %v", door, flag, other, got[0])
+ }
+ }
+ }
+}