carlos / platform Public

system update: a resolved latest never moves a channel back, and a checksum list binds its tag (hunt H6-M3, H6-M4)

H6-M3. latest.txt is unsigned, and the tag it named was never compared with
the release the channel already served, so whoever serves the feed could
point "the latest public release" at any older tag the vendor ever cut and
the console would mirror and sign it with a fresh stamp. The job now reads
the channel pointer before it ingests a resolved tag and refuses one below
the pointer's current version (resolvedSystemLatestAllowed), with --version
and carlos system rollback named as the deliberate ways back. The layout
floor is judged there too, which the handler could only do for a typed
version. A typed --version is untouched, as is a channel never promoted or
one serving a local build that places nowhere.

The CLI resolves latest.txt itself for the confirmation, so the prompt says
"v0.30.1 (the latest public release)" rather than a phrase the operator
cannot check, and the canary-to-stable ladder warning now fires for it. The
request still leaves the version out: the console resolves and judges the
tag itself, and the console's strict decoder would refuse a new "resolved"
field from a CLI one release ahead of it. A feed the CLI cannot reach is a
refusal that points at --version, not a blind promote.

H6-M4. The signature on SHA256SUMS.txt proves the vendor wrote the list, not
which release it is for, so release A's authentic list, signature and binary
served at tag B's download paths passed Feed.Sums and Feed.Asset, were
mirrored under B's immutable key, and locked the real B out of its own key.
Feed.Sums now holds the list to the tag it fetched under (BindTag): every
versioned asset, the carlos_X.Y.Z_<arch>.deb files the vendor's lists always
carry, must name the tag's version. claimactivation already binds the same
way (ruling F3); this closes the console's and carlos update's reader. A
list with no versioned asset is unbound and passes as before.

Tests: the two hunt files as written; BindTag cases; the floor leaves a
typed step back and a same-version re-promote alone and names --version in
its refusal; the CLI target names a resolved tag and refuses without a feed.
Co-Authored-By: Claude Fable 5.1 <noreply@anthropic.com>
Claude Fable (hunt fix) pushed by claude agent, operated by paul@keymail.dev 0e2afda2051c1fe4e5a3ae0b3cae7f7176e157c7 parent 84d2d25
8 files changed, +429 −14
  • internal/console/apisystemupdate.go +41 −2
  • internal/console/apisystemupdate_latest_test.go +44 −0
  • internal/console/hunt_H6-M3_test.go +156 −0
  • internal/console/hunt_H6-M4_test.go +52 −0
  • internal/publicrelease/feed.go +35 −1
  • internal/publicrelease/feed_test.go +37 −0
  • system.go +44 −11
  • system_test.go +20 −0
