store write credential: Luna copy pass, code-health fits
Luna's edits applied (result in docs/superpowers/notes). The floor check folds into adoptHost's D3 bind call, the boot log into storeBackend, and the phase into a package value, so no ratchet site grows.
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
11 files changed,
+82
−43
cmd/console/main.go+1 −1docs/site/cli.md+1 −1docs/site/live-streams-bring-your-own-livekit.md+1 −1docs/superpowers/notes/copy-luna-result-store-write-credential.md+21 −0internal/console/apistorecredentials.go+10 −5internal/console/apistorecredentials_test.go+12 −3internal/console/server.go+10 −15internal/objstore/writecred.go+1 −1internal/release/adopt.go+5 −13internal/release/consolefloor.go+17 −0store_credential.go+3 −3
diff --git a/cmd/console/main.go b/cmd/console/main.go| index 90e8a771c..510b397ae 100644 |
| --- a/cmd/console/main.go |
| +++ b/cmd/console/main.go |
| @@ -421,7 +421,6 @@ func serve() { |
| // page's S3 requests are charged to the page that made them (and a |
| // background job's to the job). |
| rec := new(perf.Recorder) |
| - logConsoleCapabilities() |
| storeProvisioner, storeDeployment := storeBackend(rec) |
| storeScanner, seedAntivirus := storeScannerFor(storeDeployment) |
| pdfLimits, pdfAddr, err := pdfSettings(os.Getenv) |
| @@ -1148,6 +1147,7 @@ func appsDomain() string { |
| // lives. CARLOS_STORE_ENDPOINT stays optional: an empty endpoint is what |
| // "real AWS S3" means (objstore.NewAWSProvisioner). |
| func storeBackend(rec *perf.Recorder) (objstore.Provisioner, objstore.Deployment) { |
| + logConsoleCapabilities() |
| // Read first, so a CARLOS_STORE_VERSIONING with no backend is refused |
| // rather than ignored with the rest of an unset store config. |
| versioning, err := storeVersioningOn(os.Getenv) |
diff --git a/docs/site/cli.md b/docs/site/cli.md| index 136e74109..d02b8aaa7 100644 |
| --- a/docs/site/cli.md |
| +++ b/docs/site/cli.md |
| @@ -2333,7 +2333,7 @@ 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. |
| +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/` or a folder under it, 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. |
diff --git a/docs/site/live-streams-bring-your-own-livekit.md b/docs/site/live-streams-bring-your-own-livekit.md| index a1bfd6836..ad655f082 100644 |
| --- a/docs/site/live-streams-bring-your-own-livekit.md |
| +++ b/docs/site/live-streams-bring-your-own-livekit.md |
| @@ -10,7 +10,7 @@ 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). The same credential gets your app a write credential for each recording. |
| +- A Service credential for media conversion, as in [the media conversion example](/docs/media-conversion#an-example). Use that credential to get 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: |
diff --git a/docs/superpowers/notes/copy-luna-result-store-write-credential.md b/docs/superpowers/notes/copy-luna-result-store-write-credential.md| new file mode 100644 |
| index 000000000..a6fa11fdb |
| --- /dev/null |
| +++ b/docs/superpowers/notes/copy-luna-result-store-write-credential.md |
| @@ -0,0 +1,21 @@ |
| +| location | old | new | why | |
| +|---|---|---|---| |
| +| `docs/site/live-streams-bring-your-own-livekit.md:13` | “The same credential gets your app a write credential for each recording.” | “Use that credential to get a write credential for each recording.” | States the action clearly. | |
| +| `docs/site/cli.md:2304` | “`create`, `status`, `grant`, `rotate` and `credential` all take `--environment`” | “`create`, `status`, `grant`, `rotate` and `credential` all take `--environment`.” | Completes the sentence cleanly. | |
| +| `store_credential.go:store_usage` | `credential --write --prefix <folder/> --ttl <duration> --app <a> [--json]` | `credential --write --prefix <folder/> --ttl <duration> --app <a> [--environment <e>] [--json]` | The usage omits a supported flag. | |
| +| `docs/site/cli.md:2336` | “it can't be `derived/`, where media conversion writes.” | “it can't be `derived/` or a folder under it, where media conversion writes.” | Matches the prefix rule. | |
| +| `internal/console/apistorecredentials.go:55` | “this store is on an S3-compatible server, and write credentials need AWS S3” | “this store uses an S3-compatible endpoint; write credentials need AWS S3 and STS” | States the actual unsupported condition and dependency. | |
| +| `internal/console/apistorecredentials.go:59` | “write credentials were just revoked; try again in a minute” | “write credentials were just revoked; try again after the retry time” | Revocation settling is about two minutes and the response supplies `Retry-After`. | |
| +| `internal/objstore/writecred.go:185` | “at most 200 characters” | “at most 200 bytes” | The validation limit is byte-based. | |
| + |
| +## Flags |
| + |
| +- The documentation presents write credentials as usable, but this branch is phase 1 and both doors always return `write_credentials_not_released`. Recommendation: state that limitation or defer publishing the usage section until phase 2. |
| +- No files were modified and no network services were called. |
| +--- |
| + |
| +Applied by the author, 2026-11-25, with two departures: |
| + |
| +- `docs/site/cli.md:2304`: not applied. The brief quoted only the start of a longer sentence ("... all take `--environment`, and each acts on that store alone."), so a full stop there would break it. |
| +- `apistorecredentials.go:59`: applied as "write credentials were just revoked; try again in about two minutes". The CLI prints this sentence and never shows the Retry-After header, so the time is in the words. |
| +- Flag (phase 1): left for Paul. The docs describe write credentials as they work once phase 2 ships. |
diff --git a/internal/console/apistorecredentials.go b/internal/console/apistorecredentials.go| index 73c25029e..49d20304a 100644 |
| --- a/internal/console/apistorecredentials.go |
| +++ b/internal/console/apistorecredentials.go |
| @@ -30,6 +30,11 @@ import ( |
| // rollback could reach is phase 1 or later. |
| const writeCredentialsReleasedPhase = 1 |
| +// writeCredentialsPhase is the phase the doors judge by: always |
| +// writeCredentialsReleasedPhase outside tests, which raise it to open the |
| +// doors (setWriteCredentialsPhase) and put it back. |
| +var writeCredentialsPhase = writeCredentialsReleasedPhase |
| + |
| // writeCredentialsBodyLimit caps the mint body: a 200-byte prefix and two |
| // small fields fit many times over. |
| const writeCredentialsBodyLimit = 4 << 10 |
| @@ -47,16 +52,16 @@ const ( |
| wcCodeNoneIssued = "no_write_credentials" |
| ) |
| -// writeCredentialsCopy is the doors' refusals by code. New copy, pending |
| -// the Luna pass (docs/superpowers/notes/copy-luna-brief-store-write-credential.md). |
| +// writeCredentialsCopy is the doors' refusals by code. Copy approved in |
| +// the Luna pass (docs/superpowers/notes/copy-luna-result-store-write-credential.md). |
| var writeCredentialsCopy = map[string]string{ |
| wcCodeNotConfigured: "write credentials are not turned on for this deployment (CARLOS_STORE_WRITE_CREDENTIALS)", |
| wcCodeNotReleased: "this console release cannot issue write credentials yet; a later release turns them on", |
| - wcCodeUnsupported: "this store is on an S3-compatible server, and write credentials need AWS S3", |
| + wcCodeUnsupported: "this store uses an S3-compatible endpoint; write credentials need AWS S3 and STS", |
| wcCodeNoStore: "this app has no store yet; create one with carlos store create", |
| wcCodeBadAccess: "the only kind of credential is write", |
| wcCodeBadTTL: "the lifetime must be from 15 minutes to 24 hours", |
| - wcCodeSettling: "write credentials were just revoked; try again in a minute", |
| + wcCodeSettling: "write credentials were just revoked; try again in about two minutes", |
| wcCodeNoneIssued: "this store has not issued any write credentials, so there is nothing to revoke", |
| } |
| @@ -91,7 +96,7 @@ func (s *Server) writeCredentialsGates(w http.ResponseWriter, r *http.Request) b |
| jsonErrorCode(w, http.StatusServiceUnavailable, wcCodeNotConfigured, writeCredentialsCopy[wcCodeNotConfigured]) |
| return false |
| } |
| - if s.writeCredentialsPhase < 2 { |
| + if writeCredentialsPhase < 2 { |
| jsonErrorCode(w, http.StatusServiceUnavailable, wcCodeNotReleased, writeCredentialsCopy[wcCodeNotReleased]) |
| return false |
| } |
diff --git a/internal/console/apistorecredentials_test.go b/internal/console/apistorecredentials_test.go| index 35b528e03..de552f716 100644 |
| --- a/internal/console/apistorecredentials_test.go |
| +++ b/internal/console/apistorecredentials_test.go |
| @@ -25,7 +25,7 @@ func newCredentials(t *testing.T, code string) *credentialsFixture { |
| t.Helper() |
| fx, prov, _, token := grantedMediaStore(t, code) |
| fx.srv.cfg.StoreDeployment.WriteCredentials = true |
| - fx.srv.writeCredentialsPhase = 2 |
| + setWriteCredentialsPhase(t, 2) |
| return &credentialsFixture{consoleFixture: fx, t: t, prov: prov, token: token} |
| } |
| @@ -115,7 +115,7 @@ func TestStoreCredentialsRevoke(t *testing.T) { |
| func TestStoreCredentialsRefusals(t *testing.T) { |
| t.Run("phase 1", func(t *testing.T) { |
| c := newCredentials(t, "code-wc-phase") |
| - c.srv.writeCredentialsPhase = writeCredentialsReleasedPhase |
| + setWriteCredentialsPhase(t, writeCredentialsReleasedPhase) |
| for _, path := range []string{"/credentials", "/credentials/revoke"} { |
| if r := c.post(path, `{"access":"write","prefix":"recordings/","ttl_seconds":3600}`); r.status != http.StatusServiceUnavailable || r.err.Code != "write_credentials_not_released" { |
| t.Fatalf("%s in phase 1: %d %s", path, r.status, r.raw) |
| @@ -158,7 +158,7 @@ func TestStoreCredentialsRefusals(t *testing.T) { |
| t.Run("no store", func(t *testing.T) { |
| fx, prov, _, token := mediaStoreFixture(t, "code-wc-nostore") |
| fx.srv.cfg.StoreDeployment.WriteCredentials = true |
| - fx.srv.writeCredentialsPhase = 2 |
| + setWriteCredentialsPhase(t, 2) |
| c := &credentialsFixture{consoleFixture: fx, t: t, prov: prov, token: token} |
| if r := c.mint("recordings/", 3600); r.status != http.StatusConflict || r.err.Code != "no_store" { |
| t.Fatalf("mint with no store: %d %s", r.status, r.raw) |
| @@ -198,3 +198,12 @@ func TestStoreCredentialsNeverLogTheSecret(t *testing.T) { |
| t.Fatalf("console log carries a credential: %s", out) |
| } |
| } |
| + |
| +// setWriteCredentialsPhase opens or shuts the doors for one test. Callers |
| +// must not be parallel. |
| +func setWriteCredentialsPhase(t *testing.T, phase int) { |
| + t.Helper() |
| + prev := writeCredentialsPhase |
| + writeCredentialsPhase = phase |
| + t.Cleanup(func() { writeCredentialsPhase = prev }) |
| +} |
diff --git a/internal/console/server.go b/internal/console/server.go| index b608503e0..b011e6e50 100644 |
| --- a/internal/console/server.go |
| +++ b/internal/console/server.go |
| @@ -1290,10 +1290,6 @@ type Server struct { |
| // door serialises these verbs per app" (objstore/walk.go:560) — and until |
| // #381 nothing did. |
| storeWalks *storeWalkLocks |
| - // writeCredentialsPhase is the write-credential rollout phase this build |
| - // is (apistorecredentials.go): writeCredentialsReleasedPhase in |
| - // production, which a test may raise to open the doors. |
| - writeCredentialsPhase int |
| // doorPublish is the door-key publication lock per app, keyed |
| // "<sqid>/<app>" (apidoorkeys.go): one publisher per app at a time, so a |
| // renewal can never land an older key set after a revoke. Built lazily |
| @@ -2050,17 +2046,16 @@ func NewServer(cfg Config, st *Store) (*Server, error) { |
| // slow-loris uploads against a stolen or shared token can't pile up |
| // goroutines and buffers without bound. |
| shipSem: make(chan struct{}, 2), releaseReads: make(chan struct{}, releaseReadsMax), |
| - delegationZone: normalizeDelegationZone(cfg.DelegationZone), |
| - steeringHost: normalizeSteeringHost(cfg.SteeringHost), |
| - lookupCNAME: net.DefaultResolver.LookupCNAME, |
| - lookupTXT: cfg.LookupTXT, |
| - storeWalks: newStoreWalkLocks(), |
| - writeCredentialsPhase: writeCredentialsReleasedPhase, |
| - consoleMail: cfg.ConsoleMail, |
| - consoleNameCfg: cfg.ConsoleName, |
| - challengeSem: make(chan struct{}, challengeSendSlots), |
| - inviteTimeout: 20 * time.Second, |
| - inviteKeymailShare: 12 * time.Second, |
| + delegationZone: normalizeDelegationZone(cfg.DelegationZone), |
| + steeringHost: normalizeSteeringHost(cfg.SteeringHost), |
| + lookupCNAME: net.DefaultResolver.LookupCNAME, |
| + lookupTXT: cfg.LookupTXT, |
| + storeWalks: newStoreWalkLocks(), |
| + consoleMail: cfg.ConsoleMail, |
| + consoleNameCfg: cfg.ConsoleName, |
| + challengeSem: make(chan struct{}, challengeSendSlots), |
| + inviteTimeout: 20 * time.Second, |
| + inviteKeymailShare: 12 * time.Second, |
| // This process's identity in the relay writer lease. Random rather |
| // than derived from the host: two consoles on one box during a |
| // deploy overlap are two writers, and they must be able to tell |
diff --git a/internal/objstore/writecred.go b/internal/objstore/writecred.go| index c780b3249..55a6c2306 100644 |
| --- a/internal/objstore/writecred.go |
| +++ b/internal/objstore/writecred.go |
| @@ -182,7 +182,7 @@ func ValidWritePrefix(prefix string) error { |
| case prefix == "" || prefix == "/": |
| return fmt.Errorf("%w: name a folder, such as recordings/; a write credential never covers the whole store", ErrBadWritePrefix) |
| case len(prefix) > writePrefixMax: |
| - return fmt.Errorf("%w: at most %d characters", ErrBadWritePrefix, writePrefixMax) |
| + return fmt.Errorf("%w: at most %d bytes", ErrBadWritePrefix, writePrefixMax) |
| case !strings.HasSuffix(prefix, "/"): |
| return fmt.Errorf("%w: end it with /, such as recordings/", ErrBadWritePrefix) |
| case strings.HasPrefix(prefix, derivedPrefix): |
diff --git a/internal/release/adopt.go b/internal/release/adopt.go| index 7d01ed2b9..fb8d27010 100644 |
| --- a/internal/release/adopt.go |
| +++ b/internal/release/adopt.go |
| @@ -1731,21 +1731,13 @@ func adoptHost(ctx context.Context, work hostwrite.Work, reg *registry.Registry, |
| } |
| } |
| - // The console floor for write credentials (consolefloor.go): once this |
| - // deployment has had a store writer, a console build from before |
| - // writers is never pointed live. Not recorded as a refusal: the floor |
| - // and the bytes are read again next pass, and nothing was restarted. |
| - if why, err := consoleFloorRefusal(ctx, s, VersionPath(optDir, RouteAccount(rt), ver, rt.App), newProg); err != nil || why != "" { |
| - if err != nil { |
| - why = "the console floor could not be checked (" + err.Error() + ")" |
| - } |
| - fmt.Printf(" %s: %s: %s; not pointed live, will retry\n", rt.Host, ver, why) |
| - return |
| - } |
| - |
| // D3's binding check (spec §4.5 check 2): the staged bytes themselves |
| // must be the proven ones, or a build this box has run well. |
| - if !cfg.bindProof(ctx, optDir, rt, sel, verdict, cur, now) { |
| + // |
| + // Before it, the console floor for write credentials (consolefloor.go): |
| + // once this deployment has had a store writer, a console build from |
| + // before writers is never pointed live. |
| + if !consoleFloorAdmits(ctx, s, optDir, rt, ver, newProg) || !cfg.bindProof(ctx, optDir, rt, sel, verdict, cur, now) { |
| return |
| } |
| var historyAttempt string |
diff --git a/internal/release/consolefloor.go b/internal/release/consolefloor.go| index fd9833007..327f501b6 100644 |
| --- a/internal/release/consolefloor.go |
| +++ b/internal/release/consolefloor.go |
| @@ -25,6 +25,7 @@ import ( |
| "os" |
| "time" |
| + "github.com/carlosframework/platform/internal/registry" |
| "github.com/carlosframework/platform/internal/safefile" |
| ) |
| @@ -114,3 +115,19 @@ func fileContains(path string, needle []byte) (bool, error) { |
| } |
| } |
| } |
| + |
| +// consoleFloorAdmits is adoptHost's use of consoleFloorRefusal for the build |
| +// staged for rt at ver: false, with the reason printed, when it may not be |
| +// pointed live. Not recorded as a refusal: the floor and the bytes are read |
| +// again next pass, and nothing was restarted. |
| +func consoleFloorAdmits(ctx context.Context, s Store, optDir string, rt registry.Route, ver, program string) bool { |
| + why, err := consoleFloorRefusal(ctx, s, VersionPath(optDir, RouteAccount(rt), ver, rt.App), program) |
| + if err != nil { |
| + why = "the console floor could not be checked (" + err.Error() + ")" |
| + } |
| + if why == "" { |
| + return true |
| + } |
| + fmt.Printf(" %s: %s: %s; not pointed live, will retry\n", rt.Host, ver, why) |
| + return false |
| +} |
diff --git a/store_credential.go b/store_credential.go| index e8e143859..d22c09f27 100644 |
| --- a/store_credential.go |
| +++ b/store_credential.go |
| @@ -23,12 +23,12 @@ import ( |
| "github.com/carlosframework/platform/internal/objstore" |
| ) |
| -// storeCredentialCopy is this verb's text by key. New copy, pending the Luna |
| -// pass (docs/superpowers/notes/copy-luna-brief-store-write-credential.md). |
| +// storeCredentialCopy is this verb's text by key. Copy approved in the |
| +// Luna pass (docs/superpowers/notes/copy-luna-result-store-write-credential.md). |
| var storeCredentialCopy = map[string]string{ |
| "usage": "usage: carlos store credential --write --prefix <folder/> --ttl <duration> --app <a> [--environment <e>] [--json]\n" + |
| " carlos store credential --revoke --app <a> [--environment <e>] [--json]", |
| - "store_usage": " credential --write --prefix <folder/> --ttl <duration> --app <a> [--json]\n" + |
| + "store_usage": " credential --write --prefix <folder/> --ttl <duration> --app <a> [--environment <e>] [--json]\n" + |
| " Prints a credential that can only upload files\n" + |
| " under one folder of the app's store, for 15 minutes\n" + |
| " to 24 hours. Give it to a service that uploads for\n" + |