carlos / platform Public

docs: write credentials in cli.md and the LiveKit page on StartEgress

New copy, pending the Luna pass (brief in docs/superpowers/notes).
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
claude agent, operated by paul@keymail.dev pushed by paul@keymail.dev 7ead3fae0080f203a4ab63a28c5eaef5ee9c1de9 parent f355d78
3 files changed, +181 −37
  • docs/site/cli.md +27 −1
  • docs/site/live-streams-bring-your-own-livekit.md +110 −36
  • docs/superpowers/notes/copy-luna-brief-store-write-credential.md +44 −0
diff --git a/docs/site/cli.md b/docs/site/cli.md
index f0d3ad3b1..136e74109 100644
--- a/docs/site/cli.md
+++ b/docs/site/cli.md
@@ -2301,7 +2301,7 @@ customer's own hostname is attached to it afterwards. `--route` is required
on `domains attach` once an app has more than one instance — the console
refuses to guess which one a hostname belongs to.
-`create`, `status`, `grant` and `rotate` all take `--environment`, and each
+`create`, `status`, `grant`, `rotate` and `credential` all take `--environment`, and each
acts on that store alone. Without it they act on the app's own store, exactly
as they always have — nothing about an app with no environment stores changes.
@@ -2323,6 +2323,32 @@ receives the same 404 as everyone else. `approvals`, `approve` and `decline`
require both the fleet-operator role and that allowlist entry, but the operator
does not need membership in the account being reviewed.
+#### carlos store credential
+
+```sh
+carlos store credential --write --prefix recordings/ --ttl 4h --app shop
+carlos store credential --write --prefix recordings/ --ttl 4h --app shop --json
+carlos store credential --revoke --app shop
+```
+
+Prints a temporary credential that can only upload files under one folder of the app's store. Give it to a service that uploads for you, such as a [LiveKit recorder](/docs/live-streams-bring-your-own-livekit), instead of the store's own credential.
+
+A write credential can upload a file under `--prefix`, including in parts, and nothing else. It can't read, list, delete or tag a file, change a bucket setting, or reach any other folder or store. It can replace a file already under its folder, so give each service a folder of its own. `--prefix` ends in `/`, and it can't be `derived/`, where media conversion writes.
+
+`--ttl` is how long it works, from 15 minutes to 24 hours. Pick enough for the longest upload you expect, with some to spare: a recorder that uploads when a 3-hour stream ends needs more than 3 hours.
+
+The answer leads with when the credential expires, then gives the access key, secret, session token, bucket and region. With `--json`, the field names are the ones LiveKit's `S3Upload` takes. An app's server mints one with its Service credential:
+
+```http
+POST /api/cli/apps/{account}/{app}/store/credentials
+Authorization: Bearer <service token>
+{"access": "write", "prefix": "recordings/", "ttl_seconds": 14400}
+```
+
+`--revoke` stops every write credential the store has issued so far. It can take a few minutes to reach every upload, and you can mint a new one a minute or two later. Rotating the store's own credential with `carlos store rotate` doesn't affect write credentials.
+
+Write credentials need AWS S3. Your operator turns them on.
+
#### carlos store uploads
```sh
diff --git a/docs/site/live-streams-bring-your-own-livekit.md b/docs/site/live-streams-bring-your-own-livekit.md
index 943c1350e..a1bfd6836 100644
--- a/docs/site/live-streams-bring-your-own-livekit.md
+++ b/docs/site/live-streams-bring-your-own-livekit.md
@@ -10,14 +10,15 @@ You need:
- A LiveKit Cloud project. Its settings page gives you the project URL, such as `wss://shop-a1b2c3.livekit.cloud`, and an API key and secret.
- An object store for the app, made with `carlos store create --app shop`, on a deployment with media conversion turned on. The store must pass the check on the media conversion page. A store made with `carlos store create` and left alone passes.
-- A Service credential for media conversion, as in [the media conversion example](/docs/media-conversion#an-example).
+- A Service credential for media conversion, as in [the media conversion example](/docs/media-conversion#an-example). The same credential gets your app a write credential for each recording.
+- Write credentials turned on for your deployment. Your operator does that. If they're off, `carlos store credential` says so.
What the platform needs from your app:
- **No egress setting.** Instances can already reach public addresses, and LiveKit Cloud's API and project hosts are public. `carlos apps set --egress-allow` is only for private addresses, and it takes IP addresses, not hostnames.
- **A public route for LiveKit's webhook.** LiveKit calls your app when a recording is done. Any path on your app's own hostname works, such as `https://shop.example.com/livekit/webhook`. A host behind [carlos gate](/docs/cli#carlos-gate) can't receive it, because the gate asks every request for the password.
-- **The store's region in every recording request.** If you leave both the region and endpoint out, LiveKit asks S3 for the bucket's location, and the store's credential isn't allowed to ask.
-- **No tags on recordings.** LiveKit can tag the files it uploads. Leave that empty: the store's credential can't tag objects, so S3 refuses the upload.
+- **The store's region in every recording request.** If you leave both the region and endpoint out, LiveKit asks S3 for the bucket's location, and a write credential isn't allowed to ask. The platform gives you the region with the credential.
+- **No tags on recordings.** LiveKit can tag the files it uploads. Leave that empty: a write credential can't tag objects, so S3 refuses the upload.
## How it fits together
@@ -26,18 +27,21 @@ What the platform needs from your app:
carlos env set --app shop LIVEKIT_URL=wss://shop-a1b2c3.livekit.cloud
carlos secrets set --app shop LIVEKIT_API_KEY=APIa1b2c3d4
carlos secrets set --app shop LIVEKIT_API_SECRET - < livekit-secret.txt
+carlos env set --app shop CARLOS_CONSOLE=https://console.example.com
+carlos env set --app shop CARLOS_ACCOUNT=<account>
add https://shop.example.com/livekit/webhook as a webhook in the LiveKit project
# per stream, on the app's server
1. mint a token for the streamer and one for each viewer -> the browsers join the room
-2. start an Egress to the app's store -> LiveKit records the room
-3. LiveKit POSTs egress_ended to /livekit/webhook -> the recording's key
-4. POST the key to media conversion, poll until done -> the files to play
+2. ask the platform for a write credential -> it can only upload to recordings/<id>/
+3. start an Egress with it -> LiveKit records the room
+4. LiveKit POSTs egress_ended to /livekit/webhook -> the recording's key
+5. POST the key to media conversion, poll until done -> the files to play
```
-The API key and secret are secrets, so they go in with `carlos secrets set`. The `-` reads the secret from the file, so it never appears on your command line. The project URL isn't secret. Your browser code needs it too.
+The API key and secret are secrets, so they go in with `carlos secrets set`. The `-` reads the secret from the file, so it never appears on your command line. The project URL isn't secret. Your browser code needs it too. `CARLOS_CONSOLE` is your console's origin and `<account>` is your account ID, as on the media conversion page.
-The examples below are in Go, with LiveKit's server SDK (`github.com/livekit/server-sdk-go/v2`) and its protocol package (`github.com/livekit/protocol`). LiveKit's other server SDKs have the same calls.
+The examples below are in Go, with LiveKit's server SDK (`github.com/livekit/server-sdk-go/v2`, checked against v2.20.1) and its protocol package (`github.com/livekit/protocol`, v1.54.1). LiveKit's other server SDKs have the same calls.
## Tokens for the streamer and the viewers
@@ -81,40 +85,100 @@ To stop someone chatting, your server calls `UpdateParticipant` on LiveKit's roo
## Recording into your store
-Your server starts an Egress, LiveKit's recorder, and points it at the app's store with the store's own credentials. The platform delivers them to every instance as `CARLOS_STORE_BUCKET`, `CARLOS_STORE_REGION`, `CARLOS_STORE_ACCESS_KEY` and `CARLOS_STORE_SECRET_KEY`.
+Your server starts an Egress, LiveKit's recorder, and points it at the app's store. LiveKit gets a write credential, not the store's own credential. It can only upload files under one folder you name, and only until it expires.
-A room composite Egress records the room as one MP4, laid out the way a viewer sees it:
+Ask the platform for a write credential just before each recording, with the Service credential:
```go
import (
+ "bytes"
"context"
+ "encoding/json"
+ "fmt"
+ "net/http"
"os"
+ "time"
"github.com/livekit/protocol/livekit"
- lksdk "github.com/livekit/server-sdk-go/v2"
)
-func storeUpload() *livekit.S3Upload {
- return &livekit.S3Upload{
- AccessKey: os.Getenv("CARLOS_STORE_ACCESS_KEY"),
- Secret: os.Getenv("CARLOS_STORE_SECRET_KEY"),
- Region: os.Getenv("CARLOS_STORE_REGION"), // required: see Before you start
- Bucket: os.Getenv("CARLOS_STORE_BUCKET"),
- // No Tagging. The store refuses tagged uploads.
+// recordingUpload asks the platform for a credential that can only upload
+// under prefix, for ttl, in the shape LiveKit takes.
+func recordingUpload(ctx context.Context, prefix string, ttl time.Duration) (*livekit.S3Upload, error) {
+ body, err := json.Marshal(map[string]any{"access": "write", "prefix": prefix, "ttl_seconds": int(ttl.Seconds())})
+ if err != nil {
+ return nil, err
+ }
+ url := os.Getenv("CARLOS_CONSOLE") + "/api/cli/apps/" + os.Getenv("CARLOS_ACCOUNT") + "/shop/store/credentials"
+ req, err := http.NewRequestWithContext(ctx, http.MethodPost, url, bytes.NewReader(body))
+ if err != nil {
+ return nil, err
+ }
+ req.Header.Set("Authorization", "Bearer "+os.Getenv("CARLOS_SERVICE_TOKEN"))
+ req.Header.Set("Content-Type", "application/json")
+ resp, err := http.DefaultClient.Do(req)
+ if err != nil {
+ return nil, err
}
+ defer resp.Body.Close()
+ if resp.StatusCode != http.StatusOK {
+ return nil, fmt.Errorf("write credential: %s", resp.Status)
+ }
+ var c struct {
+ AccessKey string `json:"access_key"`
+ Secret string `json:"secret"`
+ SessionToken string `json:"session_token"`
+ Region string `json:"region"`
+ Bucket string `json:"bucket"`
+ }
+ if err := json.NewDecoder(resp.Body).Decode(&c); err != nil {
+ return nil, err
+ }
+ return &livekit.S3Upload{
+ AccessKey: c.AccessKey,
+ Secret: c.Secret,
+ SessionToken: c.SessionToken,
+ Region: c.Region, // required: see Before you start
+ Bucket: c.Bucket,
+ // No Tagging. A write credential can't tag, so S3 refuses the upload.
+ }, nil
+}
+```
+
+Give each recording a folder of its own. A write credential can replace a file already in its folder, but it can't touch anything else.
+
+Then start the Egress with LiveKit's `StartEgress` call. A template source records the room as one MP4, laid out the way a viewer sees it:
+
+```go
+import (
+ "context"
+ "os"
+ "time"
+
+ "github.com/livekit/protocol/livekit"
+ lksdk "github.com/livekit/server-sdk-go/v2"
+)
+
+func egressClient() *lksdk.EgressClient {
+ return lksdk.NewEgressClient(os.Getenv("LIVEKIT_URL"), os.Getenv("LIVEKIT_API_KEY"), os.Getenv("LIVEKIT_API_SECRET"))
}
// startRecording records the whole room under recordings/<id>/.
func startRecording(ctx context.Context, room, id string) (string, error) {
- egress := lksdk.NewEgressClient(os.Getenv("LIVEKIT_URL"), os.Getenv("LIVEKIT_API_KEY"), os.Getenv("LIVEKIT_API_SECRET"))
- info, err := egress.StartRoomCompositeEgress(ctx, &livekit.RoomCompositeEgressRequest{
+ upload, err := recordingUpload(ctx, "recordings/"+id+"/", 4*time.Hour)
+ if err != nil {
+ return "", err
+ }
+ info, err := egressClient().StartEgress(ctx, &livekit.StartEgressRequest{
RoomName: room,
- Layout: "speaker",
- FileOutputs: []*livekit.EncodedFileOutput{{
- FileType: livekit.EncodedFileType_MP4,
- Filepath: "recordings/" + id + "/",
- Output: &livekit.EncodedFileOutput_S3{S3: storeUpload()},
+ Source: &livekit.StartEgressRequest_Template{Template: &livekit.TemplateSource{Layout: "speaker"}},
+ Outputs: []*livekit.Output{{
+ Config: &livekit.Output_File{File: &livekit.FileOutput{
+ FileType: livekit.EncodedFileType_MP4,
+ Filepath: "recordings/" + id + "/",
+ }},
}},
+ Storage: &livekit.StorageConfig{Provider: &livekit.StorageConfig_S3{S3: upload}},
})
if err != nil {
return "", err
@@ -123,24 +187,35 @@ func startRecording(ctx context.Context, room, id string) (string, error) {
}
```
-`Filepath` ends in `/`, so LiveKit names the file itself inside that folder, as `<room>-<time>.mp4`. That also keeps a retried recording from overwriting the first try. Don't record under `derived/`: media conversion won't take a source there.
+`Filepath` ends in `/`, so LiveKit names the file itself inside that folder, as `<room>-<time>.mp4`. That also keeps a retried recording from overwriting the first try. Don't record under `derived/`: media conversion won't take a source there, and the platform won't issue a write credential for it.
-A track Egress records one track as it arrives. Video is not re-encoded. Audio is re-encoded as stereo Opus. LiveKit picks the file type from the track: WebM or MP4 for video, and Ogg for audio. Media conversion reads all three. Use it when you only need the streamer's camera or microphone:
+The credential has to last until LiveKit has uploaded the file, which it does when the recording stops. LiveKit Cloud stops a room recording at 3 hours, so 4 hours covers the recording and the upload.
+
+A media source records one video track as it arrives, without re-encoding it. LiveKit picks the file type from the track's codec, so leave `FileType` unset. Media conversion reads WebM and MP4. Use it when you only need the streamer's camera:
```go
-info, err := egress.StartTrackEgress(ctx, &livekit.TrackEgressRequest{
+upload, err := recordingUpload(ctx, "recordings/"+id+"/", 13*time.Hour)
+if err != nil {
+ return err
+}
+info, err := egressClient().StartEgress(ctx, &livekit.StartEgressRequest{
RoomName: room,
- TrackId: trackID,
- Output: &livekit.TrackEgressRequest_File{File: &livekit.DirectFileOutput{
- Filepath: "recordings/" + id + "/",
- Output: &livekit.DirectFileOutput_S3{S3: storeUpload()},
+ Source: &livekit.StartEgressRequest_Media{Media: &livekit.MediaSource{
+ Video: &livekit.MediaSource_VideoTrackId{VideoTrackId: trackID},
}},
+ Encoding: &livekit.StartEgressRequest_Preset{Preset: livekit.EncodingOptionsPreset_PASSTHROUGH},
+ Outputs: []*livekit.Output{{
+ Config: &livekit.Output_File{File: &livekit.FileOutput{Filepath: "recordings/" + id + "/"}},
+ }},
+ Storage: &livekit.StorageConfig{Provider: &livekit.StorageConfig_S3{S3: upload}},
})
```
+LiveKit Cloud stops a track recording at 12 hours, so that credential asks for 13. The longest a write credential can last is 24 hours.
+
LiveKit uploads the file when the recording stops. It also writes a small JSON manifest beside the file. Set `DisableManifest: true` on the output if you don't want it.
-If your app also gets `CARLOS_STORE_ENDPOINT`, use that S3-compatible endpoint as `Endpoint` and set `ForcePathStyle: true`. LiveKit has to be able to reach that endpoint over the internet.
+Write credentials need AWS S3. If your app gets `CARLOS_STORE_ENDPOINT`, its store is on an S3-compatible server, and the platform can't issue one for it.
## When the recording is done
@@ -207,7 +282,7 @@ Conversion counts against your account's [media allowance](/docs/media-conversio
If LiveKit can't upload the recording to your store, the recording isn't in your store and there is nothing to convert. Two common causes:
- **The store is full.** A store past its plan's storage allowance refuses new objects, recordings included.
-- **The credential changed while the stream ran.** LiveKit uses the credential it was given when the recording started, and uploads at the end. If you run `carlos store rotate --finish --app shop` during a stream, the old credential stops working and the upload fails. Finish a rotation only when no recording is running.
+- **The write credential stopped working before the upload.** LiveKit uses the credential it was given when the recording started, and uploads at the end. The upload fails if the recording runs longer than the credential lasts, or if you run `carlos store credential --revoke --app shop` during a stream. Rotating the store's own credential with `carlos store rotate` doesn't affect write credentials.
Without a backup copy, the webhook reports `EGRESS_FAILED`, and its error says the upload failed. With backup storage, it reports `EGRESS_COMPLETE` with `backup_storage_used` set instead.
@@ -219,7 +294,7 @@ If your store has [virus scanning](/docs/cli#carlos-store-scan), a recording is
## Privacy: a third party in the media path
-With this setup, LiveKit Cloud carries every stream. The video, the audio and the chat pass through LiveKit's servers, and LiveKit records the stream before it reaches your store. LiveKit also holds your store's credential while a recording runs. That credential can read, overwrite and delete every object in your app's store, not only recordings. It cannot change object tags or bucket settings.
+With this setup, LiveKit Cloud carries every stream. The video, the audio and the chat pass through LiveKit's servers, and LiveKit records the stream before it reaches your store. LiveKit also holds a write credential while a recording runs. It can only upload files to that recording's folder, until it expires. It can't read, list or delete anything in your store.
The platform doesn't tell your users any of this. Whether and how to tell them is your app's decision. If you do, say it where people decide to stream or watch: near the start of your app's description, and on anything the stream produces, such as the recording's page.
@@ -231,5 +306,4 @@ The platform bills your account as usual for the instance, the recording's stora
## Not yet supported
-- **A credential that can only write recordings.** LiveKit needs your store's one credential, which can also read, overwrite and delete every other object in the store. The platform can't yet give an app a narrower credential to hand to a third party.
- **Converting recordings longer than 2 hours.** LiveKit Cloud limits a room-composite file to 3 hours, and media conversion converts up to 2 hours of video up to 1080p. To keep a longer stream playable, stop the recording and start a new one before it reaches 2 hours. Each part converts on its own.
diff --git a/docs/superpowers/notes/copy-luna-brief-store-write-credential.md b/docs/superpowers/notes/copy-luna-brief-store-write-credential.md
new file mode 100644
index 000000000..b0f1c70f4
--- /dev/null
+++ b/docs/superpowers/notes/copy-luna-brief-store-write-credential.md
@@ -0,0 +1,44 @@
+# Docs and copy pass: store write credentials
+
+You are the copy-review gate itself for this change. Paul delegated copy review of platform UI, CLI, email and docs copy to you on 2026-10-25; your verdicts ARE the review. Do NOT run the copy-review skill or start any server. Do not modify any file. You are writing a review report.
+
+## What is new
+
+A write credential: a temporary credential that can only upload files under one folder of an app's store, for 15 minutes to 24 hours, for an app to hand to a service such as a LiveKit recorder. Design: `docs/superpowers/specs/2026-11-25-store-write-credential-design.md`. Review only the human text in:
+
+1. `docs/site/cli.md`, the new `#### carlos store credential` section, and the one changed sentence beginning "`create`, `status`, `grant`, `rotate` and `credential` all take `--environment`".
+2. `docs/site/live-streams-bring-your-own-livekit.md`, the parts that changed against `origin/main` (`git diff origin/main -- docs/site/live-streams-bring-your-own-livekit.md`): "Before you start", "What the platform needs", "How it fits together", "Recording into your store" (prose, and comments and strings inside the code), "When an upload fails", "Privacy", "Not yet supported". The code samples were compile-checked against `github.com/livekit/server-sdk-go/v2` v2.20.1 and `github.com/livekit/protocol` v1.54.1: do not change identifiers.
+3. `store_credential.go`, the map `storeCredentialCopy` (CLI usage, flag help, output lines and refusals). Output lines are label and value pairs aligned in columns; keep the labels short and the alignment.
+4. `store.go`, the `storeUsage` header line (the verb list) only.
+5. `internal/console/apistorecredentials.go`, the map `writeCredentialsCopy` and the two 502 sentences in the handlers.
+6. `cmd/console/writecredentials.go`, the three error strings (operator-facing, at console boot).
+7. `infra/modules/region-host/variables.tf`, the `store_write_credentials` description (operator-facing).
+8. `internal/release/consolefloor.go`, the refusal sentence `consoleFloorRefusal` returns (operator-facing, printed by an adopting box).
+9. `internal/objstore/writecred.go`, the `ValidWritePrefix` refusal sentences (shown to members through the CLI and the door).
+
+## House rules (Paul's)
+
+- No em or en dashes used as dashes. Use a full stop and a new sentence.
+- Plain, direct, calm. No exclamation marks, no marketing tone, no "simply", no "please" padding, no filler.
+- Say what happened, then what to do. If the reader cannot fix it themselves, say who can.
+- Developer-facing, so technical words (credential, session token, prefix, multipart, Egress) are fine where the reader needs them. Undefined jargon is not.
+- CLI output leads with the state (here, when the credential expires), then the values. A person should know what it shows after about a dozen words.
+- Neutral examples only (`shop`, `shop.example.com`, `recordings/<id>/`). Never a customer or tenant name.
+
+## Facts to check against
+
+Flag any sentence that contradicts or overstates these.
+
+- Scope: `writeSessionPolicy` and `writerPolicyJSON` in `internal/objstore/writecred.go`. A write credential may PutObject (which includes uploading in parts), AbortMultipartUpload and ListMultipartUploadParts under its prefix, and nothing else: no read, head, list, delete, tag, ACL or bucket call, no other prefix, store or bucket. It can replace an object already under its prefix.
+- Prefix rules: `ValidWritePrefix`. 1 to 200 bytes ending in `/`; letters, digits, dots, underscores, hyphens and `/`; not `derived/` or under it.
+- Lifetime: `ValidWriteTTL`, 15 minutes to 24 hours, whole seconds.
+- Revocation: `claimRawRevokeWriteCredentialsIn` and `revocationInstant`. It takes effect when IAM's policy change propagates, which AWS says can take a few minutes. A new mint is refused until about two minutes after a revocation (`clockBound` twice), with 409 `revocation_settling` and a Retry-After header.
+- Rotation: the app's own key (`carlos store rotate`) and write credentials are separate IAM users; rotating does not affect write credentials (spec §2.4).
+- Availability: AWS S3 only; a store with an endpoint is refused (`write_credentials_unsupported`). The operator turns it on with `store_write_credentials` in region-host and `CARLOS_STORE_WRITE_CREDENTIALS=1` on the console. This release is phase 1: both doors answer 503 `write_credentials_not_released` whatever is set; a later release opens them (spec §10). The docs describe the feature as it will be once turned on; flag it if you think the page needs to say anything about the phase.
+- LiveKit (from LiveKit's own docs, read 2026-11-25): `StartEgress` is the unified call; a template source records the room; a media source with a single video track and the PASSTHROUGH preset records it without re-encoding, picks the container from the codec, and an explicit file type is rejected; a filepath ending in `/` gets a generated `{room_name}-{time}` name with the right extension; LiveKit Cloud stops a file output at 3 hours and a raw single track at 12 hours, and uploads the file when the recording stops.
+- The answer's field names (`access_key`, `secret`, `session_token`, `region`, `bucket`) are the ones LiveKit's `S3Upload` takes.
+
+## What to return
+
+1. A table `location | old | new | why`, with only the strings you change, quoting the old text exactly so it can be applied verbatim. Rows you leave alone are approved as they are.
+2. A `## Flags` section with only what Paul must decide, or a fact you could not verify. Keep it short and give your recommendation for each. Write "none" if there are none.