carlos / platform Public

console: CLI domain attach and detach are owner-only (H4-M7)

The CLI/API domain attach and detach doors checked membership only (or
took a publish or instance credential), while the browser twins in
appdomains.go require the owner. Both CLI doors now call apiOwnerOnly
right after domainsGate: after the family's 404, before any branch
writes. A member-minted instance token is held to its minter's role.
The browser has no passkey step here, so none is owed.

carlos deploy's first-route attach and carlos domains verify now need an
owner for a person caller.

Carries the hunt test TestHunt_H4_M7_MemberCannotDetachDomain. Domain
tests that attached as a member now attach as an owner (domainOwnerFixture,
makeOwner). Four namespace tests use an owner-minted publish credential,
since every ops-account owner is a platform operator.
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
claude agent, operated by paul@keymail.dev pushed by paul@keymail.dev 3c7897e47552ccef92b0115658d554d2ebac1b68 parent 7b6a370
20 files changed, +173 −95
  • internal/console/apidomainpaths_test.go +10 −10
  • internal/console/apidomains.go +10 −0
  • internal/console/apidomains_firstroute_test.go +2 −2
  • internal/console/apidomains_test.go +51 −32
  • internal/console/apifeatures_test.go +1 −1
  • internal/console/deletion_evidence_test.go +2 −2
  • internal/console/demo_api_origin_test.go +3 −1
  • internal/console/domaincatchall_test.go +1 −1
  • internal/console/domainplatform_test.go +8 −5
  • internal/console/domainpolicy_test.go +5 −5
  • internal/console/domainproof_test.go +4 −4
  • internal/console/hap2_wiring_test.go +1 −1
  • internal/console/hostsused_writers_test.go +1 −1
  • internal/console/hunt_H4-M7_test.go +27 −0
  • internal/console/lifetimes_create_test.go +6 −6
  • internal/console/lifetimes_retire_test.go +2 −2
  • internal/console/plancaps_doors_test.go +3 −3
  • internal/console/regional_writers_test.go +4 −3
  • internal/console/subdomains_test.go +30 −15
  • internal/console/teamdoors_test.go +2 −1
