carlos / platform Public

spec: store write credential design and Astra brief

A write-only, prefix-scoped, time-limited store credential minted with
GetFederationToken as the store's own IAM user.
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
claude agent, operated by paul@keymail.dev pushed by paul@keymail.dev bd09d8f619393e3ef11e611ac9d289df6a58c1a3 parent 65951fb
2 files changed, +415 −0
  • docs/superpowers/reviews/CODEX-REVIEW-BRIEF-store-write-credential-design.md +89 −0
  • docs/superpowers/specs/2026-11-25-store-write-credential-design.md +326 −0
diff --git a/docs/superpowers/reviews/CODEX-REVIEW-BRIEF-store-write-credential-design.md b/docs/superpowers/reviews/CODEX-REVIEW-BRIEF-store-write-credential-design.md
new file mode 100644
index 000000000..64e49b00f
--- /dev/null
+++ b/docs/superpowers/reviews/CODEX-REVIEW-BRIEF-store-write-credential-design.md
@@ -0,0 +1,89 @@
+# Review brief: store write credential design, round 1 of 3
+
+Repo carlos/platform, branch `store-write-credential`, at the commit named
+in your prompt.
+Under review: `docs/superpowers/specs/2026-11-25-store-write-credential-design.md`.
+Authorities (all on main): `internal/objstore` (`aws.go` `storePolicyJSON`
+and `EnsureUser`; `walk.go` grant, rotate, rotate-finish and converge
+walks; `provisioner.go`; `objstore.go` the record),
+`infra/modules/region-host/main.tf` (the store user boundary and
+`host_store`, from "object storage provisioning"), `internal/mediaaws`
+(the precedent for STS session policies), `internal/console/apistoreuploads.go`
+(the precedent door and its locks), `internal/svcrole/svcrole.go`,
+`.amadan/ci.d/30-minio-contract`, AGENTS.md ("Rules this repo has paid
+for", the tagging lesson).
+
+You are an independent reviewer. Read the design, then the code it names,
+and check every claim against that code. This is a security gate on
+production storage: a tenant must never get a credential that reaches
+beyond its own store and the prefix it named, and nothing may fall back to
+the store's full credential.
+
+## Fixed: do not re-argue
+
+- Paul asked for this on 2026-11-25: write-only, prefix-scoped, time-limited,
+ provider-neutral, console door plus CLI verb, never a silent fallback.
+- Never call AWS from the review.
+
+## What to check
+
+1. The mechanism (§2). Is `GetFederationToken` called as the store user,
+ via a single-use access key the console creates and deletes, sound?
+ Are the stated AWS facts right (intersection with the user's policies
+ and its permissions boundary, long-term user credentials only, 900 s to
+ 36 h, the federated session's lack of IAM and STS calls, role chaining's
+ one hour)? Is there a better mechanism inside the existing trust
+ boundaries?
+2. The ceiling (§2, §3). Can the minted credential reach anything outside
+ `arn:aws:s3:::<bucket>/<prefix>*` of its own store: another store, a
+ deployment or data bucket, a read, list, delete, tag, ACL or bucket
+ call, CopyObject or UploadPartCopy from elsewhere in the store? Does
+ every Deny the store user carries still apply?
+3. The prefix rule (§3): anything that gets a wildcard, a policy variable
+ or a surprising match into the Resource ARN? Is refusing `derived/`
+ right and enough?
+4. The widening of the store user (§2.3): `sts:GetFederationToken` on the
+ app's own key. Is the revocation Deny on `aws:TokenIssueTime` correct
+ IAM (key absent for long-term credentials, operator, resources), and do
+ `RotateFinish` plus `--revoke` close the rotation gap? Is the one-minute
+ skew margin and the mint refusal during it right? Is the teardown and
+ re-create residual acceptable as stated?
+5. The key slot (§5): races with grant, rotate, teardown, and the two-key
+ ceiling; the choice never to reap; the detached delete; the retry.
+6. Provider boundary (§6): is refusing endpoint stores, and proving the
+ session policy on MinIO's STS in CI, an honest reading of "implements
+ it through its STS or refuses clearly"?
+7. Infra (§7): is the boundary statement the narrowest that works, and
+ does the console role really need nothing new?
+8. Surface (§8): the role choice (`Service`), linked accounts, host-claim
+ consoles, never logging the secret.
+9. The record (§9): additive, and what an older console does with it.
+
+## Severity
+
+- **P1**: unsafe, would not compile, a test fails, or it would not work.
+ Blocks merge.
+- **P2**: wrong or missing. Fixed without reopening this review. (The
+ census, and review of any newly changed security, root, termination
+ or production-storage behaviour, still check the fix; see AGENTS.md,
+ "Stopping rules".)
+- **P3**: clarity or polish. Goes on a follow-up list; never a reason for
+ another round.
+
+A P1 states its failure scenario and the evidence (file:line). Do not
+raise a P2 to P1 to keep the review open.
+
+## Output
+
+Findings ranked P1, P2, P3. Each gives the section, the problem, the
+evidence (file:line, verified), the failure scenario, a concrete fix and
+the invariant or trust boundary it breaks (that is its fault family). End
+with exactly one verdict:
+
+- **READY**: no P1 and no P2.
+- **READY AFTER FIXES**: no P1. The listed P2s are fixed without another
+ round.
+- **NOT READY**: one or more P1s, listed.
+
+Do not edit files. Do not spawn Anthropic-model reviewers or subagents of
+your own. Do not run the full test suites.
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
new file mode 100644
index 000000000..d061000d9
--- /dev/null
+++ b/docs/superpowers/specs/2026-11-25-store-write-credential-design.md
@@ -0,0 +1,326 @@
+# Store write credential: design
+
+Status: draft for review, 2026-11-25. Asked for by Paul on 2026-11-25.
+Branch `store-write-credential`.
+
+## 1. What and why
+
+Today an app has exactly one store credential (`CARLOS_STORE_ACCESS_KEY`
+and `_SECRET_KEY`). It can read, overwrite and delete every object in the
+store. An app that hands its store to a third party, such as LiveKit Cloud
+Egress uploading a recording, has to hand over that whole credential
+(`docs/site/live-streams-bring-your-own-livekit.md`, "Not yet supported").
+
+This adds a second kind of credential, minted on request:
+
+- **write only**: `s3:PutObject` (which also authorises
+ CreateMultipartUpload, UploadPart and CompleteMultipartUpload),
+ `s3:AbortMultipartUpload` and `s3:ListMultipartUploadParts`, nothing else;
+- **under one key prefix** of the app's own store, named by the app;
+- **temporary**: a lifetime the app chooses, 15 minutes to 24 hours;
+- printed as access key, secret, session token, expiry, bucket and region,
+ the fields LiveKit's `S3Upload` takes (`access_key`, `secret`,
+ `session_token`, `region`, `bucket`).
+
+No read, list, delete, tagging, ACL or bucket call. Every Deny the store's
+own credential carries still applies: the platform tag keys, the storage
+grace write Deny, the history Denys.
+
+## 2. Mechanism: GetFederationToken as the store's own IAM user
+
+The console mints the credential with STS `GetFederationToken`, called as
+**the store's own IAM user** (`carlos-store-<acct>-<app>[-<env>]`), with an
+inline session policy built by the core (section 3).
+
+AWS's rule for the result: "the session permissions are the intersection of
+the IAM user policies and the session policies that you pass", and the
+user's permissions boundary limits it too ("the intersection of all three
+policy types"). So the minted credential can never do more than:
+
+1. the store user boundary (`infra/modules/region-host`, store prefix only),
+2. the store user's inline policy (`storePolicyJSON`: one bucket, every
+ Deny), and
+3. the session policy (one prefix, write only).
+
+The ceiling is the store's own principal. A bug in the session policy can
+at worst give the third party what the app's own key already has, in that
+one store. It can never reach another store or a deployment bucket, because
+layers 1 and 2 do not name them.
+
+### 2.1 Who holds the minting authority
+
+`GetFederationToken` must be called with an IAM user's long-term keys; role
+credentials are not accepted. The console runs as an EC2 role and does not
+hold the app's key (the secret's only landing place is the app's sealed
+config, walk.go §7).
+
+So each mint uses a **single-use access key**: the console, which already
+holds `iam:CreateAccessKey`/`DeleteAccessKey`/`ListAccessKeys` on the store
+user path (`host_store`), creates a key for the store user, calls
+`GetFederationToken` with it, and deletes it. The key's secret exists only
+in the console process for those seconds and is never logged, recorded or
+returned.
+
+### 2.2 Alternatives rejected
+
+- **AssumeRole of a per-store write role.** The console's credentials are
+ themselves a role session, and role chaining caps a session at one hour
+ ("Role chaining limits ... to a maximum of one hour"). A LiveKit file
+ egress runs up to 3 hours and uploads at the end, so this cannot cover a
+ stream. It would also need `iam:CreateRole` on the console, a new
+ escalation surface.
+- **One deployment-wide minting user.** Its ceiling would be every store,
+ so the session policy alone would separate tenants, and the per-store
+ Denys (storage grace, scan enforcement) would have to be copied into
+ every session policy. It also needs a long-lived secret on the console.
+- **The app mints its own token with its delivered key.** Possible once the
+ user may call `GetFederationToken` (2.3), but then each app writes IAM
+ policy itself. The scope decision belongs in the core, behind one door.
+- **Presigned URLs.** LiveKit's `S3Upload` takes keys and a session token,
+ not URLs.
+
+### 2.3 What the store user gains, and how that stays safe
+
+To call `GetFederationToken` the store user needs `sts:GetFederationToken`
+in its inline policy and in its boundary. Both are added only where the
+feature is used:
+
+- the boundary statement only with the module switch
+ `store_write_credentials = true` (section 6); off, the boundary renders
+ byte for byte as today;
+- the inline statement only for a store whose record carries a
+ `write_credentials` block, which the first mint writes. Until then that
+ store's policy is byte for byte today's.
+
+Resource: `arn:<partition>:sts::<account>:federated-user/carlos-write-*`,
+the account and partition taken from the record's `user_arn`.
+
+That statement is also reachable with the app's own delivered key, because
+IAM cannot tell one access key of a user from another. With it the app can
+mint itself federation sessions no wider than its own key. That is no new
+power over the store, with one exception, which this design closes:
+**persistence past a rotation**. AWS does not document that deleting the
+access key that minted a federation token revokes the token; it documents
+only that permissions "are evaluated each time they are used" against the
+user's policies. A thief holding a leaked app key could mint 36-hour
+sessions before the member rotates, and they would survive
+`carlos store rotate --finish`.
+
+So for a store with `write_credentials`:
+
+- the inline policy carries a revocation Deny once `revoked_before` is set:
+ `Deny s3:*` on the bucket and its objects when
+ `DateLessThan aws:TokenIssueTime <revoked_before>`. `aws:TokenIssueTime`
+ is present only for temporary credentials, so the app's long-term key is
+ never matched;
+- `RotateFinish` sets `revoked_before` and converges the policy, so a
+ finished rotation kills every federation session minted before it, the
+ console's and any the app minted itself;
+- `carlos store credential --revoke` does the same without rotating, for a
+ leaked write credential.
+
+`revoked_before` is the console's clock plus one minute, to cover skew
+against AWS's clock (the Deny compares AWS's issue time). Mints are refused
+until that minute has passed, so a fresh credential is never born revoked.
+AWS notes that "it might take a few minutes for policy updates to take
+effect", and the CLI says revocation can take a few minutes.
+
+The federated session itself can call no IAM operation and no STS operation
+except `GetCallerIdentity` (AWS: GetFederationToken), so a minted
+credential cannot mint another.
+
+One residual, stated rather than closed: a store torn down and created
+again for the same app reuses the user and bucket names. AWS ties a role's
+sessions to the role's unique id; it does not say the same for a federated
+user's parent. If it went by name, a write credential from the old store
+could write into the new one under its prefix until it expires (24 hours at
+most). The new record has no `write_credentials` block, so nothing in the
+new user's policy refers to it.
+
+## 3. The scope: the core's session policy
+
+Built in `internal/objstore` (provider-neutral, no SDK), from the bucket in
+the store's record and the validated prefix:
+
+```json
+{"Version": "2012-10-17", "Statement": [
+ {"Effect": "Allow",
+ "Action": ["s3:PutObject", "s3:AbortMultipartUpload", "s3:ListMultipartUploadParts"],
+ "Resource": "arn:aws:s3:::<bucket>/<prefix>*"},
+ {"Effect": "Deny", "Action": ["s3:PutObject"],
+ "Resource": "arn:aws:s3:::<bucket>/<prefix>*",
+ "Condition": {"Null": {"s3:RequestObjectTagKeys": "false"}}}
+]}
+```
+
+The Deny refuses any upload that carries tags at all (`x-amz-tagging`),
+beside the user policy's Deny on the platform's own tag keys: the lesson in
+AGENTS.md ("absence is not the property") applied to the new credential.
+
+The prefix is validated before it goes near a policy:
+
+- 1 to 200 bytes, ending in `/`;
+- segments of `A-Z a-z 0-9 . _ -`, no empty, `.` or `..` segment, no
+ leading `/`; this keeps IAM wildcards (`*`, `?`) and policy variables
+ (`${...}`) out of the ARN;
+- not `derived/` or under it: media conversion writes its outputs there,
+ and a third party must not be able to plant files that look
+ platform-made.
+
+It can overwrite objects under its prefix (that is what `PutObject` is).
+The docs say to give each third party a prefix of its own.
+
+## 4. Lifetime
+
+`ttl` is required, 15 minutes (STS's floor) to 24 hours. LiveKit Cloud's
+longest egress is 12 hours (track or segments; a file output is 3 hours)
+and it uploads a file when the recording stops, so 24 hours covers the
+longest recording plus its upload. STS itself allows up to 36 hours; the
+lower cap shortens a leak.
+
+## 5. The key slot and failure handling
+
+IAM allows two access keys per user. The mint runs under the same locks as
+the walks (`release.WithAppMutation`, the console's account lock and store
+walk lock), so it never overlaps a grant, rotation or teardown of the same
+store.
+
+1. `ListAccessKeys`: two keys already (a rotation not yet finished, or a
+ stray key) is a 409 telling the member to finish the rotation first.
+2. `CreateAccessKey`.
+3. `GetFederationToken`, retried with backoff for up to 30 seconds while
+ STS answers `InvalidClientTokenId` or `AccessDenied` (a new key and a
+ just-written policy both take seconds to propagate).
+4. `DeleteAccessKey`, always, also after 3 fails, on a context detached
+ from the request's cancellation and bounded to 15 seconds.
+
+The mint never reaps keys it did not create: the rotation walk's
+"delivered but not yet recorded" gap means an unnamed key can be one the
+app is using. A key a crashed mint leaves behind has no holder, and the
+next `carlos store rotate` reaps it.
+
+## 6. Provider boundary
+
+- **Core** (`internal/objstore/writecred.go`): the prefix and lifetime
+ rules, the session policy, the record block, the policy statements, the
+ walk. No SDK.
+- **AWS adapter** (`internal/objstore/aws_writecred.go`): the single-use
+ key and `GetFederationToken`. STS client from `internal/rootaws`.
+- **S3-compatible stores** (a record with an `endpoint`): refused with
+ 409 `write_credentials_unsupported`, saying a write credential needs AWS
+ S3 and STS. The console also refuses to boot with both
+ `CARLOS_STORE_WRITE_CREDENTIALS=1` and `CARLOS_STORE_ENDPOINT`, as store
+ versioning does. In this build IAM is always AWS's, so AWS STS sessions
+ would not be accepted at another endpoint. Nothing ever falls back to the
+ full credential.
+- **MinIO contract**: MinIO's STS `AssumeRole`, signed with a MinIO user's
+ key, accepts a session policy and grants the intersection of the user's
+ policy and it. The CI step proves the core's session policy, against a
+ user carrying `storePolicyJSON`'s shape, on a real policy engine: a
+ future MinIO provisioner implements the same `MintSession` seam with that
+ call.
+
+The provisioner seam gains one method:
+
+```go
+// MintSession mints a temporary credential for store user `user`, narrowed by
+// the IAM session policy `policy`, lasting ttl.
+MintSession(ctx context.Context, user, policy string, ttl time.Duration) (Session, error)
+```
+
+What a non-AWS deployment loses: write credentials. Its apps keep their
+full credential.
+
+## 7. Infra
+
+`infra/modules/region-host`:
+
+- variable `store_write_credentials` (bool, default false), precondition:
+ needs `store_bucket_prefix`;
+- when true, one statement appended to the store user boundary:
+ `Allow sts:GetFederationToken` on
+ `arn:aws:sts::<account>:federated-user/carlos-write-*`. Managed fleet
+ users share the boundary but their inline policies do not grant it, so
+ they gain nothing;
+- no change to the console role: `host_store` already grants every IAM
+ call the mint makes, and the STS call is made as the store user.
+
+## 8. Surface
+
+Console door (registered through `routedecls.go`, refused to linked
+accounts, refused on a host-claim console):
+
+```
+POST /api/cli/apps/{account}/{app}/store/credentials
+{"access": "write", "prefix": "recordings/", "ttl_seconds": 14400, "environment": ""}
+-> 200 {"access_key", "secret", "session_token", "region", "bucket",
+ "prefix", "expires_at"} Cache-Control: no-store
+
+POST /api/cli/apps/{account}/{app}/store/credentials/revoke
+-> 200 {"revoked_before"}
+```
+
+Roles: `svcrole.Allow(svcrole.Service)`, so the app's server can mint one
+per recording with the same Service credential media conversion uses (and
+Admin). A member's CLI token reaches it through membership as usual.
+
+CLI, named like `store rotate`:
+
+```
+carlos store credential --write --prefix recordings/ --ttl 4h --app shop [--environment e] [--json]
+carlos store credential --revoke --app shop [--environment e]
+```
+
+`--write` is required, so a later kind has room. The default output leads
+with the expiry and the scope, then the five values; `--json` prints the
+door's answer, whose names match LiveKit's `S3Upload`. The secret and token
+go to stdout only; nothing logs them, console or CLI.
+
+The door needs `CARLOS_STORE_WRITE_CREDENTIALS=1` on the console (the
+operator applies the module switch first); without it, 503
+`write_credentials_not_configured`.
+
+## 9. Record
+
+Additive block on the store record:
+
+```json
+"write_credentials": {"at": "...", "by": "...", "revoked_before": "..."}
+```
+
+An older console that rewrites the record drops it; the store's policy then
+loses the STS statement at its next convergence and the next mint writes
+it back. An older console's `RotateFinish` does not revoke: roll consoles
+forward before turning the switch on.
+
+## 10. Tests
+
+- Unit, test-first: prefix and ttl validation; the session policy; the
+ inline policy with and without the block and `revoked_before` (and byte
+ identical without); the walk on the in-memory provisioner (refusals, the
+ two-key 409, the key always deleted, the retry, revocation's minute);
+ the AWS adapter against stub IAM and STS clients; the door and the CLI.
+- Policy evaluation: a small IAM evaluator in the tests, run over the
+ three layers (boundary, inline, session), proving the minted scope
+ cannot read, list, delete, tag, write outside the prefix, write another
+ store or a deployment bucket, and that `revoked_before` cuts it off while
+ leaving the app's long-term key alone.
+- MinIO contract (`.amadan/ci.d/30-minio-contract`): a real session from
+ MinIO's STS narrowed by the core's session policy, against a user with
+ the store policy: put and multipart under the prefix succeed; read,
+ head, list, delete, tag, put outside the prefix, put tagged and put to
+ another bucket are denied.
+- `tofu test`: the boundary byte for byte without the switch, the
+ statement with it, the precondition.
+
+## 11. For Paul
+
+- Service credentials gain this door. An app's server needs it to mint per
+ recording, but every existing Service credential can then mint write
+ credentials for its app's store.
+- A store that has used write credentials lets its own delivered key call
+ `GetFederationToken` (2.3). Revocation on `rotate --finish` closes the
+ rotation gap; the cost is that finishing a rotation also ends every live
+ write credential, which the LiveKit page already warns about for the old
+ key.
+- A mint while a rotation is unfinished is refused (two-key ceiling).