Regional domains (#447) Task 10: the promotion floor and its override
While a regional claim exists, a system channel at or above RegionalDomainsFloor (v0.31.0) never moves below it, or to an unparseable release, without --allow-below-regional-floor (W7, spec 10.2, ruling 2). - release: RegionalFloorAllows, RegionalFloorOverrideFlag/Usage (RD-32); SystemPointer and SystemPromoteOptions gain AllowBelowRegionalFloor, signed on both builders. Boxes do not read it. - console: rootfsFloorGate becomes systemFloorGate: one pointer read, rootfsFloorJudge then regionalFloorJudge on it, one ETag returned. regionalFloorJudge reads the claims (ListWithUnread) only when the move crosses the floor; a listing error refuses, an unread claim counts as regional; RD-30 refusal, RD-31 override log. - The override is part of the activation request digest (omitempty so requests without it keep their digest) and of the held-rollback comparison; rollbackHostUpdate gains allowBelowRegionalFloor and runs the regional judge after the rootfs one on the same snapshot. - Doors: update and rollback bodies gain allow_below_regional_floor; errRegionalFloorPromotion maps to 409 as the rootfs refusal does. - CLI: --allow-below-regional-floor on carlos system update/rollback. - Existing call sites updated (rootfsfloor_test, hostactivation_test, plan9_b_test) per the controller ruling.
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
14 files changed,
+683
−49
internal/console/apisystemupdate.go+14 −7internal/console/apisystemupdate_test.go+86 −0internal/console/hostactivation.go+22 −14internal/console/hostactivation_test.go+3 −3internal/console/plan9_b_test.go+2 −2internal/console/regionalfloor.go+77 −0internal/console/regionalfloor_test.go+341 −0internal/console/rootfsfloor.go+18 −11internal/console/rootfsfloor_test.go+7 −7internal/release/layoutintent.go+25 −0internal/release/layoutintent_test.go+27 −0internal/release/systempointer.go+17 −5internal/release/systempointer_test.go+36 −0system.go+8 −0
diff --git a/internal/console/apisystemupdate.go b/internal/console/apisystemupdate.go| index a32807071..05499a8af 100644 |
| --- a/internal/console/apisystemupdate.go |
| +++ b/internal/console/apisystemupdate.go |
| @@ -357,6 +357,10 @@ type systemUpdateRequest struct { |
| // --allow-below-rootfs-floor`: the rootfs floor's override |
| // (rootfsfloor.go), part of the activation request's identity. |
| AllowBelowRootfsFloor bool `json:"allow_below_rootfs_floor"` |
| + // AllowBelowRegionalFloor is `carlos system update |
| + // --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"` |
| } |
| // handleAPISystemUpdate starts the promote and answers with a job id. The |
| @@ -417,11 +421,11 @@ func (s *Server) handleAPISystemUpdate(w http.ResponseWriter, r *http.Request) { |
| return |
| } |
| } |
| - // The rootfs floor, 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 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. |
| if in.Version != "" { |
| - if _, err := s.rootfsFloorGate(r.Context(), in.Component, in.Channel, in.Version, in.AllowBelowRootfsFloor); errors.Is(err, errRootfsFloorPromotion) { |
| + if _, err := s.systemFloorGate(r.Context(), in.Component, in.Channel, in.Version, in.AllowBelowRootfsFloor, in.AllowBelowRegionalFloor); errors.Is(err, errRootfsFloorPromotion) || errors.Is(err, errRegionalFloorPromotion) { |
| jsonError(w, http.StatusConflict, err.Error()) |
| return |
| } |
| @@ -552,7 +556,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, AllowBelowRootfsFloor: in.AllowBelowRootfsFloor}) |
| + release.SystemPromoteOptions{Actor: actor, Spread: spread, AllowBelowRootfsFloor: in.AllowBelowRootfsFloor, AllowBelowRegionalFloor: in.AllowBelowRegionalFloor}) |
| if err != nil { |
| return err |
| } |
| @@ -914,6 +918,9 @@ func (s *Server) handleAPISystemRollback(w http.ResponseWriter, r *http.Request) |
| // AllowBelowRootfsFloor is `carlos system rollback |
| // --allow-below-rootfs-floor` (rootfsfloor.go). |
| AllowBelowRootfsFloor bool `json:"allow_below_rootfs_floor"` |
| + // AllowBelowRegionalFloor is `carlos system rollback |
| + // --allow-below-regional-floor` (regionalfloor.go). |
| + AllowBelowRegionalFloor bool `json:"allow_below_regional_floor"` |
| } |
| if !readJSONStrictLimit(w, r, &in, 1<<10) { |
| return |
| @@ -943,10 +950,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) |
| + p, err := s.rollbackHostUpdate(r.Context(), in.Component, in.Channel, addr, in.AllowBelowRootfsFloor, in.AllowBelowRegionalFloor) |
| var held activationHeldError |
| switch { |
| - case errors.Is(err, errRootfsFloorPromotion): |
| + case errors.Is(err, errRootfsFloorPromotion), errors.Is(err, errRegionalFloorPromotion): |
| jsonError(w, http.StatusConflict, err.Error()) |
| return |
| case errors.Is(err, release.ErrCASConflict): |
diff --git a/internal/console/apisystemupdate_test.go b/internal/console/apisystemupdate_test.go| index 2592334e8..fcf20a21a 100644 |
| --- a/internal/console/apisystemupdate_test.go |
| +++ b/internal/console/apisystemupdate_test.go |
| @@ -614,3 +614,89 @@ func TestSystemDoorsRefuseBelowTheRootfsFloor(t *testing.T) { |
| t.Fatalf("rollback below the floor with the override = %d %v", st, out) |
| } |
| } |
| + |
| +// `carlos system update` and `carlos system rollback` refuse to move a |
| +// channel at the regional floor below it while a regional claim exists, |
| +// without --allow-below-regional-floor (#447 W7): a named version at the |
| +// door, the latest release inside the job, both before anything is |
| +// reserved or written; the rootfs override does not stand in for it; the |
| +// override goes through and is signed onto that pointer only. |
| +func TestSystemDoorsRefuseBelowTheRegionalFloor(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.31.0") |
| + owner := cliToken(t, fx, "paul@keymail.dev", "code-sys-regional-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.30.0", "v0.31.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) |
| + } |
| + putRegionalClaim(t, fx.rel, "shop.example.com", "acct", "shop", rdHomeHost, false, false) |
| + want := "canary runs v0.31.0 and this deployment has a regional domain, so it takes only v0.31.0 or later. %s is not one. to move it there anyway, pass --allow-below-regional-floor" |
| + pointer := func() *release.SystemPointer { |
| + p, _, err := release.GetSystemPointer(ctx, fx.rel, fx.pub, "router", "canary") |
| + 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.30.2"}, owner) |
| + if st != http.StatusConflict || str(t, out, "error") != fmt.Sprintf(want, "v0.30.2") { |
| + t.Fatalf("update to a named v0.30.2 = %d %v", st, out) |
| + } |
| + st, out = postJSON(t, fx.ts.URL+"/api/cli/system/rollback", map[string]any{"channel": "canary"}, owner) |
| + if st != http.StatusConflict || str(t, out, "error") != fmt.Sprintf(want, "v0.30.0") { |
| + t.Fatalf("rollback to v0.30.0 = %d %v", st, out) |
| + } |
| + st, out = postJSON(t, fx.ts.URL+"/api/cli/system/rollback", map[string]any{"channel": "canary", "allow_below_rootfs_floor": true}, owner) |
| + if st != http.StatusConflict || str(t, out, "error") != fmt.Sprintf(want, "v0.30.0") { |
| + t.Fatalf("rollback to v0.30.0 with the rootfs override = %d %v", 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(); p.Current.Version != "v0.31.0" { |
| + t.Fatalf("a refused promotion moved the pointer to %s", p.Current.Version) |
| + } |
| + |
| + 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_regional_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(); p.Current.Version != "v0.18.0" || !p.AllowBelowRegionalFloor || !p.AllowBelowRootfsFloor { |
| + t.Fatalf("the overrides' pointer = %+v", p) |
| + } |
| + time.Sleep(1100 * time.Millisecond) |
| + // Below the floor now: a rollback to v0.31.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.31.0 = %d %v", st, out) |
| + } |
| + if p := pointer(); p.Current.Version != "v0.31.0" || p.AllowBelowRegionalFloor { |
| + 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_regional_floor": true}, owner) |
| + if st != http.StatusOK || str(t, out, "version") != "v0.30.0" { |
| + t.Fatalf("rollback below the floor with the override = %d %v", st, out) |
| + } |
| + if p := pointer(); !p.AllowBelowRegionalFloor { |
| + t.Fatalf("the override's rollback pointer = %+v", p) |
| + } |
| +} |
diff --git a/internal/console/hostactivation.go b/internal/console/hostactivation.go| index d0ea8b871..0b05fe793 100644 |
| --- a/internal/console/hostactivation.go |
| +++ b/internal/console/hostactivation.go |
| @@ -112,13 +112,17 @@ 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. |
| request, err := json.Marshal(struct { |
| - Channel string |
| - Mode string |
| - Release release.SystemRelease |
| - Spread time.Duration |
| - AllowBelowRootfsFloor bool |
| - }{channel, mode, requestRelease, options.Spread, options.AllowBelowRootfsFloor}) |
| + 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}) |
| if err != nil { |
| return "", err |
| } |
| @@ -201,7 +205,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. |
| - etag, err := s.rootfsFloorGate(ctx, component, channel, rel.Version, options.AllowBelowRootfsFloor) |
| + etag, err := s.systemFloorGate(ctx, component, channel, rel.Version, options.AllowBelowRootfsFloor, options.AllowBelowRegionalFloor) |
| if err != nil { |
| return nil, err |
| } |
| @@ -216,7 +220,7 @@ func (s *Server) promoteHostUpdate(ctx context.Context, rel release.SystemReleas |
| return d.PublishActivation(ctx, id) |
| } |
| -func (s *Server) rollbackHostUpdate(ctx context.Context, component, channel, actor string, allowBelowRootfsFloor bool) (*release.SystemPointer, error) { |
| +func (s *Server) rollbackHostUpdate(ctx context.Context, component, channel, actor string, allowBelowRootfsFloor, allowBelowRegionalFloor bool) (*release.SystemPointer, error) { |
| d := hostactors.Directory{Store: s.cfg.Releases, PublicKey: release.RootSigner(s.cfg.Key).RootPublicKey(), Bucket: s.cfg.Bucket} |
| floor, err := hostfloor.Read(ctx, s.cfg.Releases, d.PublicKey, s.cfg.Bucket) |
| if err == nil { |
| @@ -232,13 +236,13 @@ 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 floor override is another |
| - // request: refused, never handed the held pointer. |
| + // A retry with another rootfs or regional 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 { |
| + if held.AllowBelowRootfsFloor != allowBelowRootfsFloor || held.AllowBelowRegionalFloor != allowBelowRegionalFloor { |
| return nil, activationHeldError{id: id, component: component, channel: channel} |
| } |
| return d.PublishActivation(ctx, id) |
| @@ -254,12 +258,16 @@ func (s *Server) rollbackHostUpdate(ctx context.Context, component, channel, act |
| return nil, release.ErrNoSystemHistory |
| } |
| target := current.History[0] |
| - // The floor judges the snapshot the target came from, and both |
| - // publication paths carry its ETag and the full options (P1-3, P2-4). |
| + // Both floors judge the snapshot the target came from, and both |
| + // publication paths carry its ETag and the full options (P1-3, P2-4; |
| + // #447 W7). |
| if err := rootfsFloorJudge(channel, current, target.Version, allowBelowRootfsFloor); err != nil { |
| return nil, err |
| } |
| - options := release.SystemPromoteOptions{Actor: actor, AllowBelowRootfsFloor: allowBelowRootfsFloor} |
| + if err := s.regionalFloorJudge(ctx, channel, current, target.Version, allowBelowRegionalFloor); err != nil { |
| + return nil, err |
| + } |
| + options := release.SystemPromoteOptions{Actor: actor, AllowBelowRootfsFloor: allowBelowRootfsFloor, AllowBelowRegionalFloor: allowBelowRegionalFloor} |
| id, err := s.reserveHostUpdate(ctx, &target, channel, "rollback", options, etag) |
| if err != nil { |
| return nil, err |
diff --git a/internal/console/hostactivation_test.go b/internal/console/hostactivation_test.go| index ceab5c7a5..9fa0aff9c 100644 |
| --- a/internal/console/hostactivation_test.go |
| +++ b/internal/console/hostactivation_test.go |
| @@ -159,7 +159,7 @@ func TestHostRollbackResumesWithoutPoppingAgain(t *testing.T) { |
| s, d, _ := activationFixture(t) |
| broken := &activationFaultStore{Store: d.Store, fail: true} |
| s.cfg.Releases = broken |
| - if _, err := s.rollbackHostUpdate(t.Context(), "router", "stable", "operator", false); err == nil { |
| + if _, err := s.rollbackHostUpdate(t.Context(), "router", "stable", "operator", false, false); err == nil { |
| t.Fatal("missing injected failure") |
| } |
| before, err := d.Read(t.Context()) |
| @@ -170,11 +170,11 @@ func TestHostRollbackResumesWithoutPoppingAgain(t *testing.T) { |
| for id = range before.Roster.Activations { |
| } |
| s.cfg.Releases = d.Store |
| - first, err := s.rollbackHostUpdate(t.Context(), "router", "stable", "operator", false) |
| + first, err := s.rollbackHostUpdate(t.Context(), "router", "stable", "operator", false, false) |
| if err != nil || first.ActivationID != id || first.Current.Version != "v1.1.0" { |
| t.Fatal(first, err) |
| } |
| - second, err := s.rollbackHostUpdate(t.Context(), "router", "stable", "operator", false) |
| + second, err := s.rollbackHostUpdate(t.Context(), "router", "stable", "operator", false, false) |
| if err != nil || second.ActivationID != id || len(second.History) != len(first.History) { |
| t.Fatal(second, err) |
| } |
diff --git a/internal/console/plan9_b_test.go b/internal/console/plan9_b_test.go| index 1a7286983..5618c34e4 100644 |
| --- a/internal/console/plan9_b_test.go |
| +++ b/internal/console/plan9_b_test.go |
| @@ -197,7 +197,7 @@ func TestPlan9OperatorCancelsAnUnpublishedActivation(t *testing.T) { |
| held := plan9Roster(t, fx.srv) |
| stale := *held.Roster.Activations[id].Publication |
| // The wedge: a different request for the channel is refused while held. |
| - if _, err := fx.srv.rollbackHostUpdate(ctx, "router", "stable", "paul@keymail.dev", false); err == nil { |
| + if _, err := fx.srv.rollbackHostUpdate(ctx, "router", "stable", "paul@keymail.dev", false, false); err == nil { |
| t.Fatal("rollback succeeded through a held activation") |
| } |
| if fx.srv.cfg.Releases == nil { |
| @@ -235,7 +235,7 @@ func TestPlan9OperatorCancelsAnUnpublishedActivation(t *testing.T) { |
| if st, out := postJSON(t, fx.ts.URL+"/api/cli/system/activation/cancel", map[string]string{"channel": "stable"}, owner); st != http.StatusNotFound { |
| t.Fatalf("cancel with nothing held = %d %v, want 404", st, out) |
| } |
| - p, err := fx.srv.rollbackHostUpdate(ctx, "router", "stable", "paul@keymail.dev", false) |
| + p, err := fx.srv.rollbackHostUpdate(ctx, "router", "stable", "paul@keymail.dev", false, false) |
| if err != nil || p.Current.Version != "v1.1.0" { |
| t.Fatalf("rollback after cancel = %v, %v", p, err) |
| } |
diff --git a/internal/console/regionalfloor.go b/internal/console/regionalfloor.go| new file mode 100644 |
| index 000000000..f67e5ca78 |
| --- /dev/null |
| +++ b/internal/console/regionalfloor.go |
| @@ -0,0 +1,77 @@ |
| +package console |
| + |
| +import ( |
| + "context" |
| + "errors" |
| + "fmt" |
| + "log" |
| + |
| + "github.com/carlosframework/platform/internal/release" |
| +) |
| + |
| +// The regional floor at the console (#447 W7, spec §10.2; Paul's ruling 2): |
| +// while a regional claim exists, a system channel whose current pointer |
| +// names release.RegionalDomainsFloor or later is never moved to a release |
| +// below it, or to one whose version does not parse, unless the operator |
| +// passes --allow-below-regional-floor. A box below the floor serves a |
| +// regional claim as nothing at all, so moving a channel below it stops |
| +// serving every regional name on that channel's boxes. |
| +// |
| +// It sits at every door the rootfs floor sits on (rootfsfloor.go): the |
| +// update door's preflight and promoteHostUpdate through systemFloorGate, |
| +// and rollbackHostUpdate on the snapshot its target came from. Both judges |
| +// decide on the one pointer read, so the ETag the publication is bound to |
| +// covers both decisions. The override is signed onto the pointer and is |
| +// part of an activation request's identity, as the rootfs one is; boxes |
| +// do not read it. |
| + |
| +// consoleRegionalFloorRefusal (RD-30) takes the channel, its current |
| +// release, the floor and the target. |
| +const consoleRegionalFloorRefusal = "%s runs %s and this deployment has a regional domain, so it takes only %s or later. %s is not one. to move it there anyway, pass --allow-below-regional-floor" |
| + |
| +// consoleRegionalFloorOverride (RD-31) takes the target, the floor and the |
| +// channel. |
| +const consoleRegionalFloorOverride = "moving to %s below %s on %s with --allow-below-regional-floor: servers on it cannot read regional domains and stop serving them" |
| + |
| +// errRegionalFloorPromotion is a promotion the regional floor refused. |
| +var errRegionalFloorPromotion = errors.New("regional floor") |
| + |
| +type regionalFloorError struct{ msg string } |
| + |
| +func (e regionalFloorError) Error() string { return e.msg } |
| +func (e regionalFloorError) Unwrap() error { return errRegionalFloorPromotion } |
| + |
| +// regionalFloorJudge refuses moving channel from cur to target where |
| +// release.RegionalFloorAllows says no and a regional claim exists; allow |
| +// is the operator's override, which is logged when it overrides. |
| +// |
| +// The claims are read only when the move crosses the floor (spec §11: an |
| +// update that does not cross it reads none), through the claims listing: |
| +// a listing error refuses, override or not, since the console cannot tell |
| +// whether the move stops serving anything; and a claim the listing shows |
| +// but nobody could read counts as regional, since it might be one. |
| +func (s *Server) regionalFloorJudge(ctx context.Context, channel string, cur *release.SystemPointer, target string, allow bool) error { |
| + if release.RegionalFloorAllows(cur.Current.Version, target) { |
| + return nil |
| + } |
| + claims, unread, err := s.claims.ListWithUnread(ctx, s.cfg.Releases) |
| + if err != nil { |
| + return fmt.Errorf("regional floor: cannot list domain claims: %w", err) |
| + } |
| + regional := len(unread) > 0 |
| + for _, c := range claims { |
| + if c.Regional() { |
| + regional = true |
| + break |
| + } |
| + } |
| + if !regional { |
| + return nil |
| + } |
| + floor := "v" + release.RegionalDomainsFloor.String() |
| + if allow { |
| + log.Printf("console: system: "+consoleRegionalFloorOverride, target, floor, channel) |
| + return nil |
| + } |
| + return regionalFloorError{msg: fmt.Sprintf(consoleRegionalFloorRefusal, channel, cur.Current.Version, floor, target)} |
| +} |
diff --git a/internal/console/regionalfloor_test.go b/internal/console/regionalfloor_test.go| new file mode 100644 |
| index 000000000..8621202ea |
| --- /dev/null |
| +++ b/internal/console/regionalfloor_test.go |
| @@ -0,0 +1,341 @@ |
| +package console |
| + |
| +import ( |
| + "context" |
| + "errors" |
| + "strings" |
| + "testing" |
| + |
| + "github.com/carlosframework/platform/internal/domains" |
| + "github.com/carlosframework/platform/internal/release" |
| +) |
| + |
| +// The regional floor (#447 W7, spec §10.2) mirrors the rootfs floor's |
| +// tests line for line (rootfsfloor_test.go), with a regional claim in the |
| +// deployment. Every channel here is above the rootfs floor, so only the |
| +// regional judge can refuse. |
| + |
| +const rdFloorClaimHost = "shop.example.com" |
| + |
| +// rdFloorWant is RD-30 for stable at from, moving to target. |
| +func rdFloorWant(from, target string) string { |
| + return "stable runs " + from + " and this deployment has a regional domain, so it takes only v0.31.0 or later. " + target + " is not one. to move it there anyway, pass --allow-below-regional-floor" |
| +} |
| + |
| +// claimListCounter counts the claim listings a promotion makes (spec §11: |
| +// an update that does not cross the floor reads no claims). fail makes |
| +// every claim listing an error. |
| +type claimListCounter struct { |
| + release.Store |
| + lists int |
| + fail bool |
| +} |
| + |
| +func (s *claimListCounter) List(ctx context.Context, prefix string) ([]string, error) { |
| + if strings.HasPrefix(prefix, domains.ClaimsPrefix) { |
| + s.lists++ |
| + if s.fail { |
| + return nil, errors.New("claims listing unavailable") |
| + } |
| + } |
| + return s.Store.List(ctx, prefix) |
| +} |
| + |
| +func (s *claimListCounter) ListMod(ctx context.Context, prefix string) ([]release.KeyMod, error) { |
| + if strings.HasPrefix(prefix, domains.ClaimsPrefix) { |
| + s.lists++ |
| + if s.fail { |
| + return nil, errors.New("claims listing unavailable") |
| + } |
| + } |
| + return s.Store.(release.ModLister).ListMod(ctx, prefix) |
| +} |
| + |
| +// [W7] A channel at the regional floor is never promoted or rolled back |
| +// below it, or to a release whose version does not parse, while a regional |
| +// claim exists, without the override; the refusal comes before any |
| +// activation reservation exists. The rootfs override does not stand in for |
| +// it. |
| +func TestRegionalFloorRefusesBeforeReservation(t *testing.T) { |
| + s, d, target := activationFixtureAt(t, "v0.31.0", "v0.30.2", "v0.28.0") |
| + putRegionalClaim(t, d.Store, rdFloorClaimHost, "acct", "shop", rdHomeHost, false, false) |
| + want := rdFloorWant("v0.31.0", "v0.30.2") |
| + if _, err := s.promoteHostUpdate(t.Context(), target, "router", "stable", release.SystemPromoteOptions{}); !errors.Is(err, errRegionalFloorPromotion) || err.Error() != want { |
| + t.Fatalf("promote below the floor = %v\nwant %q", err, want) |
| + } |
| + noActivations(t, d) |
| + if _, err := s.promoteHostUpdate(t.Context(), target, "router", "stable", release.SystemPromoteOptions{AllowBelowRootfsFloor: true}); !errors.Is(err, errRegionalFloorPromotion) || err.Error() != want { |
| + t.Fatalf("promote below the floor with the rootfs override = %v\nwant %q", err, want) |
| + } |
| + noActivations(t, d) |
| + if _, err := s.rollbackHostUpdate(t.Context(), "router", "stable", "operator", false, false); !errors.Is(err, errRegionalFloorPromotion) || err.Error() != want { |
| + t.Fatalf("rollback below the floor = %v\nwant %q", err, want) |
| + } |
| + if _, err := s.rollbackHostUpdate(t.Context(), "router", "stable", "operator", true, false); !errors.Is(err, errRegionalFloorPromotion) || err.Error() != want { |
| + t.Fatalf("rollback below the floor with the rootfs override = %v\nwant %q", err, want) |
| + } |
| + noActivations(t, d) |
| + if v := currentVersion(t, s, d); v != "v0.31.0" { |
| + t.Fatalf("the pointer moved to %s", v) |
| + } |
| + // An unparseable target meets the rootfs floor first; with its override |
| + // the regional floor refuses it too. |
| + for target, refused := range map[string]bool{"4f3c2a1": true, "": true, "v0.30.99": true, "v0.31.0": false, "v0.32.1": false} { |
| + _, err := s.systemFloorGate(t.Context(), "router", "stable", target, true, false) |
| + if errors.Is(err, errRegionalFloorPromotion) != refused { |
| + t.Errorf("systemFloorGate(%q) = %v, refused want %v", target, err, refused) |
| + } |
| + } |
| + // A channel with no pointer yet has nothing to protect. |
| + if _, err := s.systemFloorGate(t.Context(), "router", "canary", "v0.30.2", false, false); err != nil { |
| + t.Errorf("a channel with no pointer = %v", err) |
| + } |
| + |
| + // With the override the promotion reserves and publishes, and the |
| + // pointer records it (and not the rootfs one). |
| + p, err := s.promoteHostUpdate(t.Context(), target, "router", "stable", release.SystemPromoteOptions{AllowBelowRegionalFloor: true}) |
| + if err != nil { |
| + t.Fatal(err) |
| + } |
| + if p.Current.Version != "v0.30.2" || !p.AllowBelowRegionalFloor || p.AllowBelowRootfsFloor { |
| + t.Fatalf("the override's promotion = %+v", p) |
| + } |
| +} |
| + |
| +// The floor applies only while a regional claim exists: with none, or with |
| +// only single-mode claims, a channel at the floor moves below it as before, |
| +// and the pointer carries no override. |
| +func TestRegionalFloorLeavesAChannelAloneWithoutRegionalClaims(t *testing.T) { |
| + for _, single := range []bool{false, true} { |
| + for _, mode := range []string{"promote", "rollback"} { |
| + name := mode + "/no-claims" |
| + if single { |
| + name = mode + "/single-mode-claim" |
| + } |
| + t.Run(name, func(t *testing.T) { |
| + s, d, target := activationFixtureAt(t, "v0.31.0", "v0.30.2", "v0.28.0") |
| + if single { |
| + seedSingleClaim(t, d.Store) |
| + } |
| + var p *release.SystemPointer |
| + var err error |
| + if mode == "rollback" { |
| + p, err = s.rollbackHostUpdate(t.Context(), "router", "stable", "operator", false, false) |
| + } else { |
| + p, err = s.promoteHostUpdate(t.Context(), target, "router", "stable", release.SystemPromoteOptions{}) |
| + } |
| + if err != nil || p.Current.Version != "v0.30.2" || p.AllowBelowRegionalFloor { |
| + t.Fatalf("single-mode claim %v: %s below the floor = %+v, %v", single, mode, p, err) |
| + } |
| + }) |
| + } |
| + } |
| +} |
| + |
| +// seedSingleClaim stores a single-mode claim through the real writer. |
| +func seedSingleClaim(t *testing.T, st release.Store) { |
| + t.Helper() |
| + if _, _, err := domains.AttachClaim(t.Context(), st, domains.Claim{Host: "shop.example.net", Account: "acct", App: "shop", Route: rdHomeHost, CreatedAt: "2026-10-29T00:00:00Z"}); err != nil { |
| + t.Fatal(err) |
| + } |
| +} |
| + |
| +// A channel below the floor moves as before, with or without the override, |
| +// regional claim or not. |
| +func TestRegionalFloorLeavesAChannelBelowItAlone(t *testing.T) { |
| + s, d, target := activationFixtureAt(t, "v0.30.0", "v0.30.2", "v0.28.0") |
| + putRegionalClaim(t, d.Store, rdFloorClaimHost, "acct", "shop", rdHomeHost, false, false) |
| + if p, err := s.promoteHostUpdate(t.Context(), target, "router", "stable", release.SystemPromoteOptions{}); err != nil || p.Current.Version != "v0.30.2" { |
| + t.Fatalf("promote below the floor from below it = %+v, %v", p, err) |
| + } |
| +} |
| + |
| +// [W7] The override is part of the reservation's request: a retry whose |
| +// override differs from a pending reservation is refused, never handed its |
| +// signed pointer. Both transitions, for a promote and a rollback, each |
| +// after a failed publication and a console restart. The channel is below |
| +// the floor, so only the request identity tells the two requests apart. |
| +func TestRegionalFloorOverrideIsPartOfTheRequest(t *testing.T) { |
| + for _, first := range []bool{true, false} { |
| + for _, mode := range []string{"promote", "rollback"} { |
| + t.Run(mode, func(t *testing.T) { |
| + s, d, target := activationFixtureAt(t, "v0.30.0", "v0.30.2", "v0.28.0") |
| + putRegionalClaim(t, d.Store, rdFloorClaimHost, "acct", "shop", rdHomeHost, false, false) |
| + move := func(s *Server, allow bool) (*release.SystemPointer, error) { |
| + if mode == "rollback" { |
| + return s.rollbackHostUpdate(t.Context(), "router", "stable", "operator", false, allow) |
| + } |
| + return s.promoteHostUpdate(t.Context(), target, "router", "stable", release.SystemPromoteOptions{AllowBelowRegionalFloor: allow}) |
| + } |
| + // The first request reserves, and its publication fails. |
| + s.cfg.Releases = &activationFaultStore{Store: d.Store, fail: true} |
| + if _, err := move(s, first); 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, the other override: refused. |
| + restarted := &Server{cfg: s.cfg} |
| + restarted.cfg.Releases = d.Store |
| + var held activationHeldError |
| + if _, err := move(restarted, !first); !errors.As(err, &held) { |
| + t.Fatalf("allow %v after a held allow %v = %v, want the held reservation's refusal", !first, first, err) |
| + } |
| + if v := currentVersion(t, restarted, d); v != "v0.30.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, first) |
| + if err != nil { |
| + t.Fatal(err) |
| + } |
| + if p.Current.Version != "v0.30.2" || p.AllowBelowRegionalFloor != first { |
| + t.Fatalf("the held reservation published %+v, want v0.30.2 with override %v", p, first) |
| + } |
| + }) |
| + } |
| + } |
| +} |
| + |
| +// [W7] Both judges decide on the one pointer read, and the publication is |
| +// bound to its ETag. A below-floor request checks against v0.30.0 with a |
| +// regional claim present and passes; another console then moves the |
| +// channel to v0.31.0; the request resumes and must not publish over it. |
| +// Were the regional judge to read the pointer again, it would see v0.31.0 |
| +// and refuse with the floor instead of the CAS conflict this asserts. |
| +func TestRegionalFloorBindsTheJudgedPointer(t *testing.T) { |
| + for _, mode := range []string{"promote", "rollback"} { |
| + for _, reserved := range []bool{true, false} { |
| + name := mode + "/unreserved" |
| + if reserved { |
| + name = mode + "/reserved" |
| + } |
| + t.Run(name, func(t *testing.T) { |
| + s, d, target := activationFixtureAt(t, "v0.30.0", "v0.30.2", "v0.28.0") |
| + putRegionalClaim(t, d.Store, rdFloorClaimHost, "acct", "shop", rdHomeHost, false, false) |
| + if !reserved { |
| + unreserved(t, d) |
| + } |
| + floor := target |
| + floor.Version, floor.ReleaseTag, floor.Source = "v0.31.0", "v0.31.0", "release:v0.31.0" |
| + floor.Artifacts = map[string]release.SystemArtifact{"linux-amd64": {Key: release.SystemArtifactKey("v0.31.0", "linux-amd64"), SHA256: target.Artifacts["linux-amd64"].SHA256}} |
| + promoted := false |
| + s.cfg.Releases = &interleavingStore{Store: d.Store, between: func() { |
| + if _, err := release.PromoteSystem(context.Background(), d.Store, release.RootSigner(s.cfg.Key), "router", "stable", floor, release.SystemPromoteOptions{}); err != nil { |
| + t.Errorf("the other console's promotion: %v", err) |
| + } |
| + promoted = true |
| + }} |
| + var err error |
| + if mode == "rollback" { |
| + _, err = s.rollbackHostUpdate(t.Context(), "router", "stable", "operator", false, false) |
| + } else { |
| + _, err = s.promoteHostUpdate(t.Context(), target, "router", "stable", release.SystemPromoteOptions{}) |
| + } |
| + if !promoted { |
| + t.Fatal("the interleaving never ran: the request read the pointer once") |
| + } |
| + if !errors.Is(err, release.ErrCASConflict) { |
| + t.Fatalf("the resumed request = %v, want a CAS conflict", err) |
| + } |
| + if v := currentVersion(t, s, d); v != "v0.31.0" { |
| + t.Fatalf("the resumed request published over v0.31.0: the pointer is at %s", v) |
| + } |
| + noActivations(t, d) |
| + }) |
| + } |
| + } |
| +} |
| + |
| +// [W7] An unreserved rollback carries the operator's regional override |
| +// onto the signed pointer, as the reserved one does. |
| +func TestRegionalFloorUnreservedRollbackKeepsTheOverride(t *testing.T) { |
| + s, d, _ := activationFixtureAt(t, "v0.31.0", "v0.30.2", "v0.28.0") |
| + putRegionalClaim(t, d.Store, rdFloorClaimHost, "acct", "shop", rdHomeHost, false, false) |
| + unreserved(t, d) |
| + p, err := s.rollbackHostUpdate(t.Context(), "router", "stable", "operator", false, true) |
| + if err != nil { |
| + t.Fatal(err) |
| + } |
| + if p.Current.Version != "v0.30.2" || !p.AllowBelowRegionalFloor { |
| + t.Fatalf("the unreserved rollback published %+v, want v0.30.2 with the override", p) |
| + } |
| + signed, _, err := release.GetSystemPointer(t.Context(), d.Store, d.PublicKey, "router", "stable") |
| + if err != nil || !signed.AllowBelowRegionalFloor { |
| + t.Fatalf("the signed pointer lost the override: %+v, %v", signed, err) |
| + } |
| +} |
| + |
| +// [W7] A claim the listing shows but nobody could read counts as regional: |
| +// it might be one. A claims listing that fails refuses outright, override |
| +// or not, and reserves nothing. |
| +func TestRegionalFloorCountsAnUnreadClaim(t *testing.T) { |
| + s, d, target := activationFixtureAt(t, "v0.31.0", "v0.30.2", "v0.28.0") |
| + if _, err := d.Store.Put(t.Context(), domains.ClaimKey(rdFloorClaimHost), []byte("{not a claim"), ""); err != nil { |
| + t.Fatal(err) |
| + } |
| + want := rdFloorWant("v0.31.0", "v0.30.2") |
| + if _, err := s.promoteHostUpdate(t.Context(), target, "router", "stable", release.SystemPromoteOptions{}); !errors.Is(err, errRegionalFloorPromotion) || err.Error() != want { |
| + t.Fatalf("promote with an unread claim = %v\nwant %q", err, want) |
| + } |
| + if _, err := s.rollbackHostUpdate(t.Context(), "router", "stable", "operator", false, false); !errors.Is(err, errRegionalFloorPromotion) || err.Error() != want { |
| + t.Fatalf("rollback with an unread claim = %v\nwant %q", err, want) |
| + } |
| + noActivations(t, d) |
| + |
| + s.cfg.Releases = &claimListCounter{Store: d.Store, fail: true} |
| + for _, allow := range []bool{false, true} { |
| + if _, err := s.promoteHostUpdate(t.Context(), target, "router", "stable", release.SystemPromoteOptions{AllowBelowRegionalFloor: allow}); err == nil || errors.Is(err, errRegionalFloorPromotion) { |
| + t.Fatalf("promote (override %v) over a failed claims listing = %v, want the listing's error", allow, err) |
| + } |
| + if _, err := s.rollbackHostUpdate(t.Context(), "router", "stable", "operator", false, allow); err == nil || errors.Is(err, errRegionalFloorPromotion) { |
| + t.Fatalf("rollback (override %v) over a failed claims listing = %v, want the listing's error", allow, err) |
| + } |
| + } |
| + noActivations(t, d) |
| + if v := currentVersion(t, s, d); v != "v0.31.0" { |
| + t.Fatalf("the pointer moved to %s", v) |
| + } |
| +} |
| + |
| +// [W7, spec §11] Claims are read only when the move crosses the floor: a |
| +// channel moving at or above it, or one already below it, makes no claims |
| +// listing on promote or rollback. One that crosses makes exactly one. |
| +func TestRegionalFloorReadsNoClaimsWhenNotCrossing(t *testing.T) { |
| + for _, c := range []struct { |
| + name, from, to string |
| + lists int |
| + }{ |
| + {"above", "v0.31.0", "v0.32.0", 0}, |
| + {"below", "v0.30.0", "v0.30.2", 0}, |
| + {"crossing", "v0.31.0", "v0.30.2", 1}, |
| + } { |
| + for _, mode := range []string{"promote", "rollback"} { |
| + t.Run(c.name+"/"+mode, func(t *testing.T) { |
| + s, d, target := activationFixtureAt(t, c.from, c.to, "v0.28.0") |
| + putRegionalClaim(t, d.Store, rdFloorClaimHost, "acct", "shop", rdHomeHost, false, false) |
| + counter := &claimListCounter{Store: d.Store} |
| + s.cfg.Releases = counter |
| + // The override lets the crossing case publish, so each case |
| + // runs the whole promotion. |
| + var err error |
| + if mode == "rollback" { |
| + _, err = s.rollbackHostUpdate(t.Context(), "router", "stable", "operator", false, true) |
| + } else { |
| + _, err = s.promoteHostUpdate(t.Context(), target, "router", "stable", release.SystemPromoteOptions{AllowBelowRegionalFloor: true}) |
| + } |
| + if err != nil { |
| + t.Fatal(err) |
| + } |
| + if counter.lists != c.lists { |
| + t.Fatalf("%s %s -> %s listed the claims %d times, want %d", mode, c.from, c.to, counter.lists, c.lists) |
| + } |
| + if v := currentVersion(t, s, d); v != c.to { |
| + t.Fatalf("the pointer is at %s, want %s", v, c.to) |
| + } |
| + }) |
| + } |
| + } |
| +} |
diff --git a/internal/console/rootfsfloor.go b/internal/console/rootfsfloor.go| index ef7a7dd03..e90a18e7b 100644 |
| --- a/internal/console/rootfsfloor.go |
| +++ b/internal/console/rootfsfloor.go |
| @@ -15,9 +15,10 @@ import ( |
| // release.RootfsLifecycleFloor or later is never moved to a release below |
| // it, or to one whose version does not parse, unless the operator passes |
| // --allow-below-rootfs-floor. Every promotion that publishes a pointer |
| -// (promoteHostUpdate, rollbackHostUpdate) asks rootfsFloorGate first, |
| +// (promoteHostUpdate, rollbackHostUpdate) asks systemFloorGate first, |
| // before any activation reservation exists, so no box is ever handed a |
| -// pointer it would refuse and no reservation waits on one. |
| +// pointer it would refuse and no reservation waits on one. The regional |
| +// floor (regionalfloor.go) is judged on the same pointer read. |
| // consoleRootfsFloorRefusal (RFS-3-C30) takes the channel, its current |
| // release, the floor and the target. |
| @@ -35,18 +36,20 @@ type rootfsFloorError struct{ msg string } |
| func (e rootfsFloorError) Error() string { return e.msg } |
| func (e rootfsFloorError) Unwrap() error { return errRootfsFloorPromotion } |
| -// rootfsFloorGate refuses moving component/channel to target while the |
| -// channel's current pointer is at or above the floor and target is below |
| -// it or does not parse; allow is the operator's override, which is logged. |
| -// 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. |
| +// systemFloorGate refuses moving component/channel to target where either |
| +// 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. |
| // |
| // 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 |
| // ETag, so the decision covers exactly the state the publication replaces: |
| // a channel that moved in between (say to the floor) fails the CAS, never |
| // takes a release nobody checked against it (whole-branch review P1-3). |
| -func (s *Server) rootfsFloorGate(ctx context.Context, component, channel, target string, allow bool) (string, error) { |
| +func (s *Server) systemFloorGate(ctx context.Context, component, channel, target string, allowRootfs, allowRegional bool) (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 etag, nil |
| @@ -54,11 +57,15 @@ func (s *Server) rootfsFloorGate(ctx context.Context, component, channel, target |
| if err != nil { |
| return "", err |
| } |
| - return etag, rootfsFloorJudge(channel, cur, target, allow) |
| + if err := rootfsFloorJudge(channel, cur, target, allowRootfs); err != nil { |
| + return etag, err |
| + } |
| + return etag, s.regionalFloorJudge(ctx, channel, cur, target, allowRegional) |
| } |
| -// rootfsFloorJudge is rootfsFloorGate's decision on a pointer already read |
| -// (rollbackHostUpdate judges the snapshot its target came from). |
| +// rootfsFloorJudge is the rootfs half of systemFloorGate's decision, on a |
| +// pointer already read (rollbackHostUpdate judges the snapshot its target |
| +// came from). |
| func rootfsFloorJudge(channel string, cur *release.SystemPointer, target string, allow bool) error { |
| if release.RootfsFloorAllows(cur.Current.Version, target) { |
| return nil |
diff --git a/internal/console/rootfsfloor_test.go b/internal/console/rootfsfloor_test.go| index d90d29478..7491bfb7c 100644 |
| --- a/internal/console/rootfsfloor_test.go |
| +++ b/internal/console/rootfsfloor_test.go |
| @@ -43,7 +43,7 @@ func TestRootfsFloorRefusesBeforeReservation(t *testing.T) { |
| t.Fatalf("promote below the floor = %v\nwant %q", err, want) |
| } |
| noActivations(t, d) |
| - if _, err := s.rollbackHostUpdate(t.Context(), "router", "stable", "operator", false); !errors.Is(err, errRootfsFloorPromotion) || err.Error() != want { |
| + if _, err := s.rollbackHostUpdate(t.Context(), "router", "stable", "operator", false, false); !errors.Is(err, errRootfsFloorPromotion) || err.Error() != want { |
| t.Fatalf("rollback below the floor = %v\nwant %q", err, want) |
| } |
| noActivations(t, d) |
| @@ -51,13 +51,13 @@ func TestRootfsFloorRefusesBeforeReservation(t *testing.T) { |
| t.Fatalf("the pointer moved to %s", v) |
| } |
| for target, refused := range map[string]bool{"4f3c2a1": true, "": true, "v0.28.99": true, "v0.29.0": false, "v0.30.1": false} { |
| - _, err := s.rootfsFloorGate(t.Context(), "router", "stable", target, false) |
| + _, err := s.systemFloorGate(t.Context(), "router", "stable", target, false, false) |
| if errors.Is(err, errRootfsFloorPromotion) != refused { |
| - t.Errorf("rootfsFloorGate(%q) = %v, refused want %v", target, err, refused) |
| + t.Errorf("systemFloorGate(%q) = %v, refused want %v", target, err, refused) |
| } |
| } |
| // A channel with no pointer yet has nothing to protect. |
| - if _, err := s.rootfsFloorGate(t.Context(), "router", "canary", "v0.28.25", false); err != nil { |
| + if _, err := s.systemFloorGate(t.Context(), "router", "canary", "v0.28.25", false, false); err != nil { |
| t.Errorf("a channel with no pointer = %v", err) |
| } |
| @@ -93,7 +93,7 @@ func TestRootfsFloorOverrideIsPartOfTheRequest(t *testing.T) { |
| s, d, target := activationFixtureAt(t, "v0.28.20", "v0.28.25", "v0.28.0") |
| move := func(s *Server, allow bool) (*release.SystemPointer, error) { |
| if mode == "rollback" { |
| - return s.rollbackHostUpdate(t.Context(), "router", "stable", "operator", allow) |
| + return s.rollbackHostUpdate(t.Context(), "router", "stable", "operator", allow, false) |
| } |
| return s.promoteHostUpdate(t.Context(), target, "router", "stable", release.SystemPromoteOptions{AllowBelowRootfsFloor: allow}) |
| } |
| @@ -189,7 +189,7 @@ func TestRootfsFloorBindsTheJudgedPointer(t *testing.T) { |
| }} |
| var err error |
| if mode == "rollback" { |
| - _, err = s.rollbackHostUpdate(t.Context(), "router", "stable", "operator", false) |
| + _, err = s.rollbackHostUpdate(t.Context(), "router", "stable", "operator", false, false) |
| } else { |
| _, err = s.promoteHostUpdate(t.Context(), target, "router", "stable", release.SystemPromoteOptions{}) |
| } |
| @@ -213,7 +213,7 @@ func TestRootfsFloorBindsTheJudgedPointer(t *testing.T) { |
| func TestRootfsFloorUnreservedRollbackKeepsTheOverride(t *testing.T) { |
| s, d, _ := activationFixtureAt(t, "v0.29.0", "v0.28.25", "v0.28.0") |
| unreserved(t, d) |
| - p, err := s.rollbackHostUpdate(t.Context(), "router", "stable", "operator", true) |
| + p, err := s.rollbackHostUpdate(t.Context(), "router", "stable", "operator", true, false) |
| if err != nil { |
| t.Fatal(err) |
| } |
diff --git a/internal/release/layoutintent.go b/internal/release/layoutintent.go| index cd28e1b62..0e5fcdd1b 100644 |
| --- a/internal/release/layoutintent.go |
| +++ b/internal/release/layoutintent.go |
| @@ -277,6 +277,31 @@ func RootfsFloorAllows(installed, candidate string) bool { |
| return ok && c.Compare(RootfsLifecycleFloor) >= 0 |
| } |
| +// RegionalFloorOverrideFlag is the regional floor override's flag name, |
| +// on `carlos system update` and `carlos system rollback` (#447 W7). Boxes |
| +// have no counterpart: the floor binds the console's promotion alone. |
| +const RegionalFloorOverrideFlag = "allow-below-regional-floor" |
| + |
| +// RegionalFloorOverrideUsage (RD-32) is the override flag's help text, |
| +// shared by the two commands. |
| +const RegionalFloorOverrideUsage = "allow a release below v0.31.0 while regional domains exist. servers on it stop serving them" |
| + |
| +// RegionalFloorAllows is RootfsFloorAllows against RegionalDomainsFloor: |
| +// 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 reads the claims only when it says no |
| +// (console/regionalfloor.go): the floor binds only while a regional claim |
| +// exists. |
| +func RegionalFloorAllows(installed, candidate string) bool { |
| + in, ok := ParseReleaseVersion(installed) |
| + if !ok || in.Compare(RegionalDomainsFloor) < 0 { |
| + return true |
| + } |
| + c, ok := ParseReleaseVersion(candidate) |
| + return ok && c.Compare(RegionalDomainsFloor) >= 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 29300a51b..5b518d128 100644 |
| --- a/internal/release/layoutintent_test.go |
| +++ b/internal/release/layoutintent_test.go |
| @@ -174,6 +174,33 @@ func TestRootfsFloorAllows(t *testing.T) { |
| } |
| } |
| +// RegionalFloorAllows is RootfsFloorAllows against RegionalDomainsFloor |
| +// (#447 W7): a channel below the floor, or whose version does not parse, |
| +// moves anywhere; one at or above it only to a parseable candidate at or |
| +// above it. Whether a regional claim exists is the console's question. |
| +func TestRegionalFloorAllows(t *testing.T) { |
| + for _, c := range []struct { |
| + installed, candidate string |
| + want bool |
| + }{ |
| + {"v0.30.2", "v0.30.3", true}, {"v0.30.2", "abc123", true}, {"dev", "v0.20.0", true}, {"", "v0.20.0", true}, |
| + {"v0.31.0", "v0.31.0", true}, {"v0.31.0", "v0.32.1", true}, {"v0.33.0", "v0.31.0", true}, |
| + {"v0.31.0", "v0.30.2", false}, {"v0.31.0", "v0.30.99", false}, {"v1.0.0", "v0.30.0", false}, |
| + {"v0.31.0", "abc123", false}, {"v0.31.0", "", false}, {"0.31.0", "v0.31", false}, |
| + } { |
| + if got := RegionalFloorAllows(c.installed, c.candidate); got != c.want { |
| + t.Errorf("RegionalFloorAllows(%q, %q) = %v, want %v", c.installed, c.candidate, got, c.want) |
| + } |
| + } |
| + // The flag's help names the floor it overrides. |
| + if !strings.Contains(RegionalFloorOverrideUsage, "v"+RegionalDomainsFloor.String()) { |
| + t.Errorf("RegionalFloorOverrideUsage %q does not name v%s", RegionalFloorOverrideUsage, RegionalDomainsFloor) |
| + } |
| + if RegionalFloorOverrideFlag != "allow-below-regional-floor" { |
| + t.Errorf("RegionalFloorOverrideFlag = %q", RegionalFloorOverrideFlag) |
| + } |
| +} |
| + |
| 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 18fd72bd4..be53507aa 100644 |
| --- a/internal/release/systempointer.go |
| +++ b/internal/release/systempointer.go |
| @@ -36,6 +36,14 @@ type SystemPointer struct { |
| // flag is signed so a held activation's override can be compared with a |
| // retry's. Boxes do not read it. Every later write starts without it. |
| AllowBelowRootfsFloor bool `json:"allow_below_rootfs_floor,omitempty"` |
| + // AllowBelowRegionalFloor records that THIS write moved the channel |
| + // below RegionalDomainsFloor while a regional claim existed, on the |
| + // operator's override (`carlos system update` or `rollback` |
| + // --allow-below-regional-floor, #447 W7), the same way: judged by the |
| + // console (console/regionalfloor.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. |
| + AllowBelowRegionalFloor bool `json:"allow_below_regional_floor,omitempty"` |
| } |
| // SystemRelease is everything a box needs to install one version. It travels |
| @@ -261,6 +269,9 @@ type SystemPromoteOptions struct { |
| // part of an activation request's identity and is signed onto the |
| // pointer (SystemPointer.AllowBelowRootfsFloor). |
| AllowBelowRootfsFloor bool |
| + // AllowBelowRegionalFloor is the operator's regional floor override, |
| + // carried the same way (SystemPointer.AllowBelowRegionalFloor). |
| + AllowBelowRegionalFloor bool |
| } |
| // PromoteSystem writes the pointer for one channel, CAS-guarded. The |
| @@ -305,7 +316,7 @@ 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} |
| + AllowBelowRootfsFloor: o.AllowBelowRootfsFloor, AllowBelowRegionalFloor: o.AllowBelowRegionalFloor} |
| if rel.ReleasedAt.IsZero() { |
| next.Current.ReleasedAt = time.Now().UTC().Truncate(time.Second) |
| } |
| @@ -343,8 +354,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 floor override from |
| -// o; the rollback keeps the old pointer's spread. |
| +// PrepareSystemRollback takes the actor and the rootfs and regional 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) |
| @@ -364,8 +375,9 @@ 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, |
| + 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, |
| } |
| wrapper, err := signSystemPointer(sg, next) |
| if err != nil { |
diff --git a/internal/release/systempointer_test.go b/internal/release/systempointer_test.go| index a48e45ea8..4f903add6 100644 |
| --- a/internal/release/systempointer_test.go |
| +++ b/internal/release/systempointer_test.go |
| @@ -275,3 +275,39 @@ func TestSystemPromotionBindsTheExpectedETag(t *testing.T) { |
| t.Fatalf("the rollback with the override = %+v, %v", p, err) |
| } |
| } |
| + |
| +// The regional floor override (#447 W7) rides one pointer write as the |
| +// rootfs one does: signed and verified on the promote and on the rollback |
| +// that asks for it, and gone from the next write that does not. |
| +func TestSystemPointerCarriesTheRegionalFloorOverrideForOneWrite(t *testing.T) { |
| + priv, pub := testKeys(t) |
| + s := NewDirStore(t.TempDir()) |
| + ctx := context.Background() |
| + sg := RootSigner(priv) |
| + for _, v := range []string{"v0.30.0", "v0.31.0"} { |
| + if _, err := PromoteSystem(ctx, s, sg, SystemComponentRouter, "stable", testSystemRelease(v), SystemPromoteOptions{}); err != nil { |
| + t.Fatal(err) |
| + } |
| + } |
| + if _, err := PromoteSystem(ctx, s, sg, SystemComponentRouter, "stable", testSystemRelease("v0.30.2"), |
| + SystemPromoteOptions{AllowBelowRegionalFloor: true}); err != nil { |
| + t.Fatal(err) |
| + } |
| + got, _, err := GetSystemPointer(ctx, s, pub, SystemComponentRouter, "stable") |
| + if err != nil || !got.AllowBelowRegionalFloor || got.AllowBelowRootfsFloor { |
| + t.Fatalf("the verified pointer = %+v, %v; want the regional override alone", got, err) |
| + } |
| + if _, err := RollbackSystem(ctx, s, sg, SystemComponentRouter, "stable", SystemPromoteOptions{Actor: "paul"}); err != nil { |
| + t.Fatal(err) |
| + } |
| + if got, _, err := GetSystemPointer(ctx, s, pub, SystemComponentRouter, "stable"); err != nil || got.AllowBelowRegionalFloor { |
| + t.Fatalf("a rollback kept the override: %+v, %v", got, err) |
| + } |
| + p, err := RollbackSystem(ctx, s, sg, SystemComponentRouter, "stable", SystemPromoteOptions{Actor: "paul", AllowBelowRegionalFloor: true}) |
| + if err != nil || p.Current.Version != "v0.30.0" || !p.AllowBelowRegionalFloor { |
| + t.Fatalf("the rollback with the override = %+v, %v", p, err) |
| + } |
| + if got, _, err := GetSystemPointer(ctx, s, pub, SystemComponentRouter, "stable"); err != nil || !got.AllowBelowRegionalFloor { |
| + t.Fatalf("the signed rollback lost the override: %+v, %v", got, err) |
| + } |
| +} |
diff --git a/system.go b/system.go| index 2fd4cc2a6..e3d8754e0 100644 |
| --- a/system.go |
| +++ b/system.go |
| @@ -293,6 +293,7 @@ func runSystemUpdate(args []string) { |
| 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) |
| + allowBelowRegionalFloor := fs.Bool(release.RegionalFloorOverrideFlag, false, release.RegionalFloorOverrideUsage) |
| fs.Usage = flagUsage(fs, "") |
| fs.Parse(args) |
| if *file != "" && *version == "" { |
| @@ -347,6 +348,9 @@ func runSystemUpdate(args []string) { |
| if *allowBelowRootfsFloor { |
| in["allow_below_rootfs_floor"] = true |
| } |
| + if *allowBelowRegionalFloor { |
| + in["allow_below_regional_floor"] = true |
| + } |
| if *version != "" { |
| in["version"] = *version |
| } |
| @@ -574,6 +578,7 @@ func runSystemRollback(args []string) { |
| channel := fs.String("channel", "", "canary or stable (required)") |
| yes := fs.Bool("yes", false, "do not ask") |
| allowBelowRootfsFloor := fs.Bool(release.RootfsFloorOverrideFlag, false, release.RootfsFloorOverrideUsage) |
| + allowBelowRegionalFloor := fs.Bool(release.RegionalFloorOverrideFlag, false, release.RegionalFloorOverrideUsage) |
| fs.Usage = flagUsage(fs, "") |
| fs.Parse(args) |
| if *channel == "" { |
| @@ -592,6 +597,9 @@ func runSystemRollback(args []string) { |
| if *allowBelowRootfsFloor { |
| in["allow_below_rootfs_floor"] = true |
| } |
| + if *allowBelowRegionalFloor { |
| + in["allow_below_regional_floor"] = true |
| + } |
| st, body, err := sess.postJSON(context.Background(), "/api/cli/system/rollback", in) |
| if err != nil { |
| log.Fatalf("carlos system rollback: %v", err) |