diff --git a/internal/console/apidomainpaths_test.go b/internal/console/apidomainpaths_test.go
index 65ca4d4ec..d836e9049 100644
--- a/internal/console/apidomainpaths_test.go
+++ b/internal/console/apidomainpaths_test.go
@@ -76,7 +76,7 @@ func claimedHost(t *testing.T, fx *consoleFixture, member, host string) {
// TestAPIDomainPathsPublishes: the door writes the map onto the claim, and
// the answer names the normalized host it wrote to.
func TestAPIDomainPathsPublishes(t *testing.T) {
- fx, member := instanceFixture(t, "code-dom-paths-publish")
+ fx, member := domainOwnerFixture(t, "code-dom-paths-publish")
claimedHost(t, fx, member, "ti.to")
got := publishPaths(t, fx, member, "ti.to", map[string]string{"paulca": "go.tito.io"})
if got != (domainPathsResp{Host: "ti.to", Prefixes: 1, Changed: true}) {
@@ -98,7 +98,7 @@ func TestAPIDomainPathsPublishes(t *testing.T) {
// regenerates its whole map and publishes it, so an entry it no longer lists
// must be GONE. Merging would make a rollback impossible to express.
func TestAPIDomainPathsReplaces(t *testing.T) {
- fx, member := instanceFixture(t, "code-dom-paths-replace")
+ fx, member := domainOwnerFixture(t, "code-dom-paths-replace")
claimedHost(t, fx, member, "ti.to")
publishPaths(t, fx, member, "ti.to", map[string]string{"paulca": "go.tito.io"})
publishPaths(t, fx, member, "ti.to", map[string]string{"bigcorp": "go.tito.io"})
@@ -115,7 +115,7 @@ func TestAPIDomainPathsReplaces(t *testing.T) {
// state — every account back on the origin — and is how a whole migration is
// rolled back in one call.
func TestAPIDomainPathsEmptyBodyClears(t *testing.T) {
- fx, member := instanceFixture(t, "code-dom-paths-clear")
+ fx, member := domainOwnerFixture(t, "code-dom-paths-clear")
claimedHost(t, fx, member, "ti.to")
publishPaths(t, fx, member, "ti.to", map[string]string{"paulca": "go.tito.io"})
got := publishPaths(t, fx, member, "ti.to", map[string]string{})
@@ -132,7 +132,7 @@ func TestAPIDomainPathsEmptyBodyClears(t *testing.T) {
// field would otherwise clear every prefix on the hostname and answer 200.
// An empty map still means "clear it"; it just has to be said.
func TestAPIDomainPathsRequiresThePathsField(t *testing.T) {
- fx, member := instanceFixture(t, "code-dom-paths-nofield")
+ fx, member := domainOwnerFixture(t, "code-dom-paths-nofield")
claimedHost(t, fx, member, "ti.to")
publishPaths(t, fx, member, "ti.to", map[string]string{"paulca": "go.tito.io"})
@@ -155,7 +155,7 @@ func TestAPIDomainPathsRequiresThePathsField(t *testing.T) {
// account and app, so what refuses it is the claim's ownership check rather
// than the membership gate above it.
func TestAPIDomainPathsRejectsOtherAccount(t *testing.T) {
- fx, member := instanceFixture(t, "code-dom-paths-other")
+ fx, member := domainOwnerFixture(t, "code-dom-paths-other")
claimedHost(t, fx, member, "ti.to")
// The positive control, and it is not optional: an UNREGISTERED route
// answers the byte-identical 404 too, so without a publish that works
@@ -188,7 +188,7 @@ func TestAPIDomainPathsRejectsOtherAccount(t *testing.T) {
// silently truncated map would route a subset of accounts and still look
// successful, which is the worst failure this feature can have.
func TestAPIDomainPathsRejectsOversize(t *testing.T) {
- fx, member := instanceFixture(t, "code-dom-paths-oversize")
+ fx, member := domainOwnerFixture(t, "code-dom-paths-oversize")
claimedHost(t, fx, member, "ti.to")
publishPaths(t, fx, member, "ti.to", map[string]string{"paulca": "go.tito.io"})
@@ -211,7 +211,7 @@ func TestAPIDomainPathsRejectsOversize(t *testing.T) {
// never be stored. "/paulca" is the shape a caller reaches for first, so it
// is the one worth pinning.
func TestAPIDomainPathsRejectsBadPrefix(t *testing.T) {
- fx, member := instanceFixture(t, "code-dom-paths-badprefix")
+ fx, member := domainOwnerFixture(t, "code-dom-paths-badprefix")
claimedHost(t, fx, member, "ti.to")
code, _, out := rawReq(t, http.MethodPut, pathsURL(fx, "bab", "titogo", "ti.to"), member,
pathsBody(t, map[string]string{"/paulca": "go.tito.io"}))
@@ -236,7 +236,7 @@ func TestAPIDomainPathsRejectsBadPrefix(t *testing.T) {
// drops it into the wrong branch, and dropping the %w wrap in claims.go is
// enough to move every case in this test from 422 to 502.
func TestAPIDomainPathsRejectsBadTarget(t *testing.T) {
- fx, member := instanceFixture(t, "code-dom-paths-badtarget")
+ fx, member := domainOwnerFixture(t, "code-dom-paths-badtarget")
claimedHost(t, fx, member, "ti.to")
for _, target := range []string{"notahostname", "GO.tito.io", "go.tito.io.", "go tito io"} {
code, _, out := rawReq(t, http.MethodPut, pathsURL(fx, "bab", "titogo", "ti.to"), member,
@@ -270,7 +270,7 @@ func TestAPIDomainPathsRejectsBadTarget(t *testing.T) {
// regardless: this door reports what was published, and makes no judgement
// about what a box did with it.
func TestAPIDomainGetAnswersThePublishedMap(t *testing.T) {
- fx, member := instanceFixture(t, "code-dom-get-paths")
+ fx, member := domainOwnerFixture(t, "code-dom-get-paths")
claimedHost(t, fx, member, "ti.to")
// Before anything is published: an object, never null, so a client can
@@ -329,7 +329,7 @@ func getPaths(t *testing.T, fx *consoleFixture, token, host string) map[string]s
// Operate is the negative control: widening the door must widen it to a
// named pair, not to every service role.
func TestAPIDomainPathsReachesPublishAndInstance(t *testing.T) {
- fx, member := instanceFixture(t, "code-dom-paths-roles")
+ fx, member := domainOwnerFixture(t, "code-dom-paths-roles")
claimedHost(t, fx, member, "ti.to")
body := pathsBody(t, map[string]string{"paulca": "go.tito.io"})
diff --git a/internal/console/apidomains.go b/internal/console/apidomains.go
index 18bd3d167..12ca3a3c8 100644
--- a/internal/console/apidomains.go
+++ b/internal/console/apidomains.go
@@ -305,6 +305,11 @@ func (s *Server) handleAPIDomainAttach(w http.ResponseWriter, r *http.Request) {
if !ok {
return
}
+ // The browser's attach is owner-only (appdomains.go); so is this
+ // door (H4-M7). A member-minted instance token is held to its minter.
+ if !s.apiOwnerOnly(w, r, acct, "attach a domain") {
+ return
+ }
if s.refuseTemporary(w, acct, app, "attach a domain to it") {
return
}
@@ -1138,6 +1143,11 @@ func (s *Server) handleAPIDomainDetach(w http.ResponseWriter, r *http.Request) {
if !ok {
return
}
+ // The browser's detach is owner-only (appdomains.go); so is this
+ // door (H4-M7). A member-minted instance token is held to its minter.
+ if !s.apiOwnerOnly(w, r, acct, "detach a domain") {
+ return
+ }
// The NINTH control-plane door, and the same fuse as the instance
// delete: the first-route branch below calls the very
// provision.DeleteRecord that retires a route, on the same app, and this
diff --git a/internal/console/apidomains_firstroute_test.go b/internal/console/apidomains_firstroute_test.go
index 61b5ef7fe..e7482535e 100644
--- a/internal/console/apidomains_firstroute_test.go
+++ b/internal/console/apidomains_firstroute_test.go
@@ -19,7 +19,7 @@ import (
// to the host itself.
func firstRouteFixture(t *testing.T, code string) (*consoleFixture, string) {
t.Helper()
- fx, member := instanceFixture(t, code)
+ fx, member := domainOwnerFixture(t, code) // attach is owner-only (H4-M7)
ctx := context.Background()
if _, _, err := domains.AttachClaim(ctx, fx.rel, domains.Claim{
Host: "woodstar.app", Account: "bab", App: "titogo", CreatedAt: time.Now().UTC().Format(time.RFC3339),
@@ -81,7 +81,7 @@ func TestAttachKeepsAFirstRouteClaimFirstRoute(t *testing.T) {
// Another holder's claim does not take the branch: the ordinary path answers
// with its neutral refusal, exactly as before.
func TestAttachFirstRouteBranchIsOwnClaimsOnly(t *testing.T) {
- fx, member := instanceFixture(t, "code-dom-fr-other")
+ fx, member := domainOwnerFixture(t, "code-dom-fr-other")
if _, _, err := domains.AttachClaim(context.Background(), fx.rel, domains.Claim{
Host: "woodstar.app", Account: "cdef", App: "widgets", CreatedAt: time.Now().UTC().Format(time.RFC3339),
}); err != nil {
diff --git a/internal/console/apidomains_test.go b/internal/console/apidomains_test.go
index 00296732e..a2b43f0df 100644
--- a/internal/console/apidomains_test.go
+++ b/internal/console/apidomains_test.go
@@ -39,6 +39,24 @@ func domainsURL(fx *consoleFixture, acct, app string) string {
return fx.ts.URL + "/api/cli/apps/" + acct + "/" + app + "/domains"
}
+// domainOwnerFixture is instanceFixture with alice an OWNER of the account:
+// the CLI domain attach and detach doors are owner-only, as the browser's
+// are (security hunt H4-M7, TestHunt_H4_M7_MemberCannotDetachDomain).
+func domainOwnerFixture(t *testing.T, code string) (*consoleFixture, string) {
+ t.Helper()
+ fx, token := instanceFixture(t, code)
+ makeOwner(t, fx, "alice@keymail.dev")
+ return fx, token
+}
+
+// makeOwner gives address the owner role in the ops account.
+func makeOwner(t *testing.T, fx *consoleFixture, address string) {
+ t.Helper()
+ if err := fx.st.AddMember(OpsAccountID, address, RoleOwner, time.Now()); err != nil {
+ t.Fatal(err)
+ }
+}
+
// attachBody is the door's request shape. route is always sent (empty means
// "default it"), because an omitted field and an empty one must behave the
// same and the tests exercise the empty one.
@@ -111,7 +129,7 @@ func claimAbsent(t *testing.T, fx *consoleFixture, host string) {
// named route — 200, created true, and a claim object in the bucket carrying
// the member as its author.
func TestAPIDomainAttachCreates(t *testing.T) {
- fx, member := instanceFixture(t, "code-dom-create")
+ fx, member := domainOwnerFixture(t, "code-dom-create")
got := attachDomain(t, fx, member, "tickets.example.com", "go.tito.io")
if got != (domainAttachResp{Host: "tickets.example.com", Route: "go.tito.io", Created: true}) {
t.Fatalf("attach answer = %+v, want the host/route echoed with created true", got)
@@ -134,7 +152,7 @@ func TestAPIDomainAttachCreates(t *testing.T) {
}
func TestAPIDomainAttachRecordsDescriptionAndCanonicalRoute(t *testing.T) {
- fx, member := instanceFixture(t, "code-dom-message")
+ fx, member := domainOwnerFixture(t, "code-dom-message")
body := `{"host":"tickets.example.com","route":"go.tito.io","message":"attach the ticket checkout"}`
code, _, out := rawReq(t, http.MethodPost, domainsURL(fx, "bab", "titogo"), member, body)
if code != http.StatusOK {
@@ -152,7 +170,7 @@ func TestAPIDomainAttachRecordsDescriptionAndCanonicalRoute(t *testing.T) {
}
func TestAPIDomainAttachRejectsInvalidDescriptionBeforeWriting(t *testing.T) {
- fx, member := instanceFixture(t, "code-dom-message-invalid")
+ fx, member := domainOwnerFixture(t, "code-dom-message-invalid")
body := `{"host":"tickets.example.com","route":"go.tito.io","message":"first\nsecond"}`
code, _, out := rawReq(t, http.MethodPost, domainsURL(fx, "bab", "titogo"), member, body)
if code != http.StatusBadRequest {
@@ -169,7 +187,7 @@ func TestAPIDomainAttachRejectsInvalidDescriptionBeforeWriting(t *testing.T) {
// family's byte-identical 404 (apiInstancePrincipal's contract), never a
// hint that the path exists.
func TestAPIDomainAttachAppToken(t *testing.T) {
- fx, _ := instanceFixture(t, "code-dom-apptoken")
+ fx, _ := domainOwnerFixture(t, "code-dom-apptoken")
now := time.Now()
if _, err := fx.st.CreateAppIn(OpsAccountID, "other", "alice@keymail.dev", now); err != nil {
t.Fatal(err)
@@ -208,7 +226,7 @@ func TestAPIDomainAttachAppToken(t *testing.T) {
// a second identical attach is 200 with created false, and an attach naming a
// different route converges the claim in place rather than refusing it.
func TestAPIDomainAttachIdempotent(t *testing.T) {
- fx, member := instanceFixture(t, "code-dom-idem")
+ fx, member := domainOwnerFixture(t, "code-dom-idem")
if got := attachDomain(t, fx, member, "tickets.example.com", "go.tito.io"); !got.Created {
t.Fatalf("first attach = %+v, want created true", got)
}
@@ -227,7 +245,7 @@ func TestAPIDomainAttachIdempotent(t *testing.T) {
// 409 whose body says exactly one thing — never who holds it, never whether
// the holder is in this deployment at all.
func TestAPIDomainAttachConflictNeutral(t *testing.T) {
- fx, member := instanceFixture(t, "code-dom-conflict")
+ fx, member := domainOwnerFixture(t, "code-dom-conflict")
if _, _, err := domains.AttachClaim(context.Background(), fx.rel, domains.Claim{
Host: "tickets.example.com", Account: "cdef", App: "widgets",
Route: "widgets.example.net", CreatedAt: time.Now().UTC().Format(time.RFC3339),
@@ -256,7 +274,7 @@ func TestAPIDomainAttachConflictNeutral(t *testing.T) {
// (CONSOLE_REDIRECT_HOSTS, which this console still answers on and 301s
// away, such as an old console.example.org).
func TestAPIDomainAttachValidation(t *testing.T) {
- fx, member := instanceFixture(t, "code-dom-validate")
+ fx, member := domainOwnerFixture(t, "code-dom-validate")
fx.srv.cfg.DenyDomains = []string{"", "denied.test"}
fx.srv.cfg.AppsDomain = "oncarlos.test"
fx.srv.cfg.RedirectHosts = []string{"", "Carlos.Tito.Test:8443"}
@@ -298,7 +316,7 @@ func TestAPIDomainAttachValidation(t *testing.T) {
// are still refused. The apps domain, and names under the console's
// hostnames, are not.
func TestAPIDomainAttachUnreservedDefault(t *testing.T) {
- fx, member := instanceFixture(t, "code-dom-unreserved")
+ fx, member := domainOwnerFixture(t, "code-dom-unreserved")
origin, err := url.Parse(fx.srv.cfg.Origin)
if err != nil {
t.Fatal(err)
@@ -334,7 +352,7 @@ func TestAPIDomainAttachUnreservedDefault(t *testing.T) {
// exactly one thing it could mean. Two instance records make it ambiguous,
// and ambiguity names the flag that resolves it rather than guessing.
func TestAPIDomainAttachRouteDefault(t *testing.T) {
- fx, member := instanceFixture(t, "code-dom-route")
+ fx, member := domainOwnerFixture(t, "code-dom-route")
ctx := context.Background()
rec := provision.Record{Schema: 1, Host: "one.go.tito.io", Slug: "one", App: "titogo",
Account: "bab", Channel: "stable", CreatedAt: time.Now().UTC()}
@@ -367,7 +385,7 @@ func TestAPIDomainAttachRouteDefault(t *testing.T) {
// holds — so a caller cannot use detach to discover who owns a hostname.
// Only the first of the three actually removes anything.
func TestAPIDomainDetachQuiet(t *testing.T) {
- fx, member := instanceFixture(t, "code-dom-detach")
+ fx, member := domainOwnerFixture(t, "code-dom-detach")
attachDomain(t, fx, member, "tickets.example.com", "go.tito.io")
if _, _, err := domains.AttachClaim(context.Background(), fx.rel, domains.Claim{
Host: "theirs.example.com", Account: "cdef", App: "widgets",
@@ -419,7 +437,7 @@ func TestAPIDomainDetachQuiet(t *testing.T) {
// reads "live"; one no live box reports reads "pending", including one only a
// STALE box still remembers.
func TestAPIDomainList(t *testing.T) {
- fx, member := instanceFixture(t, "code-dom-list")
+ fx, member := domainOwnerFixture(t, "code-dom-list")
ctx := context.Background()
now := time.Now()
if _, err := fx.st.CreateAppIn(OpsAccountID, "other", "alice@keymail.dev", now); err != nil {
@@ -499,7 +517,7 @@ func TestAPIDomainList(t *testing.T) {
// our outage. "elsewhere" (a real, wrong answer) still earns guidance, so
// the suppression is specific to "unresolved" and not a blanket regression.
func TestAPIDomainListSuppressesGuidanceForUnresolvedDNS(t *testing.T) {
- fx, member := instanceFixture(t, "code-dom-unresolved")
+ fx, member := domainOwnerFixture(t, "code-dom-unresolved")
ctx := context.Background()
now := time.Now()
attachDomain(t, fx, member, "broken.example.com", "go.tito.io")
@@ -566,7 +584,7 @@ func domainEvents(t *testing.T, fx *consoleFixture) int {
// the STEADY STATE — a bump per pass would keep the whole fleet converging
// onto nothing, and an audit row per pass would bury the tenant's log.
func TestAPIDomainSerialBump(t *testing.T) {
- fx, member := instanceFixture(t, "code-dom-serial")
+ fx, member := domainOwnerFixture(t, "code-dom-serial")
if got := serial(t, fx); got != 0 {
t.Fatalf("serial before any domain write = %d, want 0", got)
}
@@ -645,7 +663,7 @@ func attachBodyKind(host, route, kind, channel string) string {
// two different instructions), and any kind but "static" (nothing else can
// be minted from a domain attach). Neither writes a claim.
func TestAPIDomainAttachKindValidation(t *testing.T) {
- fx, member := instanceFixture(t, "code-dom-kind-400")
+ fx, member := domainOwnerFixture(t, "code-dom-kind-400")
for name, body := range map[string]string{
"route and kind together": attachBodyKind("both.example.com", "go.tito.io", "static", ""),
"kind other than static": attachBodyKind("both.example.com", "", "binary", ""),
@@ -664,7 +682,7 @@ func TestAPIDomainAttachKindValidation(t *testing.T) {
// and the answer's route is the host itself, the primary the record just
// declared. This is `carlos deploy -kind static -host <h>`'s server half.
func TestAPIDomainAttachKindStaticFirstRoute(t *testing.T) {
- fx, member := instanceFixture(t, "code-dom-kind-first")
+ fx, member := domainOwnerFixture(t, "code-dom-kind-first")
// The fixture registry holds no titogo routes, so the core has nothing
// to alias; the first-route branch needs something shipped to resolve
// the record's channel from.
@@ -711,7 +729,7 @@ func TestAPIDomainAttachKindStaticFirstRoute(t *testing.T) {
// stores the ready route, the answer reports it, and no provision record
// appears at the host's key.
func TestAPIDomainAttachKindStaticWithReadyRouteAliases(t *testing.T) {
- fx, member := instanceFixture(t, "code-dom-kind-alias")
+ fx, member := domainOwnerFixture(t, "code-dom-kind-alias")
fx.srv.cfg.Registry = attachRegistry(t,
registry.Route{Host: "titogo.bab.oncarlos.test", Kind: "static", App: "titogo",
Account: "bab", Channel: "canary/live", Status: "ready"},
@@ -752,7 +770,7 @@ func TestAttachWildcardCNAMEGate(t *testing.T) {
wantCNAME := "_acme-challenge." + host + "." + zone + "."
t.Run("missing CNAME refuses with the record to create", func(t *testing.T) {
- fx, member := instanceFixture(t, "code-dom-wc-missing")
+ fx, member := domainOwnerFixture(t, "code-dom-wc-missing")
fx.srv.delegationZone = zone
fx.srv.lookupCNAME = func(context.Context, string) (string, error) { return "", errors.New("not found") }
code, _, out := rawReq(t, http.MethodPost, domainsURL(fx, "bab", "titogo"), member,
@@ -779,7 +797,7 @@ func TestAttachWildcardCNAMEGate(t *testing.T) {
})
t.Run("correct CNAME enables wildcard and bumps the serial", func(t *testing.T) {
- fx, member := instanceFixture(t, "code-dom-wc-ok")
+ fx, member := domainOwnerFixture(t, "code-dom-wc-ok")
fx.srv.delegationZone = zone
fx.srv.lookupCNAME = func(_ context.Context, name string) (string, error) {
if name == "_acme-challenge."+host {
@@ -806,7 +824,7 @@ func TestAttachWildcardCNAMEGate(t *testing.T) {
// zone's. A customer who typed their CNAME target in mixed case must
// still delegate, not read as a permanently broken/missing record.
t.Run("mixed-case CNAME target still delegates", func(t *testing.T) {
- fx, member := instanceFixture(t, "code-dom-wc-mixedcase")
+ fx, member := domainOwnerFixture(t, "code-dom-wc-mixedcase")
fx.srv.delegationZone = zone
mixedCase := "_ACME-Challenge." + host + "." + strings.ToUpper(zone) + "."
fx.srv.lookupCNAME = func(_ context.Context, name string) (string, error) {
@@ -832,7 +850,7 @@ func TestAttachWildcardCNAMEGate(t *testing.T) {
// this would 422 instead of succeeding, and the counter would be
// nonzero.
t.Run("re-sending wildcard true on an already-wildcard claim skips the lookup", func(t *testing.T) {
- fx, member := instanceFixture(t, "code-dom-wc-idempotent")
+ fx, member := domainOwnerFixture(t, "code-dom-wc-idempotent")
fx.srv.delegationZone = zone
calls := 0
fx.srv.lookupCNAME = func(_ context.Context, name string) (string, error) {
@@ -873,7 +891,7 @@ func TestAttachWildcardCNAMEGate(t *testing.T) {
// os.ErrNotExist and returns ErrHostUnavailable — which must answer the
// SAME byte-identical 404 every other non-owner refusal does.
t.Run("claim vanishing between attach and capability write answers the byte-identical 404", func(t *testing.T) {
- fx, member := instanceFixture(t, "code-dom-wc-vanish")
+ fx, member := domainOwnerFixture(t, "code-dom-wc-vanish")
fx.srv.delegationZone = zone
fx.srv.lookupCNAME = func(_ context.Context, name string) (string, error) {
if _, err := domains.DetachClaim(context.Background(), fx.rel, host, "bab", "titogo"); err != nil {
@@ -889,7 +907,7 @@ func TestAttachWildcardCNAMEGate(t *testing.T) {
})
t.Run("catchall without wildcard refuses and stores nothing", func(t *testing.T) {
- fx, member := instanceFixture(t, "code-dom-wc-catchall")
+ fx, member := domainOwnerFixture(t, "code-dom-wc-catchall")
fx.srv.delegationZone = zone
fx.srv.lookupCNAME = func(context.Context, string) (string, error) { return "", errors.New("not found") }
code, _, out := rawReq(t, http.MethodPost, domainsURL(fx, "bab", "titogo"), member,
@@ -906,7 +924,7 @@ func TestAttachWildcardCNAMEGate(t *testing.T) {
})
t.Run("wildcard and catchall together with a correct CNAME store both", func(t *testing.T) {
- fx, member := instanceFixture(t, "code-dom-wc-both")
+ fx, member := domainOwnerFixture(t, "code-dom-wc-both")
fx.srv.delegationZone = zone
fx.srv.lookupCNAME = func(_ context.Context, name string) (string, error) {
if name == "_acme-challenge."+host {
@@ -952,7 +970,7 @@ func TestAttachWildcardCNAMEGate(t *testing.T) {
// only writer of Wildcard/Catchall is SetClaimCapabilities, called AFTER
// the create, and gated on the zone.
t.Run("zone unset refuses, and smuggled capability fields never reach the claim", func(t *testing.T) {
- fx, member := instanceFixture(t, "code-dom-wc-nozone")
+ fx, member := domainOwnerFixture(t, "code-dom-wc-nozone")
// fx.srv.delegationZone is left at its zero value "" — no
// CARLOS_ACME_DELEGATION_ZONE configured for this fixture.
code, _, out := rawReq(t, http.MethodPost, domainsURL(fx, "bab", "titogo"), member,
@@ -978,7 +996,7 @@ func TestAttachWildcardCNAMEGate(t *testing.T) {
func TestAttachWildcardDisableCascadesCatchallOff(t *testing.T) {
const zone = "acme.oncarlos.com"
const host = "wild.example.com"
- fx, member := instanceFixture(t, "code-dom-wc-disable")
+ fx, member := domainOwnerFixture(t, "code-dom-wc-disable")
fx.srv.delegationZone = zone
wantCNAME := "_acme-challenge." + host + "." + zone + "."
fx.srv.lookupCNAME = func(_ context.Context, name string) (string, error) {
@@ -1012,7 +1030,7 @@ func TestAttachWildcardDisableCascadesCatchallOff(t *testing.T) {
// field at all.
func TestDomainsListDelegationStamp(t *testing.T) {
const zone = "acme.oncarlos.com"
- fx, member := instanceFixture(t, "code-dom-list-deleg")
+ fx, member := domainOwnerFixture(t, "code-dom-list-deleg")
fx.srv.delegationZone = zone
const wildHost = "wild.example.com"
const plainHost = "plain.example.com"
@@ -1086,7 +1104,7 @@ func TestDomainsListDelegationStamp(t *testing.T) {
// unset zone or wildcard off — never an error.
func TestDomainsListDelegationStampCapsLookups(t *testing.T) {
const zone = "acme.oncarlos.com"
- fx, member := instanceFixture(t, "code-dom-list-cap")
+ fx, member := domainOwnerFixture(t, "code-dom-list-cap")
fx.srv.delegationZone = zone
var calls int
fx.srv.lookupCNAME = func(_ context.Context, name string) (string, error) {
@@ -1212,6 +1230,7 @@ func zoneFixtureWithDelegation(t *testing.T, zone, code string) (*consoleFixture
// call built from an invalid zone.
func TestDelegationZoneInvalidAtConstruction(t *testing.T) {
fx, member := zoneFixtureWithDelegation(t, "*.bad zone", "code-dom-wc-badzone")
+ makeOwner(t, fx, "alice@keymail.dev") // the attach door is owner-only (H4-M7)
fx.srv.lookupCNAME = func(context.Context, string) (string, error) {
t.Fatal("lookupCNAME must not be called when the configured zone is invalid")
return "", nil
@@ -1447,7 +1466,7 @@ func TestLegacyAppTokensHaveSeparateWildFailBudgets(t *testing.T) {
// one did) cannot see failure mode 2 at all.
func TestAPIDomainAttachRefusesADeploymentRouteNeutrally(t *testing.T) {
ctx := context.Background()
- fx, member := instanceFixture(t, "code-dom-deproute")
+ fx, member := domainOwnerFixture(t, "code-dom-deproute")
// go.tito.io is a real, NON-ALIAS route published by a live box called
// "annie". Both halves are required: DeploymentRoutes drops any edges
@@ -1571,7 +1590,7 @@ func TestAPIDomainAttachRefusesADeploymentRouteNeutrally(t *testing.T) {
// permanent 409 on hostnames this deployment itself granted.
func TestAPIDomainAttachStillConvergesTheCallersOwnDeploymentRoute(t *testing.T) {
ctx := context.Background()
- fx, member := instanceFixture(t, "code-dom-ownroute")
+ fx, member := domainOwnerFixture(t, "code-dom-ownroute")
if _, err := fx.rel.Put(ctx, edgesfile.Key("annie"),
[]byte(`{"v":1,"box":"annie","eip":"198.51.100.9","hosts":{"mine.example.com":{"role":"home"}}}`), ""); err != nil {
t.Fatal(err)
@@ -1668,7 +1687,7 @@ func domainGetURL(fx *consoleFixture, acct, app, host string) string {
// refreshes one host and compares it against a listed row must not see a
// mirrored status flap for reasons that have nothing to do with the domain.
func TestAPIDomainGetAgreesWithTheListRow(t *testing.T) {
- fx, member := instanceFixture(t, "code-dom-get")
+ fx, member := domainOwnerFixture(t, "code-dom-get")
ctx := context.Background()
now := time.Now()
attachDomain(t, fx, member, "live.example.com", "go.tito.io")
@@ -1786,7 +1805,7 @@ func TestAPIDomainGetRefusesATraversalHost(t *testing.T) {
// consumer refreshing a single host and comparing it against a listed row
// must never see them disagree.
func TestAPIDomainFailedStateComesFromTheWarmRecord(t *testing.T) {
- fx, member := instanceFixture(t, "code-dom-warm")
+ fx, member := domainOwnerFixture(t, "code-dom-warm")
ctx := context.Background()
now := time.Now()
attachDomain(t, fx, member, "broken.example.com", "go.tito.io")
@@ -1865,7 +1884,7 @@ func TestAPIDomainFailedStateComesFromTheWarmRecord(t *testing.T) {
// writes for every domain it warms), so the join has to be by exact host or
// one tenant's certificate trouble shows up on another tenant's domain.
func TestAPIDomainWarmRecordsJoinByExactHost(t *testing.T) {
- fx, member := instanceFixture(t, "code-dom-warm-iso")
+ fx, member := domainOwnerFixture(t, "code-dom-warm-iso")
ctx := context.Background()
now := time.Now()
attachDomain(t, fx, member, "mine.example.com", "go.tito.io")
diff --git a/internal/console/apifeatures_test.go b/internal/console/apifeatures_test.go
index 0b60c91be..e06862e16 100644
--- a/internal/console/apifeatures_test.go
+++ b/internal/console/apifeatures_test.go
@@ -154,7 +154,7 @@ func TestAPIFeaturesBadShapesAre400AndWriteNothing(t *testing.T) {
// deployment block it already fetches with its CARLOS_INSTANCE_TOKEN, beside
// managed_domains — no new call, no new credential, no restart.
func TestAPIFeaturesRideTheDomainsDeploymentBlock(t *testing.T) {
- fx, member := instanceFixture(t, "code-feat-block")
+ fx, member := domainOwnerFixture(t, "code-feat-block")
app := serviceToken(t, fx.st, OpsAccountID, "router", "titogo", svcrole.Instance)
type block struct {
diff --git a/internal/console/deletion_evidence_test.go b/internal/console/deletion_evidence_test.go
index a92ab097a..ed6bf2fa3 100644
--- a/internal/console/deletion_evidence_test.go
+++ b/internal/console/deletion_evidence_test.go
@@ -169,7 +169,7 @@ func lifetimeDetachedApp(t *testing.T) ltOn {
l := newLtOn(t)
l.fx.srv.cfg.Releases = ltModStore{l.bucket}
ctx := context.Background()
- code, _, body := rawReq(t, http.MethodPost, domainsURL(l.fx, "bab", ltApp), l.member,
+ code, _, body := rawReq(t, http.MethodPost, domainsURL(l.fx, "bab", ltApp), l.operator,
`{"host":"`+ltDomain+`","kind":"static","channel":"stable"}`)
if code != http.StatusOK {
t.Fatalf("attach = %d %s", code, body)
@@ -191,7 +191,7 @@ func lifetimeDetachedApp(t *testing.T) ltOn {
if _, err := l.fx.srv.channelHosts(ctx, "bab", ltApp, "canary/x"); err != nil {
t.Fatalf("fixture: a still app = %v", err)
}
- if code, _, body := rawReq(t, http.MethodDelete, domainsURL(l.fx, "bab", ltApp)+"/"+ltDomain, l.member, ""); code != http.StatusOK {
+ if code, _, body := rawReq(t, http.MethodDelete, domainsURL(l.fx, "bab", ltApp)+"/"+ltDomain, l.operator, ""); code != http.StatusOK {
t.Fatalf("detach = %d %s", code, body)
}
if raw, _ := rawOf(t, l.fx.rel, ltApp, ltDomain); raw != nil {
diff --git a/internal/console/demo_api_origin_test.go b/internal/console/demo_api_origin_test.go
index 11c716d88..018988348 100644
--- a/internal/console/demo_api_origin_test.go
+++ b/internal/console/demo_api_origin_test.go
@@ -318,7 +318,9 @@ func TestDemoAPIHostOwnership(t *testing.T) {
}
}
claimAbsent(t, fx, "example.com")
- for _, token := range []string{member, service} {
+ // The owner and an owner-minted app token: the attach door is
+ // owner-only (H4-M7), so the member meets its 403 here.
+ for _, token := range []string{owner, service} {
if code, _, _ := rawReq(t, "POST", base, token, attachBody("other.example.com", "shop.example.net")); code != 200 {
t.Errorf("unrelated host status=%d", code)
}
diff --git a/internal/console/domaincatchall_test.go b/internal/console/domaincatchall_test.go
index b657a70a5..7e125eebf 100644
--- a/internal/console/domaincatchall_test.go
+++ b/internal/console/domaincatchall_test.go
@@ -28,7 +28,7 @@ import (
// go.tito.io.
func catchallFixture(t *testing.T, code string) (*consoleFixture, string) {
t.Helper()
- fx, member := instanceFixture(t, code)
+ fx, member := domainOwnerFixture(t, code) // attach is owner-only (H4-M7)
noCatchallProof(fx)
enableInstances(t, fx, "titogo", titoManifest())
if _, _, err := domains.AttachClaim(context.Background(), fx.rel, domains.Claim{
diff --git a/internal/console/domainplatform_test.go b/internal/console/domainplatform_test.go
index e5f3a2169..7d5bbd317 100644
--- a/internal/console/domainplatform_test.go
+++ b/internal/console/domainplatform_test.go
@@ -85,13 +85,14 @@ func TestDomainHostPolicyMatrix(t *testing.T) {
}
}
-// TestPlatformAttachRefusesMembers: an ordinary member gets the old refusal
-// without the flag and a 403 with it, and no claim is written either way.
+// TestPlatformAttachRefusesMembers: an ordinary member gets a 403 with the
+// flag or without it (without it, the attach door's owner gate, H4-M7), and
+// no claim is written either way.
func TestPlatformAttachRefusesMembers(t *testing.T) {
fx, alice, _ := platformFixture(t, "code-plat-member")
if code, _, out := rawReq(t, http.MethodPost, domainsURL(fx, "bab", "titogo"), alice,
- attachBody("carloku.test", "go.tito.io")); code != http.StatusBadRequest {
- t.Errorf("member attach without --platform = %d %s, want 400", code, out)
+ attachBody("carloku.test", "go.tito.io")); code != http.StatusForbidden {
+ t.Errorf("member attach without --platform = %d %s, want 403", code, out)
}
code, _, out := rawReq(t, http.MethodPost, domainsURL(fx, "bab", "titogo"), alice,
platformAttachBody("carloku.test", "go.tito.io"))
@@ -165,7 +166,8 @@ func TestPlatformAttachBySystemOperator(t *testing.T) {
if _, err := fx.st.CreateAppIn(42, "website", "bob@keymail.dev", now); err != nil {
t.Fatal(err)
}
- if err := fx.st.AddMember(42, "bill@keymail.dev", RoleMember, now); err != nil {
+ // An owner of cdef: the attach door is owner-only (H4-M7).
+ if err := fx.st.AddMember(42, "bill@keymail.dev", RoleOwner, now); err != nil {
t.Fatal(err)
}
bill := cliToken(t, fx, "bill@keymail.dev", "code-plat-bill")
@@ -304,6 +306,7 @@ func TestPlatformBrowserDoors(t *testing.T) {
// sidecar name to a member too, with or without a deny entry covering it.
func TestAPIAttachRefusesSidecarNames(t *testing.T) {
fx, alice, _ := platformFixture(t, "code-plat-sidecar")
+ makeOwner(t, fx, "alice@keymail.dev") // the attach door is owner-only (H4-M7)
code, _, out := rawReq(t, http.MethodPost, domainsURL(fx, "bab", "titogo"), alice,
attachBody("web.sidecar.internal", "go.tito.io"))
if code != http.StatusBadRequest {
diff --git a/internal/console/domainpolicy_test.go b/internal/console/domainpolicy_test.go
index 23753ed45..ed1a7c99e 100644
--- a/internal/console/domainpolicy_test.go
+++ b/internal/console/domainpolicy_test.go
@@ -85,7 +85,7 @@ func TestDomainHostDeniedPolicyMatrix(t *testing.T) {
}
func TestAPIDomainAttachDeniesAppsDomainAliasByDefault(t *testing.T) {
- fx, member := instanceFixture(t, "code-dom-alias-default")
+ fx, member := domainOwnerFixture(t, "code-dom-alias-default")
fx.srv.cfg.AppsDomain = "oncarlos.test"
fx.srv.cfg.ReservePlatformDomains = true
code, _, out := rawReq(t, http.MethodPost, domainsURL(fx, "bab", "titogo"), member,
@@ -97,7 +97,7 @@ func TestAPIDomainAttachDeniesAppsDomainAliasByDefault(t *testing.T) {
}
func TestAPIDomainAttachAllowsAppsDomainAlias(t *testing.T) {
- fx, member := instanceFixture(t, "code-dom-alias-allow")
+ fx, member := domainOwnerFixture(t, "code-dom-alias-allow")
fx.srv.cfg.AppsDomain = "oncarlos.test"
fx.srv.cfg.ReservePlatformDomains = true
fx.srv.cfg.AppsDomainAliasAccounts = []string{fx.sqid}
@@ -120,7 +120,7 @@ func TestAPIDomainAttachAllowsAppsDomainAlias(t *testing.T) {
}
func TestAPIDomainAttachAppsDomainAliasRejectsWildcardAndCatchall(t *testing.T) {
- fx, member := instanceFixture(t, "code-dom-alias-wild")
+ fx, member := domainOwnerFixture(t, "code-dom-alias-wild")
fx.srv.cfg.AppsDomain = "oncarlos.test"
fx.srv.cfg.ReservePlatformDomains = true
fx.srv.cfg.AppsDomainAliasAccounts = []string{fx.sqid}
@@ -142,7 +142,7 @@ func TestAPIDomainAttachAppsDomainAliasRejectsWildcardAndCatchall(t *testing.T)
}
func TestAPIDomainAttachAppsDomainAliasStillRefusesForeignClaim(t *testing.T) {
- fx, member := instanceFixture(t, "code-dom-alias-conflict")
+ fx, member := domainOwnerFixture(t, "code-dom-alias-conflict")
fx.srv.cfg.AppsDomain = "oncarlos.test"
fx.srv.cfg.ReservePlatformDomains = true
fx.srv.cfg.AppsDomainAliasAccounts = []string{fx.sqid}
@@ -165,7 +165,7 @@ func TestAPIDomainAttachAppsDomainAliasStillRefusesForeignClaim(t *testing.T) {
func TestAPIDomainAttachAppsDomainAliasStillRefusesDeploymentRoute(t *testing.T) {
ctx := context.Background()
- fx, member := instanceFixture(t, "code-dom-alias-route")
+ fx, member := domainOwnerFixture(t, "code-dom-alias-route")
fx.srv.cfg.AppsDomain = "oncarlos.test"
fx.srv.cfg.ReservePlatformDomains = true
fx.srv.cfg.AppsDomainAliasAccounts = []string{fx.sqid}
diff --git a/internal/console/domainproof_test.go b/internal/console/domainproof_test.go
index 8071c126c..73a1a081a 100644
--- a/internal/console/domainproof_test.go
+++ b/internal/console/domainproof_test.go
@@ -66,7 +66,7 @@ type proofListResp struct {
// answer says exactly which record proves it, nothing is announced to the
// fleet, and repeating the attach once the record exists verifies it.
func TestAPIDomainAttachWithoutProofIsPending(t *testing.T) {
- fx, member := instanceFixture(t, "code-dom-proof")
+ fx, member := domainOwnerFixture(t, "code-dom-proof")
fx.srv.cfg.DomainProof = true
lookups := 0
fx.srv.lookupTXT = noTXT(&lookups)
@@ -141,7 +141,7 @@ func TestAPIDomainAttachWithoutProofIsPending(t *testing.T) {
// Another account's proof is not this account's proof: the token is
// account-bound, so a record published for one account cannot be replayed.
func TestAPIDomainAttachRefusesAnotherAccountsProof(t *testing.T) {
- fx, member := instanceFixture(t, "code-dom-replay")
+ fx, member := domainOwnerFixture(t, "code-dom-replay")
fx.srv.cfg.DomainProof = true
const host = "shop.example.com"
fx.srv.lookupTXT = txtFor(fx.srv, "cdef", host)
@@ -159,7 +159,7 @@ func TestAPIDomainAttachRefusesAnotherAccountsProof(t *testing.T) {
// same bytes a verified holder produces, so a refusal still never says how
// firmly a name is held.
func TestAPIDomainProvenOwnerSupersedesSquatter(t *testing.T) {
- fx, member := instanceFixture(t, "code-dom-squat")
+ fx, member := domainOwnerFixture(t, "code-dom-squat")
fx.srv.cfg.DomainProof = true
ctx := context.Background()
const squatted, held = "shop.example.com", "held.example.com"
@@ -318,7 +318,7 @@ func serialValue(t *testing.T, fx *consoleFixture) string {
// no TXT lookup is ever made, every claim is written verified and announced,
// a first route declares its record at once, and the answer says verified.
func TestDomainProofOffBehavesAsBefore(t *testing.T) {
- fx, member := instanceFixture(t, "code-dom-proof-off")
+ fx, member := domainOwnerFixture(t, "code-dom-proof-off")
if fx.srv.cfg.DomainProof {
t.Fatal("DomainProof is on by default")
}
diff --git a/internal/console/hap2_wiring_test.go b/internal/console/hap2_wiring_test.go
index 6b0f352ef..2bf3602d1 100644
--- a/internal/console/hap2_wiring_test.go
+++ b/internal/console/hap2_wiring_test.go
@@ -478,7 +478,7 @@ func TestHAP2ProductionDoors(t *testing.T) {
}
})
t.Run("first-domain static", func(t *testing.T) {
- fx, token := instanceFixture(t, "hap2-static")
+ fx, token := domainOwnerFixture(t, "hap2-static") // attach is owner-only (H4-M7)
shipVersion(t, fx, "titogo", "v1")
seedChannel(t, fx, "titogo", "canary/live", "v1")
fx.srv.cfg.HomeRegion, fx.srv.cfg.HARegions = "ie", []string{"ie"}
diff --git a/internal/console/hostsused_writers_test.go b/internal/console/hostsused_writers_test.go
index d1dc9bc7f..d81836883 100644
--- a/internal/console/hostsused_writers_test.go
+++ b/internal/console/hostsused_writers_test.go
@@ -389,7 +389,7 @@ func TestExemptCreatesDoNotMark(t *testing.T) {
noMarks(t, c.bucket.Store)
})
t.Run("attach first route", func(t *testing.T) {
- fx, member := instanceFixture(t, "code-exempt-attach")
+ fx, member := domainOwnerFixture(t, "code-exempt-attach") // attach is owner-only (H4-M7)
c := markCase{fx: fx, bucket: wrapBucket(fx)}
on(t, c)
shipVersion(t, fx, "titogo", "v1")
diff --git a/internal/console/hunt_H4-M7_test.go b/internal/console/hunt_H4-M7_test.go
new file mode 100644
index 000000000..2a60db93d
--- /dev/null
+++ b/internal/console/hunt_H4-M7_test.go
@@ -0,0 +1,27 @@
+package console
+
+import (
+ "context"
+ "net/http"
+ "net/url"
+ "testing"
+
+ "github.com/carlosframework/platform/internal/domains"
+)
+
+func TestHunt_H4_M7_MemberCannotDetachDomain(t *testing.T) {
+ fx, member := huntInstanceFixture(t, "hunt-m7")
+ owner := huntCLIToken(t, fx, "paul@keymail.dev", "hunt-m7-owner")
+ attachDomain(t, fx, owner, "hunt.example.com", "go.tito.io")
+ fx.setUser("alice@keymail.dev")
+ browser := newBrowser(t)
+ signUp(t, fx, browser, "hunt-m7-browser")
+ if code, _, _ := postForm(t, browser, fx.u("/apps/titogo/domains/detach"), url.Values{"csrf": {sessionToken(t, fx, browser)}, "host": {"hunt.example.com"}, "confirm": {"hunt.example.com"}}); code != http.StatusNotFound {
+ t.Fatalf("browser member control: %d", code)
+ }
+ code, _, out := rawReq(t, http.MethodDelete, domainsURL(fx, fx.sqid, "titogo")+"/hunt.example.com", member, "")
+ claim, err := domains.GetClaim(context.Background(), fx.rel, "hunt.example.com")
+ if code != http.StatusForbidden && code != http.StatusNotFound || err != nil || claim == nil {
+ t.Errorf("member detached domain: status=%d claim_present=%v read_error=%v; want refusal and original claim; response=%s", code, claim != nil, err, out)
+ }
+}
diff --git a/internal/console/lifetimes_create_test.go b/internal/console/lifetimes_create_test.go
index d3bd42975..bba1fe7d9 100644
--- a/internal/console/lifetimes_create_test.go
+++ b/internal/console/lifetimes_create_test.go
@@ -1456,7 +1456,7 @@ func TestCreateChecksTheAppUnderTheLock(t *testing.T) {
once.Do(func() { purgeShop(t, l) })
}
})
- status, h, body := rawReq(t, http.MethodPost, domainsURL(l.fx, "bab", ltApp), l.member,
+ status, h, body := rawReq(t, http.MethodPost, domainsURL(l.fx, "bab", ltApp), l.operator,
`{"host":"`+ltDomain+`","kind":"static","channel":"stable"}`)
assertNotFound(t, "attach with the app gone under the lock", canonicalNotFound(t), status, h, body)
if got := claimHolder(t, l.fx.rel, ltDomain); got != "" {
@@ -1883,7 +1883,7 @@ func TestDetachCompletesThroughTheRealHandlers(t *testing.T) {
for _, door := range []string{"api", "browser"} {
t.Run(door, func(t *testing.T) {
l := newLtOn(t)
- code, _, body := rawReq(t, http.MethodPost, domainsURL(l.fx, "bab", ltApp), l.member,
+ code, _, body := rawReq(t, http.MethodPost, domainsURL(l.fx, "bab", ltApp), l.operator,
`{"host":"`+ltDomain+`","kind":"static","channel":"stable"}`)
if code != http.StatusOK {
t.Fatalf("attach = %d %s", code, body)
@@ -1892,7 +1892,7 @@ func TestDetachCompletesThroughTheRealHandlers(t *testing.T) {
done := make(chan int, 1)
go func() {
if door == "api" {
- code, _, _ := rawReq(t, http.MethodDelete, domainsURL(l.fx, "bab", ltApp)+"/"+ltDomain, l.member, "")
+ code, _, _ := rawReq(t, http.MethodDelete, domainsURL(l.fx, "bab", ltApp)+"/"+ltDomain, l.operator, "")
done <- code
return
}
@@ -2261,7 +2261,7 @@ func TestDispatchFollowsTheUnit(t *testing.T) {
answers <- fmt.Sprintf("delete %d", code)
}()
go func() {
- code, _, _ := rawReq(t, http.MethodDelete, domainsURL(l.fx, "bab", ltApp)+"/"+ltDomain, l.member, "")
+ code, _, _ := rawReq(t, http.MethodDelete, domainsURL(l.fx, "bab", ltApp)+"/"+ltDomain, l.operator, "")
answers <- fmt.Sprintf("detach %d", code)
}()
for what, g := range map[string]*pauseGate{"create": createGate, "delete": deleteGate, "detach": detachGate} {
@@ -2438,10 +2438,10 @@ func testLockOrderOfTheDoors(t *testing.T) {
t.Fatalf("the orphan retirement took %v", got)
}
// Attach and detach, through the API and the browser.
- if code, _, body := rawReq(t, http.MethodPost, domainsURL(l.fx, "bab", ltApp), l.member, `{"host":"`+ltDomain+`","kind":"static","channel":"stable"}`); code != http.StatusOK {
+ if code, _, body := rawReq(t, http.MethodPost, domainsURL(l.fx, "bab", ltApp), l.operator, `{"host":"`+ltDomain+`","kind":"static","channel":"stable"}`); code != http.StatusOK {
t.Fatalf("attach = %d %s", code, body)
}
- if code, _, body := rawReq(t, http.MethodDelete, domainsURL(l.fx, "bab", ltApp)+"/"+ltDomain, l.member, ""); code != http.StatusOK {
+ if code, _, body := rawReq(t, http.MethodDelete, domainsURL(l.fx, "bab", ltApp)+"/"+ltDomain, l.operator, ""); code != http.StatusOK {
t.Fatalf("detach = %d %s", code, body)
}
if _, ref := l.attach(t, onCtx(t, l.fx.srv), ltApp); ref != nil {
diff --git a/internal/console/lifetimes_retire_test.go b/internal/console/lifetimes_retire_test.go
index 52ce375bd..3619fb0b7 100644
--- a/internal/console/lifetimes_retire_test.go
+++ b/internal/console/lifetimes_retire_test.go
@@ -1116,7 +1116,7 @@ func TestTerminationFencesFirst(t *testing.T) {
func TestDetachMapsLifetimeErrors(t *testing.T) {
attach := func(t *testing.T, l ltOn) {
t.Helper()
- code, _, body := rawReq(t, http.MethodPost, domainsURL(l.fx, "bab", ltApp), l.member,
+ code, _, body := rawReq(t, http.MethodPost, domainsURL(l.fx, "bab", ltApp), l.operator,
`{"host":"`+ltDomain+`","kind":"static","channel":"stable"}`)
if code != http.StatusOK {
t.Fatalf("attach = %d %s", code, body)
@@ -1146,7 +1146,7 @@ func TestDetachMapsLifetimeErrors(t *testing.T) {
attach(t, l)
c.arrange(t, l)
if door == "api" {
- code, _, body := rawReq(t, http.MethodDelete, domainsURL(l.fx, "bab", ltApp)+"/"+ltDomain, l.member, "")
+ code, _, body := rawReq(t, http.MethodDelete, domainsURL(l.fx, "bab", ltApp)+"/"+ltDomain, l.operator, "")
if code != http.StatusConflict || ltErr(body) != c.msg {
t.Fatalf("detach = %d %s, want 409 %q", code, body, c.msg)
}
diff --git a/internal/console/plancaps_doors_test.go b/internal/console/plancaps_doors_test.go
index d83938067..e4117afbb 100644
--- a/internal/console/plancaps_doors_test.go
+++ b/internal/console/plancaps_doors_test.go
@@ -188,7 +188,7 @@ func TestInstanceCreateRefusedAtTheRunningThingsCap(t *testing.T) {
}
func TestFirstRouteAttachRefusedAtTheRunningThingsCap(t *testing.T) {
- fx, token := instanceFixture(t, "code-cap-firstroute")
+ fx, token := domainOwnerFixture(t, "code-cap-firstroute")
shipVersion(t, fx, "titogo", "v1")
seedChannel(t, fx, "titogo", "canary/live", "v1")
acct := atRunningCap(t, fx, 3)
@@ -363,7 +363,7 @@ func TestFleetCreateRefusedOnAPlanWithoutFleets(t *testing.T) {
}
func TestCustomDomainRefusedOnAFreePlan(t *testing.T) {
- fx, member := instanceFixture(t, "code-cap-domain")
+ fx, member := domainOwnerFixture(t, "code-cap-domain")
shipVersion(t, fx, "titogo", "v1")
seedChannel(t, fx, "titogo", "canary/live", "v1")
fx.srv.cfg.PlanCatalog = examplePlanCatalog(t)
@@ -382,7 +382,7 @@ func TestCustomDomainRefusedOnAFreePlan(t *testing.T) {
}
func TestFleetsAndDomainsWithoutACatalogUnchanged(t *testing.T) {
- fx, member := instanceFixture(t, "code-cap-domain-nocat")
+ fx, member := domainOwnerFixture(t, "code-cap-domain-nocat")
if code, _, out := rawReq(t, http.MethodPost, domainsURL(fx, "bab", "titogo"), member, `{"host":"tickets.example.com","route":"go.tito.io"}`); code != http.StatusOK {
t.Fatalf("alias attach with no catalog = %d %s", code, out)
}
diff --git a/internal/console/regional_writers_test.go b/internal/console/regional_writers_test.go
index 533c8e47b..0849693fb 100644
--- a/internal/console/regional_writers_test.go
+++ b/internal/console/regional_writers_test.go
@@ -140,7 +140,8 @@ func TestTeamScopeRefusesRegionalClaim(t *testing.T) {
}
// Attach: a hostname this app holds for a route out of the team's
// scope answers as taken, the same bytes as any other holder's.
- attachDomain(t, w.fx, w.member, "theirs.example.com", "theirs.go.tito.io")
+ owner := cliToken(t, w.fx, "paul@keymail.dev", "code-team-regional-owner") // attach is owner-only (H4-M7)
+ attachDomain(t, w.fx, owner, "theirs.example.com", "theirs.go.tito.io")
wantStatus, _, want := rawReq(t, http.MethodPost, w.url("/domains"), w.team, attachBody("theirs.example.com", "mine.go.tito.io"))
if wantStatus != http.StatusConflict {
t.Fatalf("attach over an out-of-scope claim = %d %s", wantStatus, want)
@@ -176,7 +177,7 @@ func TestTeamScopeRefusesRegionalClaim(t *testing.T) {
// other route is 409 with RD-26's text, and writes nothing. The paths door
// answers the same 409.
func TestAttachOnARegionalClaim(t *testing.T) {
- fx, member := instanceFixture(t, "code-rd-attach")
+ fx, member := domainOwnerFixture(t, "code-rd-attach")
newShopApp(t, fx)
const host = "shop.example.com"
putRegionalClaim(t, fx.rel, host, "bab", "shop", rdHomeHost, false, false)
@@ -271,7 +272,7 @@ func TestFirstRouteAttachOnARegionalHostWritesNoRecord(t *testing.T) {
// writes nothing; the same values are a 200 that writes nothing, audits
// nothing and bumps no serial.
func TestSetDomainCapabilitiesRefusesARegionalChangeBeforeDNS(t *testing.T) {
- fx, member := instanceFixture(t, "code-rd-caps")
+ fx, member := domainOwnerFixture(t, "code-rd-caps")
newShopApp(t, fx)
fx.srv.delegationZone = "acme.example.org"
var lookups atomic.Int32
diff --git a/internal/console/subdomains_test.go b/internal/console/subdomains_test.go
index ec015685c..76cab4a72 100644
--- a/internal/console/subdomains_test.go
+++ b/internal/console/subdomains_test.go
@@ -27,6 +27,7 @@ import (
"github.com/carlosframework/platform/internal/provision"
"github.com/carlosframework/platform/internal/registry"
"github.com/carlosframework/platform/internal/release"
+ "github.com/carlosframework/platform/internal/svcrole"
)
const (
@@ -56,6 +57,15 @@ func nsShopFixture(t *testing.T, code string) (fx *consoleFixture, member, opera
return fx, cliToken(t, fx, nsActor, code), cliToken(t, fx, "ops@example.com", code+"-ops")
}
+// nsAttacher is a publish-role credential for shop, minted by an owner: a
+// caller the CLI domain doors admit (they are owner-only, security hunt
+// H4-M7) that is no platform operator, as every owner of the ops account
+// is. The namespace refusals below exempt no operator either way.
+func nsAttacher(t *testing.T, fx *consoleFixture) string {
+ t.Helper()
+ return serviceToken(t, fx.st, OpsAccountID, "ns-attacher", "shop", svcrole.Publish)
+}
+
// nsNobodysCopy is the create refusal for a label no account holds, under
// the apps domain: team and www can never be names (team is a short
// sqid-shaped word, www is reserved), so they get the answer that says to
@@ -320,6 +330,7 @@ func TestCreateUnderUnassignedLabelRefused(t *testing.T) {
// approved other-account copy.
func TestCreateUnderOtherAccountsNameRefused(t *testing.T) {
fx, member, operator := nsShopFixture(t, "code-ns-other")
+ attacher := nsAttacher(t, fx)
route := nsShopRoute(fx)
nsAccount(t, fx, 82, "bdq")
nsHold(t, fx, "harbour", "bdq")
@@ -343,13 +354,13 @@ func TestCreateUnderOtherAccountsNameRefused(t *testing.T) {
door, token, body string
want int
}{
- {"API alias", member, attachBody(host, route), http.StatusBadRequest},
- {"API first route", member, attachBodyKind(host, "", "static", ""), http.StatusBadRequest},
- {"API wildcard and catchall", member, `{"host":"` + host + `","route":"` + route + `","wildcard":true,"catchall":true}`, http.StatusBadRequest},
+ {"API alias", attacher, attachBody(host, route), http.StatusBadRequest},
+ {"API first route", attacher, attachBodyKind(host, "", "static", ""), http.StatusBadRequest},
+ {"API wildcard and catchall", attacher, `{"host":"` + host + `","route":"` + route + `","wildcard":true,"catchall":true}`, http.StatusBadRequest},
{"platform door", operator, platformAttachBody(host, route), http.StatusBadRequest},
{"one-label platform door", operator, platformAttachBody("harbour."+nsApps, route), http.StatusBadRequest},
- {"instance catch-all on the name", member, `{"host":"*.harbour.` + nsApps + `"}`, http.StatusBadRequest},
- {"instance catch-all under the name", member, `{"host":"*.` + host + `"}`, http.StatusBadRequest},
+ {"instance catch-all on the name", operator, `{"host":"*.harbour.` + nsApps + `"}`, http.StatusBadRequest},
+ {"instance catch-all under the name", operator, `{"host":"*.` + host + `"}`, http.StatusBadRequest},
} {
if code, _, out := rawReq(t, http.MethodPost, u, c.token, c.body); code != c.want {
t.Errorf("%s = %d %s, want %d", c.door, code, out, c.want)
@@ -410,7 +421,8 @@ func TestPlacementsUnderOtherAccountsNameRefused(t *testing.T) {
// never a name) and marina are both nobody's; marina is then given to the
// account, and its catch-all goes through.
func TestCatchallUnderUnassignedLabelRefused(t *testing.T) {
- fx, member, _ := nsShopFixture(t, "code-ns-catchall")
+ fx, _, operator := nsShopFixture(t, "code-ns-catchall")
+ attacher := nsAttacher(t, fx)
route := nsShopRoute(fx)
enableInstances(t, fx, "shop", nsShopManifest("shop.example.com"))
ctx := context.Background()
@@ -419,12 +431,13 @@ func TestCatchallUnderUnassignedLabelRefused(t *testing.T) {
for _, label := range []string{"team", "marina"} {
parent := label + "." + nsApps
unassigned := nsNobodysCopy(label)
- code, _, out := rawReq(t, http.MethodPost, u, member, `{"host":"`+parent+`","route":"`+route+`","wildcard":true,"catchall":true}`)
+ code, _, out := rawReq(t, http.MethodPost, u, attacher, `{"host":"`+parent+`","route":"`+route+`","wildcard":true,"catchall":true}`)
if code != http.StatusUnprocessableEntity || cutoverErrorOf(out) != unassigned {
t.Errorf("wildcard and catchall on %s = %d %s, want 422 %q", parent, code, out, unassigned)
}
noClaim(t, fx, parent)
- code, _, out = rawReq(t, http.MethodPost, u, member, `{"host":"*.`+parent+`"}`)
+ // An instance catch-all is a person's act: the operator, an owner.
+ code, _, out = rawReq(t, http.MethodPost, u, operator, `{"host":"*.`+parent+`"}`)
if code != http.StatusUnprocessableEntity || cutoverErrorOf(out) != unassigned {
t.Errorf("instance catch-all on *.%s = %d %s, want 422 %q", parent, code, out, unassigned)
}
@@ -439,7 +452,7 @@ func TestCatchallUnderUnassignedLabelRefused(t *testing.T) {
if _, err := domains.SetClaimCapabilities(ctx, fx.rel, parent, fx.sqid, "shop", true, false); err != nil {
t.Fatal(err)
}
- code, _, out := rawReq(t, http.MethodPost, u, member, `{"host":"`+parent+`","route":"`+route+`","catchall":true}`)
+ code, _, out := rawReq(t, http.MethodPost, u, attacher, `{"host":"`+parent+`","route":"`+route+`","catchall":true}`)
if code != http.StatusUnprocessableEntity || cutoverErrorOf(out) != unassigned {
t.Errorf("catchall on the existing %s = %d %s, want 422 %q", parent, code, out, unassigned)
}
@@ -447,7 +460,7 @@ func TestCatchallUnderUnassignedLabelRefused(t *testing.T) {
`{"host":"` + parent + `","route":"` + route + `","wildcard":true}`,
`{"host":"` + parent + `","route":"` + route + `"}`,
} {
- if code, _, out := rawReq(t, http.MethodPost, u, member, body); code != http.StatusOK {
+ if code, _, out := rawReq(t, http.MethodPost, u, attacher, body); code != http.StatusOK {
t.Errorf("re-attach unchanged %s = %d %s, want 200", body, code, out)
}
}
@@ -473,7 +486,7 @@ func TestCatchallUnderUnassignedLabelRefused(t *testing.T) {
// Once marina is the account's, the catch-all is its to turn on.
nsHold(t, fx, "marina", fx.sqid)
- if code, _, out := rawReq(t, http.MethodPost, u, member, `{"host":"`+parent+`","route":"`+route+`","catchall":true}`); code != http.StatusOK {
+ if code, _, out := rawReq(t, http.MethodPost, u, attacher, `{"host":"`+parent+`","route":"`+route+`","catchall":true}`); code != http.StatusOK {
t.Errorf("catchall once marina is the account's = %d %s, want 200", code, out)
}
if c, err := domains.GetClaim(ctx, fx.rel, parent); err != nil || !c.Catchall {
@@ -854,7 +867,8 @@ func TestPendingCatchallClaimNotVerifiedUnderUnassignedLabel(t *testing.T) {
// that is not the account's it is refused, before any DNS gate, and the
// claim is unchanged.
func TestWildcardBesideLegacyCatchallRefused(t *testing.T) {
- fx, member, _ := nsShopFixture(t, "code-ns-wildcard")
+ fx, _, _ := nsShopFixture(t, "code-ns-wildcard")
+ attacher := nsAttacher(t, fx)
route := nsShopRoute(fx)
ctx := context.Background()
// The wildcard gate would pass: a delegation zone and the right CNAME
@@ -869,7 +883,7 @@ func TestWildcardBesideLegacyCatchallRefused(t *testing.T) {
for _, host := range []string{"marina." + nsApps, "x.marina." + nsApps} {
nsPutClaim(t, fx, domains.Claim{Schema: 1, Host: host, Account: fx.sqid, App: "shop", Route: route,
CreatedAt: "2026-11-11T00:00:00Z", Catchall: true})
- code, _, out := rawReq(t, http.MethodPost, u, member, `{"host":"`+host+`","route":"`+route+`","wildcard":true}`)
+ code, _, out := rawReq(t, http.MethodPost, u, attacher, `{"host":"`+host+`","route":"`+route+`","wildcard":true}`)
if want := nsNobodysCopy("marina"); code != http.StatusUnprocessableEntity || cutoverErrorOf(out) != want {
t.Errorf("wildcard on beside the legacy catch-all %s = %d %s, want 422 %q", host, code, out, want)
}
@@ -980,7 +994,8 @@ func TestRestoreUnderUnassignedLabelRefused(t *testing.T) {
// a catch-all on, at the attach door (the policy answer) or at the
// capability core (the other-account answer).
func TestCapabilityChangeUnderOtherAccountsNameRefused(t *testing.T) {
- fx, member, _ := nsShopFixture(t, "code-ns-cap-other")
+ fx, _, _ := nsShopFixture(t, "code-ns-cap-other")
+ attacher := nsAttacher(t, fx)
route := nsShopRoute(fx)
nsAccount(t, fx, 82, "bdq")
nsHold(t, fx, "harbour", "bdq")
@@ -988,7 +1003,7 @@ func TestCapabilityChangeUnderOtherAccountsNameRefused(t *testing.T) {
host := "x.harbour." + nsApps
nsPutClaim(t, fx, domains.Claim{Schema: 1, Host: host, Account: fx.sqid, App: "shop", Route: route,
CreatedAt: "2026-11-11T00:00:00Z", Wildcard: true})
- code, _, out := rawReq(t, http.MethodPost, domainsURL(fx, "bab", "shop"), member, `{"host":"`+host+`","route":"`+route+`","catchall":true}`)
+ code, _, out := rawReq(t, http.MethodPost, domainsURL(fx, "bab", "shop"), attacher, `{"host":"`+host+`","route":"`+route+`","catchall":true}`)
if code != http.StatusBadRequest || cutoverErrorOf(out) != "that hostname is platform-managed" {
t.Errorf("catchall at the attach door = %d %s, want 400 platform-managed", code, out)
}
diff --git a/internal/console/teamdoors_test.go b/internal/console/teamdoors_test.go
index f1939c735..1c37cf2e7 100644
--- a/internal/console/teamdoors_test.go
+++ b/internal/console/teamdoors_test.go
@@ -582,7 +582,8 @@ func TestTeamDomainDoors(t *testing.T) {
w := newTeamWorld(t, "code-team-domains")
ctx := context.Background()
// A member's claims: one on theirs, one first-route claim (Route "").
- attachDomain(t, w.fx, w.member, "theirs.example.com", "theirs.go.tito.io")
+ owner := cliToken(t, w.fx, "paul@keymail.dev", "code-team-domains-owner") // attach is owner-only (H4-M7)
+ attachDomain(t, w.fx, owner, "theirs.example.com", "theirs.go.tito.io")
if _, _, err := domains.AttachClaim(ctx, w.fx.rel, domains.Claim{Host: "first.example.com", Account: "bab", App: "titogo"}); err != nil {
t.Fatal(err)
}