carlos / platform Public

console: ops-account owners skip the daily app-creation limit (#500)

Owners of the ops account are no longer held to the per-person budget of
ten app creations a day (allowAppCreate, svcprincipal.go). Fleet creation,
service credentials and everyone else keep their budgets. A store error
is not an exemption.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>

Squashed from operator-create-limit-500 into main.
claude agent, operated by paul@keymail.dev 65420a4d9e0d919743ea2e95e20b1a649605db3d parent 06bc3d7
4 files changed, +112 −3
  • internal/console/apicli.go +4 −3
  • internal/console/authcli_test.go +72 −0
  • internal/console/fleets_test.go +20 −0
  • internal/console/svcprincipal.go +16 −0

CI passed — run details

landed from operator-create-limit-500

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 8074b5acb..14580fbd8 100644
--- a/internal/console/authcli_test.go
+++ b/internal/console/authcli_test.go
@@ -675,6 +675,78 @@ func TestPersonBudgetsAreUnchanged(t *testing.T) {
}
}
+// TestOpsOwnerSkipsTheCreateBudget is #500: an owner of the ops account
+// creates apps in any account of theirs past cliCreateBurst, because a
+// benchmark run signed in as the platform owner ran out of it. Owning some
+// other account is not enough: carol owns the same demo account and still
+// stops at the ordinary limit.
+func TestOpsOwnerSkipsTheCreateBudget(t *testing.T) {
+ fx := newConsoleFixture(t)
+ const demoID = 4242
+ if err := fx.st.CreateAccount(demoID, "cdef", "Demo", "paul@keymail.dev", time.Now()); err != nil {
+ t.Fatal(err)
+ }
+ for _, addr := range []string{"paul@keymail.dev", "carol@keymail.dev"} {
+ if err := fx.st.AddMember(demoID, addr, RoleOwner, time.Now()); err != nil {
+ t.Fatal(err)
+ }
+ }
+ paul := cliToken(t, fx, "paul@keymail.dev", "code-ops-owner-budget")
+ for i := 0; i < cliCreateBurst+2; i++ {
+ name := fmt.Sprintf("bench-%d", i)
+ if status, out := postJSON(t, fx.ts.URL+"/api/cli/apps/cdef/new", map[string]string{"name": name}, paul); status != http.StatusOK {
+ t.Fatalf("ops owner create %d = %d %v, want no daily limit", i, status, out)
+ }
+ }
+ carol := cliToken(t, fx, "carol@keymail.dev", "code-demo-owner-budget")
+ for i := 0; i < cliCreateBurst; i++ {
+ name := fmt.Sprintf("carol-%d", i)
+ if status, out := postJSON(t, fx.ts.URL+"/api/cli/apps/cdef/new", map[string]string{"name": name}, carol); status != http.StatusOK {
+ t.Fatalf("demo owner create %d = %d %v", i, status, out)
+ }
+ }
+ status, out := postJSON(t, fx.ts.URL+"/api/cli/apps/cdef/new", map[string]string{"name": "carol-over"}, carol)
+ if status != http.StatusTooManyRequests {
+ t.Errorf("demo owner create %d+1 = %d %v, want 429: only ops owners skip the limit", cliCreateBurst, status, out)
+ }
+}
+
+// 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 12a1c1482..7d5214c93 100644
--- a/internal/console/svcprincipal.go
+++ b/internal/console/svcprincipal.go
@@ -591,6 +591,22 @@ func (s *Server) allowCreate(p Principal, now time.Time) bool {
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.allowCreate(p, now)
+}
+
// allowTemporaryCreate is /new-temporary's budget: one limiter for both
// principal kinds, keyed like allowCreate (principalKey), separate from it
// so neither kind of create spends the other's day.