console: ops-account owners skip the free-account cap
carlos accounts create, run by Paul on the flagship, was refused with the
free-account cap although he owns the ops account. #500 already lets ops
owners skip the daily app budget; this does the same for account creation.
The ownership test #500 inlined in allowAppCreate is now the opsOwner
helper (svcprincipal.go), and checkNewFreeAccount passes an ops owner
through it. Both doors that create an account for a person, POST
/auth/cli/accounts and the browser's POST /accounts/new, go through
checkNewFreeAccount; the landing mint only makes a first account and is
never capped. Everyone else keeps the cap, owners of other accounts and
non-owner members of ops included. A store error is not an exemption, and
opsOwner logs it.
Accounts an ops owner creates start on the catalog's default plan; only
ops is plan-exempt. On the free plan that means no custom domains: give
one of them custom domains with carlos accounts plan --account <sqid>
--set free --sponsored limits.json --reason "...", where limits.json
holds {"custom_domains": true}, or put it on a paid plan.
Tests: TestOpsOwnerSkipsTheFreeAccountCap (new); the existing cap tests
now use people who do not own ops, and TestPlanExemptOwnershipIsNotAFree
Account exercises the planExempt skip apart from the ops-owner pass.
Reviewed once (Opus): no P1; the P2 and two P3s are fixed.
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Squashed from ops-owner-account-cap into main.
4 files changed,
+109
−27
internal/console/plancaps.go+6 −2internal/console/plancaps_doors_test.go+71 −15internal/console/planexempt_test.go+17 −6internal/console/svcprincipal.go+15 −4
CI failed — run details
diff --git a/internal/console/plancaps.go b/internal/console/plancaps.go| index 5b780901b..8f2b71981 100644 |
| --- a/internal/console/plancaps.go |
| +++ b/internal/console/plancaps.go |
| @@ -163,10 +163,14 @@ func (s *Server) checkSidecars(ctx context.Context, acct *Account, app string) e |
| // checkNewFreeAccount refuses a person a further account on a free plan once |
| // they own the catalog's allowance of them (spec §8.1; creation only). |
| -// Owning the exempt account (planExempt) is not owning a free one. |
| +// Owning the exempt account (planExempt) is not owning a free one, and its |
| +// owners have no allowance at all (opsOwner): the platform owner makes |
| +// accounts for the platform's own sites. Those accounts still start on the |
| +// default plan. Both doors that create an account (the CLI's and the |
| +// browser's) come here. |
| func (s *Server) checkNewFreeAccount(addr string) error { |
| cat := s.cfg.PlanCatalog |
| - if cat == nil || cat.FreeAccountsPerPerson <= 0 { |
| + if cat == nil || cat.FreeAccountsPerPerson <= 0 || s.opsOwner(addr) { |
| return nil |
| } |
| if p, ok := cat.Plans[cat.DefaultPlan]; ok && p.Paid { |
diff --git a/internal/console/plancaps_doors_test.go b/internal/console/plancaps_doors_test.go| index f44ea2815..00f37b91e 100644 |
| --- a/internal/console/plancaps_doors_test.go |
| +++ b/internal/console/plancaps_doors_test.go |
| @@ -244,20 +244,16 @@ func accountCount(t *testing.T, fx *consoleFixture) int { |
| func TestNewAccountRefusedForASecondFreeAccount(t *testing.T) { |
| fx := newConsoleFixture(t) |
| fx.srv.cfg.PlanCatalog = examplePlanCatalog(t) |
| - token := cliToken(t, fx, "paul@keymail.dev", "code-cap-acct") |
| - // Paul owns ops, which is exempt from plans (2026-10-28): his first |
| - // free account is allowed beside it. |
| - status, out := postJSON(t, fx.ts.URL+"/auth/cli/accounts", map[string]string{"name": "first"}, token) |
| - if status != http.StatusOK { |
| - t.Fatalf("CLI first free account beside ops = %d %v, want 200", status, out) |
| - } |
| + // Dana's first sign-in mints her first free account; she owns nothing |
| + // else, ops included. |
| + token := cliToken(t, fx, "dana@keymail.dev", "code-cap-acct") |
| before := accountCount(t, fx) |
| - status, out = postJSON(t, fx.ts.URL+"/auth/cli/accounts", map[string]string{"name": "second"}, token) |
| - if status != http.StatusConflict || out["code"] != "cap" { |
| + status, out := postJSON(t, fx.ts.URL+"/auth/cli/accounts", map[string]string{"name": "second"}, token) |
| + if status != http.StatusConflict || out["code"] != "cap" || out["error"] != capMessage("cli.cap.free_account") { |
| t.Fatalf("CLI second free account = %d %v, want 409 cap", status, out) |
| } |
| - c := signInPaul(t, fx) |
| - st, loc, _ := postForm(t, c, fx.ts.URL+"/accounts/new", url.Values{"csrf": {sessionToken(t, fx, c)}, "name": {"thirdtry"}}) |
| + c, raw := signInAs(t, fx, "dana@keymail.dev", "code-cap-acct-browser") |
| + st, loc, _ := postForm(t, c, fx.ts.URL+"/accounts/new", url.Values{"csrf": {raw}, "name": {"thirdtry"}}) |
| if st != http.StatusSeeOther || loc != "/accounts/new" { |
| t.Fatalf("browser second free account = %d -> %q, want the flash redirect back to /accounts/new", st, loc) |
| } |
| @@ -266,6 +262,62 @@ func TestNewAccountRefusedForASecondFreeAccount(t *testing.T) { |
| } |
| } |
| +// TestOpsOwnerSkipsTheFreeAccountCap is #500's exemption for accounts: an |
| +// owner of the ops account creates free accounts past the allowance through |
| +// both doors, because the platform owner makes accounts for the platform's |
| +// own sites. Each new account starts on the default plan; only ops itself |
| +// is exempt. Owning some other account is not enough: carol owns a free |
| +// account and is still refused on both doors. |
| +func TestOpsOwnerSkipsTheFreeAccountCap(t *testing.T) { |
| + fx := newConsoleFixture(t) |
| + fx.srv.cfg.PlanCatalog = examplePlanCatalog(t) |
| + token := cliToken(t, fx, "paul@keymail.dev", "code-ops-owner-acct") |
| + for _, name := range []string{"first", "second", "third"} { |
| + status, out := postJSON(t, fx.ts.URL+"/auth/cli/accounts", map[string]string{"name": name}, token) |
| + if status != http.StatusOK { |
| + t.Fatalf("ops owner CLI account %s = %d %v, want no free-account cap", name, status, out) |
| + } |
| + a, err := fx.st.AccountBySqid(str(t, out, "sqid")) |
| + if err != nil || a == nil { |
| + t.Fatalf("account %s: %v, %v", name, a, err) |
| + } |
| + if l, err := fx.srv.EffectiveLimits(a); err != nil || l == nil { |
| + t.Fatalf("account %s limits = %v, %v; want the default plan's, not exempt", name, l, err) |
| + } |
| + if row, err := fx.st.AccountPlan(a.ID); err != nil || (row != nil && row.Plan != fx.srv.cfg.PlanCatalog.DefaultPlan) { |
| + t.Fatalf("account %s plan = %+v, %v; want the default plan", name, row, err) |
| + } |
| + } |
| + c := signInPaul(t, fx) |
| + before := accountCount(t, fx) |
| + st, loc, _ := postForm(t, c, fx.ts.URL+"/accounts/new", url.Values{"csrf": {sessionToken(t, fx, c)}, "name": {"fourth"}}) |
| + if st != http.StatusSeeOther || loc == "/accounts/new" { |
| + t.Fatalf("ops owner browser account = %d -> %q, want the new account", st, loc) |
| + } |
| + if after := accountCount(t, fx); after != before+1 { |
| + t.Fatalf("accounts %d -> %d, want one more", before, after) |
| + } |
| + |
| + const demoID = 4242 |
| + if err := fx.st.CreateAccount(demoID, "cdef", "Demo", "carol@keymail.dev", planNow); err != nil { |
| + t.Fatal(err) |
| + } |
| + carol := cliToken(t, fx, "carol@keymail.dev", "code-demo-owner-acct") |
| + before = accountCount(t, fx) |
| + status, out := postJSON(t, fx.ts.URL+"/auth/cli/accounts", map[string]string{"name": "carol-two"}, carol) |
| + if status != http.StatusConflict || out["code"] != "cap" || out["error"] != capMessage("cli.cap.free_account") { |
| + t.Fatalf("demo owner CLI account = %d %v, want 409 cap: only ops owners skip it", status, out) |
| + } |
| + cc, raw := signInAs(t, fx, "carol@keymail.dev", "code-demo-owner-browser") |
| + st, loc, _ = postForm(t, cc, fx.ts.URL+"/accounts/new", url.Values{"csrf": {raw}, "name": {"carol-web"}}) |
| + if st != http.StatusSeeOther || loc != "/accounts/new" { |
| + t.Fatalf("demo owner browser account = %d -> %q, want the flash redirect back to /accounts/new", st, loc) |
| + } |
| + if after := accountCount(t, fx); after != before { |
| + t.Fatalf("accounts %d -> %d: carol got one past the cap", before, after) |
| + } |
| +} |
| + |
| func TestFirstAccountIsNeverRefused(t *testing.T) { |
| fx := newConsoleFixture(t) |
| fx.srv.cfg.PlanCatalog = examplePlanCatalog(t) |
| @@ -360,15 +412,19 @@ func TestPlatformHostnamesStayFreeOnFreePlans(t *testing.T) { |
| } |
| // Astra plans-3a finding 2: concurrent creates by one person who owns only |
| -// paid accounts must not mint more free accounts than the allowance. |
| +// paid accounts must not mint more free accounts than the allowance. Carol |
| +// does not own ops, whose owners have no allowance to exceed. |
| func TestFreeAccountCapIsExactUnderConcurrentCreates(t *testing.T) { |
| fx := newConsoleFixture(t) |
| fx.srv.cfg.PlanCatalog = examplePlanCatalog(t) |
| - ops, _ := fx.st.AccountBySqid(fx.sqid) |
| - if _, err := fx.st.SetAccountPlan(ops.ID, "personal", nil, 0, PlanSourceOperator, nil, "r", "ops@example.com", planNow); err != nil { |
| + const paidID = 4242 |
| + if err := fx.st.CreateAccount(paidID, "cdef", "Paid", "carol@keymail.dev", planNow); err != nil { |
| + t.Fatal(err) |
| + } |
| + if _, err := fx.st.SetAccountPlan(paidID, "personal", nil, 0, PlanSourceOperator, nil, "r", "ops@example.com", planNow); err != nil { |
| t.Fatal(err) |
| } |
| - token := cliToken(t, fx, "paul@keymail.dev", "code-cap-acct-race") |
| + token := cliToken(t, fx, "carol@keymail.dev", "code-cap-acct-race") |
| var mu sync.Mutex |
| created := 0 |
| var wg sync.WaitGroup |
diff --git a/internal/console/planexempt_test.go b/internal/console/planexempt_test.go| index a2873c397..e77526221 100644 |
| --- a/internal/console/planexempt_test.go |
| +++ b/internal/console/planexempt_test.go |
| @@ -161,24 +161,35 @@ func TestPlanExemptHasNoLimitsOrCaps(t *testing.T) { |
| } |
| } |
| +// TestPlanExemptOwnershipIsNotAFreeAccount is the planExempt skip in |
| +// checkNewFreeAccount. An ops owner never reaches it (opsOwner passes them |
| +// first), so the exempt account here is one kim owns without owning ops. |
| func TestPlanExemptOwnershipIsNotAFreeAccount(t *testing.T) { |
| fx := newConsoleFixture(t) |
| fx.srv.cfg.PlanCatalog = examplePlanCatalog(t) |
| - owner := "paul@example.com" |
| - ops := opsPlanAccount(t, fx, owner) |
| + owner := "kim@example.com" |
| + const exemptID = 503 |
| + if err := fx.st.CreateAccount(exemptID, "cdef", "exempt", owner, planNow); err != nil { |
| + t.Fatal(err) |
| + } |
| + fx.st.planExemptID = exemptID |
| if err := fx.srv.checkNewFreeAccount(owner); err != nil { |
| - t.Fatalf("owning ops alone counted as a free account: %v", err) |
| + t.Fatalf("owning the exempt account alone counted as a free account: %v", err) |
| } |
| - opsSponsoredRow(t, fx, ops) |
| + exempt, err := fx.st.AccountByID(exemptID) |
| + if err != nil || exempt == nil { |
| + t.Fatalf("exempt account: %v", err) |
| + } |
| + opsSponsoredRow(t, fx, exempt) |
| if err := fx.srv.checkNewFreeAccount(owner); err != nil { |
| - t.Fatalf("owning ops with a free row counted as a free account: %v", err) |
| + t.Fatalf("owning the exempt account with a free row counted as a free account: %v", err) |
| } |
| // The cap itself still holds for the person's real accounts. |
| if err := fx.st.CreateAccount(502, "bac", "mine", owner, planNow); err != nil { |
| t.Fatal(err) |
| } |
| if err := fx.srv.checkNewFreeAccount(owner); !isCap(err) { |
| - t.Fatalf("owner of ops and one free account: %v, want the cap", err) |
| + t.Fatalf("owner of the exempt account and one free account: %v, want the cap", err) |
| } |
| } |
diff --git a/internal/console/svcprincipal.go b/internal/console/svcprincipal.go| index 7d5214c93..e56f50196 100644 |
| --- a/internal/console/svcprincipal.go |
| +++ b/internal/console/svcprincipal.go |
| @@ -24,6 +24,7 @@ import ( |
| "encoding/json" |
| "errors" |
| "fmt" |
| + "log" |
| "net/http" |
| "strconv" |
| "time" |
| @@ -599,14 +600,24 @@ func (s *Server) allowCreate(p Principal, now time.Time) bool { |
| // 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 |
| - } |
| + if p.Kind == PrincipalUser && s.opsOwner(p.Address) { |
| + return true |
| } |
| return s.allowCreate(p, now) |
| } |
| +// opsOwner reports whether addr owns the ops account, which lifts the |
| +// person limits on creating things (#500): the daily app budget here and |
| +// the free-account allowance (checkNewFreeAccount). A store error is not |
| +// ownership. |
| +func (s *Server) opsOwner(addr string) bool { |
| + role, err := s.store.Role(OpsAccountID, addr) |
| + if err != nil { |
| + log.Printf("console: ops owner: role: %v", err) |
| + } |
| + return err == nil && role == RoleOwner |
| +} |
| + |
| // 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. |