| index d061000d9..4a9151ee3 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 |
| @@ -1,7 +1,9 @@ |
| # Store write credential: design |
| |
| -Status: draft for review, 2026-11-25. Asked for by Paul on 2026-11-25. |
| -Branch `store-write-credential`. |
| +Status: rev 2, 2026-11-25, after Astra design round 1 |
| +(`docs/superpowers/reviews/REVIEW-FINDINGS-store-write-credential-design-R1.md`; |
| +accepted findings are marked **(astra N)**). Asked for by Paul on |
| +2026-11-25. Branch `store-write-credential`. |
| |
| ## 1. What and why |
| |
| @@ -38,10 +40,18 @@ 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 |
| +2. the store user's inline policies (`storePolicyJSON`: one bucket, every |
| + Deny; plus the sessions policy of 2.3, which grants no S3 at all), and |
| 3. the session policy (one prefix, write only). |
| |
| +The one other source of authority is a resource policy that names the |
| +federated session's ARN, which AWS lets grant beyond the session policy |
| +**(astra 6)**. Store buckets carry no bucket policy: the store user is |
| +denied `s3:PutBucketPolicy` (`historyBucketDenies`) and the console role is |
| +never granted it on store buckets. The session policy also carries explicit |
| +Denies on everything outside its scope (section 3), and an explicit Deny |
| +wins over any resource policy, so the scope holds even if one appeared. |
| + |
| 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 |
| @@ -79,49 +89,103 @@ returned. |
| - **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 |
| +### 2.3 The sessions policy, and keeping revocation durable |
| |
| To call `GetFederationToken` the store user needs `sts:GetFederationToken` |
| -in its inline policy and in its boundary. Both are added only where the |
| +in its boundary and in an inline policy. 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 |
| + `store_write_credentials = true` (section 7); 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. |
| +- a **second inline policy on the store user, `carlos-store-sessions`**, |
| + written only for a store that has minted a write credential. The store's |
| + own `carlos-store` policy (`storePolicyJSON`) does not change at all, for |
| + any store. |
| + |
| +The sessions policy holds: |
| |
| -Resource: `arn:<partition>:sts::<account>:federated-user/carlos-write-*`, |
| -the account and partition taken from the record's `user_arn`. |
| +```json |
| +{"Version": "2012-10-17", "Statement": [ |
| + {"Effect": "Allow", "Action": ["sts:GetFederationToken"], "Resource": "*"}, |
| + {"Effect": "Deny", "Action": ["*"], "Resource": "*", |
| + "Condition": {"DateLessThan": {"aws:TokenIssueTime": "<revoked_before>"}}} |
| +]} |
| +``` |
| |
| -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: |
| +The Deny is present once the store has a revocation instant. The STS |
| +Resource is `*` here because IAM caps a user's inline policies at 2,048 |
| +characters in total and the worst-case store policy is already about |
| +1,800; the boundary pins it to |
| +`arn:aws:sts::<account>:federated-user/carlos-write-*`. A test asserts the |
| +worst case (63-character bucket, scan enforcement and the storage-grace |
| +Deny on) stays under 2,048 with the sessions policy beside it. |
| + |
| +Its state lives in its own object, **`apps/<acct>/<app>/write-credentials.json`** |
| +(an environment store: `write-credentials/<env>.json`), not in the store |
| +record **(astra 5)**: `{"schema", "account", "app", "environment", "at", |
| +"by", "revoked_before"}`. Two reasons it is separate, both about keeping a |
| +revocation once made: |
| + |
| +- **Older consoles.** An older console rewrites `store.json` through a |
| + struct that does not know a new block, and rewrites `carlos-store` |
| + wholesale. It never reads or writes this object or the sessions policy, |
| + so during a rollback a revocation stays in force in IAM and in the |
| + bucket, and the next new console carries it on. |
| +- **Concurrent policy writers (astra 1).** Storage-limit convergence runs |
| + `GrantIn` under the account lock without the store walk lock and |
| + rewrites `carlos-store` from a record it read earlier. It cannot touch |
| + the sessions policy. The sessions policy and the state object are |
| + written only by the write-credential walks (mint, revoke) and the two |
| + rotation walks, and every one of their doors holds the store walk lock |
| + for that store, so they never interleave. A test runs a stale |
| + `GrantIn` after a revocation and checks the revocation is still in |
| + force. |
| + |
| +What it costs: an older console's teardown fails at `DeleteUser` |
| +(IAM refuses a user that still has an inline policy), so the store stays |
| +standing until a current console tears it down. That is the safe |
| +direction. |
| + |
| +**Why a revocation is needed at all.** The sessions policy is reachable with |
| +the app's own delivered key too, 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: no new power over the store, with one exception, |
| **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. |
| +sessions before the member rotates. |
| + |
| +So **retiring a key revokes every session issued before it**, wherever the |
| +platform retires one **(astra 2)**: |
| + |
| +- `RotateFinish` (deletes the pending key), and |
| +- `RotateIn` when it deletes the pending key of an unfinished earlier |
| + rotation (walk.go step 1), |
| + |
| +for a store that has a state object. Each sets `revoked_before`, writes the |
| +sessions policy, and only then deletes the key, so a failure part way |
| +leaves an over-revoked store with the key still live, never a deleted key |
| +with live sessions. Re-running the walk converges. `carlos store |
| +credential --revoke` does the same without rotating, for a leaked write |
| +credential. |
| + |
| +**Clocks (astra 4).** The Deny compares AWS's issue time with |
| +`revoked_before`. The design assumes the console's clock is within |
| +ε = 1 minute of AWS's (consoles run on EC2 with the Amazon Time Sync |
| +Service; SigV4 itself refuses requests more than 15 minutes off). |
| + |
| +- `revoked_before` = console now + ε, so a session issued just before the |
| + revocation is caught even with the console up to ε behind AWS. |
| +- A mint is refused while console now < `revoked_before` + ε, which covers |
| + the console up to ε ahead. |
| +- The exact check: the adapter reports AWS's issue time (the response's |
| + `Expiration` minus the duration asked for), and a session issued less |
| + than one second after `revoked_before` is discarded and the mint |
| + refused. So no credential is ever handed out born revoked, whatever the |
| + skew. Tests cover the console ahead of and behind AWS. |
| + |
| 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. |
| |
| @@ -134,28 +198,29 @@ 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. |
| +most). Teardown deletes the state object along with the user. |
| |
| ## 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: |
| +the store's record and the validated prefix. With `R` = |
| +`arn:aws:s3:::<bucket>/<prefix>*` and `W` = the three write actions: |
| |
| ```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>*", |
| + {"Effect": "Allow", "Action": W, "Resource": R}, |
| + {"Effect": "Deny", "NotAction": W, "Resource": "*"}, |
| + {"Effect": "Deny", "Action": W, "NotResource": R}, |
| + {"Effect": "Deny", "Action": ["s3:PutObject"], "Resource": R, |
| "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 two scope Denies are what make the scope hold against a resource |
| +policy **(astra 6)**. The last 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 MinIO contract runs this exact document. |
| |
| The prefix is validated before it goes near a policy: |
| |
| @@ -172,11 +237,11 @@ 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. |
| +`ttl` is required, 15 minutes (STS's floor) to 24 hours, whole seconds. |
| +LiveKit Cloud's longest egress is 12 hours (a 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 |
| |
| @@ -185,27 +250,33 @@ 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 |
| +1. A record with a pending rotation (`prev_key_id`) is refused, 409 |
| + `rotation_unfinished`: "finish the rotation first: carlos store rotate |
| + --finish" **(astra 7)**. |
| +2. `ListAccessKeys`: two keys with no rotation pending means a stray key |
| + (a crashed mint). 409 `key_slot_full`: "run carlos store rotate, then |
| + carlos store rotate --finish", which reaps it (walk.go step 2). |
| + Both recoveries revoke live write credentials (2.3), and the message |
| + says so. |
| +3. `CreateAccessKey`. |
| +4. `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 |
| +5. `DeleteAccessKey`, always, also after 4 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. |
| +app is using. |
| |
| ## 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`. |
| + rules, the session policy, the sessions policy, the state object, the |
| + walks. No SDK. |
| +- **AWS adapter** (`internal/objstore/aws_writecred.go`): the sessions |
| + policy write, 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 |
| @@ -220,14 +291,18 @@ next `carlos store rotate` reaps it. |
| future MinIO provisioner implements the same `MintSession` seam with that |
| call. |
| |
| -The provisioner seam gains one method: |
| +The provisioner seam gains two methods: |
| |
| ```go |
| -// MintSession mints a temporary credential for store user `user`, narrowed by |
| -// the IAM session policy `policy`, lasting ttl. |
| +// PutSessionPolicy writes the store user's sessions policy (2.3). |
| +PutSessionPolicy(ctx context.Context, user, policy string) error |
| +// 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) |
| ``` |
| |
| +`DeleteUser` removes both inline policies. |
| + |
| What a non-AWS deployment loses: write credentials. Its apps keep their |
| full credential. |
| |
| @@ -237,32 +312,35 @@ full credential. |
| |
| - 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; |
| +- when true, the store user boundary gains `Allow sts:GetFederationToken` |
| + on `arn:aws:sts::<account>:federated-user/carlos-write-*`, and the two |
| + multipart actions (already there under `store_conversion`) are included |
| + when either switch is on **(astra 3)**. Managed fleet users share the |
| + boundary but their inline policies grant neither, 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. |
| + call the walks make (`CreateAccessKey`, `DeleteAccessKey`, |
| + `ListAccessKeys`, `PutUserPolicy` conditioned on the boundary, |
| + `DeleteUserPolicy`), and the STS call is made as the store user. |
| |
| ## 8. Surface |
| |
| -Console door (registered through `routedecls.go`, refused to linked |
| +Console doors (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": ""} |
| +POST /api/cli/apps/{account}/{app}/store/credentials[?environment=e] |
| +{"access": "write", "prefix": "recordings/", "ttl_seconds": 14400} |
| -> 200 {"access_key", "secret", "session_token", "region", "bucket", |
| "prefix", "expires_at"} Cache-Control: no-store |
| |
| -POST /api/cli/apps/{account}/{app}/store/credentials/revoke |
| +POST /api/cli/apps/{account}/{app}/store/credentials/revoke[?environment=e] |
| -> 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. |
| +Admin). A member's CLI token reaches it through membership as usual. Both |
| +doors take the account lock and then the store walk lock, as uploads does. |
| |
| CLI, named like `store rotate`: |
| |
| @@ -276,42 +354,43 @@ 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 |
| +The doors need `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": "..."} |
| -``` |
| +## 9. Rollout and rollback |
| |
| -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. |
| +- Roll every console forward before setting the switch: an older console's |
| + rotation walks do not revoke. |
| +- After the switch is on, rolling a console back keeps every revocation |
| + already made (2.3), but while the older console runs, a rotation it |
| + performs does not revoke sessions, and its teardown of a store that used |
| + write credentials fails at `DeleteUser` until a current console runs it. |
| |
| ## 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. |
| + sessions policy and the 2,048-character worst case; the state object; the |
| + walks on the in-memory provisioner (refusals, both two-key cases, the key |
| + always deleted, the retry, revocation's margin and the exact AWS-time |
| + check with the console ahead and behind, rotate-twice and finish |
| + revoking before deleting, a stale `GrantIn` leaving a revocation in |
| + force); the AWS adapter against stub IAM and STS clients; the doors 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. |
| + layers (boundary, both inline policies, session policy, and a resource |
| + policy naming the session), proving the minted scope cannot read, list, |
| + delete, tag, write outside the prefix, write another store or a |
| + deployment bucket, and that a revocation 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. |
| + statements with it (with and without `store_conversion`), the |
| + precondition. |
| |
| ## 11. For Paul |
| |
| @@ -319,8 +398,8 @@ forward before turning the switch on. |
| 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. |
| + `GetFederationToken` (2.3). Revocation on every key retirement 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). |