console: scope the ops-owner create exemption to apps only
Astra review round 1: the exemption sat in allowCreate, which fleet creation also uses, so ops owners lost the fleet budget too. Fleet names are global with no delete door, and #500 asked about apps. Move it to allowAppCreate, used only by app creation. Tests pin that fleets keep the budget for ops owners and that removal from the ops account ends the exemption at once. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Human
Prompt
Can we take #500?
From this commit's own message. The prompt ledger has no entries for it — which is what a squashed, rebased or amended commit looks like, and what every commit looks like in a repo without a ledger.
Summary
allowAppCreate wraps allowCreate with the ops-owner exemption; fleet create keeps the plain budget. New tests for the fleet budget and for removal.
4 files changed,
+75
−10
internal/console/apicli.go+4 −3internal/console/authcli_test.go+36 −0internal/console/fleets_test.go+20 −0internal/console/svcprincipal.go+15 −7
CI passed — run details
diff --git a/internal/console/apicli.go b/internal/console/apicli.go| index b37cde32e..9f46c68e5 100644 |
| --- a/internal/console/apicli.go |
| +++ b/internal/console/apicli.go |
| @@ -391,11 +391,12 @@ func (s *Server) handleAPICreateApp(w http.ResponseWriter, r *http.Request) { |
| return |
| } |
| addr := auditActor(p, acct) |
| - // allowCreate picks the person or the service create budget from the |
| + // allowAppCreate picks the person or the service create budget from the |
| // principal (svcprincipal.go) — a person keyed on the ADDRESS as before |
| // (a token-keyed counter is one the holder of several tokens resets at |
| - // will), a service on its NAME, own budget from the operator's. |
| - if !s.allowCreate(p, time.Now()) { |
| + // will), a service on its NAME, own budget from the operator's. An |
| + // ops-account owner has no limit (#500). |
| + if !s.allowAppCreate(p, time.Now()) { |
| jsonError(w, http.StatusTooManyRequests, |
| "app creation limit reached for today — use the console's New app form") |
| return |
diff --git a/internal/console/authcli_test.go b/internal/console/authcli_test.go| index 211b238e6..14580fbd8 100644 |
| --- a/internal/console/authcli_test.go |
| +++ b/internal/console/authcli_test.go |
| @@ -711,6 +711,42 @@ func TestOpsOwnerSkipsTheCreateBudget(t *testing.T) { |
| } |
| } |
| +// TestOpsOwnerExemptionEndsWithOwnership: the exemption is read on every |
| +// create, so an ops owner who is removed from the ops account is back on |
| +// the ordinary budget at once. Exempt creates spent none of it. |
| +func TestOpsOwnerExemptionEndsWithOwnership(t *testing.T) { |
| + fx := newConsoleFixture(t) |
| + const demoID = 4242 |
| + if err := fx.st.CreateAccount(demoID, "cdef", "Demo", "dana@keymail.dev", time.Now()); err != nil { |
| + t.Fatal(err) |
| + } |
| + for _, id := range []int64{OpsAccountID, demoID} { |
| + if err := fx.st.AddMember(id, "dana@keymail.dev", RoleOwner, time.Now()); err != nil { |
| + t.Fatal(err) |
| + } |
| + } |
| + dana := cliToken(t, fx, "dana@keymail.dev", "code-ops-owner-removed") |
| + for i := 0; i < cliCreateBurst+2; i++ { |
| + name := fmt.Sprintf("exempt-%d", i) |
| + if status, out := postJSON(t, fx.ts.URL+"/api/cli/apps/cdef/new", map[string]string{"name": name}, dana); status != http.StatusOK { |
| + t.Fatalf("ops owner create %d = %d %v", i, status, out) |
| + } |
| + } |
| + if err := fx.st.RemoveMember(OpsAccountID, "dana@keymail.dev"); err != nil { |
| + t.Fatal(err) |
| + } |
| + for i := 0; i < cliCreateBurst; i++ { |
| + name := fmt.Sprintf("after-%d", i) |
| + if status, out := postJSON(t, fx.ts.URL+"/api/cli/apps/cdef/new", map[string]string{"name": name}, dana); status != http.StatusOK { |
| + t.Fatalf("create %d after removal = %d %v, want the whole budget left", i, status, out) |
| + } |
| + } |
| + status, out := postJSON(t, fx.ts.URL+"/api/cli/apps/cdef/new", map[string]string{"name": "after-over"}, dana) |
| + if status != http.StatusTooManyRequests { |
| + t.Errorf("create %d+1 after removal = %d %v, want 429", cliCreateBurst, status, out) |
| + } |
| +} |
| + |
| // TestTwoNamedServicesHaveSeparateBudgets is Minor 5 (Task 5 review): two |
| // DIFFERENT named services in one account must not share a budget just |
| // because they share an account — closing this alongside C32's empty-name |
diff --git a/internal/console/fleets_test.go b/internal/console/fleets_test.go| index 117279db8..e14742e66 100644 |
| --- a/internal/console/fleets_test.go |
| +++ b/internal/console/fleets_test.go |
| @@ -16,6 +16,7 @@ import ( |
| "crypto/sha256" |
| "encoding/hex" |
| "errors" |
| + "fmt" |
| "io" |
| "net/http" |
| "net/url" |
| @@ -59,6 +60,25 @@ func openTestReg(t *testing.T, fx *consoleFixture) *registry.Registry { |
| return reg |
| } |
| +// TestFleetCreateKeepsTheBudgetForOpsOwners: #500 lifted the app create |
| +// budget for ops owners, not the fleet one. Fleet names are global and |
| +// have no delete door, so paul (an ops owner) still stops at cliCreateBurst. |
| +func TestFleetCreateKeepsTheBudgetForOpsOwners(t *testing.T) { |
| + fx, token := fleetFixture(t, "code-fleet-budget") |
| + for i := 0; i < cliCreateBurst; i++ { |
| + name := fmt.Sprintf("acme-%d", i) |
| + if status, body := postJSON(t, fleetsURL(fx, fx.sqid)+"/new", |
| + map[string]string{"name": name, "bucket": name + "-data"}, token); status != http.StatusOK { |
| + t.Fatalf("create %s = %d %v, want 200", name, status, body) |
| + } |
| + } |
| + status, body := postJSON(t, fleetsURL(fx, fx.sqid)+"/new", |
| + map[string]string{"name": "acme-over", "bucket": "acme-over-data"}, token) |
| + if status != http.StatusTooManyRequests { |
| + t.Errorf("create %d+1 = %d %v, want 429", cliCreateBurst, status, body) |
| + } |
| +} |
| + |
| // TestFleetCreateListRoundTrip: create, then list, and the created fleet |
| // comes back with an empty (never null) boxes array. |
| func TestFleetCreateListRoundTrip(t *testing.T) { |
diff --git a/internal/console/svcprincipal.go b/internal/console/svcprincipal.go| index e99996bf1..7d5214c93 100644 |
| --- a/internal/console/svcprincipal.go |
| +++ b/internal/console/svcprincipal.go |
| @@ -584,19 +584,27 @@ func principalKey(p Principal) string { |
| // one it is talking to — a call site that got it wrong would be a server |
| // drawing down an operator's budget, which is the bug this whole change is |
| // about. |
| -// |
| -// An owner of the ops account skips the person budget (#500): it is a |
| -// ceiling on a stolen token, and the platform owner's token already |
| -// carries the whole platform. Their benchmark runs create dozens of apps |
| -// a day on demo accounts. A store error is not an exemption. |
| func (s *Server) allowCreate(p Principal, now time.Time) bool { |
| + if p.Kind == PrincipalUser { |
| + return s.cli.create.allow(principalKey(p), now) |
| + } |
| + return s.cli.svcCreate.allow(principalKey(p), now) |
| +} |
| + |
| +// allowAppCreate is allowCreate for app creation, where an owner of the |
| +// ops account skips the person budget (#500). The budget is a ceiling on a |
| +// stolen token, and the platform owner's token already carries the whole |
| +// platform; their benchmark runs create dozens of apps a day on demo |
| +// accounts. Apps only: fleet names are global with no delete door, so |
| +// fleet creation keeps allowCreate as it is. A store error is not an |
| +// exemption, and an exempt create spends nothing. |
| +func (s *Server) allowAppCreate(p Principal, now time.Time) bool { |
| if p.Kind == PrincipalUser { |
| if role, err := s.store.Role(OpsAccountID, p.Address); err == nil && role == RoleOwner { |
| return true |
| } |
| - return s.cli.create.allow(principalKey(p), now) |
| } |
| - return s.cli.svcCreate.allow(principalKey(p), now) |
| + return s.allowCreate(p, now) |
| } |
| // allowTemporaryCreate is /new-temporary's budget: one limiter for both |