carlos / platform Public

store: self-serve object storage from the plan, scanning forced where required

Summary

A plan with storage_self_serve now lets the member's own carlos store create provision the app's store (grant source plan); until now the flag was only printed and every account needed an operator's approval, paid plans included. Where the plan also sets storage_scan_required, the provision door refuses a store it could not scan (an environment store, no engine, scanning switched off, a client-encrypted attestation) and turns scanning and enforcement on as the store is made. A plan-scanned store cannot later be attested client-encrypted. Sponsored rows and per-instance stores still need an approval; an approval keeps its own path. New member-facing sentences are copy-pending placeholders until Paul's review.
Agent notes
forceStoreScanning does scan request + grant + enforce on in that order under the provision door's account lock; re-running create resumes it. Store reply gains self_serve (additive); old CLIs read the entitlement only and keep telling self-serve members to apply.
claude agent, operated by paul@keymail.dev e3e653e8e067a588b7d78b292ccf2d316fea834d parent 8ea79a4
11 files changed, +515 −13
  • apimode.go +4 −0
  • internal/console/apiscan.go +16 −0
  • internal/console/apistore.go +10 −0
  • internal/console/apistore_provision.go +31 −7
  • internal/console/storepage.go +11 −0
  • internal/console/storeselfserve.go +223 −0
  • internal/console/storeselfserve_test.go +176 −0
  • internal/objstore/objstore.go +5 −0
  • internal/objstore/walk.go +1 −1
  • store.go +11 −5
  • store_selfserve_test.go +27 −0

CI failed — run details

