carlos / platform Public

console: removal and demotion end platform delegation; customer owner

Review round 3, where the branch meets main's platform accounts.

- Removing a member revokes the per-customer credentials they minted
  in person and, via endPlatformMintsTx, every one their platform
  credentials minted, in the removal's transaction (Astra P1, Fable P2).
- A platform credential is held to its minter's current owner role at
  the platform doors and in the mint's insert transaction (Astra P2).
- A live per-customer Publish credential is an owner of its customer
  account in ownerAuthority (Paul's ruling); the password-off door
  keeps the owner rule without that delegation.
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
claude agent, operated by paul@keymail.dev pushed by paul@keymail.dev c3af558c62ae1aca0ae7a848229656e43443d3c3 parent 21fbd5b
8 files changed, +330 −14
  • internal/console/apiinstances.go +3 −2
  • internal/console/apiplatformcustomers.go +12 −1
  • internal/console/apiplatformcustomers_test.go +20 −2
  • internal/console/apiservices.go +45 −0
  • internal/console/memberrevoke.go +34 −0
  • internal/console/memberrevoke_test.go +100 −0
  • internal/console/platform_credentials.go +10 −6
  • internal/console/platform_credentials_test.go +106 −3
diff --git a/internal/console/apiinstances.go b/internal/console/apiinstances.go
index 409d4b406..9466c8379 100644
--- a/internal/console/apiinstances.go
+++ b/internal/console/apiinstances.go
@@ -3115,8 +3115,9 @@ func (s *Server) handleAPIInstanceUpdate(w http.ResponseWriter, r *http.Request)
}
// Turning a password off is the owner's act (H4-M12): the browser asks
// an owner and a passkey, and the CLI has no step-up yet, so this door
- // asks the owner. Setting one stays any member's.
- if req.Gate != nil && *req.Gate == "" && !s.apiOwnerOnly(w, r, acct, "turn off an instance's password") {
+ // asks the owner. Setting one stays any member's. A platform's
+ // per-customer credential is no owner here (apiStepUpOwnerOnly).
+ if req.Gate != nil && *req.Gate == "" && !s.apiStepUpOwnerOnly(w, r, acct, "turn off an instance's password") {
return
}
// A team credential may not repoint a hostname's upstream (§4): addrs
diff --git a/internal/console/apiplatformcustomers.go b/internal/console/apiplatformcustomers.go
index 8ba8e4338..15902f032 100644
--- a/internal/console/apiplatformcustomers.go
+++ b/internal/console/apiplatformcustomers.go
@@ -141,7 +141,8 @@ func (s *Server) platformGate(w http.ResponseWriter, r *http.Request, failRow st
//
// - apiPrincipalAccount: the platform credential's own account, or an
// account the person belongs to; anything else is the family's 404;
-// - a person who is not an owner is 403 door.not_owner;
+// - a person who is not an owner, or a platform credential whose minter
+// is not one now, is 403 door.not_owner;
// - no grant is 403 door.not_platform, and a grant whose generation is not
// live is 403 door.revoked. It authorizes on PlatformGenerationLive,
// never on the grant row's state alone: a deleted platform's grant row
@@ -176,6 +177,16 @@ func (s *Server) platformAuthorizeDoor(w http.ResponseWriter, r *http.Request, f
http.NotFound(w, r)
return platformCaller{}, false
}
+ // A platform credential is held to its minter's role now, as a
+ // person is above and as every owner gate holds a service
+ // credential (ownerAuthority): an owner who steps down to member
+ // takes the platform doors from what they minted (review round 3,
+ // Astra P2). The mint re-checks it in its insert transaction
+ // (platformMinterHolds).
+ if !s.ownerAuthority(p, acct) {
+ jsonError(w, http.StatusForbidden, platformCopy["door.not_owner"])
+ return platformCaller{}, false
+ }
gen = p.PlatformGeneration
default:
http.NotFound(w, r)
diff --git a/internal/console/apiplatformcustomers_test.go b/internal/console/apiplatformcustomers_test.go
index ce6bea5e4..feaad5f48 100644
--- a/internal/console/apiplatformcustomers_test.go
+++ b/internal/console/apiplatformcustomers_test.go
@@ -3,6 +3,7 @@ package console
import (
"bytes"
"context"
+ "database/sql"
"encoding/json"
"errors"
"fmt"
@@ -60,10 +61,27 @@ func grantPlatformAccount(t *testing.T, fx *consoleFixture, sqid string, max int
return got
}
-// platformToken mints the platform account's platform credential.
+// platformToken mints the platform account's platform credential, as one of
+// its current owners: a platform credential is held to its minter's
+// current role at the platform doors (review round 3), so a fixture minter
+// that is no member would leave it refused. An account with no owner falls
+// back to serviceToken's passing owner.
func platformToken(t *testing.T, fx *consoleFixture, platformID int64, name string) string {
t.Helper()
- return serviceToken(t, fx.st, platformID, name, "", svcrole.Platform)
+ var owner string
+ err := fx.st.db.QueryRow(`SELECT address FROM memberships WHERE account_id = ? AND role = ? ORDER BY address LIMIT 1`,
+ platformID, RoleOwner).Scan(&owner)
+ if errors.Is(err, sql.ErrNoRows) {
+ return serviceToken(t, fx.st, platformID, name, "", svcrole.Platform)
+ }
+ if err != nil {
+ t.Fatal(err)
+ }
+ raw, err := fx.st.NewServicePrincipal(platformID, name, "", svcrole.Platform, owner, time.Now())
+ if err != nil {
+ t.Fatalf("NewServicePrincipal(%q): %v", name, err)
+ }
+ return raw
}
// callJSON is one request with no *testing.T, so goroutines can make it.
diff --git a/internal/console/apiservices.go b/internal/console/apiservices.go
index 4cb832e53..26d483f35 100644
--- a/internal/console/apiservices.go
+++ b/internal/console/apiservices.go
@@ -158,10 +158,55 @@ func (s *Server) apiOwnerOnly(w http.ResponseWriter, r *http.Request, acct *Acco
return false
}
+// apiStepUpOwnerOnly is apiOwnerOnly for a door the browser holds behind
+// an owner and a passkey step-up that Paul's review-round-3 ruling keeps
+// from a platform's delegation (turning an instance's password off): the
+// owner rule without the per-customer credential's standing
+// (stepUpOwnerAuthority). Same refusal as apiOwnerOnly.
+func (s *Server) apiStepUpOwnerOnly(w http.ResponseWriter, r *http.Request, acct *Account, purpose string) bool {
+ p, _ := principalFrom(r.Context())
+ if s.stepUpOwnerAuthority(p, acct) {
+ return true
+ }
+ jsonError(w, http.StatusForbidden, "only an account owner can "+purpose)
+ return false
+}
+
// ownerAuthority is apiOwnerOnly's rule without the answer. A store error
// is not ownership.
+//
+// A live per-customer Publish credential is an owner of its customer
+// account (review round 3, Paul's ruling): the platform runs that account
+// (platform accounts spec §6.2, §7), and an unclaimed customer has no
+// member to hold it to. Its link and grant were re-checked when it
+// resolved on this request (platformCustomerPrincipal). Everything else is
+// stepUpOwnerAuthority.
func (s *Server) ownerAuthority(p Principal, acct *Account) bool {
+ if platformCustomerOwner(p, acct) {
+ return true
+ }
+ return s.stepUpOwnerAuthority(p, acct)
+}
+
+// platformCustomerOwner reports whether p is a per-customer credential
+// (kind platform) of role Publish bound to acct: a platform's credential,
+// on a customer account that is not the platform's own, and on no app.
+// The platform credential itself (role Platform, bound to the platform's
+// own account) is not one: it is held to its minter.
+func platformCustomerOwner(p Principal, acct *Account) bool {
+ return p.Kind == PrincipalService && p.Role == svcrole.Publish && p.App == "" &&
+ p.PlatformAccountID != 0 && p.Platform != "" && p.PlatformGeneration != 0 &&
+ p.AccountID == acct.ID && p.PlatformAccountID != acct.ID
+}
+
+// stepUpOwnerAuthority is the owner rule with no platform delegation: a
+// person must hold the owner role, and a service credential is held to its
+// minter's role now (apiOwnerOnly). A per-customer credential never passes
+// here, whoever minted it.
+func (s *Server) stepUpOwnerAuthority(p Principal, acct *Account) bool {
switch {
+ case p.Kind == PrincipalService && p.PlatformAccountID != 0 && p.PlatformAccountID != p.AccountID:
+ return false
case p.Kind == PrincipalUser:
return acct.Role == RoleOwner
case p.Kind == PrincipalService:
diff --git a/internal/console/memberrevoke.go b/internal/console/memberrevoke.go
index 6a3375776..600bfc930 100644
--- a/internal/console/memberrevoke.go
+++ b/internal/console/memberrevoke.go
@@ -16,6 +16,11 @@ package console
// cli_tokens kind 'app' instance tokens (NewAppToken; any member)
// cli_tokens kind 'service' service credentials of every role, team and
// deploy and run among them (owner-minted)
+// cli_tokens kind 'platform' per-customer credentials on a platform
+// account's customers: those the member minted
+// in person, and every one a platform
+// credential the member minted had minted
+// (endPlatformMintsTx); revoked with no permit
// cli_tokens kind 'link' link credentials, with their links rows
// (approved by any member who creates apps)
// door_keys door keys (any member), by created_by, and
@@ -65,6 +70,8 @@ import (
"log"
"net/http"
"time"
+
+ "github.com/carlosframework/platform/internal/svcrole"
)
// memberRevocationOverdue is the age past which a queued row that still
@@ -107,11 +114,38 @@ func revokeMemberCredentialsTx(tx *sql.Tx, accountID int64, address string, now
if gated {
appFree = " AND app = ''"
}
+ // The member's live platform credentials, read before the update below
+ // revokes them: each one's per-customer mints end with it, as at its
+ // own revoke (endPlatformMintsTx). A platform credential names no app.
+ platformRows, err := tx.Query(`SELECT name FROM cli_tokens
+WHERE account_id = ? AND address = ? AND kind = ? AND role = ? AND name != '' AND revoked_at = 0`,
+ accountID, address, cliKindService, string(svcrole.Platform))
+ if err != nil {
+ return out, err
+ }
+ platformNames, err := scanStrings(platformRows)
+ if err != nil {
+ return out, err
+ }
if _, err := tx.Exec(`UPDATE cli_tokens SET revoked_at = ?
WHERE account_id = ? AND address = ? AND kind IN (?, ?, ?) AND revoked_at = 0`+appFree,
now.Unix(), accountID, address, cliKindApp, cliKindService, cliKindLink); err != nil {
return out, err
}
+ for _, name := range platformNames {
+ if err := endPlatformMintsTx(context.Background(), tx, accountID, name, now); err != nil {
+ return out, err
+ }
+ }
+ // The per-customer credentials the member minted in person, on any
+ // customer of this platform account: their rows sit on the customer's
+ // account and carry the person's address. Revoking one needs no permit
+ // under the claim gate (store_gate.go RevokeFree), app-bound or not.
+ if _, err := tx.Exec(`UPDATE cli_tokens SET revoked_at = ?
+WHERE kind = ? AND platform_account_id = ? AND address = ? AND revoked_at = 0`,
+ now.Unix(), cliKindPlatform, accountID, address); err != nil {
+ return out, err
+ }
links, err := tx.Query(`SELECT id FROM links WHERE account_id = ? AND created_by = ? AND revoked_at = 0 ORDER BY id`,
accountID, address)
if err != nil {
diff --git a/internal/console/memberrevoke_test.go b/internal/console/memberrevoke_test.go
index bc8ea7216..88af1f5b0 100644
--- a/internal/console/memberrevoke_test.go
+++ b/internal/console/memberrevoke_test.go
@@ -409,3 +409,103 @@ func TestRemovalPublicationWaitsForASigningKey(t *testing.T) {
t.Errorf("queue after publishing = %+v, %v; want empty", rows, err)
}
}
+
+// TestRemovingAPlatformOwnerEndsTheirCustomerCredentials (review round 3,
+// Astra P1 / Fable P2): removing an owner of a platform account ends the
+// per-customer credentials they minted in person and every one their own
+// platform credential minted, in the removal's transaction. Another
+// owner's platform credential, and what it minted, go on working.
+func TestRemovingAPlatformOwnerEndsTheirCustomerCredentials(t *testing.T) {
+ fx, p, tok, cust := customerWorld(t, "free")
+ const alice = "alice@example.com"
+ if err := fx.st.AddMember(p.ID, alice, RoleOwner, time.Now()); err != nil {
+ t.Fatal(err)
+ }
+ person := cliToken(t, fx, alice, "code-platform-owner-removal")
+ status, out := postJSON(t, servicesURL(fx, p.Sqid), map[string]any{"name": "alice-cms", "role": "platform"}, person)
+ if status != http.StatusCreated {
+ t.Fatalf("alice's platform credential = %d %v, want 201", status, out)
+ }
+ aliceCMS, _ := out["token"].(string)
+ if _, err := fx.st.CreateAppIn(cust.ID, "site", "service:"+p.Sqid+"/cms", time.Now()); err != nil {
+ t.Fatal(err)
+ }
+ publish := map[string]any{"role": "publish"}
+ deploy := map[string]any{"role": "deploy", "app": "site", "rungs": []string{"edge"}}
+ gone := map[string]string{
+ "alice's platform credential": aliceCMS,
+ "its publish mint": tokenIn(t, customerCredential(t, fx, p.Sqid, cust.Sqid, aliceCMS, publish)),
+ "its deploy mint": tokenIn(t, customerCredential(t, fx, p.Sqid, cust.Sqid, aliceCMS, deploy)),
+ "the publish credential alice minted": tokenIn(t, customerCredential(t, fx, p.Sqid, cust.Sqid, person, publish)),
+ }
+ kept := map[string]string{
+ "the other owner's platform credential": tok,
+ "its mint": tokenIn(t, customerCredential(t, fx, p.Sqid, cust.Sqid, tok, publish)),
+ }
+
+ if err := fx.st.RemoveMember(p.ID, alice); err != nil {
+ t.Fatal(err)
+ }
+ now := time.Now()
+ for what, raw := range gone {
+ if pr, ok := fx.st.CLIPrincipal(raw, now); ok {
+ t.Errorf("after alice's removal, %s resolves to %+v", what, pr)
+ }
+ }
+ for what, raw := range kept {
+ if _, ok := fx.st.CLIPrincipal(raw, now); !ok {
+ t.Errorf("after alice's removal, %s no longer resolves", what)
+ }
+ }
+}
+
+// TestRemovingAPlatformOwnerUnderTheGateEndsTheirCustomerCredentials is
+// the same removal with the host claim's SQL gate armed: a per-customer
+// credential, app-bound or not, is revoked with no permit, so the removal
+// ends it in its own transaction rather than leaving it to a queue.
+func TestRemovingAPlatformOwnerUnderTheGateEndsTheirCustomerCredentials(t *testing.T) {
+ s, _, _ := sqlIngestFixture(t)
+ ctx := context.Background()
+ p := newPlatform(t, s, "bcd")
+ grantPlatform(t, s, p)
+ if _, err := s.db.ExecContext(ctx, `UPDATE accounts SET platform = 'bcd', platform_ref = 'census' WHERE id = ?`, gateAcct); err != nil {
+ t.Fatal(err)
+ }
+ const alice = "alice@example.com"
+ if err := s.AddMember(p, alice, RoleOwner, platformNow); err != nil {
+ t.Fatal(err)
+ }
+ platformTok, err := s.NewServicePrincipal(p, "alice-cms", "", svcrole.Platform, alice, platformNow)
+ if err != nil {
+ t.Fatal(err)
+ }
+ minter, ok := s.CLIPrincipal(platformTok, time.Now())
+ if !ok {
+ t.Fatal("platform credential does not resolve")
+ }
+ now := time.Now()
+ viaService, _, err := s.NewPlatformCustomerCredential(ctx, PlatformCredentialRequest{CustomerID: gateAcct, PlatformAccountID: p,
+ Generation: minter.PlatformGeneration, Minter: minter, MinterTokenHash: hashToken(platformTok), Name: "alice-cms",
+ MintedBy: "service:bcd/alice-cms", Role: svcrole.Deploy, App: "blog", Rungs: []string{"edge"}}, now)
+ if err != nil {
+ t.Fatalf("gated mint by the platform credential: %v", err)
+ }
+ inPerson, _, err := s.NewPlatformCustomerCredential(ctx, PlatformCredentialRequest{CustomerID: gateAcct, PlatformAccountID: p,
+ Generation: minter.PlatformGeneration, Minter: Principal{Kind: PrincipalUser, Address: alice}, Name: alice,
+ MintedBy: alice, Role: svcrole.Publish}, now)
+ if err != nil {
+ t.Fatalf("gated mint in person: %v", err)
+ }
+
+ if err := s.RemoveMember(p, alice); err != nil {
+ t.Fatalf("RemoveMember under the gate = %v", err)
+ }
+ for what, raw := range map[string]string{"platform credential": platformTok, "its deploy mint": viaService, "alice's own mint": inPerson} {
+ if tokenRevokedAt(t, s, hashToken(raw)) == 0 {
+ t.Errorf("%s not revoked by the removal", what)
+ }
+ if pr, ok := s.CLIPrincipal(raw, time.Now()); ok {
+ t.Errorf("%s resolves to %+v after the removal", what, pr)
+ }
+ }
+}
diff --git a/internal/console/platform_credentials.go b/internal/console/platform_credentials.go
index 21c57b492..ef1bbe2d7 100644
--- a/internal/console/platform_credentials.go
+++ b/internal/console/platform_credentials.go
@@ -42,7 +42,8 @@ var (
// ErrPlatformAuthorityEnded is a mint whose authority was gone by the
// time its insert transaction ran: the grant generation ended, the
// customer's link ended, or the minter lost its own authority (its
- // platform credential revoked, or the person no longer an owner).
+ // platform credential revoked, or the person, or the person who minted
+ // that platform credential, no longer an owner).
// Nothing is written.
ErrPlatformAuthorityEnded = errors.New("console: the platform's grant or the minter's authority ended during the request")
// errPlatformCredentialNoApp is a Deploy mint whose app the customer no
@@ -199,8 +200,10 @@ VALUES (?, ?, '', '', ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, '', '', ?, ?)`,
// own row (by credential id) is a live platform credential of this platform
// at req.Generation, and still holds the secret the request authenticated
// with (req.MinterTokenHash: a rotation replaces it, a revoke sets
-// revoked_at, and either ends the mint); a person is an owner of the
-// platform account. Any other principal holds nothing.
+// revoked_at, and either ends the mint), and the person who minted that
+// credential (its address) is still an owner of the platform account
+// (review round 3, Astra P2); a person is an owner of the platform
+// account. Any other principal holds nothing.
func platformMinterHolds(ctx context.Context, tx *sql.Tx, req PlatformCredentialRequest, now time.Time) (bool, error) {
var one int
var err error
@@ -209,11 +212,12 @@ func platformMinterHolds(ctx context.Context, tx *sql.Tx, req PlatformCredential
if req.Minter.CredentialID == "" || req.MinterTokenHash == "" {
return false, nil
}
- err = tx.QueryRowContext(ctx, `SELECT 1 FROM cli_tokens WHERE credential_id = ? AND token_hash = ? AND kind = ?
+ err = tx.QueryRowContext(ctx, `SELECT 1 FROM cli_tokens t WHERE credential_id = ? AND token_hash = ? AND kind = ?
AND role = ? AND account_id = ? AND platform_account_id = ? AND platform_generation = ? AND revoked_at = 0
- AND (expires_at = 0 OR expires_at >= ?)`,
+ AND (expires_at = 0 OR expires_at >= ?)
+ AND EXISTS (SELECT 1 FROM memberships m WHERE m.account_id = t.account_id AND m.address = t.address AND m.role = ?)`,
req.Minter.CredentialID, req.MinterTokenHash, cliKindService, string(svcrole.Platform), req.PlatformAccountID,
- req.PlatformAccountID, req.Generation, now.Unix()).Scan(&one)
+ req.PlatformAccountID, req.Generation, now.Unix(), RoleOwner).Scan(&one)
case PrincipalUser:
if req.Minter.Address == "" {
return false, nil
diff --git a/internal/console/platform_credentials_test.go b/internal/console/platform_credentials_test.go
index 0b8c581cc..1e1a47b00 100644
--- a/internal/console/platform_credentials_test.go
+++ b/internal/console/platform_credentials_test.go
@@ -954,7 +954,7 @@ func TestUnknownTokenKindStillRefused(t *testing.T) {
}
func TestPersonalTokenListOmitsCustomerCredentials(t *testing.T) {
- fx, p, _, cust := customerWorld(t, "free")
+ fx, p, cms, cust := customerWorld(t, "free")
addr := "owner" + p.Sqid + "@example.com"
owner := cliToken(t, fx, addr, "code-customer-cred-list")
raw := tokenIn(t, customerCredential(t, fx, p.Sqid, cust.Sqid, owner, map[string]any{"role": "publish"}))
@@ -973,8 +973,18 @@ func TestPersonalTokenListOmitsCustomerCredentials(t *testing.T) {
if err != nil {
t.Fatal(err)
}
- if len(tokens) != 1 || tokens[0].ID != hashToken(owner) {
- t.Fatalf("CLITokens(%s) = %+v, want the person's own terminal alone", addr, tokens)
+ // The person's terminal and the platform credential cms they minted
+ // (platformToken mints as the platform's owner); never the customer
+ // credential.
+ ids := make([]string, 0, len(tokens))
+ for _, tk := range tokens {
+ ids = append(ids, tk.ID)
+ }
+ slices.Sort(ids)
+ want := []string{hashToken(owner), hashToken(cms)}
+ slices.Sort(want)
+ if !slices.Equal(ids, want) {
+ t.Fatalf("CLITokens(%s) = %+v, want the person's own terminal and cms alone", addr, tokens)
}
}
@@ -1319,3 +1329,96 @@ func TestCustomerDeployCredentialEndsWithItsApp(t *testing.T) {
wantEnded(t, fx, "while site is trashed", cust.Sqid, "site", raw)
})
}
+
+// TestDemotedOwnersPlatformCredentialMintsNothing (review round 3, Astra
+// P2): a platform credential is held to its minter's current role, as a
+// person is. Once its minter steps down to member it mints no per-customer
+// credential, whether the demotion lands before the request or while the
+// mint waits on its insert.
+func TestDemotedOwnersPlatformCredentialMintsNothing(t *testing.T) {
+ fx, p, _, cust := customerWorld(t, "free")
+ const alice = "alice@example.com"
+ if err := fx.st.AddMember(p.ID, alice, RoleOwner, time.Now()); err != nil {
+ t.Fatal(err)
+ }
+ person := cliToken(t, fx, alice, "code-demoted-platform-minter")
+ status, out := postJSON(t, servicesURL(fx, p.Sqid), map[string]any{"name": "alice-cms", "role": "platform"}, person)
+ if status != http.StatusCreated {
+ t.Fatalf("alice's platform credential = %d %v, want 201", status, out)
+ }
+ aliceCMS, _ := out["token"].(string)
+ customerCredential(t, fx, p.Sqid, cust.Sqid, aliceCMS, map[string]any{"role": "publish"})
+
+ demote := func() {
+ if err := fx.st.AddMember(p.ID, alice, RoleMember, time.Now()); err != nil {
+ t.Error(err)
+ }
+ }
+ demote()
+ status, out, _ = mintCustomerCredential(t, fx.ts.URL, p.Sqid, cust.Sqid, aliceCMS, map[string]any{"role": "publish"})
+ wantPlatformError(t, "a demoted owner's platform credential", status, out, http.StatusForbidden, "door.not_owner")
+ if n := customerCredentialRows(t, fx.st, cust.ID); n != 1 {
+ t.Fatalf("kind platform rows = %d, want only the mint made while alice was an owner", n)
+ }
+
+ // Demoted while the mint waits: the door admitted it, and the insert
+ // transaction's re-check refuses it.
+ if err := fx.st.AddMember(p.ID, alice, RoleOwner, time.Now()); err != nil {
+ t.Fatal(err)
+ }
+ var mu sync.Mutex
+ var cur *seamGate
+ set := func(g *seamGate) { mu.Lock(); cur = g; mu.Unlock() }
+ fx.srv.platformCredentialBeforeInsert = func() {
+ mu.Lock()
+ g := cur
+ mu.Unlock()
+ if g != nil {
+ g.block()
+ }
+ }
+ status, out, _ = pausedMint(t, fx, set, p.Sqid, cust.Sqid, aliceCMS, demote)
+ wantPlatformError(t, "a platform credential whose minter is demoted during the mint", status, out, http.StatusForbidden, "door.revoked")
+ if n := customerCredentialRows(t, fx.st, cust.ID); n != 1 {
+ t.Fatalf("kind platform rows = %d after the paused mint, want 1", n)
+ }
+}
+
+// TestCustomerPublishCredentialIsTheCustomersOwner (review round 3, Paul's
+// ruling): a live per-customer Publish credential counts as an owner at the
+// customer account's owner-only doors, so a platform keeps attaching
+// domains and deleting apps for a customer nobody has claimed (platform
+// accounts spec §6.2, §7). A door the browser also holds behind a step-up
+// (turning an instance's password off) is not one of them.
+func TestCustomerPublishCredentialIsTheCustomersOwner(t *testing.T) {
+ fx, p, tok, cust := customerWorld(t, "free")
+ raw := tokenIn(t, customerCredential(t, fx, p.Sqid, cust.Sqid, tok, map[string]any{"role": "publish"}))
+ if status, _, body := rawReq(t, http.MethodPost, fx.ts.URL+"/api/cli/apps/"+cust.Sqid+"/new", raw, `{"name":"site"}`); status/100 != 2 {
+ t.Fatalf("create site = %d %s", status, body)
+ }
+ detach := domainsURL(fx, cust.Sqid, "site") + "/nothing.example.com"
+ if status, _, body := rawReq(t, http.MethodDelete, detach, raw, ""); status != http.StatusOK {
+ t.Fatalf("detach with the customer's publish credential = %d %s, want 200", status, body)
+ }
+ if status, _, body := rawReq(t, http.MethodPost, fx.ts.URL+"/api/cli/apps/"+cust.Sqid+"/site/delete", raw, ""); status != http.StatusOK {
+ t.Fatalf("delete site with the customer's publish credential = %d %s, want 200", status, body)
+ }
+
+ pr, ok := fx.st.CLIPrincipal(raw, time.Now())
+ if !ok {
+ t.Fatal("the customer credential does not resolve")
+ }
+ if !fx.srv.ownerAuthority(pr, cust) {
+ t.Error("ownerAuthority refuses the customer's publish credential")
+ }
+ if fx.srv.stepUpOwnerAuthority(pr, cust) {
+ t.Error("the step-up owner rule admits the customer's publish credential")
+ }
+ // Not on any other account: the platform's own, or another customer.
+ c2 := secondCustomer(t, fx, p, tok)
+ for _, acct := range []*Account{p, c2} {
+ if fx.srv.ownerAuthority(pr, acct) {
+ t.Errorf("ownerAuthority admits the customer's credential on %s", acct.Sqid)
+ }
+ }
+}