carlos / platform Public

console: service credentials meet owner gates as their minter (H4 r1)

Review round 1 (Fable P2-3): ownerAuthority passed every named service
principal, so an owner who transferred ownership away kept owner-only
reach (delete, place, pipeline, domains, gate clear) through the Publish
or Admin credentials they had minted. Every service credential is now
held to its minter's current role, as the legacy instance token already
was. The door's role set still limits what it may call.

TestDemotedOwnersServiceLosesOwnerDoors. Eleven tests that drive an
owner door with the fixture credential now have its minter be an owner
(ownerMintsServices).
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
claude agent, operated by paul@keymail.dev pushed by paul@keymail.dev c008e3e1d154e03498eeac1b002cacb142a2c841 parent b4e6bda
8 files changed, +55 −9
  • internal/console/apidomains_test.go +4 −0
  • internal/console/apipipeline_test.go +1 −0
  • internal/console/apiservices.go +8 −9
  • internal/console/controlplane_test.go +1 −0
  • internal/console/memberrevoke_test.go +29 −0
  • internal/console/subdomains_test.go +1 −0
  • internal/console/svcfixture_test.go +10 −0
  • internal/console/teamdoors_test.go +1 −0
diff --git a/internal/console/apidomains_test.go b/internal/console/apidomains_test.go
index a2b43f0df..abdc94b73 100644
--- a/internal/console/apidomains_test.go
+++ b/internal/console/apidomains_test.go
@@ -1277,6 +1277,7 @@ func TestWildcardEnableIsNotRateLimited(t *testing.T) {
attempts, cliInstanceBurst, svcWriteBurst, domainsCeilingBurst)
}
fx, _ := instanceFixture(t, "code-wc-exempt")
+ ownerMintsServices(t, fx)
svc := serviceToken(t, fx.st, OpsAccountID, "hub", "titogo", svcrole.Publish)
fx.srv.delegationZone = zone
fx.srv.lookupCNAME = func(_ context.Context, name string) (string, error) {
@@ -1305,6 +1306,7 @@ func TestWildcardEnableIsNotRateLimited(t *testing.T) {
// it — the ceiling applies to the door, not to the wildcard flags.
func TestDomainsCeilingBoundsConvergenceRate(t *testing.T) {
fx, _ := instanceFixture(t, "code-wc-ceiling")
+ ownerMintsServices(t, fx)
svc := serviceToken(t, fx.st, OpsAccountID, "hub", "titogo", svcrole.Publish)
var saw429 bool
for i := 0; i < domainsCeilingBurst+5; i++ {
@@ -1333,6 +1335,7 @@ func TestDomainsCeilingBoundsConvergenceRate(t *testing.T) {
func TestFailedWildcardEnableIsBounded(t *testing.T) {
const zone = "acme.example"
fx, _ := instanceFixture(t, "code-wc-bounded")
+ ownerMintsServices(t, fx)
svc := serviceToken(t, fx.st, OpsAccountID, "hub", "titogo", svcrole.Publish)
fx.srv.delegationZone = zone
fx.srv.lookupCNAME = func(context.Context, string) (string, error) {
@@ -1363,6 +1366,7 @@ func TestFailedWildcardEnableIsBounded(t *testing.T) {
func TestIdempotentReattachTouchesNeitherBudget(t *testing.T) {
const zone = "acme.example"
fx, _ := instanceFixture(t, "code-wc-idempotent")
+ ownerMintsServices(t, fx)
svc := serviceToken(t, fx.st, OpsAccountID, "hub", "titogo", svcrole.Instance)
fx.srv.delegationZone = zone
const host = "one.pages.example"
diff --git a/internal/console/apipipeline_test.go b/internal/console/apipipeline_test.go
index 36bd5c30a..62e4a11b3 100644
--- a/internal/console/apipipeline_test.go
+++ b/internal/console/apipipeline_test.go
@@ -380,6 +380,7 @@ func TestAPIPipelinePutStoreFailureStatuses(t *testing.T) {
// breaks a test instead of silently locking every service out.
func TestAPIPipelinePutNoServiceRoleReachesIt(t *testing.T) {
fx := newConsoleFixture(t)
+ ownerMintsServices(t, fx)
if _, err := fx.st.CreateAppIn(OpsAccountID, "widget", "paul@keymail.dev", time.Now()); err != nil {
t.Fatal(err)
}
diff --git a/internal/console/apiservices.go b/internal/console/apiservices.go
index 9d1d14553..84506a56d 100644
--- a/internal/console/apiservices.go
+++ b/internal/console/apiservices.go
@@ -142,12 +142,13 @@ func (s *Server) apiOwnerAccountFor(w http.ResponseWriter, r *http.Request, purp
// It answers apiOwnerAccountFor's 403 in the same words: the caller has
// proved membership, so the refusal hides nothing (security hunt H4).
//
-// A person must hold the owner role. A service credential minted through
-// the services doors carries the authority of the owner who minted it
-// (those doors are owner-only) and passes; the door's role set is its
-// limit. A legacy instance token (kind 'app', no name), which ANY member
-// may mint, is held to its minter's role now: otherwise a member reaches an
-// owner-only act by minting one and calling the door with it.
+// A person must hold the owner role. A service credential is held to its
+// minter's role NOW, whatever its kind: a legacy instance token, which any
+// member may mint, so that a member cannot reach an owner-only act by
+// minting one; and a named service credential, so that an owner who
+// transfers ownership away (and steps down to member) takes the owner-only
+// reach of what they minted with them (review round 1). The door's role
+// set still limits what the credential may call at all.
func (s *Server) apiOwnerOnly(w http.ResponseWriter, r *http.Request, acct *Account, purpose string) bool {
p, _ := principalFrom(r.Context())
if s.ownerAuthority(p, acct) {
@@ -163,14 +164,12 @@ func (s *Server) ownerAuthority(p Principal, acct *Account) bool {
switch {
case p.Kind == PrincipalUser:
return acct.Role == RoleOwner
- case p.Kind == PrincipalService && p.Name == "":
+ case p.Kind == PrincipalService:
role, err := s.store.Role(acct.ID, p.Address)
if err != nil {
log.Printf("console: owner gate %s: minter role: %v", acct.Sqid, err)
}
return err == nil && role == RoleOwner
- case p.Kind == PrincipalService:
- return true
}
return false
}
diff --git a/internal/console/controlplane_test.go b/internal/console/controlplane_test.go
index d7ebc1b16..17bef1460 100644
--- a/internal/console/controlplane_test.go
+++ b/internal/console/controlplane_test.go
@@ -1230,6 +1230,7 @@ func TestControlPlaneDomainDetachRefusalIsNotAnOracle(t *testing.T) {
// deliberately not conditional on which branch would have run.
func TestControlPlaneAppRefusesAServiceDomainAttach(t *testing.T) {
fx := newConsoleFixture(t)
+ ownerMintsServices(t, fx)
if err := fx.st.SetAppControlPlane(OpsAccountID, "kass", true); err != nil {
t.Fatal(err)
}
diff --git a/internal/console/memberrevoke_test.go b/internal/console/memberrevoke_test.go
index 97709e19f..17597c218 100644
--- a/internal/console/memberrevoke_test.go
+++ b/internal/console/memberrevoke_test.go
@@ -289,3 +289,32 @@ func TestRemovalDoorKeyPublicationIsDurable(t *testing.T) {
t.Errorf("queued follow-ups after the drain = %+v, %v; want none", rows, err)
}
}
+
+// TestDemotedOwnersServiceLosesOwnerDoors (review round 1, Fable P2-3): a
+// service credential is held to its minter's current role at every owner
+// gate. Minted by an owner it passes; once that owner steps down to
+// member, it meets the owner gate's 403.
+func TestDemotedOwnersServiceLosesOwnerDoors(t *testing.T) {
+ fx := newConsoleFixture(t)
+ now := time.Now()
+ if _, err := fx.st.CreateAppIn(OpsAccountID, "titogo", "paul@keymail.dev", now); err != nil {
+ t.Fatal(err)
+ }
+ if err := fx.st.AddMember(OpsAccountID, "alice@keymail.dev", RoleOwner, now); err != nil {
+ t.Fatal(err)
+ }
+ svc, err := fx.st.NewServicePrincipal(OpsAccountID, "ci", "titogo", svcrole.Publish, "alice@keymail.dev", now)
+ if err != nil {
+ t.Fatal(err)
+ }
+ detach := domainsURL(fx, "bab", "titogo") + "/nothing.example.com"
+ if code, _, out := rawReq(t, http.MethodDelete, detach, svc, ""); code != http.StatusOK {
+ t.Fatalf("owner-minted service at an owner door = %d %s, want 200", code, out)
+ }
+ if err := fx.st.AddMember(OpsAccountID, "alice@keymail.dev", RoleMember, now); err != nil {
+ t.Fatal(err)
+ }
+ if code, _, out := rawReq(t, http.MethodDelete, detach, svc, ""); code != http.StatusForbidden {
+ t.Fatalf("a demoted owner's service at an owner door = %d %s, want 403", code, out)
+ }
+}
diff --git a/internal/console/subdomains_test.go b/internal/console/subdomains_test.go
index 76cab4a72..1e74aa2c0 100644
--- a/internal/console/subdomains_test.go
+++ b/internal/console/subdomains_test.go
@@ -63,6 +63,7 @@ func nsShopFixture(t *testing.T, code string) (fx *consoleFixture, member, opera
// is. The namespace refusals below exempt no operator either way.
func nsAttacher(t *testing.T, fx *consoleFixture) string {
t.Helper()
+ ownerMintsServices(t, fx)
return serviceToken(t, fx.st, OpsAccountID, "ns-attacher", "shop", svcrole.Publish)
}
diff --git a/internal/console/svcfixture_test.go b/internal/console/svcfixture_test.go
index f771faeab..c8a8ac9c2 100644
--- a/internal/console/svcfixture_test.go
+++ b/internal/console/svcfixture_test.go
@@ -36,3 +36,13 @@ func teamToken(t *testing.T, st *Store, accountID int64, name, app, scope string
}
return raw
}
+
+// ownerMintsServices makes serviceToken's and teamToken's minter an owner
+// of the ops account: every owner gate holds a service credential to its
+// minter's current role (review round 1), so a test that drives an
+// owner-only door with a fixture credential needs an owner to have minted
+// it. A service is never a platform operator, whatever its minter is.
+func ownerMintsServices(t *testing.T, fx *consoleFixture) {
+ t.Helper()
+ makeOwner(t, fx, "paul@example.test")
+}
diff --git a/internal/console/teamdoors_test.go b/internal/console/teamdoors_test.go
index 1c37cf2e7..3f3b6ceb5 100644
--- a/internal/console/teamdoors_test.go
+++ b/internal/console/teamdoors_test.go
@@ -580,6 +580,7 @@ func TestTeamRestartScopeDoor(t *testing.T) {
// with Route "" is out of scope at every door.
func TestTeamDomainDoors(t *testing.T) {
w := newTeamWorld(t, "code-team-domains")
+ ownerMintsServices(t, w.fx)
ctx := context.Background()
// A member's claims: one on theirs, one first-route claim (Route "").
owner := cliToken(t, w.fx, "paul@keymail.dev", "code-team-domains-owner") // attach is owner-only (H4-M7)