diff --git a/apimode.go b/apimode.go
index 44bbafd5b..e2e2a35b2 100644
--- a/apimode.go
+++ b/apimode.go
@@ -2154,6 +2154,10 @@ type apiStoreReply struct {
// exactly as it always did.
Scanning *apiScanBlock `json:"scanning,omitempty"`
Entitlement *objstore.Entitlement `json:"entitlement"`
+ // SelfServe says the account's plan lets `carlos store create`
+ // provision the store with no operator approval (#1076). An older
+ // console never sends it, which reads as false: the approval alone.
+ SelfServe bool `json:"self_serve,omitempty"`
// Size is the bucket's size from the console's daily storage sweep, nil
// before a sweep has measured it (and from an older console).
Size *apiStoreSize `json:"size"`
diff --git a/internal/console/apiscan.go b/internal/console/apiscan.go
index c64aa339c..d732fd87c 100644
--- a/internal/console/apiscan.go
+++ b/internal/console/apiscan.go
@@ -284,6 +284,18 @@ func (s *Server) handleAPIScanRequest(w http.ResponseWriter, r *http.Request) {
defer cancel()
rec, err := s.writeScanRecord(ctx, acct, app, func(rec *objstore.Record) error {
+ // A store the plan made and requires scanned (#1076) cannot be
+ // attested client-encrypted: that would leave the plan's scanning
+ // nothing it can read.
+ if *req.Encrypted {
+ required, err := s.storeScanRequiredFor(acct, rec)
+ if err != nil {
+ return err
+ }
+ if required {
+ return errScanRequiredEncrypted
+ }
+ }
if rec.Scanning == nil {
rec.Scanning = &objstore.ScanBlock{}
}
@@ -292,6 +304,10 @@ func (s *Server) handleAPIScanRequest(w http.ResponseWriter, r *http.Request) {
}
return nil
})
+ if errors.Is(err, errScanRequiredEncrypted) {
+ jsonError(w, http.StatusConflict, copyPending("store.scan_required.encrypted"))
+ return
+ }
if errors.Is(err, objstore.ErrNotDeclared) {
jsonError(w, http.StatusConflict,
"no store is declared for this app — run `carlos store create` first")
diff --git a/internal/console/apistore.go b/internal/console/apistore.go
index ef1df0513..13a6c62d5 100644
--- a/internal/console/apistore.go
+++ b/internal/console/apistore.go
@@ -214,6 +214,12 @@ func (s *Server) storeReply(ctx context.Context, acct *Account, app, env string,
if err != nil {
return nil, err
}
+ selfServe := false
+ if !entitlement.Approved() {
+ if selfServe, _, err = s.storeSelfServe(acct); err != nil {
+ return nil, err
+ }
+ }
prefix := storeEffectivePrefix(rec)
wantEndpoint := rec.Provisioned != nil && rec.Provisioned.Endpoint != ""
bucket, region, endpoint, accessKey, secretKey := objstore.EnvNames(prefix)
@@ -241,6 +247,10 @@ func (s *Server) storeReply(ctx context.Context, acct *Account, app, env string,
// so it is always present and always says which.
"environment": env,
"entitlement": tenantEntitlement(entitlement, ctx),
+ // self_serve: the account's plan lets the member's own `carlos
+ // store create` provision this store with no approval (#1076). A
+ // CLI that predates it reads the entitlement alone, as before.
+ "self_serve": selfServe,
"backend": s.cfg.StoreDeployment.Backend,
"declared": rec.Declared,
"grant": rec.Grant,
diff --git a/internal/console/apistore_provision.go b/internal/console/apistore_provision.go
index 83238d178..65053d3ff 100644
--- a/internal/console/apistore_provision.go
+++ b/internal/console/apistore_provision.go
@@ -10,8 +10,9 @@ import (
"github.com/carlosframework/platform/internal/objstore"
)
-// Provision spends the account approval on one app. Grant owns retry and
-// repair: a grant block without provisioning must still run the walk.
+// Provision spends the account approval, or the plan's self-serve storage
+// (#1076, storeselfserve.go), on one app. Grant owns retry and repair: a
+// grant block without provisioning must still run the walk.
func (s *Server) handleAPIStoreProvision(w http.ResponseWriter, r *http.Request) {
actor, acct, app, ok := s.apiAccountApp(w, r)
if !ok {
@@ -26,7 +27,7 @@ func (s *Server) handleAPIStoreProvision(w http.ResponseWriter, r *http.Request)
}
preCtx, preCancel := context.WithTimeout(r.Context(), storeTimeout)
defer preCancel()
- if _, ok := s.storeProvisionApproval(preCtx, w, acct); !ok {
+ if _, ok := s.storeProvisionAuthority(preCtx, w, acct, actor); !ok {
return
}
p, _ := principalFrom(r.Context())
@@ -56,15 +57,19 @@ func (s *Server) handleAPIStoreProvision(w http.ResponseWriter, r *http.Request)
// holding a spent context and fail its first Get for no reason at all.
ctx, cancel := context.WithTimeout(r.Context(), storeGrantTimeout)
defer cancel()
- // A queued request may have waited while an operator revoked approval.
- // An already-running walk completes; decline does not tear down estate.
- e, ok := s.storeProvisionApproval(ctx, w, acct)
+ // A queued request may have waited while an operator revoked approval,
+ // or the plan changed. An already-running walk completes; decline does
+ // not tear down estate.
+ auth, ok := s.storeProvisionAuthority(ctx, w, acct, actor)
if !ok {
return
}
+ if !s.storeScanPreflight(ctx, w, acct, app, auth, env) {
+ return
+ }
rec, err := claimAppCall(s, ctx, acct, app, "store-provision", func(ctx context.Context) (*objstore.Record, error) {
return objstore.GrantIn(ctx, s.cfg.Releases, s.cfg.StoreProvisioner, s.cfg.StoreDeployment,
- sealer, acct.Sqid, app, env, e.Decision.By, objstore.GrantSourceAccountApproval, "", time.Now())
+ sealer, acct.Sqid, app, env, auth.by, auth.source, "", time.Now())
})
switch {
case errors.Is(err, objstore.ErrNotDeclared):
@@ -80,6 +85,25 @@ func (s *Server) handleAPIStoreProvision(w http.ResponseWriter, r *http.Request)
return
}
s.audit(acct, app, actor, "store-provision", "provisioned a store in bucket "+storeBucketName(rec)+storeEnvSuffix(env)+" (cli)")
+ if auth.scanRequired {
+ // The plan requires the store scanned (#1076). The store exists
+ // now; if scanning does not come on, the member is told and
+ // re-running `carlos store create` resumes here.
+ if err := s.forceStoreScanning(ctx, sealer, acct, app, actor); err != nil {
+ log.Printf("console: api store provision %s/%s: force scanning: %v", acct.Sqid, app, err)
+ s.bumpSerial(ctx)
+ if errors.Is(err, errScanRequiredEncrypted) {
+ jsonError(w, http.StatusConflict, copyPending("store.scan_required.encrypted"))
+ return
+ }
+ jsonError(w, http.StatusBadGateway, copyPending("store.scan_required.unfinished"))
+ return
+ }
+ s.audit(acct, app, actor, "store-scan-grant", "the plan requires scanning: enabled scanning and enforcement on the store")
+ if r, _, err := objstore.GetIn(ctx, s.cfg.Releases, acct.Sqid, app, env); err == nil && r != nil {
+ rec = r
+ }
+ }
s.bumpSerial(ctx)
s.storeWalkReply(ctx, w, acct, app, env, rec)
}
diff --git a/internal/console/storepage.go b/internal/console/storepage.go
index 927c7c011..7e07fc79d 100644
--- a/internal/console/storepage.go
+++ b/internal/console/storepage.go
@@ -57,6 +57,17 @@ func (s *Server) accountStorePane(ctx context.Context, acct *Account) *accountSt
v.State = "Declined"
}
}
+ // A plan with self-serve storage (#1076) needs no application: the
+ // member's own create provisions the store. An approval still wins,
+ // and so does a pending application, which an operator may yet decide.
+ if !v.Unavailable && (e == nil || (!e.Approved() && !e.Pending())) {
+ if selfServe, _, err := s.storeSelfServe(acct); err != nil {
+ log.Printf("console: storage settings %s: plan limits: %v", acct.Sqid, err)
+ } else if selfServe {
+ v.State = copyPending("store.pane.included")
+ v.CanApply = false
+ }
+ }
events, err := s.store.Events(acct.ID, "", activityCap)
if err != nil {
log.Printf("console: account storage events %s: %v", acct.Sqid, err)
diff --git a/internal/console/storeselfserve.go b/internal/console/storeselfserve.go
new file mode 100644
index 000000000..2798f63c2
--- /dev/null
+++ b/internal/console/storeselfserve.go
@@ -0,0 +1,223 @@
+package console
+
+import (
+ "context"
+ "errors"
+ "fmt"
+ "log"
+ "net/http"
+ "time"
+
+ "github.com/carlosframework/platform/internal/appconfig"
+ "github.com/carlosframework/platform/internal/objstore"
+ "github.com/carlosframework/platform/internal/release"
+)
+
+// Self-serve object storage from the plan (#1076). Until then an account
+// provisioned a store only once an operator approved it (store
+// entitlements, #381), whatever its plan's storage_self_serve said; that
+// flag was printed and never read. Now a plan that sets it lets the
+// member's own `carlos store create` provision the app's store, and a plan
+// that also sets storage_scan_required gets virus scanning and its
+// enforcement turned on as the store is made (forceStoreScanning).
+//
+// Two kinds of account keep needing an operator:
+// - a sponsored row (an operator's sponsorship, or the launch's): its
+// limits are "no limits", storage included, and approval was the one
+// gate on that spend. Sponsorship stays a reason to be generous with
+// caps, not a way round the approval queue.
+// - every account, for per-instance stores (instanceprivatestore.go):
+// those are many buckets per app, and stay an operator's call.
+//
+// An approved account keeps the approval path, and its stores are scanned
+// only on request, as before.
+
+// storeAuthority is why a store may be provisioned: who authorised the
+// spend, under which grant source, and whether its scanning is required.
+type storeAuthority struct {
+ by string
+ source string
+ scanRequired bool
+}
+
+// storeSelfServe reports whether acct's plan lets it provision object
+// storage itself, and whether the plan requires the stores scanned. Plans
+// off, the exempt account and a sponsored row are never self-serve.
+func (s *Server) storeSelfServe(acct *Account) (selfServe, scanRequired bool, err error) {
+ l, err := s.EffectiveLimits(acct)
+ if err != nil || l == nil || !l.StorageSelfServe {
+ return false, false, err
+ }
+ if sp, err := s.planSponsored(acct); err != nil || sp {
+ return false, false, err
+ }
+ return true, l.StorageScanRequired, nil
+}
+
+// storeProvisionAuthority answers the provision door: the account's
+// approval when it has one, else its plan's self-serve storage, else the
+// existing refusal. actor is the member asking.
+func (s *Server) storeProvisionAuthority(ctx context.Context, w http.ResponseWriter, acct *Account, actor string) (storeAuthority, bool) {
+ e, _, err := objstore.GetEntitlement(ctx, s.cfg.Releases, acct.Sqid)
+ if err != nil {
+ log.Printf("console: api store provision %s: read entitlement: %v", acct.Sqid, err)
+ jsonError(w, http.StatusBadGateway, "could not read the storage application. try again")
+ return storeAuthority{}, false
+ }
+ if e.Approved() {
+ return storeAuthority{by: e.Decision.By, source: objstore.GrantSourceAccountApproval}, true
+ }
+ selfServe, scan, err := s.storeSelfServe(acct)
+ if err != nil {
+ log.Printf("console: api store provision %s: plan limits: %v", acct.Sqid, err)
+ jsonError(w, http.StatusBadGateway, "could not read the storage application. try again")
+ return storeAuthority{}, false
+ }
+ if !selfServe {
+ jsonError(w, http.StatusForbidden, "this account is not approved for object storage. run `carlos store apply` to ask for it")
+ return storeAuthority{}, false
+ }
+ return storeAuthority{by: actor, source: objstore.GrantSourcePlan, scanRequired: scan}, true
+}
+
+// storeScanPreflight refuses, before anything is created, a self-serve
+// store whose plan requires scanning that this deployment could not scan:
+// an environment store (the scan doors cover the app's own store only), or
+// a deployment with no engine or with scanning switched off. A store made
+// anyway would be exactly the unscanned store the plan rules out.
+//
+// A store its member already attested client-encrypted is refused too: a
+// scanner cannot read ciphertext, and the attestation is the member's to
+// make, never this door's to overwrite.
+func (s *Server) storeScanPreflight(ctx context.Context, w http.ResponseWriter, acct *Account, app string, a storeAuthority, env string) bool {
+ if !a.scanRequired {
+ return true
+ }
+ if env != "" {
+ jsonError(w, http.StatusConflict, copyPending("store.scan_required.environment"))
+ return false
+ }
+ rec, _, err := objstore.Get(ctx, s.cfg.Releases, acct.Sqid, app)
+ if err != nil {
+ log.Printf("console: api store provision %s/%s: read record: %v", acct.Sqid, app, err)
+ jsonError(w, http.StatusBadGateway, "could not read the store record — try again")
+ return false
+ }
+ if rec != nil && rec.Scanning != nil && rec.Scanning.Requested != nil && rec.Scanning.Requested.Encrypted {
+ jsonError(w, http.StatusConflict, copyPending("store.scan_required.encrypted"))
+ return false
+ }
+ if s.cfg.StoreScanner == nil {
+ jsonError(w, http.StatusServiceUnavailable, copyPending("store.scan_required.no_engine"))
+ return false
+ }
+ on, err := release.AntivirusEnabled(ctx, s.cfg.Releases)
+ if err != nil {
+ log.Printf("console: api store provision: read antivirus record: %v", err)
+ jsonError(w, http.StatusBadGateway, "could not read the scanning state — try again")
+ return false
+ }
+ if !on {
+ jsonError(w, http.StatusServiceUnavailable, copyPending("store.scan_required.no_engine"))
+ return false
+ }
+ return true
+}
+
+var (
+ errScanRequiredNoEngine = errors.New("console: scanning required, but no engine is configured")
+ errScanRequiredEncrypted = errors.New("console: scanning required on a store attested client-encrypted")
+)
+
+// forceStoreScanning turns virus scanning and its enforcement on for the
+// app's own store, on the plan's authority rather than a member's request
+// and an operator's grant (#1076): the member chose a plan whose storage is
+// always scanned, and creating the store is the consent. It does what
+// `carlos store scan request --plaintext`, `scan grant` and `scan enforce
+// on` do together, in their order: the backend first, then the record, then
+// the policy that carries the Deny. Idempotent: re-running the provision
+// door resumes a store whose scanning did not finish.
+//
+// The caller holds the account lock (the grant door's rule, fleet secrets
+// key spec §5.2.1) and passes the app's sealer.
+func (s *Server) forceStoreScanning(ctx context.Context, sealer appconfig.Sealer, acct *Account, app, actor string) error {
+ if s.cfg.StoreScanner == nil {
+ return errScanRequiredNoEngine
+ }
+ rec, _, err := objstore.Get(ctx, s.cfg.Releases, acct.Sqid, app)
+ if err != nil {
+ return err
+ }
+ if rec == nil || rec.Provisioned == nil {
+ return fmt.Errorf("console: force scanning %s/%s: the store is not provisioned", acct.Sqid, app)
+ }
+ engine, _, err := s.cfg.StoreScanner.Provenance(ctx)
+ if err != nil {
+ return fmt.Errorf("scanning engine: %w", err)
+ }
+ deny := s.cfg.StoreScanner.Enforcement()
+ bucket := rec.Provisioned.Bucket
+ err = s.appMutation(ctx, acct, app, "store-scan-grant", func(ctx context.Context) error {
+ if err := s.cfg.StoreScanner.EnsureEnabled(ctx, bucket); err != nil {
+ return err
+ }
+ _, err := s.writeScanRecord(ctx, acct, app, func(rec *objstore.Record) error {
+ now := time.Now().UTC()
+ if rec.Scanning == nil {
+ rec.Scanning = &objstore.ScanBlock{}
+ }
+ sc := rec.Scanning
+ if sc.Requested != nil && sc.Requested.Encrypted {
+ return errScanRequiredEncrypted
+ }
+ if sc.Requested == nil {
+ sc.Requested = &objstore.ScanRequested{At: now, By: actor, Encrypted: false}
+ }
+ if sc.Enabled == nil {
+ sc.Enabled = &objstore.ScanEnabled{Engine: engine, At: now, By: actor}
+ }
+ if s.cfg.CallbackSigner != nil && sc.WebhookGen == 0 {
+ gen, err := randomWebhookGeneration()
+ if err != nil {
+ return err
+ }
+ sc.WebhookGen = gen
+ }
+ d := deny
+ sc.Enforce = &d
+ return nil
+ })
+ return err
+ })
+ if err != nil {
+ return err
+ }
+ return s.appMutation(ctx, acct, app, "scan-regrant", func(ctx context.Context) error {
+ if err := s.regrantForScanning(ctx, sealer, acct, app, actor); err != nil {
+ return err
+ }
+ if s.cfg.CallbackSigner == nil {
+ return nil
+ }
+ _, _, err := s.convergeCallbackKey(ctx, acct, app)
+ return err
+ })
+}
+
+// storeScanRequiredFor reports whether rec is a self-serve store whose
+// account's plan still requires scanning: such a store may not be attested
+// client-encrypted, which would leave the plan's scanning nothing to read.
+func (s *Server) storeScanRequiredFor(acct *Account, rec *objstore.Record) (bool, error) {
+ if rec == nil || rec.Grant == nil || rec.Grant.Source != objstore.GrantSourcePlan {
+ return false, nil
+ }
+ _, scan, err := s.storeSelfServe(acct)
+ return scan, err
+}
+
+// copyPending stands in for a member-facing sentence that is still in
+// Paul's copy review (#1076). The approved text replaces each call before
+// this branch merges; the key is what the review lists.
+func copyPending(key string) string {
+ return "copy pending review (#1076): " + key
+}
diff --git a/internal/console/storeselfserve_test.go b/internal/console/storeselfserve_test.go
new file mode 100644
index 000000000..91072feb1
--- /dev/null
+++ b/internal/console/storeselfserve_test.go
@@ -0,0 +1,176 @@
+package console
+
+import (
+ "net/http"
+ "strings"
+ "testing"
+ "time"
+
+ "github.com/carlosframework/platform/internal/objstore"
+ "github.com/carlosframework/platform/internal/plans"
+)
+
+// draftFreeStorageCatalog is the #1076 draft: Free's storage is self-serve
+// and scanning is required.
+func draftFreeStorageCatalog(t *testing.T) *plans.Catalog {
+ t.Helper()
+ c, err := plans.LoadCatalog("../../deploy/billing/catalog-2026-11-15-v1.json")
+ if err != nil {
+ t.Fatal(err)
+ }
+ return c
+}
+
+// selfServeArmed is storeArmed under the draft catalog, with a declared
+// store, a working engine and scanning switched on for the deployment. The
+// fixture's account is the ops account, which plans exempt; here it is an
+// ordinary account with no plan row, so it is on the default plan, Free.
+func selfServeArmed(t *testing.T, code string) (*consoleFixture, *objstore.MemProvisioner, string) {
+ t.Helper()
+ fx, fake, token, _ := storeArmed(t, code)
+ fx.st.planExemptID = 0
+ fx.srv.cfg.PlanCatalog = draftFreeStorageCatalog(t)
+ fx.srv.cfg.StoreScanner = objstore.NewMemScanner()
+ enableDeploymentScanning(t, fx)
+ declareStore(t, fx, token)
+ return fx, fake, token
+}
+
+const enforcementDenyMark = "s3:ExistingObjectTag"
+
+func TestSelfServeStoreIsProvisionedAndScanned(t *testing.T) {
+ fx, fake, token := selfServeArmed(t, "code-selfserve-happy")
+ fx.srv.cfg.StoreOperators = nil // no operator anywhere in this path
+
+ status, out := postJSON(t, storeProvisionURL(fx, "titogo"), map[string]any{}, token)
+ if status != http.StatusOK {
+ t.Fatalf("self-serve provision = %d %v, want 200", status, out)
+ }
+ if out["self_serve"] != true {
+ t.Errorf("reply self_serve = %v, want true", out["self_serve"])
+ }
+ rec := storedRecord(t, fx, "titogo")
+ if rec.Provisioned == nil || rec.Grant == nil || rec.Grant.Source != objstore.GrantSourcePlan || rec.Grant.By != "alice@keymail.dev" {
+ t.Fatalf("record = %+v grant %+v, want provisioned on the plan's authority by the member", rec.Provisioned, rec.Grant)
+ }
+ sc := rec.Scanning
+ if sc == nil || sc.Requested == nil || sc.Requested.Encrypted || sc.Enabled == nil || sc.Enforce == nil {
+ t.Fatalf("scanning = %+v, want requested plaintext, enabled and enforcing", sc)
+ }
+ if !strings.Contains(fake.PolicyFor(objstore.UserName(fx.sqid, "titogo")), enforcementDenyMark) {
+ t.Fatal("the plan's enforcement never reached the store policy")
+ }
+ // A re-run is a no-op that still answers 200.
+ if status, out := postJSON(t, storeProvisionURL(fx, "titogo"), map[string]any{}, token); status != http.StatusOK {
+ t.Fatalf("re-run = %d %v", status, out)
+ }
+}
+
+// A plan that requires scanning gets no store a deployment cannot scan.
+func TestSelfServeRefusedWhereScanningCannotRun(t *testing.T) {
+ t.Run("no engine", func(t *testing.T) {
+ fx, fake, token := selfServeArmed(t, "code-selfserve-noengine")
+ fx.srv.cfg.StoreScanner = nil
+ status, _ := postJSON(t, storeProvisionURL(fx, "titogo"), map[string]any{}, token)
+ if status != http.StatusServiceUnavailable {
+ t.Fatalf("provision with no engine = %d, want 503", status)
+ }
+ untouched(t, fake, "a self-serve provision with no engine")
+ })
+ t.Run("an environment store", func(t *testing.T) {
+ fx, fake, token := selfServeArmed(t, "code-selfserve-env")
+ status, out := postJSON(t, storeProvisionURL(fx, "titogo")+"?environment=staging", map[string]any{}, token)
+ if status != http.StatusConflict || !strings.Contains(out["error"].(string), "store.scan_required.environment") {
+ t.Fatalf("self-serve environment store = %d %v, want the scan-required refusal", status, out)
+ }
+ untouched(t, fake, "a self-serve environment store")
+ })
+ t.Run("attested client-encrypted", func(t *testing.T) {
+ fx, fake, token := selfServeArmed(t, "code-selfserve-encrypted")
+ requestScanning(t, fx, token, true)
+ status, _ := postJSON(t, storeProvisionURL(fx, "titogo"), map[string]any{}, token)
+ if status != http.StatusConflict {
+ t.Fatalf("provision of an encrypted-attested store = %d, want 409", status)
+ }
+ untouched(t, fake, "a self-serve provision of an encrypted store")
+ })
+}
+
+// Once the plan made the store, the member cannot attest it encrypted; a
+// plaintext request is still fine.
+func TestSelfServeStoreRefusesAnEncryptedAttestation(t *testing.T) {
+ fx, _, token := selfServeArmed(t, "code-selfserve-attest")
+ if status, out := postJSON(t, storeProvisionURL(fx, "titogo"), map[string]any{}, token); status != http.StatusOK {
+ t.Fatalf("provision = %d %v", status, out)
+ }
+ if status, _ := postJSON(t, scanURL(fx, "titogo"), map[string]any{"encrypted": true}, token); status != http.StatusConflict {
+ t.Fatalf("encrypted attestation on a plan-scanned store = %d, want 409", status)
+ }
+ if rec := storedRecord(t, fx, "titogo"); rec.Scanning.Requested.Encrypted {
+ t.Fatal("the refused attestation was written")
+ }
+ requestScanning(t, fx, token, false)
+}
+
+// A sponsored row keeps needing an operator: sponsorship is generous caps,
+// not a way round the approval queue.
+func TestSelfServeIsNotForSponsoredAccounts(t *testing.T) {
+ fx, fake, token := selfServeArmed(t, "code-selfserve-sponsored")
+ if _, err := fx.st.SetAccountPlan(OpsAccountID, "free", nil, PlanSourceSponsored,
+ &plans.Limits{StorageBytes: 1 << 40, StorageSelfServe: true}, "launch", "plans", time.Now()); err != nil {
+ t.Fatal(err)
+ }
+ status, _ := postJSON(t, storeProvisionURL(fx, "titogo"), map[string]any{}, token)
+ if status != http.StatusForbidden {
+ t.Fatalf("sponsored self-serve = %d, want 403", status)
+ }
+ untouched(t, fake, "a sponsored account's provision")
+}
+
+// The catalog decides: a Free plan without storage_self_serve (the
+// flagship's live catalog) still needs the approval.
+func TestSelfServeNeedsThePlanFlag(t *testing.T) {
+ fx, fake, token := selfServeArmed(t, "code-selfserve-flag")
+ c, err := plans.LoadCatalog("../../deploy/billing/catalog-2026-11-14-v1.json")
+ if err != nil {
+ t.Fatal(err)
+ }
+ fx.srv.cfg.PlanCatalog = c
+ if status, _ := postJSON(t, storeProvisionURL(fx, "titogo"), map[string]any{}, token); status != http.StatusForbidden {
+ t.Fatalf("provision under a catalog without self-serve Free = %d, want 403", status)
+ }
+ untouched(t, fake, "a provision the plan does not allow")
+}
+
+// A paid plan's self-serve storage is not scanned unless asked for.
+func TestSelfServePaidPlanIsNotForcedToScan(t *testing.T) {
+ fx, _, token := selfServeArmed(t, "code-selfserve-paid")
+ fx.srv.cfg.StoreScanner = nil // a paid store needs no engine
+ if _, err := fx.st.SetAccountPlan(OpsAccountID, "personal", nil, PlanSourceOperator, nil, "test", "op", time.Now()); err != nil {
+ t.Fatal(err)
+ }
+ if status, out := postJSON(t, storeProvisionURL(fx, "titogo"), map[string]any{}, token); status != http.StatusOK {
+ t.Fatalf("paid self-serve provision = %d %v", status, out)
+ }
+ rec := storedRecord(t, fx, "titogo")
+ if rec.Grant.Source != objstore.GrantSourcePlan || rec.Scanning != nil {
+ t.Fatalf("grant %+v scanning %+v, want the plan's grant and no scanning", rec.Grant, rec.Scanning)
+ }
+ // The attestation is the member's to make on a store no plan requires
+ // scanned.
+ requestScanning(t, fx, token, true)
+}
+
+// An approval wins over the plan: the store keeps the approval's
+// provenance, and is scanned only on request.
+func TestApprovedAccountKeepsTheApprovalPath(t *testing.T) {
+ fx, _, token := selfServeArmed(t, "code-selfserve-approved")
+ approveStoreAccount(t, fx, "operator@keymail.dev")
+ if status, out := postJSON(t, storeProvisionURL(fx, "titogo"), map[string]any{}, token); status != http.StatusOK {
+ t.Fatalf("approved provision = %d %v", status, out)
+ }
+ rec := storedRecord(t, fx, "titogo")
+ if rec.Grant.Source != objstore.GrantSourceAccountApproval || rec.Scanning != nil {
+ t.Fatalf("grant %+v scanning %+v, want the approval's grant and no forced scanning", rec.Grant, rec.Scanning)
+ }
+}
diff --git a/internal/objstore/objstore.go b/internal/objstore/objstore.go
index 8126cf90d..8da2a32b0 100644
--- a/internal/objstore/objstore.go
+++ b/internal/objstore/objstore.go
@@ -54,6 +54,11 @@ const (
// operator who approved the account — a real person who really did
// authorise this spend, one level up.
GrantSourceAccountApproval = "account-approval"
+ // GrantSourcePlan: the account's PLAN includes self-serve object
+ // storage (#1076), so the member's own declare provisioned it with no
+ // operator in the loop. By names that member. A plan that also requires
+ // scanning has it switched on as the store is made.
+ GrantSourcePlan = "plan"
)
type GrantBlock struct {
diff --git a/internal/objstore/walk.go b/internal/objstore/walk.go
index 9f7bd0487..f0aa74a42 100644
--- a/internal/objstore/walk.go
+++ b/internal/objstore/walk.go
@@ -200,7 +200,7 @@ func ValidBucketName(name string) bool { return bucketNameRe.MatchString(name) }
// existing bucket to adopt instead of minting one; it is honoured only on the
// FIRST grant, since the recorded bucket is what the app's data is in.
//
-// source is GrantSourceOperator or GrantSourceAccountApproval — why this grant
+// source is GrantSourceOperator, GrantSourceAccountApproval or GrantSourcePlan — why this grant
// is authorised — and lands in the grant block beside actor. It is recorded
// only on the FIRST grant, with the block itself: a re-run repairs an estate
// whose authority was already established and must not restate it, exactly as
diff --git a/store.go b/store.go
index d0feee809..775051e8b 100644
--- a/store.go
+++ b/store.go
@@ -234,7 +234,7 @@ func storeCreateAndProvision(ctx context.Context, sess *apiSession, acct apiAcct
return err
}
printStoreCreate(out, res)
- if res.Backend == "" || !res.Entitlement.Approved() {
+ if res.Backend == "" || !res.mayProvision() {
return nil
}
res, err = sess.storeProvision(ctx, acct, app, env)
@@ -486,7 +486,7 @@ func printStoreCreate(w io.Writer, res apiStoreReply) {
fmt.Fprintf(w, " provisioned: bucket %s in %s, user %s\n", p.Bucket, p.Region, p.IAMUser)
if len(res.MissingVars) > 0 {
verb := "grant"
- if res.Entitlement.Approved() {
+ if res.mayProvision() {
verb = "create"
}
warnf(w, "credentials are not fully delivered: %s. re-run `carlos store %s --app %s` to repair",
@@ -496,7 +496,7 @@ func printStoreCreate(w io.Writer, res apiStoreReply) {
}
return
}
- if !res.Entitlement.Approved() {
+ if !res.mayProvision() {
// The four-state printer, not the one-line "go apply": a PENDING
// applicant told to apply again overwrites their own Applied.At, and
// the queue sorts oldest first, so following that instruction sends
@@ -509,6 +509,12 @@ func printStoreCreate(w io.Writer, res apiStoreReply) {
}
}
+// mayProvision reports whether the member's own create provisions the
+// store: the account is approved, or its plan is self-serve (#1076).
+func (res apiStoreReply) mayProvision() bool {
+ return res.Entitlement.Approved() || res.SelfServe
+}
+
// printStoreGrant answers `carlos store grant`: the walk already ran inline
// (the console's handleAPIStoreGrant does not return 200 until it has),
// which is why this can name the bucket/region/user rather than hedging like
@@ -613,7 +619,7 @@ func printStoreStatus(w io.Writer, res apiStoreReply) {
p.Bucket, p.Region, p.IAMUser, p.KeyID, p.At.Format(time.RFC3339))
printStoreSize(w, res.Size)
} else {
- if res.Entitlement.Approved() {
+ if res.mayProvision() {
mutedf(w, " nothing is provisioned yet. re-run carlos store create --app %s", res.App)
} else {
mutedf(w, " nothing is provisioned yet. waiting on a deployment operator (carlos store grant --app %s)", res.App)
@@ -642,7 +648,7 @@ func printStoreStatus(w io.Writer, res apiStoreReply) {
// no way to know from one snapshot, so the line names the repair
// rather than pronouncing a verdict.
verb := "grant"
- if res.Entitlement.Approved() {
+ if res.mayProvision() {
verb = "create"
}
warnf(w, "drift: %s not yet delivered to this app's config. re-run `carlos store %s --app %s` to "+
diff --git a/store_selfserve_test.go b/store_selfserve_test.go
new file mode 100644
index 000000000..32126f94d
--- /dev/null
+++ b/store_selfserve_test.go
@@ -0,0 +1,27 @@
+package main
+
+import (
+ "bytes"
+ "strings"
+ "testing"
+)
+
+// A self-serve store (#1076) is provisioned by the member's own create: the
+// CLI does not send them to apply, and names create as the repair.
+func TestStoreCreateSelfServeIsNotSentToApply(t *testing.T) {
+ res := apiStoreReply{App: "blog", Backend: "aws", Declared: &apiStoreDeclared{EnvPrefix: "CARLOS_STORE"}, SelfServe: true}
+ if !res.mayProvision() {
+ t.Fatal("a self-serve reply may not provision")
+ }
+ var out bytes.Buffer
+ printStoreCreate(&out, res)
+ if strings.Contains(out.String(), "store apply") {
+ t.Fatalf("self-serve create sent the member to apply:\n%s", out.String())
+ }
+ res.SelfServe = false
+ out.Reset()
+ printStoreCreate(&out, res)
+ if !strings.Contains(out.String(), "store apply") {
+ t.Fatalf("an unapproved, non-self-serve create no longer names apply:\n%s", out.String())
+ }
+}