diff --git a/internal/console/apisystemupdate.go b/internal/console/apisystemupdate.go
index f3f3dd9b5..54ce7a517 100644
--- a/internal/console/apisystemupdate.go
+++ b/internal/console/apisystemupdate.go
@@ -374,8 +374,9 @@ func (s *Server) handleAPISystemUpdate(w http.ResponseWriter, r *http.Request) {
// A named release below the layout floor is refused here, before a
// job starts, while any box reports a nested, fenced or conflict row
// or no layout at all (layoutguard.go). Only a named version can be
- // judged: "the latest public release" is resolved inside the job and
- // is never below the floor, since the floor is a past release.
+ // judged here: "the latest public release" is resolved inside the job,
+ // which judges it there (resolvedSystemLatestAllowed), since latest.txt is
+ // unsigned and can name any tag the vendor ever cut.
if in.Version != "" && in.Upload == "" {
if reason := s.layoutDowngradeBlocked(r.Context(), in.Version); reason != "" {
jsonError(w, http.StatusConflict, reason)
@@ -489,6 +490,11 @@ func (s *Server) runSystemUpdate(ctx context.Context, id string, job *systemJob,
if !publicrelease.TagRe.MatchString(tag) {
return fmt.Errorf("%q is not a release tag; use --file for a local build", tag)
}
+ if in.Version == "" {
+ if err := s.resolvedSystemLatestAllowed(ctx, in.Component, in.Channel, tag); err != nil {
+ return err
+ }
+ }
job.step("resolved %s", tag)
platforms, err := s.systemPlatforms(ctx)
if err != nil {
@@ -526,6 +532,39 @@ func (s *Server) runSystemUpdate(ctx context.Context, id string, job *systemJob,
job.finish(err)
}
+// resolvedSystemLatestAllowed is the floor under "the latest public
+// release" (hunt H6-M3). latest.txt is unsigned, so whoever serves it can
+// name any tag the vendor ever cut, and every one of those is an authentic
+// signed release; nothing in the feed says which is newest. A resolved tag
+// below the release the channel already serves is therefore refused as a
+// steer, not a promote. The channel pointer is the console's own signed
+// record of what the channel serves, which is why it, and not the boxes'
+// heartbeats, is the floor. A step back is still available, as the deliberate
+// act it is: name the tag with --version, or run carlos system rollback.
+//
+// A channel never promoted has no floor. A current version that does not
+// parse as a release (a local build promoted with --file) places nothing,
+// so a feed tag over it goes through: that is the dev-to-release move.
+// The layout floor is judged here too, for the tag the job resolved, since
+// the handler could judge only a named one.
+func (s *Server) resolvedSystemLatestAllowed(ctx context.Context, component, channel, tag string) error {
+ cur, _, err := release.GetSystemPointer(ctx, s.cfg.Releases, s.cfg.ReleasePub, component, channel)
+ switch {
+ case errors.Is(err, os.ErrNotExist):
+ case err != nil:
+ return fmt.Errorf("reading the %s/%s pointer before resolving the latest release: %w", component, channel, err)
+ default:
+ if have, ok := release.ParseReleaseVersion(cur.Current.Version); ok && release.BelowFloor(tag, have) {
+ return fmt.Errorf("the feed's latest.txt names %s, below the %s that %s/%s already serves; a resolved latest never moves a channel back. To step back on purpose name the release with --version, or run carlos system rollback",
+ tag, cur.Current.Version, component, channel)
+ }
+ }
+ if reason := s.layoutDowngradeBlocked(ctx, tag); reason != "" {
+ return errors.New(reason)
+ }
+ return nil
+}
+
// systemPlatforms: the distinct platforms the fleet reports; linux-arm64
// when nothing has reported the field yet. STRICT — a fleet this console
// cannot enumerate stops the promote, because a platform silently left out
diff --git a/internal/console/apisystemupdate_latest_test.go b/internal/console/apisystemupdate_latest_test.go
new file mode 100644
index 000000000..0cda0fca5
--- /dev/null
+++ b/internal/console/apisystemupdate_latest_test.go
@@ -0,0 +1,44 @@
+package console
+
+import (
+ "context"
+ "strings"
+ "testing"
+
+ "github.com/carlosframework/platform/internal/release"
+)
+
+// The floor under a resolved latest (hunt H6-M3) is only that: re-promoting
+// the release the channel already serves is idempotent, and the same older
+// tag typed as --version stays the deliberate step back it always was.
+func TestResolvedLatestFloorLeavesTypedVersionsAlone(t *testing.T) {
+ fx := newConsoleFixture(t)
+ feed := newHuntFeed(t, fx)
+ feed.publish("v0.30.0", map[string][]byte{"carlos-linux-arm64": []byte("ELF v0.30.0 arm64")})
+ feed.publish("v0.30.1", map[string][]byte{"carlos-linux-arm64": []byte("ELF v0.30.1 arm64")})
+ seedBox(t, fx, "ie", "linux-arm64", "stable", "v0.30.0")
+ owner := cliToken(t, fx, "paul@keymail.dev", "code-hunt-m3b")
+ feed.setLatest("v0.30.1")
+ if job := huntUpdate(t, fx, owner, map[string]any{"channel": "stable", "spread": "0s"}); job["error"] != "" {
+ t.Fatalf("setup: latest over an empty channel: %v", job)
+ }
+ // The same release again, resolved: not a step back.
+ if job := huntUpdate(t, fx, owner, map[string]any{"channel": "stable", "spread": "0s"}); job["error"] != "" {
+ t.Fatalf("the same release resolved again: %v", job)
+ }
+ // Typed, the older release is the operator's deliberate choice.
+ if job := huntUpdate(t, fx, owner, map[string]any{"channel": "stable", "version": "v0.30.0", "spread": "0s"}); job["error"] != "" {
+ t.Fatalf("a typed --version step back was refused: %v", job)
+ }
+ p, _, err := release.GetSystemPointer(context.Background(), fx.rel, fx.pub, "router", "stable")
+ if err != nil || p.Current.Version != "v0.30.0" {
+ t.Fatalf("pointer after the typed step back = %+v, %v", p, err)
+ }
+ // And the refusal names what it compared, so the operator knows the way
+ // back is --version or rollback.
+ feed.setLatest("v0.29.9")
+ job := huntUpdate(t, fx, owner, map[string]any{"channel": "stable", "spread": "0s"})
+ if e, _ := job["error"].(string); e == "" || !strings.Contains(e, "v0.29.9, below the v0.30.0") || !strings.Contains(e, "--version") {
+ t.Fatalf("refusal = %q", e)
+ }
+}
diff --git a/internal/console/hunt_H6-M3_test.go b/internal/console/hunt_H6-M3_test.go
new file mode 100644
index 000000000..5a3993924
--- /dev/null
+++ b/internal/console/hunt_H6-M3_test.go
@@ -0,0 +1,156 @@
+package console
+
+import (
+ "context"
+ "crypto/ed25519"
+ "crypto/sha256"
+ "encoding/base64"
+ "encoding/hex"
+ "fmt"
+ "net/http"
+ "net/http/httptest"
+ "sort"
+ "strings"
+ "sync"
+ "testing"
+
+ "github.com/carlosframework/platform/internal/publicrelease"
+ "github.com/carlosframework/platform/internal/release"
+)
+
+// huntRelease is one authentic vendor release: its signed checksum list,
+// signature and assets, all made with the feed's one vendor key.
+type huntRelease struct {
+ sums string
+ sig string
+ assets map[string][]byte
+}
+
+// huntFeed is the vendor feed over real HTTP with a mutable latest.txt and a
+// mutable map of what each tag's download paths serve, so a test can replay
+// one release's authentic files under another tag's paths.
+type huntFeed struct {
+ mu sync.Mutex
+ priv ed25519.PrivateKey
+ latest string
+ serve map[string]huntRelease // tag path -> what is served there
+ real map[string]huntRelease // tag -> its authentic files
+}
+
+func newHuntFeed(t *testing.T, fx *consoleFixture) *huntFeed {
+ t.Helper()
+ pub, priv, _ := ed25519.GenerateKey(nil)
+ f := &huntFeed{priv: priv, serve: map[string]huntRelease{}, real: map[string]huntRelease{}}
+ mux := http.NewServeMux()
+ mux.HandleFunc("/latest.txt", func(w http.ResponseWriter, r *http.Request) {
+ f.mu.Lock()
+ defer f.mu.Unlock()
+ fmt.Fprintln(w, f.latest)
+ })
+ mux.HandleFunc("/dl/", func(w http.ResponseWriter, r *http.Request) {
+ parts := strings.SplitN(strings.TrimPrefix(r.URL.Path, "/dl/"), "/", 2)
+ if len(parts) != 2 {
+ http.NotFound(w, r)
+ return
+ }
+ f.mu.Lock()
+ rel, ok := f.serve[parts[0]]
+ f.mu.Unlock()
+ if !ok {
+ http.NotFound(w, r)
+ return
+ }
+ switch parts[1] {
+ case "SHA256SUMS.txt":
+ fmt.Fprint(w, rel.sums)
+ case "SHA256SUMS.txt.sig":
+ fmt.Fprintln(w, rel.sig)
+ default:
+ b, ok := rel.assets[parts[1]]
+ if !ok {
+ http.NotFound(w, r)
+ return
+ }
+ w.Write(b)
+ }
+ })
+ ts := httptest.NewServer(mux)
+ t.Cleanup(ts.Close)
+ fx.srv.cfg.SystemFeed = publicrelease.Feed{LatestURL: ts.URL + "/latest.txt", DownloadBase: ts.URL + "/dl", PubKey: base64.StdEncoding.EncodeToString(pub)}
+ return f
+}
+
+// publish makes tag an authentic signed release with the given assets and
+// serves it at its own paths. extraSums lines (e.g. versioned deb names)
+// go into the signed list too.
+func (f *huntFeed) publish(tag string, assets map[string][]byte, extraSums ...string) {
+ var names []string
+ for n := range assets {
+ names = append(names, n)
+ }
+ sort.Strings(names)
+ var sums strings.Builder
+ for _, n := range names {
+ s := sha256.Sum256(assets[n])
+ fmt.Fprintf(&sums, "%s %s\n", hex.EncodeToString(s[:]), n)
+ }
+ for _, l := range extraSums {
+ sums.WriteString(l + "\n")
+ }
+ rel := huntRelease{sums: sums.String(), sig: base64.StdEncoding.EncodeToString(ed25519.Sign(f.priv, []byte(sums.String()))), assets: assets}
+ f.mu.Lock()
+ f.real[tag], f.serve[tag] = rel, rel
+ f.mu.Unlock()
+}
+
+func (f *huntFeed) setLatest(tag string) { f.mu.Lock(); f.latest = tag; f.mu.Unlock() }
+
+// replayAt serves release from's authentic files at tag at's paths.
+func (f *huntFeed) replayAt(at, from string) {
+ f.mu.Lock()
+ f.serve[at] = f.real[from]
+ f.mu.Unlock()
+}
+func (f *huntFeed) repair(tag string) { f.mu.Lock(); f.serve[tag] = f.real[tag]; f.mu.Unlock() }
+
+func huntUpdate(t *testing.T, fx *consoleFixture, owner string, body map[string]any) map[string]any {
+ t.Helper()
+ st, out := postJSON(t, fx.ts.URL+"/api/cli/system/update", body, owner)
+ if st != http.StatusOK {
+ t.Fatalf("update %v = %d %v", body, st, out)
+ }
+ return waitJob(t, fx, owner, str(t, out, "job"))
+}
+
+// H6-M3: latest.txt is unsigned and the latest-resolved tag is never compared
+// with the channel's current version. SECURE expectation: a "latest" request
+// never moves the pointer to an older release than the channel already serves.
+func TestHunt_H6_M3_LatestDiscoveryCannotRollTheChannelBack(t *testing.T) {
+ fx := newConsoleFixture(t)
+ feed := newHuntFeed(t, fx)
+ feed.publish("v0.30.0", map[string][]byte{"carlos-linux-arm64": []byte("ELF v0.30.0 arm64")})
+ feed.publish("v0.30.1", map[string][]byte{"carlos-linux-arm64": []byte("ELF v0.30.1 arm64 (security fix)")})
+ seedBox(t, fx, "ie", "linux-arm64", "stable", "v0.30.0")
+ owner := cliToken(t, fx, "paul@keymail.dev", "code-hunt-m3")
+
+ feed.setLatest("v0.30.1")
+ if job := huntUpdate(t, fx, owner, map[string]any{"channel": "stable", "spread": "0s"}); job["error"] != "" {
+ t.Fatalf("setup: first update: %v", job)
+ }
+ before, _, err := release.GetSystemPointer(context.Background(), fx.rel, fx.pub, "router", "stable")
+ if err != nil || before.Current.Version != "v0.30.1" {
+ t.Fatalf("setup: pointer %+v, %v", before, err)
+ }
+
+ // The attacker controls latest.txt and names the older authentic tag.
+ feed.setLatest("v0.30.0")
+ job := huntUpdate(t, fx, owner, map[string]any{"channel": "stable", "spread": "0s"})
+ after, _, err := release.GetSystemPointer(context.Background(), fx.rel, fx.pub, "router", "stable")
+ if err != nil {
+ t.Fatal(err)
+ }
+ if after.Current.Version != "v0.30.1" {
+ t.Fatalf("H6-M3: a no-version (latest) update moved stable BACK from v0.30.1 to %s with a fresh signature (PromotedAt %s -> %s); job %v",
+ after.Current.Version, before.PromotedAt.Format("15:04:05"), after.PromotedAt.Format("15:04:05"), job["error"])
+ }
+}
diff --git a/internal/console/hunt_H6-M4_test.go b/internal/console/hunt_H6-M4_test.go
new file mode 100644
index 000000000..d9a407bed
--- /dev/null
+++ b/internal/console/hunt_H6-M4_test.go
@@ -0,0 +1,52 @@
+package console
+
+import (
+ "bytes"
+ "context"
+ "errors"
+ "os"
+ "strings"
+ "testing"
+
+ "github.com/carlosframework/platform/internal/release"
+)
+
+// H6-M4: the signed SHA256SUMS.txt does not name its tag, so release A's
+// authentic sums, signature and binary served at tag B's download paths pass
+// Feed.Sums and Feed.Asset. SECURE expectation: nothing is mirrored or signed
+// under B, and once the origin serves B's real files again B ingests.
+func TestHunt_H6_M4_ReplayedSignedSumsCannotPoisonAnotherVersion(t *testing.T) {
+ fx := newConsoleFixture(t)
+ feed := newHuntFeed(t, fx)
+ binA := []byte("ELF carlos v0.30.0 arm64")
+ binB := []byte("ELF carlos v0.30.1 arm64")
+ feed.publish("v0.30.0", map[string][]byte{"carlos-linux-arm64": binA},
+ strings.Repeat("a", 64)+" carlos_0.30.0_arm64.deb")
+ feed.publish("v0.30.1", map[string][]byte{"carlos-linux-arm64": binB},
+ strings.Repeat("b", 64)+" carlos_0.30.1_arm64.deb")
+ seedBox(t, fx, "ie", "linux-arm64", "canary", "v0.29.0")
+ owner := cliToken(t, fx, "paul@keymail.dev", "code-hunt-m4")
+
+ // The attacker serves A's authentic files at B's paths.
+ feed.replayAt("v0.30.1", "v0.30.0")
+ job := huntUpdate(t, fx, owner, map[string]any{"channel": "canary", "version": "v0.30.1", "spread": "0s"})
+ key := release.SystemArtifactKey("v0.30.1", "linux-arm64")
+ mirrored, _, merr := fx.rel.Get(context.Background(), key)
+ p, _, perr := release.GetSystemPointer(context.Background(), fx.rel, fx.pub, "router", "canary")
+ if merr == nil && bytes.Equal(mirrored, binA) {
+ t.Errorf("H6-M4 mirror: v0.30.0's bytes were mirrored under %s (job error %q)", key, job["error"])
+ } else if merr != nil && !errors.Is(merr, os.ErrNotExist) {
+ t.Fatal(merr)
+ }
+ if perr == nil && p.Current.Version == "v0.30.1" {
+ t.Errorf("H6-M4 pointer: canary signed as v0.30.1 over artifact sha %s (A's bytes: %v)", p.Current.Artifacts["linux-arm64"].SHA256,
+ bytes.Equal(mirrored, binA))
+ }
+
+ // The origin is repaired; the operator re-runs the update.
+ feed.repair("v0.30.1")
+ job = huntUpdate(t, fx, owner, map[string]any{"channel": "canary", "version": "v0.30.1", "spread": "0s"})
+ if e, _ := job["error"].(string); e != "" {
+ t.Errorf("H6-M4 recovery: the correct v0.30.1 can no longer be ingested: %s", e)
+ }
+}
diff --git a/internal/publicrelease/feed.go b/internal/publicrelease/feed.go
index 65f1e5270..842e14656 100644
--- a/internal/publicrelease/feed.go
+++ b/internal/publicrelease/feed.go
@@ -15,6 +15,7 @@ import (
"io"
"net/http"
"regexp"
+ "sort"
"strings"
"time"
)
@@ -76,8 +77,38 @@ func (f Feed) Latest(ctx context.Context) (string, error) {
return tag, nil
}
+// versionedAsset picks the release version out of an asset name that carries
+// one: the debs are "carlos_X.Y.Z_<arch>.deb" (README, "Releasing the
+// platform"), and any future "carlos-vX.Y.Z-..." archive binds the same way.
+// The raw binaries, "carlos-<goos>-<goarch>", carry none.
+var versionedAsset = regexp.MustCompile(`^carlos[_-]v?([0-9]+\.[0-9]+\.[0-9]+)[_.-]`)
+
+// BindTag refuses a checksum list that belongs to another release. The
+// signature on SHA256SUMS.txt proves the vendor wrote the list, not which
+// release it is for, so an authentic list, signature and binary from tag A
+// served at tag B's download paths verify as B. The list names its own
+// release through its versioned assets, the debs: every one must carry tag's
+// version. A list with no versioned asset carries no binding and passes, as
+// before; the vendor's lists always include the two debs.
+func BindTag(sums map[string]string, tag string) error {
+ want := strings.TrimPrefix(tag, "v")
+ names := make([]string, 0, len(sums))
+ for name := range sums {
+ names = append(names, name)
+ }
+ sort.Strings(names)
+ for _, name := range names {
+ m := versionedAsset.FindStringSubmatch(name)
+ if m != nil && m[1] != want {
+ return fmt.Errorf("the checksum list served for %s is release v%s's (it lists %s); refusing the release", tag, m[1], name)
+ }
+ }
+ return nil
+}
+
// Sums fetches SHA256SUMS.txt and its .sig for tag, verifies the signature
-// with PubKey, and returns asset → sha256 hex.
+// with PubKey, checks the list is tag's own (BindTag), and returns asset →
+// sha256 hex.
func (f Feed) Sums(ctx context.Context, tag string) (map[string]string, error) {
base := f.DownloadBase + "/" + tag + "/"
sums, err := f.get(ctx, base+"SHA256SUMS.txt", 1<<20)
@@ -103,6 +134,9 @@ func (f Feed) Sums(ctx context.Context, tag string) (map[string]string, error) {
out[fields[1]] = fields[0]
}
}
+ if err := BindTag(out, tag); err != nil {
+ return nil, err
+ }
return out, nil
}
diff --git a/internal/publicrelease/feed_test.go b/internal/publicrelease/feed_test.go
index d77de5fed..e30aafed7 100644
--- a/internal/publicrelease/feed_test.go
+++ b/internal/publicrelease/feed_test.go
@@ -85,3 +85,40 @@ func TestFeedLatestRequiresATag(t *testing.T) {
t.Fatal("accepted a non-tag latest")
}
}
+
+// The signature proves the vendor wrote a checksum list, not which release
+// it is for, so an authentic list for v0.30.0 served at v0.30.1's paths used
+// to verify as v0.30.1 (hunt H6-M4). The versioned debs name the release the
+// list belongs to, and Sums holds them to the tag it fetched under.
+func TestFeedSumsBindTheirTag(t *testing.T) {
+ f, _ := testFeed(t, true, map[string][]byte{
+ "carlos-linux-arm64": []byte("ELF v0.17.0"),
+ "carlos_0.17.0_arm64.deb": []byte("deb"),
+ })
+ if _, err := f.Sums(context.Background(), "v0.18.0"); err == nil || !strings.Contains(err.Error(), "v0.17.0's") {
+ t.Fatalf("a v0.17.0 list served at v0.18.0 was accepted: %v", err)
+ }
+ // Asset goes through Sums, so a replayed binary is refused before it
+ // is fetched, whatever its bytes are.
+ if _, _, err := f.Asset(context.Background(), "v0.18.0", "carlos-linux-arm64", 1<<20); err == nil {
+ t.Fatal("an asset from a replayed list was accepted")
+ }
+ for name, tc := range map[string]struct {
+ sums map[string]string
+ tag string
+ ok bool
+ }{
+ "the tag's own debs": {map[string]string{"carlos_0.18.0_arm64.deb": "x", "carlos_0.18.0_amd64.deb": "x", "carlos-linux-arm64": "x"}, "v0.18.0", true},
+ "a future versioned archive": {map[string]string{"carlos-v0.18.0-linux-arm64.tar.gz": "x"}, "v0.18.0", true},
+ "another release's deb": {map[string]string{"carlos_0.18.0_arm64.deb": "x", "carlos_0.17.0_amd64.deb": "x"}, "v0.18.0", false},
+ "another release's archive": {map[string]string{"carlos-v0.17.0-linux-arm64.tar.gz": "x"}, "v0.18.0", false},
+ "a prefix is not a match": {map[string]string{"carlos_0.18.01_arm64.deb": "x"}, "v0.18.0", false},
+ "no versioned asset, unbound": {map[string]string{"carlos-linux-arm64": "x", "carlos-windows-amd64.zip": "x"}, "v0.18.0", true},
+ } {
+ t.Run(name, func(t *testing.T) {
+ if err := BindTag(tc.sums, tc.tag); (err == nil) != tc.ok {
+ t.Fatalf("BindTag(%v, %s) = %v, want ok=%t", tc.sums, tc.tag, err, tc.ok)
+ }
+ })
+ }
+}
diff --git a/system.go b/system.go
index f3ae7a1c2..0cc504740 100644
--- a/system.go
+++ b/system.go
@@ -309,11 +309,17 @@ func runSystemUpdate(args []string) {
reach = append(reach, fmt.Sprintf("%s (%s, running %s)", b.Label, orDash(b.Platform), orDash(b.Release)))
}
}
- what := "the latest public release"
- if *version != "" {
- what = *version
+ // Without --version the tag comes from the feed's latest.txt, resolved
+ // HERE too so the prompt names it: an unsigned pointer the operator
+ // never sees is one they cannot judge (hunt H6-M3). The console still
+ // resolves it itself, and refuses one below the channel's current
+ // release, so a feed that changes its mind in between cannot move the
+ // channel back.
+ target, err := systemUpdateTarget(*version, func() (string, error) { return fetchLatest(10 * time.Second) })
+ if err != nil {
+ log.Fatalf("carlos system update: %v", err)
}
- fmt.Fprintf(stdout, "promote %s to %s/%s — %d box(es) will roll over %s:\n", what, systemComponentRouter, *channel, len(reach), *spread)
+ fmt.Fprintf(stdout, "promote %s to %s/%s — %d box(es) will roll over %s:\n", target.what, systemComponentRouter, *channel, len(reach), *spread)
for _, r := range reach {
fmt.Fprintf(stdout, " %s\n", r)
}
@@ -323,7 +329,7 @@ func runSystemUpdate(args []string) {
if cur.Partial {
fmt.Fprintf(stdout, " %s\n", colorFor(stdout).warn("some fleets could not be read; more boxes than these may roll"))
}
- if msg := systemLadderWarning(cur.Pointers, *channel, *version); msg != "" {
+ if msg := systemLadderWarning(cur.Pointers, *channel, target.tag); msg != "" {
fmt.Fprintf(stdout, "%s\n", colorFor(stdout).warn(msg))
}
if !*yes {
@@ -336,8 +342,8 @@ func runSystemUpdate(args []string) {
}
in := map[string]any{"channel": *channel, "spread": *spread}
- if *version != "" {
- in["version"] = *version
+ if target.typed {
+ in["version"] = target.tag
}
if *file != "" {
handle, err := sess.uploadSystemBinary(ctx, *file, *version, *platform)
@@ -374,16 +380,43 @@ func runSystemUpdate(args []string) {
colorFor(stdout).ok("promoted"), *channel, *channel)
}
+// systemUpdateTarget is what `carlos system update` is about to promote:
+// the tag, how the prompt names it, and whether the operator typed it. A
+// typed --version is itself, and is what the request names. An empty one is
+// resolved through resolve (the feed's latest.txt) so the prompt can say
+// "v0.30.1 (the latest public release)" instead of a phrase the operator
+// cannot check; the request still leaves the version out, since the console
+// resolves and judges the latest release itself, and an older console does
+// not know a field that says "resolved". A feed that cannot be reached is an
+// error, not a fallback to a blind promote: the operator can name the
+// release with --version.
+type systemTarget struct {
+ tag string
+ what string
+ typed bool
+}
+
+func systemUpdateTarget(version string, resolve func() (string, error)) (systemTarget, error) {
+ if version != "" {
+ return systemTarget{tag: version, what: version, typed: true}, nil
+ }
+ tag, err := resolve()
+ if err != nil {
+ return systemTarget{}, fmt.Errorf("could not resolve the latest public release: %v. Name one with --version", err)
+ }
+ return systemTarget{tag: tag, what: tag + " (the latest public release)"}, nil
+}
+
// systemLadderWarning is the canary → stable ladder, said out loud and not
// enforced. A promote straight to stable is a legitimate thing to do — a
// hotfix at three in the morning, a build that has already proved itself
// somewhere else — so this is a line to read, never a refusal: the operator
// is the one who knows whether the rung was skipped on purpose.
//
-// It stays quiet unless it is certain. Without --version the console is
-// promoting "the latest public release", a tag only the server resolves, so
-// there is nothing here to compare against the canary pointer and a warning
-// would be a guess. Only stable has a rung below it worth naming.
+// It stays quiet unless it is certain. Without --version the tag is the one
+// systemUpdateTarget resolved from the feed, so it is compared like a typed
+// one; an empty version (no tag to name) says nothing, since a warning would
+// be a guess. Only stable has a rung below it worth naming.
func systemLadderWarning(pointers map[string]*systemPointerRow, channel, version string) string {
if channel != "stable" || version == "" {
return ""
diff --git a/system_test.go b/system_test.go
index 68d95bc74..165347462 100644
--- a/system_test.go
+++ b/system_test.go
@@ -332,3 +332,23 @@ func TestPrintSystemStatusSaysWhenBootstrapLags(t *testing.T) {
})
}
}
+
+// Without --version the CLI resolves the feed's latest.txt itself, so the
+// prompt names the tag the operator is about to confirm (hunt H6-M3); the
+// request still leaves the version out for the console to resolve and
+// judge. A feed that cannot be reached is a refusal that points at
+// --version, never a blind promote.
+func TestSystemUpdateTargetNamesTheResolvedLatest(t *testing.T) {
+ typed, err := systemUpdateTarget("v0.30.1", func() (string, error) { t.Fatal("a typed version must not resolve"); return "", nil })
+ if err != nil || typed != (systemTarget{tag: "v0.30.1", what: "v0.30.1", typed: true}) {
+ t.Fatalf("typed = %+v, %v", typed, err)
+ }
+ resolved, err := systemUpdateTarget("", func() (string, error) { return "v0.30.1", nil })
+ if err != nil || resolved != (systemTarget{tag: "v0.30.1", what: "v0.30.1 (the latest public release)"}) {
+ t.Fatalf("resolved = %+v, %v", resolved, err)
+ }
+ _, err = systemUpdateTarget("", func() (string, error) { return "", errors.New("dial tcp: no route") })
+ if err == nil || !strings.Contains(err.Error(), "--version") || !strings.Contains(err.Error(), "no route") {
+ t.Fatalf("unreachable feed = %v, want a refusal that names --version and the cause", err)
+ }
+}