carlos / platform Public

store write credential: writer core, console floor gate, tests

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
claude agent, operated by paul@keymail.dev pushed by paul@keymail.dev 2279b9ea7659d6be93d80b767e13ba54ac62c15d parent c17ac2a
6 files changed, +489 −0
  • internal/objstore/aws_writecred_test.go +212 −0
  • internal/objstore/writecred.go +6 −0
  • internal/objstore/writecred_test.go +6 −0
  • internal/release/adopt.go +12 −0
  • internal/release/consolefloor.go +116 −0
  • internal/release/consolefloor_test.go +137 −0
diff --git a/internal/objstore/aws_writecred_test.go b/internal/objstore/aws_writecred_test.go
new file mode 100644
index 000000000..351540d84
--- /dev/null
+++ b/internal/objstore/aws_writecred_test.go
@@ -0,0 +1,212 @@
+package objstore
+
+import (
+ "context"
+ "errors"
+ "strings"
+ "testing"
+ "time"
+
+ "github.com/aws/aws-sdk-go-v2/aws"
+ "github.com/aws/aws-sdk-go-v2/service/iam"
+ iamtypes "github.com/aws/aws-sdk-go-v2/service/iam/types"
+ "github.com/aws/aws-sdk-go-v2/service/sts"
+ ststypes "github.com/aws/aws-sdk-go-v2/service/sts/types"
+)
+
+type stubSTS struct {
+ calls []*sts.GetFederationTokenInput
+ // answer is called per attempt; attempt counts from 0.
+ answer func(attempt int, in *sts.GetFederationTokenInput) (*sts.GetFederationTokenOutput, error)
+}
+
+func (s *stubSTS) GetFederationToken(_ context.Context, in *sts.GetFederationTokenInput, _ ...func(*sts.Options)) (*sts.GetFederationTokenOutput, error) {
+ s.calls = append(s.calls, in)
+ return s.answer(len(s.calls)-1, in)
+}
+
+func federationOK(expires time.Time) func(int, *sts.GetFederationTokenInput) (*sts.GetFederationTokenOutput, error) {
+ return func(int, *sts.GetFederationTokenInput) (*sts.GetFederationTokenOutput, error) {
+ return &sts.GetFederationTokenOutput{Credentials: &ststypes.Credentials{
+ AccessKeyId: aws.String("ASIAWRITE"), SecretAccessKey: aws.String("sessionsecret"),
+ SessionToken: aws.String("token"), Expiration: aws.Time(expires),
+ }}, nil
+ }
+}
+
+// mintStub is an IAM stub for one writer: it lists keys, records creates and
+// deletes, and hands the single-use key to the STS factory.
+type mintStub struct {
+ keys []string
+ created []string
+ deleted []string
+ signedAs []string
+ sleeps []time.Duration
+ createErr error
+}
+
+func (m *mintStub) provisioner(t *testing.T, st *stubSTS) *awsProvisioner {
+ stub := &stubIAM{t: t,
+ listAccessKeys: func(*iam.ListAccessKeysInput) (*iam.ListAccessKeysOutput, error) {
+ out := &iam.ListAccessKeysOutput{}
+ for _, k := range m.keys {
+ out.AccessKeyMetadata = append(out.AccessKeyMetadata, iamtypes.AccessKeyMetadata{AccessKeyId: aws.String(k)})
+ }
+ return out, nil
+ },
+ createAccessKey: func(in *iam.CreateAccessKeyInput) (*iam.CreateAccessKeyOutput, error) {
+ if m.createErr != nil {
+ return nil, m.createErr
+ }
+ m.created = append(m.created, aws.ToString(in.UserName))
+ return &iam.CreateAccessKeyOutput{AccessKey: &iamtypes.AccessKey{
+ AccessKeyId: aws.String("AKIASINGLEUSE"), SecretAccessKey: aws.String("singleusesecret"),
+ }}, nil
+ },
+ deleteAccessKey: func(in *iam.DeleteAccessKeyInput) (*iam.DeleteAccessKeyOutput, error) {
+ m.deleted = append(m.deleted, aws.ToString(in.AccessKeyId))
+ return &iam.DeleteAccessKeyOutput{}, nil
+ },
+ }
+ return &awsProvisioner{iam: stub, region: "eu-west-1",
+ newSTS: func(id, secret string) stsAPI { m.signedAs = append(m.signedAs, id+":"+secret); return st },
+ sleepFn: func(_ context.Context, d time.Duration) error {
+ m.sleeps = append(m.sleeps, d)
+ return nil
+ },
+ }
+}
+
+func TestAWSMintSession(t *testing.T) {
+ expires := time.Date(2026, 11, 25, 14, 0, 0, 0, time.UTC)
+ st := &stubSTS{answer: federationOK(expires)}
+ m := &mintStub{keys: []string{"AKIASTRAY"}}
+ p := m.provisioner(t, st)
+ policy := writeSessionPolicy("carlos-store-bab-titogo", "recordings/")
+ sess, err := p.MintSession(context.Background(), "carlos-w-bab-titogo", policy, 4*time.Hour)
+ if err != nil {
+ t.Fatal(err)
+ }
+ if sess.AccessKeyID != "ASIAWRITE" || sess.SecretAccessKey != "sessionsecret" || sess.SessionToken != "token" ||
+ !sess.Expires.Equal(expires) || !sess.Issued.Equal(expires.Add(-4*time.Hour)) {
+ t.Fatalf("session = %+v", sess)
+ }
+ // The stray key is reaped first, the single-use key is made, used to
+ // sign the STS call and deleted.
+ if strings.Join(m.deleted, ",") != "AKIASTRAY,AKIASINGLEUSE" || len(m.created) != 1 || m.created[0] != "carlos-w-bab-titogo" {
+ t.Fatalf("deleted %v, created %v", m.deleted, m.created)
+ }
+ if len(m.signedAs) != 1 || m.signedAs[0] != "AKIASINGLEUSE:singleusesecret" {
+ t.Fatalf("STS signed as %v", m.signedAs)
+ }
+ in := st.calls[0]
+ if aws.ToString(in.Policy) != policy || aws.ToInt32(in.DurationSeconds) != 4*3600 ||
+ !strings.HasPrefix(aws.ToString(in.Name), FederatedNamePrefix) || len(aws.ToString(in.Name)) > 32 {
+ t.Fatalf("GetFederationToken input = %+v", in)
+ }
+}
+
+// A new key and a just-written policy take seconds to reach STS: the mint
+// retries those two answers, and still deletes its key.
+func TestAWSMintSessionRetriesPropagation(t *testing.T) {
+ expires := time.Now().Add(time.Hour)
+ ok := federationOK(expires)
+ st := &stubSTS{answer: func(attempt int, in *sts.GetFederationTokenInput) (*sts.GetFederationTokenOutput, error) {
+ switch attempt {
+ case 0:
+ return nil, &smithyAPIErrorStub{code: "InvalidClientTokenId", msg: "not yet"}
+ case 1:
+ return nil, &smithyAPIErrorStub{code: "AccessDenied", msg: "not yet"}
+ }
+ return ok(attempt, in)
+ }}
+ m := &mintStub{}
+ if _, err := m.provisioner(t, st).MintSession(context.Background(), "carlos-w-bab-titogo", "{}", time.Hour); err != nil {
+ t.Fatal(err)
+ }
+ if len(st.calls) != 3 || len(m.sleeps) != 2 || m.sleeps[0] != federationBackoff[0] {
+ t.Fatalf("%d calls, sleeps %v", len(st.calls), m.sleeps)
+ }
+ if strings.Join(m.deleted, ",") != "AKIASINGLEUSE" {
+ t.Fatalf("deleted %v", m.deleted)
+ }
+}
+
+// Any other STS answer fails at once, the single-use key is still deleted,
+// and neither secret is in the error.
+func TestAWSMintSessionFailureDeletesKeyAndKeepsSecrets(t *testing.T) {
+ st := &stubSTS{answer: func(int, *sts.GetFederationTokenInput) (*sts.GetFederationTokenOutput, error) {
+ return nil, &smithyAPIErrorStub{code: "MalformedPolicyDocument", msg: "bad"}
+ }}
+ m := &mintStub{}
+ _, err := m.provisioner(t, st).MintSession(context.Background(), "carlos-w-bab-titogo", "{}", time.Hour)
+ if err == nil || len(st.calls) != 1 || len(m.sleeps) != 0 {
+ t.Fatalf("err %v after %d calls", err, len(st.calls))
+ }
+ if strings.Join(m.deleted, ",") != "AKIASINGLEUSE" {
+ t.Fatalf("deleted %v", m.deleted)
+ }
+ if strings.Contains(err.Error(), "singleusesecret") {
+ t.Fatalf("error carries the key's secret: %v", err)
+ }
+ // Retries end after the schedule, still deleting the key.
+ m2 := &mintStub{}
+ st2 := &stubSTS{answer: func(int, *sts.GetFederationTokenInput) (*sts.GetFederationTokenOutput, error) {
+ return nil, &smithyAPIErrorStub{code: "AccessDenied", msg: "never"}
+ }}
+ if _, err := m2.provisioner(t, st2).MintSession(context.Background(), "carlos-w-bab-titogo", "{}", time.Hour); err == nil {
+ t.Fatal("a mint STS never accepted succeeded")
+ }
+ if len(st2.calls) != len(federationBackoff)+1 || strings.Join(m2.deleted, ",") != "AKIASINGLEUSE" {
+ t.Fatalf("%d calls, deleted %v", len(st2.calls), m2.deleted)
+ }
+}
+
+func TestAWSMintSessionRefusals(t *testing.T) {
+ st := &stubSTS{answer: federationOK(time.Now())}
+ m := &mintStub{}
+ p := m.provisioner(t, st)
+ p.endpoint = "https://s3.example.com"
+ if _, err := p.MintSession(context.Background(), "carlos-w-bab-titogo", "{}", time.Hour); !errors.Is(err, ErrWriteCredentialsUnsupported) {
+ t.Fatalf("mint behind an S3-compatible endpoint: %v", err)
+ }
+ p.endpoint = ""
+ if _, err := p.MintSession(context.Background(), "carlos-w-bab-titogo", "{}", 48*time.Hour); !errors.Is(err, ErrBadWriteTTL) {
+ t.Fatalf("mint for 48h: %v", err)
+ }
+ if len(m.created) != 0 || len(st.calls) != 0 {
+ t.Fatal("a refused mint made a key or called STS")
+ }
+}
+
+func TestAWSEnsureWriter(t *testing.T) {
+ var created *iam.CreateUserInput
+ var put *iam.PutUserPolicyInput
+ exists := false
+ stub := &stubIAM{t: t,
+ createUser: func(in *iam.CreateUserInput) (*iam.CreateUserOutput, error) {
+ created = in
+ if exists {
+ return nil, &iamtypes.EntityAlreadyExistsException{Message: aws.String("exists")}
+ }
+ return &iam.CreateUserOutput{User: &iamtypes.User{Arn: aws.String("arn")}}, nil
+ },
+ putUserPolicy: func(in *iam.PutUserPolicyInput) (*iam.PutUserPolicyOutput, error) {
+ put = in
+ return &iam.PutUserPolicyOutput{}, nil
+ },
+ }
+ p := &awsProvisioner{iam: stub, boundary: "arn:aws:iam::123456789012:policy/carlos-store-boundary"}
+ for _, e := range []bool{false, true} {
+ exists = e
+ if err := p.EnsureWriter(context.Background(), "carlos-w-bab-titogo", UserPath, "{\"policy\":1}"); err != nil {
+ t.Fatalf("exists=%v: %v", e, err)
+ }
+ if aws.ToString(created.PermissionsBoundary) != p.boundary || aws.ToString(created.Path) != UserPath {
+ t.Fatalf("writer created as %+v", created)
+ }
+ if aws.ToString(put.UserName) != "carlos-w-bab-titogo" || aws.ToString(put.PolicyName) != policyName || aws.ToString(put.PolicyDocument) != "{\"policy\":1}" {
+ t.Fatalf("writer policy put as %+v", put)
+ }
+ }
+}
diff --git a/internal/objstore/writecred.go b/internal/objstore/writecred.go
index 709d7eb55..c780b3249 100644
--- a/internal/objstore/writecred.go
+++ b/internal/objstore/writecred.go
@@ -420,6 +420,12 @@ func claimRawMintWriteCredentialIn(ctx context.Context, s release.Store, p Provi
}
}
if wc == nil {
+ // The console floor first (release/consolefloor.go, spec §10): from
+ // here on no box points a console route at a build that does not
+ // know writers, so none can purge this store and leave its writer.
+ if err := release.PutConsoleStoreWritersFloor(ctx, s, now); err != nil {
+ return nil, err
+ }
wc = &WriteCredentials{At: now.UTC(), By: by}
if _, err := claimRawPutWriteCredentialsIn(ctx, s, acct, app, env, wc, ""); err != nil {
return nil, fmt.Errorf("objstore: record write credentials for %s/%s: %w", acct, app, err)
diff --git a/internal/objstore/writecred_test.go b/internal/objstore/writecred_test.go
index 474859b8c..0bfbaceb9 100644
--- a/internal/objstore/writecred_test.go
+++ b/internal/objstore/writecred_test.go
@@ -202,6 +202,9 @@ func TestMintWriteCredential(t *testing.T) {
if got := p.PolicyFor(storeUser); got != storePolicy || strings.Contains(got, "sts:") {
t.Fatalf("store user's policy changed or names STS: %s", got)
}
+ if _, _, err := s.Get(context.Background(), release.ConsoleStoreWritersFloorKey); err != nil {
+ t.Fatalf("the first mint wrote no console floor: %v", err)
+ }
if p.SingleUseKeys != 1 {
t.Fatalf("%d single-use keys, want 1", p.SingleUseKeys)
}
@@ -274,6 +277,9 @@ func assertNothingMinted(t *testing.T, s release.Store, p *MemProvisioner) {
if wc, _, _ := GetWriteCredentialsIn(context.Background(), s, "bab", "titogo", ""); wc != nil {
t.Fatalf("a refused mint wrote the state object: %+v", wc)
}
+ if _, _, err := s.Get(context.Background(), release.ConsoleStoreWritersFloorKey); err == nil {
+ t.Fatal("a refused mint wrote the console floor")
+ }
}
// Paul, 2026-11-25: no refusal during a rotation. The writer is another
diff --git a/internal/release/adopt.go b/internal/release/adopt.go
index 157938cc3..7d01ed2b9 100644
--- a/internal/release/adopt.go
+++ b/internal/release/adopt.go
@@ -1731,6 +1731,18 @@ func adoptHost(ctx context.Context, work hostwrite.Work, reg *registry.Registry,
}
}
+ // The console floor for write credentials (consolefloor.go): once this
+ // deployment has had a store writer, a console build from before
+ // writers is never pointed live. Not recorded as a refusal: the floor
+ // and the bytes are read again next pass, and nothing was restarted.
+ if why, err := consoleFloorRefusal(ctx, s, VersionPath(optDir, RouteAccount(rt), ver, rt.App), newProg); err != nil || why != "" {
+ if err != nil {
+ why = "the console floor could not be checked (" + err.Error() + ")"
+ }
+ fmt.Printf(" %s: %s: %s; not pointed live, will retry\n", rt.Host, ver, why)
+ return
+ }
+
// D3's binding check (spec §4.5 check 2): the staged bytes themselves
// must be the proven ones, or a build this box has run well.
if !cfg.bindProof(ctx, optDir, rt, sel, verdict, cur, now) {
diff --git a/internal/release/consolefloor.go b/internal/release/consolefloor.go
new file mode 100644
index 000000000..fd9833007
--- /dev/null
+++ b/internal/release/consolefloor.go
@@ -0,0 +1,116 @@
+// The console floor for write credentials (spec
+// 2026-11-25-store-write-credential-design.md §10, Paul's option A): once a
+// deployment has had a store writer, no box points a console route live on
+// a console build from before writers existed. Such a console would purge a
+// store and leave its writer user standing, and would leave the
+// storage-grace Deny off it.
+//
+// It sits beside D2 (program.go) and for the same reason: a console
+// rollback can come by any route, a console door or a bucket-direct
+// promote, and every one of them ends at an adopting box. Like D2 it judges
+// the staged bytes, not the manifest.
+//
+// The floor object is a deployment-bucket record any region host can
+// write. A forged one only makes boxes refuse console builds from before
+// the floor: a refusal, never an admission.
+package release
+
+import (
+ "bytes"
+ "context"
+ "encoding/json"
+ "errors"
+ "fmt"
+ "io"
+ "os"
+ "time"
+
+ "github.com/carlosframework/platform/internal/safefile"
+)
+
+const (
+ // ConsoleProgram is the console's Go main package path, as its build
+ // info records it (FileProgram).
+ ConsoleProgram = "github.com/carlosframework/platform/cmd/console"
+ // ConsoleStoreWritersCapability is in the bytes of every console build
+ // that knows store writers (cmd/console logs it at boot, so the linker
+ // keeps it). No console build from before them carries it.
+ ConsoleStoreWritersCapability = "carlos-console-capability:store-writers.v1"
+ // ConsoleStoreWritersFloorKey is written, create-only, by a console's
+ // first write-credential mint, before any writer exists. It is never
+ // deleted: once a deployment has had a writer, the floor stays.
+ ConsoleStoreWritersFloorKey = "control/console-floors/store-writers.json"
+ // consoleFloorScanChunk is the scanner's read size.
+ consoleFloorScanChunk = 1 << 20
+)
+
+// PutConsoleStoreWritersFloor records the floor. A floor already there is
+// kept as it is.
+func PutConsoleStoreWritersFloor(ctx context.Context, s Store, now time.Time) error {
+ body, err := json.Marshal(struct {
+ Schema int `json:"schema"`
+ Capability string `json:"capability"`
+ At time.Time `json:"at"`
+ }{1, ConsoleStoreWritersCapability, now.UTC()})
+ if err != nil {
+ return err
+ }
+ if _, err := s.Put(ctx, ConsoleStoreWritersFloorKey, append(body, '\n'), ""); err != nil && !errors.Is(err, ErrCASConflict) {
+ return fmt.Errorf("release: record the console floor: %w", err)
+ }
+ return nil
+}
+
+// consoleFloorRefusal is why the staged build at path, whose Go program is
+// program, may not be pointed live: "" when it may. An error (the floor or
+// the build could not be read) refuses for this pass; the next asks again.
+func consoleFloorRefusal(ctx context.Context, s Store, path, program string) (string, error) {
+ if program != ConsoleProgram {
+ return "", nil
+ }
+ if _, _, err := s.Get(ctx, ConsoleStoreWritersFloorKey); err != nil {
+ if errors.Is(err, os.ErrNotExist) {
+ return "", nil
+ }
+ return "", fmt.Errorf("read %s: %w", ConsoleStoreWritersFloorKey, err)
+ }
+ has, err := fileContains(path, []byte(ConsoleStoreWritersCapability))
+ if err != nil {
+ return "", err
+ }
+ if has {
+ return "", nil
+ }
+ return "this console build predates write credentials, and this deployment has had a store writer (" +
+ ConsoleStoreWritersFloorKey + "), so it would leave writers behind. Promote a console build that knows store writers", nil
+}
+
+// fileContains reports whether the file at path holds needle, reading it in
+// chunks that overlap by len(needle)-1 so a match across a boundary counts.
+func fileContains(path string, needle []byte) (bool, error) {
+ f, err := safefile.OpenFile(path, os.O_RDONLY, 0)
+ if err != nil {
+ return false, err
+ }
+ defer f.Close()
+ buf := make([]byte, consoleFloorScanChunk+len(needle)-1)
+ carry := 0
+ for {
+ n, err := f.Read(buf[carry:])
+ if bytes.Contains(buf[:carry+n], needle) {
+ return true, nil
+ }
+ if err == io.EOF {
+ return false, nil
+ }
+ if err != nil {
+ return false, err
+ }
+ if keep := len(needle) - 1; carry+n > keep {
+ copy(buf, buf[carry+n-keep:carry+n])
+ carry = keep
+ } else {
+ carry += n
+ }
+ }
+}
diff --git a/internal/release/consolefloor_test.go b/internal/release/consolefloor_test.go
new file mode 100644
index 000000000..1f1db4746
--- /dev/null
+++ b/internal/release/consolefloor_test.go
@@ -0,0 +1,137 @@
+package release
+
+import (
+ "bytes"
+ "context"
+ "os"
+ "path/filepath"
+ "strings"
+ "testing"
+ "time"
+)
+
+func writeBinary(t *testing.T, body []byte) string {
+ t.Helper()
+ p := filepath.Join(t.TempDir(), "console")
+ if err := os.WriteFile(p, body, 0o755); err != nil {
+ t.Fatal(err)
+ }
+ return p
+}
+
+// The floor (spec 2026-11-25-store-write-credential-design.md §10): once a
+// deployment has had a writer, an adopting box refuses a console build
+// without the capability marker, and admits one with it.
+func TestConsoleStoreWritersFloor(t *testing.T) {
+ ctx := context.Background()
+ s := NewDirStore(t.TempDir())
+ // The marker straddles the scanner's buffer boundary, which a naive
+ // chunked search would miss.
+ pad := bytes.Repeat([]byte{0}, consoleFloorScanChunk-7)
+ aware := writeBinary(t, append(append(pad, ConsoleStoreWritersCapability...), 0))
+ old := writeBinary(t, append(pad, "carlos-console-capability:other"...))
+
+ // No floor yet: everything is admitted.
+ for _, p := range []string{aware, old} {
+ if why, err := consoleFloorRefusal(ctx, s, p, ConsoleProgram); err != nil || why != "" {
+ t.Fatalf("no floor: %q, %v", why, err)
+ }
+ }
+ if err := PutConsoleStoreWritersFloor(ctx, s, time.Now()); err != nil {
+ t.Fatal(err)
+ }
+ // Written once; a second write keeps the first.
+ first, _, _ := s.Get(ctx, ConsoleStoreWritersFloorKey)
+ if err := PutConsoleStoreWritersFloor(ctx, s, time.Now().Add(time.Hour)); err != nil {
+ t.Fatal(err)
+ }
+ if again, _, _ := s.Get(ctx, ConsoleStoreWritersFloorKey); !bytes.Equal(first, again) {
+ t.Fatal("a second floor write replaced the first")
+ }
+
+ if why, err := consoleFloorRefusal(ctx, s, aware, ConsoleProgram); err != nil || why != "" {
+ t.Fatalf("writer-aware console refused: %q, %v", why, err)
+ }
+ why, err := consoleFloorRefusal(ctx, s, old, ConsoleProgram)
+ if err != nil || !strings.Contains(why, "predates write credentials") {
+ t.Fatalf("pre-floor console: %q, %v", why, err)
+ }
+ // Any other program is none of this gate's business.
+ if why, err := consoleFloorRefusal(ctx, s, old, "github.com/example/shop"); err != nil || why != "" {
+ t.Fatalf("another program: %q, %v", why, err)
+ }
+ // A console build that cannot be read is refused for this pass.
+ if _, err := consoleFloorRefusal(ctx, s, filepath.Join(t.TempDir(), "missing"), ConsoleProgram); err == nil {
+ t.Fatal("an unreadable console build was admitted")
+ }
+}
+
+// A floor read that fails refuses for this pass rather than admitting.
+func TestConsoleStoreWritersFloorReadFailureRefuses(t *testing.T) {
+ ctx := context.Background()
+ p := writeBinary(t, []byte("no marker"))
+ if _, err := consoleFloorRefusal(ctx, floorReadFailStore{NewDirStore(t.TempDir())}, p, ConsoleProgram); err == nil {
+ t.Fatal("a failed floor read admitted a console build")
+ }
+}
+
+type floorReadFailStore struct{ Store }
+
+func (floorReadFailStore) Get(context.Context, string) ([]byte, string, error) {
+ return nil, "", os.ErrDeadlineExceeded
+}
+
+// The floor at the adopting box: with the floor recorded, a pass refuses to
+// point a console route at a console build without the marker, restarts
+// nothing, and adopts the next build that carries it.
+func TestBoxRefusesAPreFloorConsole(t *testing.T) {
+ host := "console.example.com"
+ s := NewDirStore(t.TempDir())
+ ctx := context.Background()
+ priv, pub := testKeys(t)
+ opt, bake := t.TempDir(), t.TempDir()
+ reg := testRegistry(t)
+ plain := tinyProgram(t, ConsoleProgram)
+ aware := append(plain[:len(plain):len(plain)], ConsoleStoreWritersCapability...)
+ shipRelease(t, s, "bab", "console", "aware1", adoptPlatform, aware)
+ shipRelease(t, s, "bab", "console", "old", adoptPlatform, plain)
+ aware2 := append(aware[:len(aware):len(aware)], 0)
+ shipRelease(t, s, "bab", "console", "aware2", adoptPlatform, aware2)
+ if err := StageArtifact(opt, "bab", "aware1", "console", aware); err != nil {
+ t.Fatal(err)
+ }
+ addRoute(t, reg, host, "console", "canary/x", false)
+ if err := PointLive(opt, host, "bab", "aware1", "console"); err != nil {
+ t.Fatal(err)
+ }
+ if err := PutConsoleStoreWritersFloor(ctx, s, time.Now()); err != nil {
+ t.Fatal(err)
+ }
+ if err := Promote(ctx, s, priv, "bab", "console", "canary/x", "old"); err != nil {
+ t.Fatal(err)
+ }
+ restarted := 0
+ restart := func(string) error { restarted++; return nil }
+ var out bytes.Buffer
+ withCapturedStdout(t, &out, func() {
+ if err := Pass(ctx, reg, s, pub, opt, restart, BakeDir(bake)); err != nil {
+ t.Fatalf("Pass: %v", err)
+ }
+ })
+ if v, _ := LiveVersion(opt, host); v != "aware1" {
+ t.Fatalf("live = %q after a rollback to a pre-floor console, want aware1", v)
+ }
+ if restarted != 0 || !strings.Contains(out.String(), "old: this console build predates write credentials") ||
+ !strings.Contains(out.String(), "not pointed live, will retry") {
+ t.Fatalf("restarted %d, printed %q", restarted, out.String())
+ }
+ if err := Promote(ctx, s, priv, "bab", "console", "canary/x", "aware2"); err != nil {
+ t.Fatal(err)
+ }
+ if err := Pass(ctx, reg, s, pub, opt, restart, BakeDir(bake)); err != nil {
+ t.Fatalf("Pass: %v", err)
+ }
+ if v, _ := LiveVersion(opt, host); v != "aware2" {
+ t.Fatalf("live = %q, want the writer-aware aware2", v)
+ }
+}