store write credential: answer Astra code round 1
Floor kept by the deployment bucket's policy and checked by key alone; writer names claimed per store; parity row; converge doc and test.
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
11 files changed,
+330
−23
docs/parity.md+4 −2docs/superpowers/specs/2026-11-25-store-write-credential-design.md+19 −7infra/modules/deployment-buckets/main.tf+25 −0infra/modules/deployment-buckets/tests/console_floors.tftest.hcl+48 −0internal/objstore/walk.go+16 −3internal/objstore/writecred.go+51 −5internal/objstore/writecred_test.go+98 −0internal/release/consolefloor.go+26 −4internal/release/consolefloor_test.go+41 −2parity/cli.tsv+1 −0parity/parity.tsv+1 −0
diff --git a/docs/parity.md b/docs/parity.md| index a7988f9da..f8fbbafe5 100644 |
| --- a/docs/parity.md |
| +++ b/docs/parity.md |
| @@ -12,10 +12,10 @@ CLI rows are checked against the command registry (`parity/cli.tsv`). |
| |---|---:| |
| | both | 48 | |
| | partial | 9 | |
| -| gap | 68 | |
| +| gap | 69 | |
| | cli-only | 20 | |
| | console-only | 18 | |
| -| Total | 163 | |
| +| Total | 164 | |
| ## account |
| @@ -243,6 +243,7 @@ CLI rows are checked against the command registry (`parity/cli.tsv`). |
| | store-status | both | `store status` | `GET /a/{sqid}/apps/{app}/settings/{section}` | | | |
| | store-apply | both | `store apply` | `GET /a/{sqid}/settings`<br>`POST /a/{sqid}/store/apply` | | | |
| | store-rotate | gap | `store rotate` | | [wp-email-storage](#wp-email-storage) | | |
| +| store-credential | gap | `store credential` | | [wp-email-storage](#wp-email-storage) | | |
| | store-scan | gap | `store scan request`<br>`store scan status`<br>`store scan grant`<br>`store scan revoke`<br>`store scan sweep`<br>`store scan enforce`<br>`store scan rotate-webhook-key` | | [wp-email-storage](#wp-email-storage) | | |
| | store-uploads | gap | `store uploads enable`<br>`store uploads status`<br>`store uploads disable` | | [wp-email-storage](#wp-email-storage) | | |
| | store-versioning | gap | `store versioning on`<br>`store versioning status`<br>`store versions`<br>`store restore` | | [wp-email-storage](#wp-email-storage) | The console has no versioning page yet; store status shows whether it is on. | |
| @@ -332,6 +333,7 @@ Discussion #737. |
| - `store-create` (storage), CLI has `store create` |
| - `store-rotate` (storage), CLI has `store rotate` |
| +- `store-credential` (storage), CLI has `store credential` |
| - `store-scan` (storage), CLI has `store scan request`, `store scan status`, `store scan grant`, `store scan revoke`, `store scan sweep`, `store scan enforce`, `store scan rotate-webhook-key` |
| - `store-uploads` (storage), CLI has `store uploads enable`, `store uploads status`, `store uploads disable` |
| - `store-versioning` (storage), CLI has `store versioning on`, `store versioning status`, `store versions`, `store restore` |
diff --git a/docs/superpowers/specs/2026-11-25-store-write-credential-design.md b/docs/superpowers/specs/2026-11-25-store-write-credential-design.md| index 8bb223c52..a533f6d89 100644 |
| --- a/docs/superpowers/specs/2026-11-25-store-write-credential-design.md |
| +++ b/docs/superpowers/specs/2026-11-25-store-write-credential-design.md |
| @@ -82,8 +82,12 @@ policy's explicit Denies win over any resource policy anyway. |
| - **Name:** `carlos-w-` followed by the store user's name without |
| `carlos-store-`, so `carlos-w-<acct>-<app>[-<env>]`. It is shorter than |
| the store user's name, so it always fits IAM's 64 characters, and it is |
| - unique exactly when store user names are, which the name claims already |
| - enforce (`nameclaim.go`). No name on the store path starts `carlos-w-`. |
| + unique exactly when store user names are. It belongs to one store by a |
| + name claim under the same `users/` namespace (`nameclaim.go`), taken by |
| + the first mint before anything else is written, and refused while a |
| + colliding store granted before claims exists. A store that does not hold |
| + the claim never mints through, rewrites or deletes the writer (code |
| + review round 1). No name on the store path starts `carlos-w-`. |
| - **Path and boundary:** the store user path (`UserPath`) and the store |
| user boundary, through the same `EnsureUser`-style create that stamps |
| the boundary. The console role's existing `iam:CreateUser` and |
| @@ -95,8 +99,9 @@ policy's explicit Denies win over any resource policy anyway. |
| - **Keys:** none that last. Only a mint makes a key for it, and the mint |
| deletes it (§5). The app is never given a writer key. |
| - **Reaped with the store:** teardown deletes the writer (keys, inline |
| - policy, user) and then the state object, before the record, which goes |
| - last as always. Each step treats "already gone" as done, so a re-run |
| + policy, user) and gives its claim back, when this store holds the claim, |
| + then deletes the state object, before the record, which goes last as |
| + always. Each step treats "already gone" as done, so a re-run |
| converges. |
| ### 2.2 The writer's inline policy |
| @@ -432,14 +437,21 @@ One line: `writeCredentialsPhase = 2`. |
| keeps it). No earlier console carries it. |
| - The first mint writes `control/console-floors/store-writers.json` to |
| the deployment bucket, create-only, before it writes the state object or |
| - creates any writer. It is never deleted. |
| + creates any writer. It is never deleted, and storage enforces that: the |
| + deployment bucket's policy (`infra/modules/deployment-buckets`, |
| + `ConsoleFloorsAreCreateOnly`, `ConsoleFloorsAreNeverDeleted`) denies, |
| + to every principal, a delete or a replacement under |
| + `control/console-floors/`, as it already does for box evidence. No box |
| + credential can remove the floor (code review round 1). |
| `adoptHost` (`internal/release/adopt.go`), beside D2, refuses to point a |
| route live on a build whose Go program is the console |
| (`github.com/carlosframework/platform/cmd/console`, read from the staged |
| bytes as D2 reads it) when the floor object exists and the staged bytes |
| -lack the marker. The refusal prints why and points nothing live; the next |
| -pass asks again. A floor read that fails also refuses for that pass. This |
| +lack the marker. The box checks the floor's existence with a one-key |
| +bounded listing and never reads its body, whose size a region host could |
| +choose. The refusal prints why and points nothing live; the next pass asks |
| +again. A floor read that fails also refuses for that pass. This |
| is where D2 and D3 already enforce console releases, on the box, so a |
| rollback by any route (a console door, a bucket-direct promote) meets it. |
diff --git a/infra/modules/deployment-buckets/main.tf b/infra/modules/deployment-buckets/main.tf| index 240166d7a..4fcbe3bbd 100644 |
| --- a/infra/modules/deployment-buckets/main.tf |
| +++ b/infra/modules/deployment-buckets/main.tf |
| @@ -237,6 +237,31 @@ resource "aws_s3_bucket_policy" "deployment_box_records" { |
| Action = ["s3:DeleteObject", "s3:DeleteObjectVersion"] |
| Resource = [for p in local.box_evidence_prefixes : "${aws_s3_bucket.deployment.arn}/${p}/*"] |
| }, |
| + # The console floor for store write credentials (store write |
| + # credential spec, 2026-11-25, §10): written once, create-only, by a |
| + # console's first write-credential mint, and never deleted. An |
| + # adopting box refuses a console build from before writers while it |
| + # exists, so deleting it would reopen a rollback that leaves writers |
| + # behind. Like the box evidence, storage enforces it, against every |
| + # principal, so no box credential can remove or replace it. |
| + { |
| + Sid = "ConsoleFloorsAreCreateOnly" |
| + Effect = "Deny" |
| + Principal = "*" |
| + Action = "s3:PutObject" |
| + Resource = "${aws_s3_bucket.deployment.arn}/control/console-floors/*" |
| + Condition = { |
| + Null = { "s3:if-none-match" = "true" } |
| + Bool = { "s3:ObjectCreationOperation" = "true" } |
| + } |
| + }, |
| + { |
| + Sid = "ConsoleFloorsAreNeverDeleted" |
| + Effect = "Deny" |
| + Principal = "*" |
| + Action = ["s3:DeleteObject", "s3:DeleteObjectVersion"] |
| + Resource = "${aws_s3_bucket.deployment.arn}/control/console-floors/*" |
| + }, |
| { |
| Sid = "OnlyBoxRolesWriteTerminationFences" |
| Effect = "Deny" |
diff --git a/infra/modules/deployment-buckets/tests/console_floors.tftest.hcl b/infra/modules/deployment-buckets/tests/console_floors.tftest.hcl| new file mode 100644 |
| index 000000000..f6047089b |
| --- /dev/null |
| +++ b/infra/modules/deployment-buckets/tests/console_floors.tftest.hcl |
| @@ -0,0 +1,48 @@ |
| +# The console floor for store write credentials (store write credential |
| +# spec, 2026-11-25, §10): create-only and never deleted, for everyone, on |
| +# exactly control/console-floors/. Each statement is checked whole. |
| + |
| +mock_provider "aws" {} |
| + |
| +override_resource { |
| + target = aws_s3_bucket.deployment |
| + values = { arn = "arn:aws:s3:::dep" } |
| +} |
| + |
| +variables { |
| + deployment_bucket_name = "dep" |
| + data_bucket_name = "data" |
| +} |
| + |
| +run "console_floors_are_create_only_and_never_deleted" { |
| + command = plan |
| + |
| + assert { |
| + condition = jsonencode([ |
| + for s in jsondecode(aws_s3_bucket_policy.deployment_box_records.policy).Statement : s if s.Sid == "ConsoleFloorsAreCreateOnly" |
| + ]) == jsonencode([{ |
| + Action = "s3:PutObject" |
| + Condition = { |
| + Bool = { "s3:ObjectCreationOperation" = "true" } |
| + Null = { "s3:if-none-match" = "true" } |
| + } |
| + Effect = "Deny" |
| + Principal = "*" |
| + Resource = "arn:aws:s3:::dep/control/console-floors/*" |
| + Sid = "ConsoleFloorsAreCreateOnly" |
| + }]) |
| + error_message = "ConsoleFloorsAreCreateOnly must Deny, to everyone, every PutObject without If-None-Match on control/console-floors/ alone" |
| + } |
| + assert { |
| + condition = jsonencode([ |
| + for s in jsondecode(aws_s3_bucket_policy.deployment_box_records.policy).Statement : s if s.Sid == "ConsoleFloorsAreNeverDeleted" |
| + ]) == jsonencode([{ |
| + Action = ["s3:DeleteObject", "s3:DeleteObjectVersion"] |
| + Effect = "Deny" |
| + Principal = "*" |
| + Resource = "arn:aws:s3:::dep/control/console-floors/*" |
| + Sid = "ConsoleFloorsAreNeverDeleted" |
| + }]) |
| + error_message = "ConsoleFloorsAreNeverDeleted must Deny, to everyone, both delete actions on control/console-floors/ alone" |
| + } |
| +} |
diff --git a/internal/objstore/walk.go b/internal/objstore/walk.go| index 5a644a16d..6a34262fe 100644 |
| --- a/internal/objstore/walk.go |
| +++ b/internal/objstore/walk.go |
| @@ -340,8 +340,10 @@ func claimRawGrantIn(ctx context.Context, s release.Store, p Provisioner, d Depl |
| // 2a. the store's writer (writecred.go), if it has one: its policy |
| // carries the storage-grace Deny too, and this walk is how a change to |
| // writes_denied reaches it. A store with no bucket yet has no writer. |
| + // A writer this store does not hold the claim for is not this walk's to |
| + // touch (claimWriterName); the mint refuses to make one. |
| if rec.Provisioned != nil { |
| - if err := claimRawConvergeWriterIn(ctx, s, p, acct, app, env, bucket); err != nil { |
| + if err := claimRawConvergeWriterIn(ctx, s, p, acct, app, env, bucket); err != nil && !errors.Is(err, ErrStoreNameTaken) { |
| return nil, err |
| } |
| } |
| @@ -823,9 +825,20 @@ func claimRawTeardownIn(ctx context.Context, s release.Store, p Provisioner, sc |
| if wc, _, err := GetWriteCredentialsIn(ctx, s, acct, app, env); err != nil { |
| return fmt.Errorf("objstore: read write credentials for %s/%s: %w", acct, app, err) |
| } else if wc != nil { |
| + // Only a writer this store holds the claim for (claimWriterName): a |
| + // colliding store's writer is that store's to tear down. |
| writer := WriterName(UserNameIn(acct, app, env)) |
| - if err := p.DeleteUser(ctx, writer); err != nil { |
| - return fmt.Errorf("objstore: delete writer %s: %w", writer, err) |
| + held, err := holdsWriterName(ctx, s, acct, app, env) |
| + if err != nil { |
| + return fmt.Errorf("objstore: writer claim for %s/%s: %w", acct, app, err) |
| + } |
| + if held { |
| + if err := p.DeleteUser(ctx, writer); err != nil { |
| + return fmt.Errorf("objstore: delete writer %s: %w", writer, err) |
| + } |
| + if err := releaseName(ctx, s, userClaimKey(writer), acct, app, env); err != nil { |
| + return fmt.Errorf("objstore: release writer claim %s: %w", writer, err) |
| + } |
| } |
| if err := s.Delete(ctx, WriteCredentialsKey(acct, app, env)); err != nil { |
| return fmt.Errorf("objstore: delete write credentials state for %s/%s: %w", acct, app, err) |
diff --git a/internal/objstore/writecred.go b/internal/objstore/writecred.go| index 55a6c2306..147d0f715 100644 |
| --- a/internal/objstore/writecred.go |
| +++ b/internal/objstore/writecred.go |
| @@ -337,17 +337,32 @@ func writerPolicyNow(ctx context.Context, s release.Store, acct, app, env, bucke |
| // claimRawConvergeWriterIn makes the writer's policy match the store's |
| // record and state object, for a store that has a writer (nothing to do |
| -// otherwise). The walks that write it do not share one console lock, so it |
| -// is write-then-validate (spec §2.3): write the policy computed from what |
| -// was read, read again, and write again if the answer changed. A |
| -// revocation writes the state object before the policy, so a write |
| -// computed from older inputs is always followed by one from newer ones. |
| +// otherwise), and refuses with ErrStoreNameTaken a writer this store does |
| +// not hold the claim for. |
| +// |
| +// THE SAFETY IS THE CALLERS' LOCKS, not this loop (spec §2.3). One console |
| +// per deployment; the mint and revoke doors hold the account lock and then |
| +// the store walk lock; every grant walk caller holds the account lock or |
| +// the walk lock. revoked_before, the input a revocation's safety rests on, |
| +// is written only under both, so no writer of this policy that could hold a |
| +// stale copy of it runs at the same time. Write-then-validate is retry |
| +// assistance on top: write the policy computed from what was read, read |
| +// again, and write again if the answer changed, up to three times. A |
| +// validation read that fails, a cancelled context or an exhausted retry |
| +// returns an error, so the door or the next pass runs the walk again. |
| func claimRawConvergeWriterIn(ctx context.Context, s release.Store, p Provisioner, acct, app, env, bucket string) error { |
| writer := WriterName(UserNameIn(acct, app, env)) |
| want, err := writerPolicyNow(ctx, s, acct, app, env, bucket) |
| if err != nil || want == "" { |
| return err |
| } |
| + held, err := holdsWriterName(ctx, s, acct, app, env) |
| + if err != nil { |
| + return err |
| + } |
| + if !held { |
| + return fmt.Errorf("%w: %s", ErrStoreNameTaken, writer) |
| + } |
| for attempt := 0; attempt < 3; attempt++ { |
| if err := p.EnsureWriter(ctx, writer, UserPath, want); err != nil { |
| return fmt.Errorf("objstore: ensure writer %s: %w", writer, err) |
| @@ -364,6 +379,34 @@ func claimRawConvergeWriterIn(ctx context.Context, s release.Store, p Provisione |
| return errWriterUnsettled |
| } |
| +// The writer's name is a store name like the store user's (nameclaim.go): |
| +// carlos-w-<acct>-<app>[-<env>] collides exactly when the store user's name |
| +// does, so a writer belongs to one store by a claim under the same users/ |
| +// namespace, taken before its state object or the user exists. A store that |
| +// does not hold that claim never creates, rewrites or deletes the writer |
| +// (Astra code round 1). |
| + |
| +// claimWriterName takes this store's writer name, refusing it when a |
| +// colliding store granted before claims existed could share it, or when |
| +// another store already holds it. |
| +func claimWriterName(ctx context.Context, s release.Store, acct, app, env string, now time.Time) error { |
| + others, err := grantedColliders(ctx, s, acct, app, env) |
| + if err != nil { |
| + return err |
| + } |
| + writer := WriterName(UserNameIn(acct, app, env)) |
| + if len(others) > 0 { |
| + return fmt.Errorf("%w: %s could be the writer of %s/%s environment %q too", ErrStoreNameTaken, writer, acct, others[0].App, others[0].Environment) |
| + } |
| + return claimName(ctx, s, userClaimKey(writer), writer, acct, app, env, now) |
| +} |
| + |
| +// holdsWriterName reports whether this store holds its writer's claim. |
| +func holdsWriterName(ctx context.Context, s release.Store, acct, app, env string) (bool, error) { |
| + c, err := getNameClaim(ctx, s, userClaimKey(WriterName(UserNameIn(acct, app, env)))) |
| + return c != nil && c.heldBy(acct, app, env), err |
| +} |
| + |
| // writeStore is the provisioned store a write-credential walk acts on: its |
| // record and the coordinates the record names, checked the way |
| // claimRawConvergePolicyIn checks them. |
| @@ -419,6 +462,9 @@ func claimRawMintWriteCredentialIn(ctx context.Context, s release.Store, p Provi |
| return nil, &RevocationSettlingError{Until: until} |
| } |
| } |
| + if err := claimWriterName(ctx, s, acct, app, env, now); err != nil { |
| + return nil, err |
| + } |
| 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 |
diff --git a/internal/objstore/writecred_test.go b/internal/objstore/writecred_test.go| index 0bfbaceb9..0aea37f74 100644 |
| --- a/internal/objstore/writecred_test.go |
| +++ b/internal/objstore/writecred_test.go |
| @@ -502,3 +502,101 @@ func TestWriteCredentialsStateMismatch(t *testing.T) { |
| t.Fatalf("an environment's state object %s is under the stores collection", got) |
| } |
| } |
| + |
| +// Stores whose names collide by construction (app shop-eu, and app shop's |
| +// environment eu) would share one writer. The writer belongs to whichever |
| +// store claimed it; the other can neither mint through it, rewrite its |
| +// policy nor tear it down (Astra code round 1). |
| +func TestWriterBelongsToOneStore(t *testing.T) { |
| + ctx := context.Background() |
| + s := release.NewDirStore(t.TempDir()) |
| + _, pub := testSealKeypair(t) |
| + p := NewMemProvisioner("eu-west-1") |
| + declare(t, s, "bab", "shop-eu", "SHOP_S3") |
| + if _, err := Grant(ctx, s, p, testDeployment(), storeTestSealer(pub, "bab", "shop-eu"), "bab", "shop-eu", "op", GrantSourceOperator, "", time.Now().UTC()); err != nil { |
| + t.Fatal(err) |
| + } |
| + now := time.Now().UTC() |
| + if _, err := MintWriteCredentialIn(ctx, s, p, "bab", "shop-eu", "", "m@example.com", "recordings/", time.Hour, now); err != nil { |
| + t.Fatal(err) |
| + } |
| + writer := WriterName(UserNameIn("bab", "shop-eu", "")) |
| + if writer != WriterName(UserNameIn("bab", "shop", "eu")) { |
| + t.Fatal("fixture: the two stores' writers do not collide") |
| + } |
| + if _, err := RevokeWriteCredentialsIn(ctx, s, p, "bab", "shop-eu", "", now); err != nil { |
| + t.Fatal(err) |
| + } |
| + policy := p.Users[writer].Policy |
| + |
| + // The colliding store, as a record from before name claims, carrying a |
| + // state object of its own. |
| + a, _, _ := GetIn(ctx, s, "bab", "shop-eu", "") |
| + b := &Record{Declared: a.Declared, Grant: a.Grant, Provisioned: a.Provisioned} |
| + if _, err := PutIn(ctx, s, "bab", "shop", "eu", b, ""); err != nil { |
| + t.Fatal(err) |
| + } |
| + if _, err := claimRawPutWriteCredentialsIn(ctx, s, "bab", "shop", "eu", &WriteCredentials{At: now, By: "x"}, ""); err != nil { |
| + t.Fatal(err) |
| + } |
| + sessions := len(p.Sessions) |
| + if _, err := MintWriteCredentialIn(ctx, s, p, "bab", "shop", "eu", "m@example.com", "recordings/", time.Hour, now.Add(time.Hour)); !errors.Is(err, ErrStoreNameTaken) { |
| + t.Fatalf("mint through another store's writer: %v", err) |
| + } |
| + if _, err := RevokeWriteCredentialsIn(ctx, s, p, "bab", "shop", "eu", now.Add(time.Hour)); !errors.Is(err, ErrStoreNameTaken) { |
| + t.Fatalf("revoke through another store's writer: %v", err) |
| + } |
| + if err := claimRawConvergeWriterIn(ctx, s, p, "bab", "shop", "eu", a.Provisioned.Bucket); !errors.Is(err, ErrStoreNameTaken) { |
| + t.Fatalf("converge another store's writer: %v", err) |
| + } |
| + if len(p.Sessions) != sessions || p.Users[writer].Policy != policy { |
| + t.Fatal("the colliding store minted through, or rewrote, the other store's writer") |
| + } |
| + if err := TeardownIn(ctx, s, p, nil, "bab", "shop", "eu"); err != nil { |
| + t.Fatal(err) |
| + } |
| + if u, ok := p.Users[writer]; !ok || u.Policy != policy { |
| + t.Fatal("the colliding store's teardown removed or changed the other store's writer") |
| + } |
| + if held, err := holdsWriterName(ctx, s, "bab", "shop-eu", ""); err != nil || !held { |
| + t.Fatalf("the owner lost its writer claim: %v, %v", held, err) |
| + } |
| + // The owner's own teardown removes the writer and gives the name back. |
| + if err := Teardown(ctx, s, p, nil, "bab", "shop-eu"); err != nil { |
| + t.Fatal(err) |
| + } |
| + if _, ok := p.Users[writer]; ok { |
| + t.Fatal("the owner's teardown left its writer") |
| + } |
| + if c, err := getNameClaim(ctx, s, userClaimKey(writer)); err != nil || c != nil { |
| + t.Fatalf("the writer's claim outlived its store: %+v, %v", c, err) |
| + } |
| +} |
| + |
| +// A validation read that fails after a successful policy write fails the |
| +// walk, so the caller runs it again (Astra code round 1, finding 6). |
| +func TestConvergeWriterFailsWhenValidationCannotRead(t *testing.T) { |
| + ctx := context.Background() |
| + s, p, _ := writeFixture(t) |
| + if _, err := mint(t, s, p, "recordings/", time.Hour, time.Now().UTC()); err != nil { |
| + t.Fatal(err) |
| + } |
| + rec, _, _ := GetIn(ctx, s, "bab", "titogo", "") |
| + fs := &failAfterStore{Store: s} |
| + p.AfterEnsureWriter = func(string) { fs.fail = true } |
| + if err := claimRawConvergeWriterIn(ctx, fs, p, "bab", "titogo", "", rec.Provisioned.Bucket); err == nil { |
| + t.Fatal("converge succeeded though its validation read failed") |
| + } |
| +} |
| + |
| +type failAfterStore struct { |
| + release.Store |
| + fail bool |
| +} |
| + |
| +func (f *failAfterStore) Get(ctx context.Context, key string) ([]byte, string, error) { |
| + if f.fail { |
| + return nil, "", errors.New("store unavailable") |
| + } |
| + return f.Store.Get(ctx, key) |
| +} |
diff --git a/internal/release/consolefloor.go b/internal/release/consolefloor.go| index 327f501b6..a635c601a 100644 |
| --- a/internal/release/consolefloor.go |
| +++ b/internal/release/consolefloor.go |
| @@ -23,6 +23,7 @@ import ( |
| "fmt" |
| "io" |
| "os" |
| + "slices" |
| "time" |
| "github.com/carlosframework/platform/internal/registry" |
| @@ -69,12 +70,13 @@ func consoleFloorRefusal(ctx context.Context, s Store, path, program string) (st |
| if program != ConsoleProgram { |
| return "", nil |
| } |
| - if _, _, err := s.Get(ctx, ConsoleStoreWritersFloorKey); err != nil { |
| - if errors.Is(err, os.ErrNotExist) { |
| - return "", nil |
| - } |
| + present, err := consoleFloorExists(ctx, s) |
| + if err != nil { |
| return "", fmt.Errorf("read %s: %w", ConsoleStoreWritersFloorKey, err) |
| } |
| + if !present { |
| + return "", nil |
| + } |
| has, err := fileContains(path, []byte(ConsoleStoreWritersCapability)) |
| if err != nil { |
| return "", err |
| @@ -86,6 +88,26 @@ func consoleFloorRefusal(ctx context.Context, s Store, path, program string) (st |
| ConsoleStoreWritersFloorKey + "), so it would leave writers behind. Promote a console build that knows store writers", nil |
| } |
| +// consoleFloorExists reports whether the floor object exists, without |
| +// reading its body: any region host can write that key, so its size is not |
| +// root's to trust (Astra code round 1). A one-key bounded listing whose |
| +// prefix is the key itself answers it, because the key sorts before any |
| +// longer key that starts with it. A store with no bounded listing degrades |
| +// to List, as PageLister's other callers do. |
| +func consoleFloorExists(ctx context.Context, s Store) (bool, error) { |
| + var keys []string |
| + var err error |
| + if pl, ok := s.(PageLister); ok { |
| + keys, err = pl.ListPage(ctx, ConsoleStoreWritersFloorKey, "", 1) |
| + } else { |
| + keys, err = s.List(ctx, ConsoleStoreWritersFloorKey) |
| + } |
| + if err != nil { |
| + return false, err |
| + } |
| + return slices.Contains(keys, ConsoleStoreWritersFloorKey), 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) { |
diff --git a/internal/release/consolefloor_test.go b/internal/release/consolefloor_test.go| index 1f1db4746..968b022b6 100644 |
| --- a/internal/release/consolefloor_test.go |
| +++ b/internal/release/consolefloor_test.go |
| @@ -77,8 +77,47 @@ func TestConsoleStoreWritersFloorReadFailureRefuses(t *testing.T) { |
| type floorReadFailStore struct{ Store } |
| -func (floorReadFailStore) Get(context.Context, string) ([]byte, string, error) { |
| - return nil, "", os.ErrDeadlineExceeded |
| +func (floorReadFailStore) List(context.Context, string) ([]string, error) { |
| + return nil, os.ErrDeadlineExceeded |
| +} |
| + |
| +// floorNoBodyStore fails the test if the floor's body is ever read: any |
| +// region host can write that object, so root must not load it (Astra code |
| +// round 1). Its ListPage is the DirStore's, and look-alike keys beside the |
| +// floor do not change the answer. |
| +type floorNoBodyStore struct { |
| + *DirStore |
| + t *testing.T |
| +} |
| + |
| +func (f floorNoBodyStore) Get(ctx context.Context, key string) ([]byte, string, error) { |
| + if key == ConsoleStoreWritersFloorKey { |
| + f.t.Fatal("the floor's body was read") |
| + } |
| + return f.DirStore.Get(ctx, key) |
| +} |
| + |
| +func TestConsoleStoreWritersFloorNeverReadsTheBody(t *testing.T) { |
| + ctx := context.Background() |
| + ds := NewDirStore(t.TempDir()) |
| + s := floorNoBodyStore{ds, t} |
| + p := writeBinary(t, []byte("no marker")) |
| + // Look-alikes only: no floor. |
| + for _, k := range []string{ConsoleStoreWritersFloorKey + "x", ConsoleStoreWritersFloorKey + ".bak"} { |
| + if _, err := ds.Put(ctx, k, []byte("{}"), ""); err != nil { |
| + t.Fatal(err) |
| + } |
| + } |
| + if why, err := consoleFloorRefusal(ctx, s, p, ConsoleProgram); err != nil || why != "" { |
| + t.Fatalf("look-alike keys made a floor: %q, %v", why, err) |
| + } |
| + // A large floor is judged by its key alone. |
| + if _, err := ds.Put(ctx, ConsoleStoreWritersFloorKey, bytes.Repeat([]byte("x"), 8<<20), ""); err != nil { |
| + t.Fatal(err) |
| + } |
| + if why, err := consoleFloorRefusal(ctx, s, p, ConsoleProgram); err != nil || why == "" { |
| + t.Fatalf("a floor was not seen: %q, %v", why, err) |
| + } |
| } |
| // The floor at the adopting box: with the floor recorded, a pass refuses to |
diff --git a/parity/cli.tsv b/parity/cli.tsv| index e9b52298b..f2ceb5ef4 100644 |
| --- a/parity/cli.tsv |
| +++ b/parity/cli.tsv |
| @@ -255,6 +255,7 @@ store apply customer - - - - - |
| store approvals operator - - - - - |
| store approve operator - - - - - |
| store create customer - - - - - |
| +store credential customer - - - - - |
| store decline operator - - - - - |
| store grant operator - - - - - |
| store restore customer - - - - - |
diff --git a/parity/parity.tsv b/parity/parity.tsv| index b8e681e65..4e4b7aa77 100644 |
| --- a/parity/parity.tsv |
| +++ b/parity/parity.tsv |
| @@ -132,6 +132,7 @@ store-create storage gap store create wp-email-storage The Storage section pri |
| store-status storage both store status GET /a/{sqid}/apps/{app}/settings/{section} |
| store-apply storage both store apply GET /a/{sqid}/settings ; POST /a/{sqid}/store/apply |
| store-rotate storage gap store rotate wp-email-storage |
| +store-credential storage gap store credential wp-email-storage |
| store-scan storage gap store scan request ; store scan status ; store scan grant ; store scan revoke ; store scan sweep ; store scan enforce ; store scan rotate-webhook-key wp-email-storage |
| store-uploads storage gap store uploads enable ; store uploads status ; store uploads disable wp-email-storage |
| store-versioning storage gap store versioning on ; store versioning status ; store versions ; store restore wp-email-storage The console has no versioning page yet; store status shows whether it is on. |