store uploads: write-ahead intent, policy-only convergence
Task 9 fix round 1. Enable records the rules it is about to write as pending before any bucket write and promotes them after both land; a rule with a recorded or pending hash is the platform's own, so a crash, a half write or a write that landed and then errored heals on the next call. The put-back path is gone. The bucket is inspected again right before the writes. The policy converges through the new objstore.ConvergePolicyIn (EnsureUser only: no key, config, record or seed mark touched). Disable beside a foreign rule refuses 409 and keeps the record. Enable and disable write audit rows. CLI strings and audit text move to deck rows pending the Luna pass. Verification accepts the pending rules too.
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
13 files changed,
+704
−181
apimode.go+1 −1docs/superpowers/notes/media-conversion-copy-deck.md+23 −0internal/console/apistoreuploads.go+186 −108internal/console/apistoreuploads_test.go+273 −40internal/console/media_copy.go+3 −0internal/console/mediastore.go+37 −7internal/objstore/objstore.go+11 −3internal/objstore/walk.go+49 −0internal/objstore/walk_test.go+50 −0store.go+2 −6store_test.go+1 −1store_uploads.go+37 −15store_uploads_test.go+31 −0
diff --git a/apimode.go b/apimode.go| index b4f1b8f9c..85ed6b3a0 100644 |
| --- a/apimode.go |
| +++ b/apimode.go |
| @@ -2521,7 +2521,7 @@ func (s *apiSession) storeUploadsCall(ctx context.Context, a apiAcct, app string |
| } |
| var out apiUploadsReply |
| if err := json.Unmarshal(body, &out); err != nil { |
| - return apiUploadsReply{}, fmt.Errorf("store uploads: unreadable response: %w", err) |
| + return apiUploadsReply{}, fmt.Errorf(storeUploadsText("cli.uploads.unreadable"), err) |
| } |
| return out, nil |
| } |
diff --git a/docs/superpowers/notes/media-conversion-copy-deck.md b/docs/superpowers/notes/media-conversion-copy-deck.md| index 59191b31d..fa44f17e4 100644 |
| --- a/docs/superpowers/notes/media-conversion-copy-deck.md |
| +++ b/docs/superpowers/notes/media-conversion-copy-deck.md |
| @@ -339,6 +339,29 @@ $ carlos store uploads status --app shop |
| uploads off |
| ``` |
| +**Pending Luna pass** (added in Task 9 fix round 1; the code reads them by |
| +key: root `storeUploadsCopy`, console `mediaCopy`). Help and usage text is |
| +`%s`-filled with the sub-verb where shown; `cli.uploads.unreadable` wraps |
| +the decoder's error. |
| + |
| +| Key | Text | |
| +|---|---| |
| +| `cli.uploads.usage` | `usage: carlos store uploads <enable\|status\|disable> --app <a> [flags]` | |
| +| `cli.uploads.usage_enable` | ` enable --app <a> [--origin <o>]...` | |
| +| `cli.uploads.usage_status` | ` status --app <a>` | |
| +| `cli.uploads.usage_disable` | ` disable --app <a>` | |
| +| `cli.uploads.usage_verb` | `usage: carlos store uploads %s --app <a> [--account <sqid-or-name>] [--console <origin>]` | |
| +| `cli.uploads.flags` | `Flags: --account/--account-id to disambiguate, --console to pick a console.` | |
| +| `cli.uploads.flag_app` | `app whose store browsers upload to` | |
| +| `cli.uploads.flag_origin` | `an origin browsers upload from: https:// and a host, or http://localhost:<port>. Repeat for more, at most 8` | |
| +| `cli.uploads.unreadable` | `store uploads: unreadable response: %w` | |
| +| `cli.uploads.store_usage` | the `carlos store` usage entry: ` uploads <enable\|status\|disable> --app <a> [--origin <o>]...` then `docs.cli.store_uploads`, wrapped at the usage's 26-column indent | |
| +| `audit.uploads_enable` | `turned on browser uploads from %s (cli)` (the origins, comma separated) | |
| +| `audit.uploads_disable` | `turned off browser uploads (cli)` | |
| + |
| +The `carlos store uploads` usage block is `cli.uploads.usage`, the three |
| +`usage_*` lines, `docs.cli.store_uploads` and `cli.uploads.flags`. |
| + |
| ## Docs headings in `docs/site/cli.md` (Task 10) |
| One sentence under each heading Task 10 adds. Task 11 drafts the media page |
diff --git a/internal/console/apistoreuploads.go b/internal/console/apistoreuploads.go| index a3b553ffe..aa05ad8f9 100644 |
| --- a/internal/console/apistoreuploads.go |
| +++ b/internal/console/apistoreuploads.go |
| @@ -19,8 +19,9 @@ import ( |
| // writes the platform's one CORS rule (the origins the member names) and its |
| // one lifecycle rule (abort incomplete multipart uploads after a day) onto |
| // the store's bucket, records both by hash in the store record's conversion |
| -// block (objstore.Uploads), and re-runs the grant so the store user's policy |
| -// carries the two multipart actions (storePolicyJSON). |
| +// block (objstore.Uploads, with a write-ahead PendingUploads), and converges |
| +// the store user's policy so it carries the two multipart actions |
| +// (objstore.ConvergePolicyIn, storePolicyJSON). |
| // |
| // The invariant this file exists to keep: the platform never replaces, |
| // merges into or deletes a CORS or lifecycle configuration it did not write. |
| @@ -29,8 +30,8 @@ import ( |
| // store is trusted for its incarnation tag only (mediaStoreCheck reads |
| // nothing else of a verified bucket), so a rule set by hand since then is |
| // seen only here. A configuration is the platform's only when its canonical |
| -// hash is the one the record holds; with nothing recorded, any configuration |
| -// at all is foreign. |
| +// hash is one the record holds (recorded, or pending from a write that may |
| +// not have finished); with neither, any configuration at all is foreign. |
| // |
| // Every refusal is jsonErrorCode with the copy deck's message by key |
| // (media_copy.go). No SQLite transaction is opened here. |
| @@ -133,29 +134,49 @@ func uploadsOrigins(raw []string) (origins []string, code, msg string) { |
| return origins, "", "" |
| } |
| +// uploadsOurs: a configuration the bucket holds is absent, or its hash is |
| +// one the record accounts for (the recorded rules or the pending ones). |
| +func uploadsOurs(held []byte, hashes ...string) bool { |
| + if len(held) == 0 { |
| + return true |
| + } |
| + h := storecfg.Hash(held) |
| + for _, want := range hashes { |
| + if want != "" && want == h { |
| + return true |
| + } |
| + } |
| + return false |
| +} |
| + |
| // uploadsForeign is the check (storecfg.CheckLifecycle or CheckCORS) whose |
| -// configuration the bucket holds and the platform did not write, "" when it |
| -// holds none it did not write. up is what the record says the platform |
| -// wrote, nil for nothing: then any configuration present is foreign. An |
| -// absent configuration is never foreign; there is nothing in it to replace. |
| -func uploadsForeign(f storecfg.Facts, up *objstore.Uploads) string { |
| - var lh, ch string |
| - if up != nil { |
| - lh, ch = up.LifecycleHash, up.CORSHash |
| - } |
| - if len(f.Lifecycle) > 0 && (lh == "" || storecfg.Hash(f.Lifecycle) != lh) { |
| +// configuration the bucket holds and the platform did not write, in |
| +// storecfg.Verify's order, "" when it holds none it did not write. A |
| +// configuration is the platform's when its hash is the recorded one or the |
| +// pending one (a write-ahead intent), each judged on its own, since a write |
| +// may have landed one rule and not the other. Nothing recorded and nothing |
| +// pending: any configuration present is foreign. An absent configuration is |
| +// never foreign; there is nothing in it to replace. |
| +func uploadsForeign(f storecfg.Facts, recorded, pending *objstore.Uploads) string { |
| + var lh, ch []string |
| + for _, u := range []*objstore.Uploads{recorded, pending} { |
| + if u != nil { |
| + lh, ch = append(lh, u.LifecycleHash), append(ch, u.CORSHash) |
| + } |
| + } |
| + if !uploadsOurs(f.Lifecycle, lh...) { |
| return storecfg.CheckLifecycle |
| } |
| - if len(f.CORS) > 0 && (ch == "" || storecfg.Hash(f.CORS) != ch) { |
| + if !uploadsOurs(f.CORS, ch...) { |
| return storecfg.CheckCORS |
| } |
| return "" |
| } |
| // uploadsMismatch compares a bucket with uploads that are on: the check |
| -// whose configuration is not exactly the recorded one, "" when both are. An |
| -// absent configuration differs too (browsers cannot upload through a CORS |
| -// rule that is gone): a recorded hash is always of a non-empty rule set. |
| +// whose configuration is not exactly up's, "" when both are. An absent |
| +// configuration differs too (browsers cannot upload through a CORS rule |
| +// that is gone): a recorded hash is always of a non-empty rule set. |
| func uploadsMismatch(f storecfg.Facts, up *objstore.Uploads) string { |
| if storecfg.Hash(f.Lifecycle) != up.LifecycleHash { |
| return storecfg.CheckLifecycle |
| @@ -166,13 +187,34 @@ func uploadsMismatch(f storecfg.Facts, up *objstore.Uploads) string { |
| return "" |
| } |
| -// recordedUploads is the uploads block of a store record, nil when it has |
| -// none. |
| -func recordedUploads(rec *objstore.Record) *objstore.Uploads { |
| +// pendingLanded: the bucket shows that the pending write landed, at least |
| +// in part, so the pending rules must become the recorded ones before a new |
| +// intent replaces them (else a rule the platform wrote would stand with no |
| +// hash the record holds). The CORS rule is the pending one and not the |
| +// recorded one; or nothing is recorded and the pending lifecycle rule is |
| +// there. |
| +func pendingLanded(f storecfg.Facts, recorded, pending *objstore.Uploads) bool { |
| + if len(f.CORS) > 0 && storecfg.Hash(f.CORS) == pending.CORSHash && (recorded == nil || recorded.CORSHash != pending.CORSHash) { |
| + return true |
| + } |
| + return recorded == nil && len(f.Lifecycle) > 0 && storecfg.Hash(f.Lifecycle) == pending.LifecycleHash |
| +} |
| + |
| +// sameUploads: a and b are both absent, or carry the same two hashes. |
| +func sameUploads(a, b *objstore.Uploads) bool { |
| + if a == nil || b == nil { |
| + return a == b |
| + } |
| + return a.CORSHash == b.CORSHash && a.LifecycleHash == b.LifecycleHash |
| +} |
| + |
| +// uploadsBlocks is the record's recorded and pending uploads blocks, nil |
| +// when it has none. |
| +func uploadsBlocks(rec *objstore.Record) (recorded, pending *objstore.Uploads) { |
| if rec == nil || rec.Provisioned == nil || rec.Conversion == nil { |
| - return nil |
| + return nil, nil |
| } |
| - return rec.Conversion.Uploads |
| + return rec.Conversion.Uploads, rec.Conversion.PendingUploads |
| } |
| // uploadsOff is the answer for uploads that are off. |
| @@ -180,25 +222,27 @@ func uploadsOff() uploadsAnswer { |
| return uploadsAnswer{Origins: []string{}, BucketMatches: true} |
| } |
| -// uploadsOn is the answer for a recorded uploads block and the bucket's |
| -// state against it. |
| +// uploadsOn is the answer for an uploads block and the bucket's state |
| +// against it. |
| func uploadsOn(up *objstore.Uploads, mismatch string) uploadsAnswer { |
| return uploadsAnswer{Enabled: true, Origins: append([]string{}, up.Origins...), |
| BucketMatches: mismatch == "", Mismatch: mismatch} |
| } |
| // errUploadsStoreMoved: the store record changed under the walk lock in a |
| -// way the uploads write cannot follow (another bucket, or another |
| -// incarnation). Nothing is recorded; the caller undoes its bucket write. |
| +// way the uploads write cannot follow (another bucket, another incarnation, |
| +// or uploads blocks other than the ones the bucket was checked against). |
| +// Nothing is recorded. |
| var errUploadsStoreMoved = errors.New("console: uploads: the store record changed while uploads were written") |
| -// writeUploadsRecord sets the record's uploads block to up (nil clears it), |
| -// in a write conditional on the record as read, retried on a lost race |
| -// with another writer of the record (a scan or plan-storage write, which do |
| -// not take the walk lock). It refuses, with errUploadsStoreMoved, a record |
| -// whose bucket is no longer bucket or, when inc is not "", whose verified |
| -// incarnation is no longer inc. |
| -func (s *Server) writeUploadsRecord(ctx context.Context, sqid, app, bucket, inc string, up *objstore.Uploads) error { |
| +// mutateUploads applies change to the record's conversion block in a write |
| +// conditional on the record as read, retried on a lost race with another |
| +// writer of the record (a scan or plan-storage write, which do not take the |
| +// walk lock). It refuses, with errUploadsStoreMoved, a record whose bucket |
| +// is no longer bucket or, when inc is not "", whose verified incarnation is |
| +// no longer inc. A record with no conversion block, when inc is "", has |
| +// nothing to change. |
| +func (s *Server) mutateUploads(ctx context.Context, sqid, app, bucket, inc string, change func(c *objstore.Conversion) error) error { |
| var lastErr error |
| for attempt := 0; attempt < 3; attempt++ { |
| rec, etag, err := objstore.GetIn(ctx, s.cfg.Releases, sqid, app, "") |
| @@ -209,7 +253,7 @@ func (s *Server) writeUploadsRecord(ctx context.Context, sqid, app, bucket, inc |
| return errUploadsStoreMoved |
| } |
| if rec.Conversion == nil { |
| - if up == nil { |
| + if inc == "" { |
| return nil |
| } |
| return errUploadsStoreMoved |
| @@ -217,7 +261,9 @@ func (s *Server) writeUploadsRecord(ctx context.Context, sqid, app, bucket, inc |
| if inc != "" && (rec.Conversion.VerifiedAt == nil || rec.Conversion.Incarnation != inc) { |
| return errUploadsStoreMoved |
| } |
| - rec.Conversion.Uploads = up |
| + if err := change(rec.Conversion); err != nil { |
| + return err |
| + } |
| if _, err := objstore.PutIn(ctx, s.cfg.Releases, sqid, app, "", rec, etag); err != nil { |
| if errors.Is(err, release.ErrCASConflict) { |
| lastErr = err |
| @@ -236,10 +282,17 @@ func uploadsInternal(w http.ResponseWriter, what string, err error) { |
| jsonError(w, http.StatusInternalServerError, "internal error") |
| } |
| +// uploadsRefuseForeign answers 409 store_unverified with check's phrase. |
| +func uploadsRefuseForeign(w http.ResponseWriter, check string) { |
| + mediaRefuse(w, http.StatusConflict, mediaCodeStoreUnverified, mediaText("media.store_unverified", mediaText("media.check."+check))) |
| +} |
| + |
| // handleAPIStoreUploadsGet is GET /api/cli/apps/{account}/{app}/store/uploads: |
| // `carlos store uploads status`. It reads the record and, when uploads are |
| -// on, Inspects the bucket and compares it with what the record says the |
| -// platform wrote. It writes nothing and takes no lock. |
| +// on or pending, Inspects the bucket and compares it with the rules the |
| +// record says the platform wrote: the pending ones when the bucket holds |
| +// exactly those (a write that landed and was not confirmed) or nothing is |
| +// recorded, else the recorded ones. It writes nothing and takes no lock. |
| func (s *Server) handleAPIStoreUploadsGet(w http.ResponseWriter, r *http.Request) { |
| _, acct, app, ok := s.apiAccountApp(w, r) |
| if !ok { |
| @@ -264,8 +317,8 @@ func (s *Server) handleAPIStoreUploadsGet(w http.ResponseWriter, r *http.Request |
| uploadsInternal(w, "status "+acct.Sqid+"/"+app, err) |
| return |
| } |
| - up := recordedUploads(rec) |
| - if up == nil { |
| + recorded, pending := uploadsBlocks(rec) |
| + if recorded == nil && pending == nil { |
| writeJSON(w, http.StatusOK, uploadsOff()) |
| return |
| } |
| @@ -274,7 +327,11 @@ func (s *Server) handleAPIStoreUploadsGet(w http.ResponseWriter, r *http.Request |
| uploadsInternal(w, "status inspect "+acct.Sqid+"/"+app, err) |
| return |
| } |
| - writeJSON(w, http.StatusOK, uploadsOn(up, uploadsMismatch(facts, up))) |
| + ref := recorded |
| + if pending != nil && (recorded == nil || uploadsMismatch(facts, pending) == "") { |
| + ref = pending |
| + } |
| + writeJSON(w, http.StatusOK, uploadsOn(ref, uploadsMismatch(facts, ref))) |
| } |
| // handleAPIStoreUploadsSet is POST /api/cli/apps/{account}/{app}/store/uploads: |
| @@ -289,23 +346,28 @@ func (s *Server) handleAPIStoreUploadsGet(w http.ResponseWriter, r *http.Request |
| // 5. enable: an origin that is not one: 400 bad_origin; more than 8 |
| // after repeats are dropped: 400 too_many_origins |
| // |
| -// Then disable is handleUploadsDisable, and enable, under the account lock |
| -// (the regrant's key choice) and the app's store walk lock: |
| +// Then disable is handleUploadsDisable, and enable, under the app's store |
| +// walk lock: |
| // |
| // 6. no origins given: the app's ready platform hostnames as https:// |
| // origins; none: 409 no_hosts; more than 8: 400 too_many_origins |
| // 7. mediaStoreEligible: 409 no_store, 409 store_unverified |
| -// 8. Inspect now, whatever 7 said: a lifecycle or CORS configuration the |
| -// record does not hold the hash of: 409 store_unverified with that |
| -// check's phrase. Nothing of uploads has been written (7 may have |
| -// recorded the store's verification, as the media door's check does). |
| -// 9. the grant re-runs, so the store user's policy carries the multipart |
| -// actions (before any bucket write, so a failure here leaves nothing |
| -// half done) |
| -// 10. PutUploads, then the record's uploads block. A record write that |
| -// fails puts the bucket back as the record still describes it, so the |
| -// platform's own rules never stand unrecorded (which would read as |
| -// foreign to every later check). |
| +// 8. Inspect, whatever 7 said: a lifecycle or CORS configuration whose |
| +// hash the record holds neither as recorded nor as pending: 409 |
| +// store_unverified with that check's phrase. Nothing of uploads has |
| +// been written (7 may have recorded the store's verification, as the |
| +// media door's check does). |
| +// 9. the store user's policy is converged (objstore.ConvergePolicyIn: the |
| +// multipart actions; no key, no config, no record written) |
| +// 10. Inspect again and the same check, immediately before the writes |
| +// 11. the write-ahead intent: the rules about to be written go into the |
| +// record as pending (a pending write the bucket shows landed becomes |
| +// the recorded one first) |
| +// 12. PutUploads, then pending becomes recorded. |
| +// |
| +// A failure after 11 leaves the pending hashes standing, so whatever the |
| +// bucket was left holding (nothing, one rule, both) is the platform's own |
| +// to the next enable, update or disable, which converge. |
| func (s *Server) handleAPIStoreUploadsSet(w http.ResponseWriter, r *http.Request) { |
| addr, acct, app, ok := s.apiAccountApp(w, r) |
| if !ok { |
| @@ -328,7 +390,7 @@ func (s *Server) handleAPIStoreUploadsSet(w http.ResponseWriter, r *http.Request |
| return |
| } |
| if !body.Enabled { |
| - s.handleUploadsDisable(w, r, acct, app) |
| + s.handleUploadsDisable(w, r, addr, acct, app) |
| return |
| } |
| origins, code, msg := uploadsOrigins(body.Origins) |
| @@ -337,13 +399,6 @@ func (s *Server) handleAPIStoreUploadsSet(w http.ResponseWriter, r *http.Request |
| return |
| } |
| - // The account lock from the key choice through the regrant (fleet |
| - // secrets key spec §5.2.1), then the walk lock, the grant door's order. |
| - defer s.lockAccount(acct.Sqid)() |
| - sealer, ok := s.scanRegrantSealer(w, r.Context(), acct, app) |
| - if !ok { |
| - return |
| - } |
| ctx, cancel := context.WithTimeout(r.Context(), storeGrantTimeout) |
| defer cancel() |
| defer s.storeWalks.lock(acct.Sqid, app, "")() |
| @@ -380,75 +435,93 @@ func (s *Server) handleAPIStoreUploadsSet(w http.ResponseWriter, r *http.Request |
| mediaRefuse(w, http.StatusConflict, mediaCodeNoStore, mediaText("media.no_store", app, app)) |
| return |
| case mediaCodeStoreUnverified: |
| - mediaRefuse(w, http.StatusConflict, mediaCodeStoreUnverified, mediaText("media.store_unverified", mediaText("media.check."+check))) |
| + uploadsRefuseForeign(w, check) |
| return |
| default: |
| uploadsInternal(w, "store check "+acct.Sqid+"/"+app, errors.New("unknown code "+code)) |
| return |
| } |
| - bucket, inc, prior := rec.Provisioned.Bucket, rec.Conversion.Incarnation, rec.Conversion.Uploads |
| + bucket, inc := rec.Provisioned.Bucket, rec.Conversion.Incarnation |
| + recorded, pending := rec.Conversion.Uploads, rec.Conversion.PendingUploads |
| - // Every store, verified or not: the bucket as it is now. |
| + // The first look: a refusal here has written nothing of uploads. |
| facts, err := s.cfg.StoreBuckets.Inspect(ctx, bucket) |
| if err != nil { |
| uploadsInternal(w, "inspect "+acct.Sqid+"/"+app, err) |
| return |
| } |
| - if check := uploadsForeign(facts, prior); check != "" { |
| - mediaRefuse(w, http.StatusConflict, mediaCodeStoreUnverified, mediaText("media.store_unverified", mediaText("media.check."+check))) |
| + if check := uploadsForeign(facts, recorded, pending); check != "" { |
| + uploadsRefuseForeign(w, check) |
| return |
| } |
| - if err := s.regrantForScanning(ctx, sealer, acct, app, addr); err != nil { |
| - uploadsInternal(w, "regrant "+acct.Sqid+"/"+app, err) |
| + if _, err := claimAppCall(s, ctx, acct, app, "store-uploads", func(ctx context.Context) (*objstore.Record, error) { |
| + return objstore.ConvergePolicyIn(ctx, s.cfg.Releases, s.cfg.StoreProvisioner, acct.Sqid, app, "") |
| + }); err != nil { |
| + uploadsInternal(w, "policy "+acct.Sqid+"/"+app, err) |
| return |
| } |
| - if err := s.cfg.StoreBuckets.PutUploads(ctx, bucket, origins); err != nil { |
| - uploadsInternal(w, "put rules "+acct.Sqid+"/"+app, err) |
| + |
| + // The second look, immediately before the writes. |
| + facts, err = s.cfg.StoreBuckets.Inspect(ctx, bucket) |
| + if err != nil { |
| + uploadsInternal(w, "inspect "+acct.Sqid+"/"+app, err) |
| + return |
| + } |
| + if check := uploadsForeign(facts, recorded, pending); check != "" { |
| + uploadsRefuseForeign(w, check) |
| return |
| } |
| - up := &objstore.Uploads{ |
| + |
| + next := &objstore.Uploads{ |
| Origins: origins, |
| CORSHash: storecfg.Hash(storecfg.UploadsCORS(origins)), |
| LifecycleHash: storecfg.Hash(storecfg.UploadsLifecycle()), |
| At: s.now().UTC(), |
| By: addr, |
| } |
| - if err := s.writeUploadsRecord(ctx, acct.Sqid, app, bucket, inc, up); err != nil { |
| - s.restoreUploads(ctx, bucket, prior) |
| - uploadsInternal(w, "record "+acct.Sqid+"/"+app, err) |
| + if err := s.mutateUploads(ctx, acct.Sqid, app, bucket, inc, func(c *objstore.Conversion) error { |
| + if !sameUploads(c.Uploads, recorded) || !sameUploads(c.PendingUploads, pending) { |
| + return errUploadsStoreMoved |
| + } |
| + if pending != nil && pendingLanded(facts, recorded, pending) { |
| + c.Uploads = pending |
| + } |
| + c.PendingUploads = next |
| + return nil |
| + }); err != nil { |
| + uploadsInternal(w, "record intent "+acct.Sqid+"/"+app, err) |
| return |
| } |
| - writeJSON(w, http.StatusOK, uploadsOn(up, "")) |
| -} |
| - |
| -// restoreUploads puts the bucket's rules back to what prior (the record, |
| -// still unchanged) describes, after a record write failed: before the |
| -// write, the bucket held only prior's rules or none (uploadsForeign), so |
| -// this returns it to a state the record accounts for. Best effort: a |
| -// failure is logged, and leaves the platform's rules on the bucket |
| -// unrecorded, which every later check refuses as foreign until an operator |
| -// removes them. |
| -func (s *Server) restoreUploads(ctx context.Context, bucket string, prior *objstore.Uploads) { |
| - var err error |
| - if prior != nil { |
| - err = s.cfg.StoreBuckets.PutUploads(ctx, bucket, prior.Origins) |
| - } else { |
| - err = s.cfg.StoreBuckets.DeleteUploads(ctx, bucket) |
| + if err := s.cfg.StoreBuckets.PutUploads(ctx, bucket, origins); err != nil { |
| + uploadsInternal(w, "put rules "+acct.Sqid+"/"+app, err) |
| + return |
| } |
| - if err != nil { |
| - log.Printf("console: store uploads: bucket %s holds rules no record names, and putting it back failed: %v", bucket, err) |
| + if err := s.mutateUploads(ctx, acct.Sqid, app, bucket, inc, func(c *objstore.Conversion) error { |
| + if !sameUploads(c.PendingUploads, next) { |
| + return errUploadsStoreMoved |
| + } |
| + c.Uploads, c.PendingUploads = next, nil |
| + return nil |
| + }); err != nil { |
| + uploadsInternal(w, "record "+acct.Sqid+"/"+app, err) |
| + return |
| } |
| + s.audit(acct, app, addr, "store-uploads-enable", mediaText("audit.uploads_enable", strings.Join(origins, ", "))) |
| + writeJSON(w, http.StatusOK, uploadsOn(next, "")) |
| } |
| // handleUploadsDisable is `carlos store uploads disable`, under the app's |
| -// store walk lock. With uploads recorded, it Inspects the bucket and calls |
| -// DeleteUploads only when every configuration the bucket holds is the one |
| -// recorded (DeleteUploads removes both, so a foreign rule beside the |
| -// platform's is never deleted with it), then clears the uploads block. A |
| -// foreign rule is left where it is, and the answer says so (bucket_matches |
| -// false). With nothing recorded it writes nothing and reads no bucket. |
| -func (s *Server) handleUploadsDisable(w http.ResponseWriter, r *http.Request, acct *Account, app string) { |
| +// store walk lock. With nothing recorded or pending it writes nothing and |
| +// reads no bucket. Otherwise it Inspects the bucket: a configuration the |
| +// record accounts for neither as recorded nor as pending refuses 409 |
| +// store_unverified with that check's phrase, writing nothing and keeping |
| +// the record (DeleteUploads removes both configurations, so it never runs |
| +// beside a foreign one; once an operator removes the hand-set rule, disable |
| +// works). Else DeleteUploads, when the bucket holds anything, then both |
| +// uploads blocks are cleared. A failure between the two leaves the record |
| +// naming rules that are gone, which the next disable clears. |
| +func (s *Server) handleUploadsDisable(w http.ResponseWriter, r *http.Request, addr string, acct *Account, app string) { |
| ctx, cancel := context.WithTimeout(r.Context(), storeGrantTimeout) |
| defer cancel() |
| defer s.storeWalks.lock(acct.Sqid, app, "")() |
| @@ -457,8 +530,8 @@ func (s *Server) handleUploadsDisable(w http.ResponseWriter, r *http.Request, ac |
| uploadsInternal(w, "disable "+acct.Sqid+"/"+app, err) |
| return |
| } |
| - up := recordedUploads(rec) |
| - if up == nil { |
| + recorded, pending := uploadsBlocks(rec) |
| + if recorded == nil && pending == nil { |
| writeJSON(w, http.StatusOK, uploadsOff()) |
| return |
| } |
| @@ -468,18 +541,23 @@ func (s *Server) handleUploadsDisable(w http.ResponseWriter, r *http.Request, ac |
| uploadsInternal(w, "disable inspect "+acct.Sqid+"/"+app, err) |
| return |
| } |
| - answer := uploadsOff() |
| - if foreign := uploadsForeign(facts, up); foreign != "" { |
| - answer.BucketMatches, answer.Mismatch = false, foreign |
| - } else if len(facts.CORS) > 0 || len(facts.Lifecycle) > 0 { |
| + if check := uploadsForeign(facts, recorded, pending); check != "" { |
| + uploadsRefuseForeign(w, check) |
| + return |
| + } |
| + if len(facts.CORS) > 0 || len(facts.Lifecycle) > 0 { |
| if err := s.cfg.StoreBuckets.DeleteUploads(ctx, bucket); err != nil { |
| uploadsInternal(w, "delete rules "+acct.Sqid+"/"+app, err) |
| return |
| } |
| } |
| - if err := s.writeUploadsRecord(ctx, acct.Sqid, app, bucket, "", nil); err != nil { |
| + if err := s.mutateUploads(ctx, acct.Sqid, app, bucket, "", func(c *objstore.Conversion) error { |
| + c.Uploads, c.PendingUploads = nil, nil |
| + return nil |
| + }); err != nil { |
| uploadsInternal(w, "disable record "+acct.Sqid+"/"+app, err) |
| return |
| } |
| - writeJSON(w, http.StatusOK, answer) |
| + s.audit(acct, app, addr, "store-uploads-disable", mediaText("audit.uploads_disable")) |
| + writeJSON(w, http.StatusOK, uploadsOff()) |
| } |
diff --git a/internal/console/apistoreuploads_test.go b/internal/console/apistoreuploads_test.go| index 013c0b443..7e321628d 100644 |
| --- a/internal/console/apistoreuploads_test.go |
| +++ b/internal/console/apistoreuploads_test.go |
| @@ -5,12 +5,14 @@ import ( |
| "context" |
| "encoding/json" |
| "errors" |
| + "maps" |
| "net/http" |
| "slices" |
| "strings" |
| "sync/atomic" |
| "testing" |
| + "github.com/carlosframework/platform/internal/appconfig" |
| "github.com/carlosframework/platform/internal/objstore" |
| "github.com/carlosframework/platform/internal/registry" |
| "github.com/carlosframework/platform/internal/release" |
| @@ -228,9 +230,11 @@ func TestUploadsEnableWritesOneRuleEach(t *testing.T) { |
| up.LifecycleHash != storecfg.Hash(f.Lifecycle) || up.By != "alice@keymail.dev" || up.At.IsZero() { |
| t.Fatalf("recorded uploads = %+v", up) |
| } |
| - if !storecfg.ValidIncarnation(rec.Conversion.Incarnation) || rec.Conversion.VerifiedAt == nil { |
| + if !storecfg.ValidIncarnation(rec.Conversion.Incarnation) || rec.Conversion.VerifiedAt == nil || rec.Conversion.PendingUploads != nil { |
| t.Fatalf("conversion block = %+v", rec.Conversion) |
| } |
| + auditedBy(t, u.consoleFixture, "titogo", "store-uploads-enable", "alice@keymail.dev", |
| + "turned on browser uploads from http://localhost:3000, https://shop.example.com (cli)") |
| if p := u.prov.PolicyFor(u.user()); !strings.Contains(p, "s3:AbortMultipartUpload") || !strings.Contains(p, "s3:ListMultipartUploadParts") { |
| t.Fatalf("the grant did not re-run: policy %q", p) |
| } |
| @@ -407,24 +411,32 @@ func TestUploadsDisableLeavesForeignRules(t *testing.T) { |
| if s := u.status(); s.status != http.StatusOK || s.ans.Enabled { |
| t.Fatalf("status after disable = %s", s.raw) |
| } |
| + auditedBy(t, u.consoleFixture, "titogo", "store-uploads-disable", "alice@keymail.dev", "turned off browser uploads (cli)") |
| }) |
| - t.Run("a hand-changed rule stays, and so does the platform's beside it", func(t *testing.T) { |
| + t.Run("a hand-set rule refuses, and keeps the record, until it is gone", func(t *testing.T) { |
| u := newUploads(t, "code-uploads-disable-foreign") |
| u.wantOK(u.enable("https://shop.example.com")) |
| u.setFacts(func(f *storecfg.Facts) { f.CORS = foreignCORS() }) |
| - r := u.disable() |
| - u.wantOK(r) |
| - if r.ans.Enabled || r.ans.BucketMatches || r.ans.Mismatch != "cors" { |
| - t.Fatalf("answer = %s", r.raw) |
| - } |
| + before, _ := rawStoreRecord(t, u.consoleFixture) |
| + u.wantRefused(u.disable(), http.StatusConflict, "store_unverified", uploadsUnverified("cors")) |
| if n := u.buckets.CallCount("DeleteUploads"); n != 0 { |
| t.Fatalf("DeleteUploads called %d times beside a foreign rule", n) |
| } |
| if f := u.facts(); !bytes.Equal(f.CORS, foreignCORS()) || !bytes.Equal(f.Lifecycle, storecfg.UploadsLifecycle()) { |
| t.Fatalf("bucket = %s %s", f.CORS, f.Lifecycle) |
| } |
| - if up := storedRecord(t, u.consoleFixture, "titogo").Conversion.Uploads; up != nil { |
| - t.Fatalf("record kept uploads: %+v", up) |
| + if after, _ := rawStoreRecord(t, u.consoleFixture); !bytes.Equal(before, after) { |
| + t.Fatal("a refused disable wrote the record") |
| + } |
| + // An operator removes the hand-set rule: an absent rule is not |
| + // foreign, so disable now removes the platform's own. |
| + u.setFacts(func(f *storecfg.Facts) { f.CORS = nil }) |
| + u.wantOK(u.disable()) |
| + if f := u.facts(); f.CORS != nil || f.Lifecycle != nil { |
| + t.Fatalf("rules left: %s %s", f.CORS, f.Lifecycle) |
| + } |
| + if c := storedRecord(t, u.consoleFixture, "titogo").Conversion; c.Uploads != nil || c.PendingUploads != nil { |
| + t.Fatalf("record kept uploads: %+v", c) |
| } |
| }) |
| t.Run("nothing recorded: nothing read, nothing written", func(t *testing.T) { |
| @@ -500,9 +512,9 @@ func TestUploadsRefusesNoStoreAndUnverifiedStore(t *testing.T) { |
| } |
| } |
| -// The grant runs before any bucket write, so a failed grant leaves the |
| -// bucket as it was. |
| -func TestUploadsGrantFailureWritesNoRules(t *testing.T) { |
| +// The policy converges before any bucket write, so a failed convergence |
| +// leaves the bucket and the record as they were. |
| +func TestUploadsPolicyFailureWritesNoRules(t *testing.T) { |
| u := newUploads(t, "code-uploads-grantfail") |
| u.prov.FailNext["EnsureUser"] = errors.New("iam down") |
| r := u.enable("https://shop.example.com") |
| @@ -510,17 +522,56 @@ func TestUploadsGrantFailureWritesNoRules(t *testing.T) { |
| t.Fatalf("status = %d %s", r.status, r.raw) |
| } |
| if n := u.buckets.CallCount("PutUploads"); n != 0 { |
| - t.Fatalf("PutUploads called %d times after a failed grant", n) |
| + t.Fatalf("PutUploads called %d times after a failed convergence", n) |
| } |
| - if up := storedRecord(t, u.consoleFixture, "titogo").Conversion.Uploads; up != nil { |
| - t.Fatalf("recorded = %+v", up) |
| + if c := storedRecord(t, u.consoleFixture, "titogo").Conversion; c.Uploads != nil || c.PendingUploads != nil { |
| + t.Fatalf("recorded = %+v", c) |
| } |
| u.wantOK(u.enable("https://shop.example.com")) |
| } |
| -// uploadsRecordFailStore fails every write of the store record while armed. On |
| -// a verified, healthy store the only such write an enable makes is the one |
| -// after PutUploads. |
| +// Fable 7: the default origins are held to the same cap as named ones. |
| +func TestUploadsDefaultOriginsAreCapped(t *testing.T) { |
| + u := newUploads(t, "code-uploads-default-cap") |
| + for i := range 9 { |
| + u.addRoute(t, registry.Route{Host: "s" + string(rune('a'+i)) + ".shop.example.com", Kind: "instance", |
| + Status: "ready", App: "titogo", Account: u.sqid, Platform: true}) |
| + } |
| + before, _ := rawStoreRecord(t, u.consoleFixture) |
| + u.wantRefused(u.enable(), http.StatusBadRequest, "too_many_origins", "uploads accept at most 8 origins") |
| + if after, _ := rawStoreRecord(t, u.consoleFixture); !bytes.Equal(before, after) || len(u.buckets.Calls) != 0 { |
| + t.Fatalf("a capped enable touched the store: %v", u.buckets.Calls) |
| + } |
| +} |
| + |
| +// uploadsHookBuckets is the fake with PutUploads replaceable, for the |
| +// write-ahead tests. |
| +type uploadsHookBuckets struct { |
| + *storecfg.Fake |
| + put func(ctx context.Context, bucket string, origins []string) error |
| +} |
| + |
| +func (b *uploadsHookBuckets) PutUploads(ctx context.Context, bucket string, origins []string) error { |
| + if b.put != nil { |
| + return b.put(ctx, bucket, origins) |
| + } |
| + return b.Fake.PutUploads(ctx, bucket, origins) |
| +} |
| + |
| +// uploadsHookProvisioner runs a hook before EnsureUser: the convergence step. |
| +type uploadsHookProvisioner struct { |
| + objstore.Provisioner |
| + beforeEnsureUser func() |
| +} |
| + |
| +func (p *uploadsHookProvisioner) EnsureUser(ctx context.Context, name, path, bucketARN string, deny *objstore.DenyTag, denyWrites bool) (string, error) { |
| + if p.beforeEnsureUser != nil { |
| + p.beforeEnsureUser() |
| + } |
| + return p.Provisioner.EnsureUser(ctx, name, path, bucketARN, deny, denyWrites) |
| +} |
| + |
| +// uploadsRecordFailStore fails the store record's writes while armed. |
| type uploadsRecordFailStore struct { |
| release.Store |
| key string |
| @@ -534,39 +585,221 @@ func (s *uploadsRecordFailStore) Put(ctx context.Context, key string, body []byt |
| return s.Store.Put(ctx, key, body, ifMatch) |
| } |
| -// A record write that fails after PutUploads puts the bucket back to what |
| -// the record still says, so the platform's own rules never stand |
| -// unrecorded (which every later check would read as foreign). |
| -func TestUploadsRecordFailurePutsTheBucketBack(t *testing.T) { |
| - u := newUploads(t, "code-uploads-recordfail") |
| +// hooked is newUploads with the hookable buckets and a record store that |
| +// can be made to fail, the store verified first so an enable's only record |
| +// writes are its own. |
| +func hooked(t *testing.T, code string) (*uploadsFixture, *uploadsHookBuckets, *uploadsRecordFailStore) { |
| + t.Helper() |
| + u := newUploads(t, code) |
| if _, code, _, err := eligible(t, u.consoleFixture); err != nil || code != "" { |
| t.Fatalf("verify: %q %v", code, err) |
| } |
| + hb := &uploadsHookBuckets{Fake: u.buckets} |
| + u.srv.cfg.StoreBuckets = hb |
| fs := &uploadsRecordFailStore{Store: u.srv.cfg.Releases, key: objstore.Key(u.sqid, "titogo")} |
| u.srv.cfg.Releases = fs |
| + return u, hb, fs |
| +} |
| - // Nothing recorded before: the rules are removed again. |
| - fs.armed.Store(true) |
| - if r := u.enable("https://shop.example.com"); r.status != http.StatusInternalServerError { |
| - t.Fatalf("status = %d %s", r.status, r.raw) |
| +func (u *uploadsFixture) conversion() *objstore.Conversion { |
| + u.t.Helper() |
| + return storedRecord(u.t, u.consoleFixture, "titogo").Conversion |
| +} |
| + |
| +// wantConverged: uploads are on with origins, the bucket holds exactly |
| +// their rules, and nothing is pending. |
| +func (u *uploadsFixture) wantConverged(origins ...string) { |
| + u.t.Helper() |
| + f := u.facts() |
| + if !bytes.Equal(f.CORS, storecfg.UploadsCORS(origins)) || !bytes.Equal(f.Lifecycle, storecfg.UploadsLifecycle()) { |
| + u.t.Fatalf("bucket = %s %s", f.CORS, f.Lifecycle) |
| } |
| - if f := u.facts(); f.CORS != nil || f.Lifecycle != nil { |
| - t.Fatalf("unrecorded rules left: %s %s", f.CORS, f.Lifecycle) |
| + c := u.conversion() |
| + if c.PendingUploads != nil || c.Uploads == nil || c.Uploads.CORSHash != storecfg.Hash(f.CORS) || c.Uploads.LifecycleHash != storecfg.Hash(f.Lifecycle) { |
| + u.t.Fatalf("record = %+v / %+v", c.Uploads, c.PendingUploads) |
| + } |
| + if s := u.status(); !s.ans.Enabled || !s.ans.BucketMatches || !slices.Equal(s.ans.Origins, origins) { |
| + u.t.Fatalf("status = %s", s.raw) |
| + } |
| +} |
| + |
| +// Fix round 1, ruling 1: a write-ahead intent. Whatever an interrupted |
| +// write leaves on the bucket is the platform's own to the next call. |
| +func TestUploadsWriteAheadIntentHeals(t *testing.T) { |
| + a := []string{"https://shop.example.com"} |
| + b := []string{"https://www.shop.example.com"} |
| + c := []string{"https://cdn.shop.example.com"} |
| + partial := func(u *uploadsFixture) func(context.Context, string, []string) error { |
| + return func(_ context.Context, bucket string, origins []string) error { |
| + u.setFacts(func(f *storecfg.Facts) { f.CORS = storecfg.UploadsCORS(origins) }) |
| + return errors.New("lifecycle write failed") |
| + } |
| + } |
| + landsThenErrs := func(hb *uploadsHookBuckets) func(context.Context, string, []string) error { |
| + return func(ctx context.Context, bucket string, origins []string) error { |
| + if err := hb.Fake.PutUploads(ctx, bucket, origins); err != nil { |
| + return err |
| + } |
| + return errors.New("timed out after it landed") |
| + } |
| } |
| - fs.armed.Store(false) |
| + |
| + t.Run("the first rule lands and the second fails", func(t *testing.T) { |
| + u, hb, _ := hooked(t, "code-uploads-wal-partial") |
| + hb.put = partial(u) |
| + if r := u.enable(a...); r.status != http.StatusInternalServerError { |
| + t.Fatalf("status = %d %s", r.status, r.raw) |
| + } |
| + if c := u.conversion(); c.Uploads != nil || c.PendingUploads == nil { |
| + t.Fatalf("record after the failure = %+v", c) |
| + } |
| + hb.put = nil |
| + u.wantOK(u.enable(a...)) |
| + u.wantConverged(a...) |
| + }) |
| + t.Run("the write lands and then returns an error", func(t *testing.T) { |
| + u, hb, _ := hooked(t, "code-uploads-wal-lands") |
| + u.wantOK(u.enable(a...)) |
| + hb.put = landsThenErrs(hb) |
| + if r := u.enable(b...); r.status != http.StatusInternalServerError { |
| + t.Fatalf("status = %d %s", r.status, r.raw) |
| + } |
| + // The bucket holds b's rules; the record still says a, b pending. |
| + if s := u.status(); !s.ans.BucketMatches || !slices.Equal(s.ans.Origins, b) { |
| + t.Fatalf("status = %s", s.raw) |
| + } |
| + hb.put = nil |
| + u.wantOK(u.enable(c...)) |
| + u.wantConverged(c...) |
| + }) |
| + t.Run("a crash between the bucket writes and the final record write", func(t *testing.T) { |
| + u, hb, fs := hooked(t, "code-uploads-wal-crash") |
| + u.wantOK(u.enable(a...)) |
| + hb.put = func(ctx context.Context, bucket string, origins []string) error { |
| + err := hb.Fake.PutUploads(ctx, bucket, origins) |
| + fs.armed.Store(true) // the record write that follows never lands |
| + return err |
| + } |
| + if r := u.enable(b...); r.status != http.StatusInternalServerError { |
| + t.Fatalf("status = %d %s", r.status, r.raw) |
| + } |
| + fs.armed.Store(false) |
| + if cv := u.conversion(); cv.Uploads == nil || cv.Uploads.CORSHash != storecfg.Hash(storecfg.UploadsCORS(a)) || |
| + cv.PendingUploads == nil || cv.PendingUploads.CORSHash != storecfg.Hash(storecfg.UploadsCORS(b)) { |
| + t.Fatalf("record after the crash = %+v / %+v", cv.Uploads, cv.PendingUploads) |
| + } |
| + // The next update writes its own intent over b's, and then fails |
| + // before touching the bucket: b's landed rule must have become the |
| + // recorded one, or the call after would call it foreign. |
| + hb.put = func(context.Context, string, []string) error { return errors.New("down") } |
| + if r := u.enable(c...); r.status != http.StatusInternalServerError { |
| + t.Fatalf("status = %d %s", r.status, r.raw) |
| + } |
| + if cv := u.conversion(); cv.Uploads == nil || cv.Uploads.CORSHash != storecfg.Hash(storecfg.UploadsCORS(b)) { |
| + t.Fatalf("b's landed rules were not promoted: %+v", cv.Uploads) |
| + } |
| + hb.put = nil |
| + u.wantOK(u.enable(c...)) |
| + u.wantConverged(c...) |
| + }) |
| + t.Run("disable after an unconfirmed first enable", func(t *testing.T) { |
| + u, hb, _ := hooked(t, "code-uploads-wal-disable") |
| + hb.put = partial(u) |
| + if r := u.enable(a...); r.status != http.StatusInternalServerError { |
| + t.Fatalf("status = %d %s", r.status, r.raw) |
| + } |
| + if s := u.status(); !s.ans.Enabled || s.ans.BucketMatches { |
| + t.Fatalf("status of a half write = %s", s.raw) |
| + } |
| + u.wantOK(u.disable()) |
| + if f := u.facts(); f.CORS != nil || f.Lifecycle != nil { |
| + t.Fatalf("rules left: %s %s", f.CORS, f.Lifecycle) |
| + } |
| + if cv := u.conversion(); cv.Uploads != nil || cv.PendingUploads != nil { |
| + t.Fatalf("record = %+v", cv) |
| + } |
| + }) |
| + t.Run("a store verified again accepts the pending rules", func(t *testing.T) { |
| + u, hb, _ := hooked(t, "code-uploads-wal-reverify") |
| + hb.put = landsThenErrs(hb) |
| + if r := u.enable(a...); r.status != http.StatusInternalServerError { |
| + t.Fatalf("status = %d %s", r.status, r.raw) |
| + } |
| + hb.put = nil |
| + // The bucket loses its incarnation tag, so the next use verifies it |
| + // from its settings: the pending rules are the platform's. |
| + delete(u.buckets.Tags[u.bucket], storecfg.IncarnationTag) |
| + if _, code, check, err := eligible(t, u.consoleFixture); err != nil || code != "" { |
| + t.Fatalf("verify with pending rules: %q %q %v", code, check, err) |
| + } |
| + u.wantOK(u.enable(a...)) |
| + u.wantConverged(a...) |
| + }) |
| +} |
| + |
| +// Fix round 1, ruling 2: the bucket is inspected again after the policy |
| +// converges, immediately before the writes. |
| +func TestUploadsInspectsAgainBeforeWriting(t *testing.T) { |
| + u := newUploads(t, "code-uploads-second-look") |
| + u.srv.cfg.StoreProvisioner = &uploadsHookProvisioner{Provisioner: u.prov, beforeEnsureUser: func() { |
| + u.setFacts(func(f *storecfg.Facts) { f.CORS = foreignCORS() }) |
| + }} |
| + u.wantRefused(u.enable("https://shop.example.com"), http.StatusConflict, "store_unverified", uploadsUnverified("cors")) |
| + if n := u.buckets.CallCount("PutUploads"); n != 0 { |
| + t.Fatalf("PutUploads called %d times", n) |
| + } |
| + if !bytes.Equal(u.facts().CORS, foreignCORS()) { |
| + t.Fatal("foreign rule replaced") |
| + } |
| + if c := u.conversion(); c.Uploads != nil || c.PendingUploads != nil { |
| + t.Fatalf("record = %+v", c) |
| + } |
| +} |
| + |
| +// Fix round 1, ruling 3: enable converges the policy only. A store whose |
| +// delivery is incomplete keeps its live key and its config as they are, and |
| +// a seed's mark on the declaration stays. |
| +func TestUploadsConvergesThePolicyOnly(t *testing.T) { |
| + u := newUploads(t, "code-uploads-policy-only") |
| + ctx := context.Background() |
| + rec, etag, err := objstore.Get(ctx, u.rel, u.sqid, "titogo") |
| + if err != nil { |
| + t.Fatal(err) |
| + } |
| + rec.Declared.Seed = "seed-1" |
| + if _, err := objstore.Put(ctx, u.rel, u.sqid, "titogo", rec, etag); err != nil { |
| + t.Fatal(err) |
| + } |
| + var dropped string |
| + for name := range appVars(t, u.consoleFixture, "titogo") { |
| + if strings.HasSuffix(name, "_BUCKET") { |
| + dropped = name |
| + } |
| + } |
| + if dropped == "" { |
| + t.Fatal("no delivered bucket variable") |
| + } |
| + if _, err := appconfig.Apply(ctx, u.rel, u.sqid, "titogo", nil, []string{dropped}); err != nil { |
| + t.Fatal(err) |
| + } |
| + keyID := storedRecord(t, u.consoleFixture, "titogo").Provisioned.KeyID |
| + keys := maps.Clone(u.prov.Users[u.user()].Keys) |
| + vars := appVars(t, u.consoleFixture, "titogo") |
| + u.stalePolicy() |
| + |
| u.wantOK(u.enable("https://shop.example.com")) |
| - // Uploads on before: the recorded rules are put back. |
| - fs.armed.Store(true) |
| - if r := u.enable("https://www.shop.example.com"); r.status != http.StatusInternalServerError { |
| - t.Fatalf("status = %d %s", r.status, r.raw) |
| + after := storedRecord(t, u.consoleFixture, "titogo") |
| + if after.Provisioned.KeyID != keyID || !maps.Equal(u.prov.Users[u.user()].Keys, keys) { |
| + t.Fatalf("key changed: %s -> %s, keys %v -> %v", keyID, after.Provisioned.KeyID, keys, u.prov.Users[u.user()].Keys) |
| } |
| - fs.armed.Store(false) |
| - if got := u.facts().CORS; !bytes.Equal(got, storecfg.UploadsCORS([]string{"https://shop.example.com"})) { |
| - t.Fatalf("CORS = %s, want the recorded rule back", got) |
| + if got := appVars(t, u.consoleFixture, "titogo"); !maps.Equal(got, vars) { |
| + t.Fatalf("delivered config changed: %v -> %v", vars, got) |
| } |
| - if s := u.status(); !s.ans.BucketMatches { |
| - t.Fatalf("status after a failed update = %s", s.raw) |
| + if after.Declared.Seed != "seed-1" { |
| + t.Fatalf("seed mark = %q", after.Declared.Seed) |
| + } |
| + if p := u.prov.PolicyFor(u.user()); !strings.Contains(p, "s3:AbortMultipartUpload") { |
| + t.Fatalf("policy not converged: %q", p) |
| } |
| - u.wantOK(u.enable("https://www.shop.example.com")) |
| } |
diff --git a/internal/console/media_copy.go b/internal/console/media_copy.go| index 80bb66ebd..a8e810648 100644 |
| --- a/internal/console/media_copy.go |
| +++ b/internal/console/media_copy.go |
| @@ -42,6 +42,9 @@ var mediaCopy = map[string]string{ |
| "uploads.bad_origin": "%q is not an origin uploads accept. use https:// and a host, or http://localhost:<port>", |
| "uploads.too_many_origins": "uploads accept at most 8 origins", |
| "uploads.no_hosts": "this app has no ready platform hostname yet. name the origins with --origin", |
| + // Audit rows (pending Luna pass): enable's origins, comma separated. |
| + "audit.uploads_enable": "turned on browser uploads from %s (cli)", |
| + "audit.uploads_disable": "turned off browser uploads (cli)", |
| // Store checks: one fills media.store_unverified. |
| "media.check.name": "its bucket is not named the way this deployment names buckets", |
diff --git a/internal/console/mediastore.go b/internal/console/mediastore.go| index 9d6e1632c..367878862 100644 |
| --- a/internal/console/mediastore.go |
| +++ b/internal/console/mediastore.go |
| @@ -88,14 +88,11 @@ func (s *Server) mediaStoreCheck(ctx context.Context, sqid, app string) (rec *ob |
| Account: s.cfg.StoreAccountID, |
| Region: rec.Provisioned.Region, |
| } |
| - var uploads *objstore.Uploads |
| + var uploads, pending *objstore.Uploads |
| if rec.Conversion != nil { |
| - uploads = rec.Conversion.Uploads |
| + uploads, pending = rec.Conversion.Uploads, rec.Conversion.PendingUploads |
| } |
| - if uploads != nil { |
| - want.LifecycleHash, want.CORSHash = uploads.LifecycleHash, uploads.CORSHash |
| - } |
| - if failed := storecfg.Verify(facts, want); failed != "" { |
| + if failed := verifyUploadsEither(facts, want, uploads, pending); failed != "" { |
| return rec, mediaCodeStoreUnverified, failed, nil |
| } |
| inc, err := storecfg.NewIncarnation() |
| @@ -110,13 +107,46 @@ func (s *Server) mediaStoreCheck(ctx context.Context, sqid, app string) (rec *ob |
| return nil, "", "", fmt.Errorf("console: media store %s/%s: %w", sqid, app, err) |
| } |
| now := s.now().UTC() |
| - rec.Conversion = &objstore.Conversion{Incarnation: inc, VerifiedAt: &now, Uploads: uploads} |
| + rec.Conversion = &objstore.Conversion{Incarnation: inc, VerifiedAt: &now, Uploads: uploads, PendingUploads: pending} |
| if _, err := objstore.PutIn(ctx, s.cfg.Releases, sqid, app, "", rec, etag); err != nil { |
| return nil, "", "", fmt.Errorf("console: media store %s/%s: record verification: %w", sqid, app, err) |
| } |
| return rec, "", "", nil |
| } |
| +// verifyUploadsEither is storecfg.Verify with the uploads rules the record |
| +// accounts for: each of the bucket's lifecycle and CORS configurations may |
| +// carry the recorded hash or the pending one (a write-ahead intent from |
| +// apistoreuploads.go), independently, since a write may have landed one |
| +// rule and not the other. It answers Verify's first failure with the |
| +// recorded hashes when no pairing passes. |
| +func verifyUploadsEither(f storecfg.Facts, want storecfg.Want, uploads, pending *objstore.Uploads) string { |
| + var lifecycle, cors []string |
| + for _, u := range []*objstore.Uploads{uploads, pending} { |
| + if u != nil { |
| + lifecycle, cors = append(lifecycle, u.LifecycleHash), append(cors, u.CORSHash) |
| + } |
| + } |
| + if len(lifecycle) == 0 { |
| + return storecfg.Verify(f, want) |
| + } |
| + first := "" |
| + for _, l := range lifecycle { |
| + for _, c := range cors { |
| + w := want |
| + w.LifecycleHash, w.CORSHash = l, c |
| + failed := storecfg.Verify(f, w) |
| + if failed == "" { |
| + return "" |
| + } |
| + if first == "" { |
| + first = failed |
| + } |
| + } |
| + } |
| + return first |
| +} |
| + |
| // mediaStoreFacts is mediaStoreCheck in the shape dispatch re-checks |
| // (mediajobs.StoreGuard.Current): the console's StoreGuard answers Current |
| // with this, under the same walk lock, outside any transaction. A store |
diff --git a/internal/objstore/objstore.go b/internal/objstore/objstore.go| index 8e1a3c56a..8d1b5dc38 100644 |
| --- a/internal/objstore/objstore.go |
| +++ b/internal/objstore/objstore.go |
| @@ -185,10 +185,18 @@ type Record struct { |
| // back the same value, so a bucket made again under the same name, which |
| // carries no tag, is verified afresh and never inherits an old store's |
| // media jobs, whatever state this record was left in. |
| +// |
| +// PendingUploads is the uploads configuration the console is about to write |
| +// (write-ahead intent): recorded before the bucket is written, promoted to |
| +// Uploads once both rules are written. While it stands, a rule on the bucket |
| +// with its hash is the platform's own, so a write that crashed, landed |
| +// halfway, or landed and then reported an error is never mistaken for a |
| +// foreign rule. Additive, like the rest of the block. |
| type Conversion struct { |
| - Incarnation string `json:"incarnation"` |
| - VerifiedAt *time.Time `json:"verified_at,omitempty"` |
| - Uploads *Uploads `json:"uploads,omitempty"` |
| + Incarnation string `json:"incarnation"` |
| + VerifiedAt *time.Time `json:"verified_at,omitempty"` |
| + Uploads *Uploads `json:"uploads,omitempty"` |
| + PendingUploads *Uploads `json:"pending_uploads,omitempty"` |
| } |
| // Uploads records the CORS and lifecycle configuration the platform wrote |
diff --git a/internal/objstore/walk.go b/internal/objstore/walk.go| index f0aa74a42..2d1f97750 100644 |
| --- a/internal/objstore/walk.go |
| +++ b/internal/objstore/walk.go |
| @@ -404,6 +404,45 @@ func claimRawGrantIn(ctx context.Context, s release.Store, p Provisioner, d Depl |
| return rec, nil |
| } |
| +// claimRawConvergePolicyIn rewrites the store user's inline policy from the |
| +// current record, and does nothing else (ErrNotProvisioned for a store the |
| +// walk never provisioned): step 2 of the grant walk alone. It |
| +// runs EnsureUser exactly as the walk does (the user, if somehow absent, is |
| +// created again under the boundary; the policy is recomputed from the |
| +// record's Scanning.Enforce and WritesDenied and written wholesale), with |
| +// the bucket the grant chose. It never reaps or mints a key, never touches |
| +// delivered config, never writes the record (so no seed mark moves), and |
| +// never creates a bucket. That makes it the convergence for a door that |
| +// needs the policy current and must leave a member's live credential |
| +// alone, whatever state the delivery is in (`carlos store uploads enable`: |
| +// the multipart actions storePolicyJSON grants every store). |
| +func claimRawConvergePolicyIn(ctx context.Context, s release.Store, p Provisioner, acct, app, env string) (*Record, error) { |
| + rec, _, err := GetIn(ctx, s, acct, app, env) |
| + if err != nil { |
| + return nil, err |
| + } |
| + if rec == nil || rec.Grant == nil || rec.Provisioned == nil { |
| + return nil, ErrNotProvisioned |
| + } |
| + bucket := rec.Grant.Bucket |
| + if bucket == "" || bucket != rec.Provisioned.Bucket || !ValidBucketName(bucket) { |
| + return nil, fmt.Errorf("objstore: store %s/%s names bucket %q in its grant and %q as provisioned; run the grant to repair it", |
| + acct, app, rec.Grant.Bucket, rec.Provisioned.Bucket) |
| + } |
| + user := UserNameIn(acct, app, env) |
| + if !ValidUserName(user) { |
| + return nil, fmt.Errorf("objstore: IAM user name %q is %d characters, over AWS's %d", user, len(user), MaxIAMUserName) |
| + } |
| + var deny *DenyTag |
| + if rec.Scanning != nil { |
| + deny = rec.Scanning.Enforce |
| + } |
| + if _, err := p.EnsureUser(ctx, user, UserPath, "arn:aws:s3:::"+bucket, deny, rec.WritesDenied != nil); err != nil { |
| + return nil, fmt.Errorf("objstore: ensure user %s: %w", user, err) |
| + } |
| + return rec, nil |
| +} |
| + |
| // Rotate mints a fresh key, delivers it, and leaves the OLD key active (§8). |
| // That overlap is the whole point: adoption swaps a symlink, it does not |
| // restart processes, so at the instant the new credentials land there are |
| @@ -947,6 +986,16 @@ func GrantInFor(ctx context.Context, s release.Store, p Provisioner, d Deploymen |
| }) |
| return |
| } |
| + |
| +// ConvergePolicyIn is claimRawConvergePolicyIn inside the app mutation, as |
| +// every walk is. |
| +func ConvergePolicyIn(ctx context.Context, s release.Store, p Provisioner, acct, app, env string) (claimResult0 *Record, claimResult1 error) { |
| + claimResult1 = release.WithAppMutation(ctx, s, acct, app, "objstore.ConvergePolicyIn", func(claimContext context.Context) error { |
| + claimResult0, claimResult1 = claimRawConvergePolicyIn(claimContext, s, p, acct, app, env) |
| + return claimResult1 |
| + }) |
| + return |
| +} |
| func Rotate(ctx context.Context, s release.Store, p Provisioner, seal appconfig.Sealer, acct, app string, now time.Time) (claimResult0 *Record, claimResult1 error) { |
| claimResult1 = release.WithAppMutation(ctx, s, acct, app, "objstore.Rotate", func(claimContext context.Context) error { |
| claimResult0, claimResult1 = claimRawRotate(claimContext, s, p, seal, acct, app, now) |
diff --git a/internal/objstore/walk_test.go b/internal/objstore/walk_test.go| index 2bf057e83..f05c7265f 100644 |
| --- a/internal/objstore/walk_test.go |
| +++ b/internal/objstore/walk_test.go |
| @@ -1579,3 +1579,53 @@ func TestGrantRefusesRetryAgainstAnotherProvision(t *testing.T) { |
| t.Fatalf("the competing grant was clobbered: %+v, %v", stored.Provisioned, err) |
| } |
| } |
| + |
| +// ConvergePolicyIn is the grant walk's policy step alone: the user's policy |
| +// is rewritten from the record, and no key, no delivered variable and no |
| +// byte of the record moves, even where the full walk would repair (here: a |
| +// delivered variable is missing, so Grant would reap and mint). |
| +func TestConvergePolicyInWritesThePolicyOnly(t *testing.T) { |
| + ctx := context.Background() |
| + s := release.NewDirStore(t.TempDir()) |
| + _, pub := testSealKeypair(t) |
| + p := NewMemProvisioner("eu-west-1") |
| + if _, err := ConvergePolicyIn(ctx, s, p, "bab", "titogo", ""); !errors.Is(err, ErrNotProvisioned) { |
| + t.Fatalf("no store: %v, want ErrNotProvisioned", err) |
| + } |
| + rotateFixture(t, s, pub, p) |
| + if _, err := appconfig.Apply(ctx, s, "bab", "titogo", nil, []string{"TITO_S3_BUCKET"}); err != nil { |
| + t.Fatal(err) |
| + } |
| + user := UserName("bab", "titogo") |
| + u := p.Users[user] |
| + u.Policy = "stale" |
| + p.Users[user] = u |
| + keys := len(p.Users[user].Keys) |
| + before, etag, _ := s.Get(ctx, Key("bab", "titogo")) |
| + cfgBefore, cfgEtag, _ := s.Get(ctx, appconfig.Key("bab", "titogo")) |
| + |
| + if _, err := ConvergePolicyIn(ctx, s, p, "bab", "titogo", ""); err != nil { |
| + t.Fatal(err) |
| + } |
| + if got := p.PolicyFor(user); !strings.Contains(got, "s3:AbortMultipartUpload") { |
| + t.Fatalf("policy = %q", got) |
| + } |
| + if len(p.Users[user].Keys) != keys { |
| + t.Fatalf("keys %d -> %d", keys, len(p.Users[user].Keys)) |
| + } |
| + after, etag2, _ := s.Get(ctx, Key("bab", "titogo")) |
| + cfgAfter, cfgEtag2, _ := s.Get(ctx, appconfig.Key("bab", "titogo")) |
| + if string(before) != string(after) || etag != etag2 || string(cfgBefore) != string(cfgAfter) || cfgEtag != cfgEtag2 { |
| + t.Fatal("convergence wrote the record or the config") |
| + } |
| + // The write deny and the enforcement deny follow the record, as in the walk. |
| + if _, err := SetWritesDenied(ctx, s, "bab", "titogo", "", &WritesDenied{Reason: "plan storage", At: time.Now().UTC()}); err != nil { |
| + t.Fatal(err) |
| + } |
| + if _, err := ConvergePolicyIn(ctx, s, p, "bab", "titogo", ""); err != nil { |
| + t.Fatal(err) |
| + } |
| + if writeDenyOf(t, p.PolicyFor(user)) == nil { |
| + t.Fatalf("write deny not converged:\n%s", p.PolicyFor(user)) |
| + } |
| +} |
diff --git a/store.go b/store.go| index a3a0e384d..b5d63e179 100644 |
| --- a/store.go |
| +++ b/store.go |
| @@ -46,7 +46,7 @@ import ( |
| "github.com/carlosframework/platform/internal/objstore" |
| ) |
| -const storeUsage = `usage: carlos store <create|status|apply|approvals|approve|decline|grant|rotate|scan> [flags] |
| +var storeUsage = `usage: carlos store <create|status|apply|approvals|approve|decline|grant|rotate|scan|uploads> [flags] |
| create --app <a> [--env-prefix <PREFIX>] [--environment <e>] |
| @@ -86,11 +86,7 @@ const storeUsage = `usage: carlos store <create|status|apply|approvals|approve|d |
| the sub-verbs. A clean result on a client-encrypted |
| store means nothing, and the CLI says so rather |
| than claiming coverage it cannot have. |
| - uploads <enable|status|disable> --app <a> [--origin <o>]... |
| - Lets browsers on the origins you name upload large |
| - files in parts straight to the app's store. With no |
| - --origin, it uses and prints the app's hostnames |
| - today. disable removes the rules again. |
| +` + storeUploadsText("cli.uploads.store_usage") + ` |
| --account <sqid|name> account the app belongs to (default: your only |
| account, or the configured/chosen one) — |
diff --git a/store_test.go b/store_test.go| index 72e92216e..d63dcc484 100644 |
| --- a/store_test.go |
| +++ b/store_test.go |
| @@ -830,7 +830,7 @@ func TestStoreVerbDispatchAndRefusals(t *testing.T) { |
| if err == nil { |
| t.Fatalf("carlos %v exited 0:\n%s", args, out) |
| } |
| - if !strings.Contains(out, "usage: carlos store <create|status|apply|approvals|approve|decline|grant|rotate|scan>") { |
| + if !strings.Contains(out, "usage: carlos store <create|status|apply|approvals|approve|decline|grant|rotate|scan|uploads>") { |
| t.Fatalf("carlos %v = %q, want the store usage block", args, out) |
| } |
| } |
diff --git a/store_uploads.go b/store_uploads.go| index 8c2f06a19..e6e52dc30 100644 |
| --- a/store_uploads.go |
| +++ b/store_uploads.go |
| @@ -19,16 +19,39 @@ import ( |
| "github.com/carlosframework/platform/internal/clireg" |
| ) |
| -const storeUploadsUsage = `usage: carlos store uploads <enable|status|disable> --app <a> [flags] |
| - |
| - enable --app <a> [--origin <o>]... |
| - status --app <a> |
| - disable --app <a> |
| +// storeUploadsCopy is this verb's text by copy deck key |
| +// (docs/superpowers/notes/media-conversion-copy-deck.md, `carlos store |
| +// uploads`). The rows marked pending there await the Luna pass; apply its |
| +// result here verbatim. |
| +var storeUploadsCopy = map[string]string{ |
| + "cli.uploads.usage": "usage: carlos store uploads <enable|status|disable> --app <a> [flags]", |
| + "cli.uploads.usage_enable": " enable --app <a> [--origin <o>]...", |
| + "cli.uploads.usage_status": " status --app <a>", |
| + "cli.uploads.usage_disable": " disable --app <a>", |
| + "cli.uploads.usage_verb": "usage: carlos store uploads %s --app <a> [--account <sqid-or-name>] [--console <origin>]", |
| + "cli.uploads.flags": "Flags: --account/--account-id to disambiguate, --console to pick a console.", |
| + "cli.uploads.flag_app": "app whose store browsers upload to", |
| + "cli.uploads.flag_origin": "an origin browsers upload from: https:// and a host, or http://localhost:<port>. Repeat for more, at most 8", |
| + "cli.uploads.unreadable": "store uploads: unreadable response: %w", |
| + "cli.uploads.store_usage": " uploads <enable|status|disable> --app <a> [--origin <o>]...\n" + |
| + " Lets browsers on the origins you name upload large\n" + |
| + " files in parts straight to the app's store. With no\n" + |
| + " --origin, it uses and prints the app's hostnames\n" + |
| + " today. disable removes the rules again.", |
| + // docs.cli.store_uploads, approved. |
| + "docs.cli.store_uploads": "Lets browsers on the origins you name upload large files in parts straight to the app's store. With no --origin, it uses and prints the app's hostnames today. disable removes the rules again.", |
| +} |
| -Lets browsers on the origins you name upload large files in parts straight to the app's store. With no --origin, it uses and prints the app's hostnames today. disable removes the rules again. |
| +// storeUploadsText is the deck's row for key. |
| +func storeUploadsText(key string) string { return storeUploadsCopy[key] } |
| -Flags: --account/--account-id to disambiguate, --console to pick a console. |
| -` |
| +// storeUploadsUsage is the uploads node's usage, from the deck's rows. |
| +var storeUploadsUsage = storeUploadsText("cli.uploads.usage") + "\n\n" + |
| + storeUploadsText("cli.uploads.usage_enable") + "\n" + |
| + storeUploadsText("cli.uploads.usage_status") + "\n" + |
| + storeUploadsText("cli.uploads.usage_disable") + "\n\n" + |
| + storeUploadsText("docs.cli.store_uploads") + "\n\n" + |
| + storeUploadsText("cli.uploads.flags") + "\n" |
| // The deck's lines for `carlos store uploads` (cli.uploads.*). |
| const ( |
| @@ -62,10 +85,10 @@ func storeUploadsCommand() *clireg.Node { |
| func runStoreUploads(args []string, verb string) { |
| fs := flag.NewFlagSet("store uploads "+verb, flag.ExitOnError) |
| - app := appFlag(fs, "app whose store to "+verb+" browser uploads for") |
| + app := appFlag(fs, storeUploadsText("cli.uploads.flag_app")) |
| var origins multiFlag |
| if verb == "enable" { |
| - fs.Var(&origins, "origin", "an origin browsers upload from: https:// and a host, or http://localhost:<port>. Repeat for more, at most 8") |
| + fs.Var(&origins, "origin", storeUploadsText("cli.uploads.flag_origin")) |
| } |
| acctRaw, acctIDRaw, _ := accountFlags(fs) |
| consoleFlag := consoleOption(fs, "console origin to act through (API mode only; default: the only logged-in one)") |
| @@ -73,7 +96,7 @@ func runStoreUploads(args []string, verb string) { |
| fs.Parse(args) |
| name := strings.TrimSpace(*app) |
| - usage := "usage: carlos store uploads " + verb + " --app <a> [--account <sqid-or-name>] [--console <origin>]" |
| + usage := fmt.Sprintf(storeUploadsText("cli.uploads.usage_verb"), verb) |
| if name != "" { |
| if err := validAppName(name); err != nil { |
| log.Fatalf("store uploads %s: %v", verb, err) |
| @@ -89,7 +112,9 @@ func runStoreUploads(args []string, verb string) { |
| } |
| // runStoreUploadsWith calls the door for verb and prints its answer: |
| -// enable and status the same block, disable `uploads off`. |
| +// enable and status the same block, disable `uploads off`. What is printed |
| +// is always the door's answer; a refused disable (a rule this platform did |
| +// not write is on the bucket) is the door's error, and prints nothing. |
| func runStoreUploadsWith(ctx context.Context, s *apiSession, a apiAcct, app, verb string, origins []string, w io.Writer) error { |
| var res apiUploadsReply |
| var err error |
| @@ -110,9 +135,6 @@ func runStoreUploadsWith(ctx context.Context, s *apiSession, a apiAcct, app, ver |
| if err != nil { |
| return err |
| } |
| - if verb == "disable" { |
| - res.Enabled = false |
| - } |
| printStoreUploads(w, res, verb == "enable" && len(origins) == 0) |
| return nil |
| } |
diff --git a/store_uploads_test.go b/store_uploads_test.go| index 902dbdf7d..2d7bc7987 100644 |
| --- a/store_uploads_test.go |
| +++ b/store_uploads_test.go |
| @@ -95,3 +95,34 @@ func TestStoreUploadsRefusalIsTheConsolesSentence(t *testing.T) { |
| t.Fatalf("err = %v, out %q", err, out.String()) |
| } |
| } |
| + |
| +// A refused disable (a rule this platform did not write is on the bucket) |
| +// never prints `uploads off`: the door did not disable anything. |
| +func TestStoreUploadsRefusedDisablePrintsNothing(t *testing.T) { |
| + const msg = "this store cannot be used for conversion or browser uploads: its bucket has a CORS rule this platform did not write. ask this deployment's operator to fix that, then try again" |
| + ts := httptest.NewServer(http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) { |
| + w.Header().Set("Content-Type", "application/json") |
| + w.WriteHeader(http.StatusConflict) |
| + json.NewEncoder(w).Encode(map[string]string{"code": "store_unverified", "error": msg}) |
| + })) |
| + defer ts.Close() |
| + var out bytes.Buffer |
| + err := runStoreUploadsWith(context.Background(), newTestSession(ts.URL), apiAcct{Seg: "bab"}, "shop", "disable", nil, &out) |
| + if err == nil || err.Error() != msg || out.Len() != 0 { |
| + t.Fatalf("err = %v, out %q", err, out.String()) |
| + } |
| +} |
| + |
| +// Every text the verb prints or offers comes from a deck row. |
| +func TestStoreUploadsCopyRowsExist(t *testing.T) { |
| + for _, key := range []string{"cli.uploads.usage", "cli.uploads.usage_enable", "cli.uploads.usage_status", |
| + "cli.uploads.usage_disable", "cli.uploads.usage_verb", "cli.uploads.flags", "cli.uploads.flag_app", |
| + "cli.uploads.flag_origin", "cli.uploads.unreadable", "cli.uploads.store_usage", "docs.cli.store_uploads"} { |
| + if storeUploadsText(key) == "" { |
| + t.Errorf("no text for %s", key) |
| + } |
| + } |
| + if !strings.Contains(storeUsage, storeUploadsText("cli.uploads.store_usage")) { |
| + t.Fatal("carlos store's usage lacks the uploads entry") |
| + } |
| +} |