console: account subdomain review fixes, round 1 (T5)
I1: the attach's own-claim exemption is pinned to the claim revision it read (claimPin on the request context, pinnedClaimStore in attachDomainClaim): a claim gone or changed before the write refuses, never recreated. Host-claim first routes resting on one are refused. I2: new serving coverage is judged on effect (verified, Wildcard and Catchall), before and after: a pending catch-all claim a re-attach would verify, and Wildcard turned on beside a legacy Catchall, are creates. I3: the new tests use a neutral shop fixture and principals. Also: AccountNamespaces skips names SubdomainRuleRefusal refuses (boxes derive nothing from *.bdq or *.www); instance create refuses one-label hosts of another account's namespace; refuse.create.unassignable for labels that can never be names; the untrusted namespace claim is logged once; tests for the failed own-claim read, unreadable listings at instance create and placements, a restore and a capability change. Census: record-write re-pins two console units and adds pinnedClaimStore.Put; root-read re-proposes the internal/domains envelope. Not approved.
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
14 files changed,
+684
−106
internal/console/apidomains.go+22 −9internal/console/apiinstances.go+5 −2internal/console/apiplacements.go+8 −1internal/console/claim_alias.go+9 −3internal/console/domainattach.go+21 −3internal/console/domainproof_test.go+1 −1internal/console/subdomain_copy.go+2 −0internal/console/subdomains.go+175 −29internal/console/subdomains_test.go+362 −53internal/domains/namespace.go+6 −1internal/domains/namespace_test.go+23 −1internal/domains/namespacealiases_test.go+26 −0internal/provision/account_subdomains_census_test.go+23 −2internal/provision/testdata/plan14-root-reads-account-subdomains.tsv+1 −1
CI failed — run details
Intent
Attributed to this commit: 24.8 g CO₂e (3,149,177 tokens). This is an attribution, not a measurement — usage counted from this commit's own marker forward to the next one on design-account-name-hosts, never backward from it. A turn that produced more than one commit books all of its tokens to the last one, and a concurrent session on this branch can add to the same figure. Some of it was priced using the shared default rate, because no model-specific factor row exists yet for at least one model involved. The Carbon view has the repo total, which is never derived from this attribution.
diff --git a/internal/console/apidomains.go b/internal/console/apidomains.go| index 945a665e2..c21defecc 100644 |
| --- a/internal/console/apidomains.go |
| +++ b/internal/console/apidomains.go |
| @@ -453,10 +453,14 @@ func (s *Server) handleAPIDomainAttach(w http.ResponseWriter, r *http.Request) { |
| // already has on. setDomainCapabilities asks again under regionalMu, |
| // on the claim it reads there; this earlier answer keeps an attach that |
| // asks for a catch-all from writing its claim first. |
| - if ref := s.attachCreateRefusal(ctx, v, host, acct.Sqid, in.Catchall != nil && *in.Catchall); ref != nil { |
| + pin, ref := s.attachCreateRefusal(ctx, v, host, acct.Sqid, in.Catchall != nil && *in.Catchall) |
| + if ref != nil { |
| jsonError(w, ref.Status, ref.Msg) |
| return |
| } |
| + // The alias write below is pinned to the claim that decision read; the |
| + // static branch's core decides (and pins) again on its own read. |
| + ctx = withClaimPin(ctx, pin) |
| if in.Kind != "" && in.Route != "" { |
| jsonError(w, http.StatusBadRequest, |
| "route and kind are two different instructions — name a route to alias, or a kind to mint, not both") |
| @@ -611,7 +615,11 @@ func (s *Server) handleAPIDomainAttach(w http.ResponseWriter, r *http.Request) { |
| // review finding on Task 1 — an attach body smuggling |
| // "wildcard":true alongside host/route must not reach this literal). |
| }, time.Now(), s.domainProver(ctx, v, host, acct.Sqid)) |
| - if errors.Is(err, domains.ErrHostUnavailable) { |
| + if pe := (*claimPinError)(nil); errors.As(err, &pe) { |
| + // The claim the namespace decision admitted has gone or changed. |
| + jsonError(w, pe.ref.Status, pe.ref.Msg) |
| + return |
| + } else if errors.Is(err, domains.ErrHostUnavailable) { |
| // Exactly these bytes, whoever holds it: naming the holder — or even |
| // distinguishing "held by another app of yours" from "held by a |
| // stranger" — would make this door a hostname-ownership oracle. |
| @@ -773,14 +781,19 @@ func (s *Server) setDomainCapabilities(w http.ResponseWriter, r *http.Request, c |
| // shows but could not read) answer RD-28, so the answer never says which |
| // name sits under host. A claim whose Catchall is already on needs no |
| // scan: the PUT refuses a regional name under it while it is on. |
| + // Account subdomains §4.2: names below host that would serve after |
| + // this change and do not before it are a create under host's label, |
| + // which must be this account's. Judged on serving coverage, not one |
| + // bit: Catchall turned on beside a Wildcard, and Wildcard turned on |
| + // beside a Catchall a legacy claim already carries, both count. The |
| + // pending state is left out of "after": a pending claim given both |
| + // serves them the moment a re-attach verifies it. |
| + if wildcard && catchall && !servesBelow(cur) && s.createRefusal(v, host, acct.Sqid, createExpandsCoverage) { |
| + ref := s.createDoorRefusal(v, host, acct.Sqid) |
| + jsonError(w, ref.Status, ref.Msg) |
| + return false |
| + } |
| if catchall && !cur.Catchall { |
| - // New names below host would serve: a create under its label, so |
| - // the label must be this account's (account subdomains §4.2). |
| - if s.createRefusal(v, host, acct.Sqid, createExpandsCoverage) { |
| - ref := s.createDoorRefusal(v, host, acct.Sqid) |
| - jsonError(w, ref.Status, ref.Msg) |
| - return false |
| - } |
| if ref := s.regionalDescendantRefusal(ctx, host); ref != nil { |
| if ref.Status == http.StatusConflict { |
| ref = &doorRefusal{Status: http.StatusConflict, Msg: catchallOverRegionalMsg(host)} |
diff --git a/internal/console/apiinstances.go b/internal/console/apiinstances.go| index 08fab5495..be7cefa80 100644 |
| --- a/internal/console/apiinstances.go |
| +++ b/internal/console/apiinstances.go |
| @@ -1735,11 +1735,14 @@ func (s *Server) handleAPIInstanceCreate(w http.ResponseWriter, r *http.Request) |
| // so under the apps domain its own label (not the manifest domain's |
| // standing) must be this account's sqid or a name it holds. Every |
| // create through this door asks, the seed, import and restore forms |
| - // included; a restore has already had its ownership answer above. |
| + // included; a restore has already had its ownership answer above. A |
| + // one-label host (harbour.<apps>, bdq.<apps>, from a manifest pinned to |
| + // the apps domain itself) is refused when it is another account's |
| + // namespace, as the attach doors refuse it. |
| if nv, ref := s.doorNamespaces(ctx, host); ref != nil { |
| jsonError(w, ref.Status, ref.Msg) |
| return |
| - } else if s.createRefusal(nv, host, acct.Sqid, createNewHost) { |
| + } else if s.createRefusal(nv, host, acct.Sqid, createNewHost) || s.otherAccountsNamespace(nv, host, acct.Sqid) { |
| ref := s.createDoorRefusal(nv, host, acct.Sqid) |
| jsonError(w, ref.Status, ref.Msg) |
| return |
diff --git a/internal/console/apiplacements.go b/internal/console/apiplacements.go| index 0a615715d..7ac0ca7f1 100644 |
| --- a/internal/console/apiplacements.go |
| +++ b/internal/console/apiplacements.go |
| @@ -535,7 +535,14 @@ func (s *Server) handleAPIDomainPlacementsPut(w http.ResponseWriter, r *http.Req |
| // account already holds at host is not a new host. Decided from the |
| // label and the account's own claim only, so it says nothing about |
| // anyone else's. |
| - if ref := s.namespaceCreateRefusal(v, host, acct.Sqid, cur, in.Catchall != nil && *in.Catchall); ref != nil { |
| + // Serving coverage after the write: the caller's own regional claim |
| + // keeps its fixed capabilities; anything else is replaced by the |
| + // body's. |
| + coverageAfter := wantWildcard && wantCatchall |
| + if cur != nil && cur.Account == acct.Sqid && cur.Regional() { |
| + coverageAfter = cur.Wildcard && cur.Catchall |
| + } |
| + if ref := s.namespaceCreateRefusal(v, host, acct.Sqid, cur, coverageAfter); ref != nil { |
| jsonError(w, ref.Status, ref.Msg) |
| return |
| } |
diff --git a/internal/console/claim_alias.go b/internal/console/claim_alias.go| index 53eb15c73..94ede5240 100644 |
| --- a/internal/console/claim_alias.go |
| +++ b/internal/console/claim_alias.go |
| @@ -34,11 +34,17 @@ import ( |
| // a catch-all on for this write to race, and taking regionalMu inside the |
| // alias registration's lifecycle would order an app mutation before it, |
| // the reverse of the catch-all doors. |
| +// |
| +// The claim key is read and written through claimStoreFor: pinned, when the |
| +// request's namespace decision rested on the claim it read (account |
| +// subdomains §4.2), to that revision, so the write refuses rather than |
| +// creates or converges over a claim that has gone or changed since. |
| func (s *Server) attachDomainClaim(ctx context.Context, acct *Account, app string, incoming domains.Claim, now time.Time, prove func() bool) (bool, bool, bool, error) { |
| + store := s.claimStoreFor(ctx, incoming.Host) |
| if !s.cfg.HostClaim { |
| s.regionalMu.Lock() |
| defer s.regionalMu.Unlock() |
| - return domains.AttachClaimProven(ctx, s.cfg.Releases, incoming, now, prove) |
| + return domains.AttachClaimProven(ctx, store, incoming, now, prove) |
| } |
| a := s.cfg.ClaimAuthority |
| if a == nil || a.Control == nil || incoming.Route == "" { |
| @@ -94,7 +100,7 @@ func (s *Server) attachDomainClaim(ctx context.Context, acct *Account, app strin |
| return false, false, false, err |
| } |
| key := domains.ClaimKey(incoming.Host) |
| - raw, etag, err := s.cfg.Releases.Get(ctx, key) |
| + raw, etag, err := store.Get(ctx, key) |
| absent := errors.Is(err, os.ErrNotExist) |
| if err != nil && !absent { |
| return false, false, false, err |
| @@ -137,7 +143,7 @@ func (s *Server) attachDomainClaim(ctx context.Context, acct *Account, app strin |
| incoming.RecordIncarnation = target.Claim.Holder.Incarnation |
| incoming.OwnershipState = "owned" |
| effects := claimStoreEffects{Runner: start.Runner(time.Now), OperationID: id} |
| - guarded := claimAliasStore{data: s.cfg.Releases, key: key, etag: etag, acquisition: acquisition, incarnation: incoming.RecordIncarnation, account: acct.Sqid, app: app, effects: effects} |
| + guarded := claimAliasStore{data: store, key: key, etag: etag, acquisition: acquisition, incarnation: incoming.RecordIncarnation, account: acct.Sqid, app: app, effects: effects} |
| return domains.AttachClaimProven(ctx, guarded, incoming, now, prove) |
| } |
diff --git a/internal/console/domainattach.go b/internal/console/domainattach.go| index fa5212d32..2b6b8b29c 100644 |
| --- a/internal/console/domainattach.go |
| +++ b/internal/console/domainattach.go |
| @@ -167,11 +167,17 @@ func (s *Server) attachDomainAs(ctx context.Context, view *namespaceView, acct * |
| // Choice B (account subdomains §4.2): a new host under a label that is |
| // not this account's sqid or name is refused, the platform door |
| // included. A claim the account already holds at host is a re-attach, |
| - // not a create, and passes. Decided from the label and the account's |
| - // own claim only, so the answer is the same whoever else holds host. |
| - if ref := s.attachCreateRefusal(ctx, v, host, acct.Sqid, false); ref != nil { |
| + // not a create, and passes, unless the attach would verify a pending |
| + // claim that serves names below host. Decided from the label and the |
| + // account's own claim only, so the answer is the same whoever else |
| + // holds host. When the decision read that claim, the claim write below |
| + // is pinned to it (withClaimPin): it refuses if the claim has gone or |
| + // changed, and never creates in its place. |
| + pin, ref := s.attachCreateRefusal(ctx, v, host, acct.Sqid, false) |
| + if ref != nil { |
| return attachResult{}, ref |
| } |
| + ctx = withClaimPin(ctx, pin) |
| // Plans 3a: custom domains need a plan that includes them. |
| if ref := s.customDomainRefusal(acct, host); ref != nil { |
| return attachResult{}, ref |
| @@ -269,6 +275,13 @@ func (s *Server) attachDomainAs(ctx context.Context, view *namespaceView, acct * |
| } |
| } |
| if s.cfg.HostClaim { |
| + // The host-claim first route writes through the claim mutation |
| + // boundary, which cannot carry the revision a namespace exemption |
| + // was decided on, so a first route that rests on one is refused |
| + // as the create it would be. (Host claims are shelved.) |
| + if pin != nil && pin.present { |
| + return attachResult{}, pin.gone |
| + } |
| return s.attachClaimFirstRoute(ctx, v, acct, app, host, channel, principal) |
| } |
| if lifetimesUnit(ctx) { |
| @@ -802,6 +815,11 @@ func (s *Server) rollbackAttachLocked(ctx context.Context, acct *Account, app, h |
| // the same bytes the CLI API door answers, so the two doors cannot be |
| // diffed against each other to learn anything either one refuses to say. |
| func claimRefusal(host string, err error) *doorRefusal { |
| + // A claim write pinned to the revision a namespace decision read |
| + // (withClaimPin), refused because the claim has gone or changed since. |
| + if pe := (*claimPinError)(nil); errors.As(err, &pe) { |
| + return pe.ref |
| + } |
| if msg, ok := claimAliasRefusal(err); ok { |
| return &doorRefusal{Status: http.StatusConflict, Msg: msg} |
| } |
diff --git a/internal/console/domainproof_test.go b/internal/console/domainproof_test.go| index e93edb327..0833c1517 100644 |
| --- a/internal/console/domainproof_test.go |
| +++ b/internal/console/domainproof_test.go |
| @@ -454,7 +454,7 @@ func TestOwnSubdomainNeedsNoProof(t *testing.T) { |
| if !fx.srv.firstRouteOutsideNamespace(v, host, "bdq") || fx.srv.firstRouteOutsideNamespace(v, host, fx.sqid) { |
| t.Error("firstRouteOutsideNamespace does not treat harbour as a namespace") |
| } |
| - res, ref := fx.srv.attachDomain(context.Background(), acct, "story", host, "", "", "paul@keymail.dev") |
| + res, ref := fx.srv.attachDomain(context.Background(), acct, "story", host, "", "", "owner@example.com") |
| if ref != nil { |
| t.Fatalf("attach under the account's own name refused %+v", ref) |
| } |
diff --git a/internal/console/subdomain_copy.go b/internal/console/subdomain_copy.go| index df29ffd03..57a091621 100644 |
| --- a/internal/console/subdomain_copy.go |
| +++ b/internal/console/subdomain_copy.go |
| @@ -40,6 +40,8 @@ const ( |
| subdomainCreateUnassignedCopy = "nothing can be added under %s until an account has that subdomain. ask a platform operator to assign it to this account" |
| // refuse.create.other_account |
| subdomainCreateOtherAccountCopy = "%s belongs to another account" |
| + // refuse.create.unassignable |
| + subdomainCreateUnassignableCopy = "nothing can be added under %s. use an address under the account's own label, or a custom domain" |
| // refuse.create.unreadable |
| subdomainCreateUnreadableCopy = "could not check which account holds %s. try again" |
| ) |
diff --git a/internal/console/subdomains.go b/internal/console/subdomains.go| index 1012b85ca..49aebd73f 100644 |
| --- a/internal/console/subdomains.go |
| +++ b/internal/console/subdomains.go |
| @@ -31,9 +31,11 @@ import ( |
| "slices" |
| "sort" |
| "strings" |
| + "sync" |
| "github.com/carlosframework/platform/internal/domains" |
| "github.com/carlosframework/platform/internal/provision" |
| + "github.com/carlosframework/platform/internal/release" |
| ) |
| // namespaceView is the account namespaces in force under the apps domain, |
| @@ -118,12 +120,31 @@ func (s *Server) loadNamespaces(ctx context.Context) (namespaceView, error) { |
| if name, ok := domains.ParseNamespaceHost(c.Host, domain); ok { |
| if _, held := v.byName[name]; !held { |
| v.unread[name] = true |
| + sayUntrustedNamespaceOnce(c) |
| } |
| } |
| } |
| return v, nil |
| } |
| +// untrustedNamespaceSaid holds the namespace claims already logged as |
| +// untrusted, so the line is written once per claim revision per process, |
| +// not on every request that loads the view. |
| +var untrustedNamespaceSaid sync.Map |
| + |
| +// sayUntrustedNamespaceOnce logs a namespace claim the view counts as |
| +// unread because AccountNamespaces does not trust it (pending, carrying |
| +// more than the namespace, or an invalid account). No door writes such a |
| +// claim, so only a direct bucket write gets here, and every create under |
| +// its label is refused until an operator fixes or removes the claim: the |
| +// line names it so they can. |
| +func sayUntrustedNamespaceOnce(c domains.Claim) { |
| + key := c.Host + "\x00" + c.Account + "\x00" + c.CreatedAt |
| + if _, said := untrustedNamespaceSaid.LoadOrStore(key, true); !said { |
| + log.Printf("console: namespace claim %s (account %q) is not one this console trusts (pending, or carrying more than the namespace); every create under it is refused until it is fixed or removed", c.Host, c.Account) |
| + } |
| +} |
| + |
| // appsDomain is the deployment's apps domain, normalized. |
| func (s *Server) appsDomain() string { |
| return strings.ToLower(strings.TrimSpace(s.cfg.AppsDomain)) |
| @@ -187,10 +208,11 @@ func (s *Server) createRefusal(v namespaceView, host, account string, kind creat |
| // label's claim did not read; the other-account answer when another account |
| // holds the label as a name, or as its sqid (live or deleted, |
| // AccountAnyBySqid, the lookup otherAccountsNamespace makes); and otherwise |
| -// the answer naming the fix (an operator assigns the label). A sqid-shaped |
| -// label no account has held is nobody's, so it gets that last answer. The |
| -// text never names the other account. Only the refusal path pays the |
| -// lookup. |
| +// the answer naming the fix (an operator assigns the label), or, for a label |
| +// that can never be a name (SubdomainRuleRefusal), the answer that says to |
| +// use the account's own label or a custom domain instead. A sqid-shaped |
| +// label no account has held is nobody's. The text never names the other |
| +// account. Only the refusal path pays the lookup. |
| func (s *Server) createDoorRefusal(v namespaceView, host, account string) *doorRefusal { |
| label, _ := s.appsLabel(strings.TrimPrefix(host, "*.")) |
| where := label + "." + s.appsDomain() |
| @@ -215,51 +237,175 @@ func (s *Server) createDoorRefusal(v namespaceView, host, account string) *doorR |
| return other |
| } |
| } |
| + // Nobody's. A label §4.2 refuses as a name (a short sqid-shaped one, a |
| + // reserved one) can never be assigned, so the fix the unassigned answer |
| + // names is not on offer for it. |
| + if domains.SubdomainRuleRefusal(label) != "" { |
| + return &doorRefusal{Status: http.StatusUnprocessableEntity, Msg: fmt.Sprintf(subdomainCreateUnassignableCopy, where)} |
| + } |
| return &doorRefusal{Status: http.StatusUnprocessableEntity, Msg: fmt.Sprintf(subdomainCreateUnassignedCopy, where)} |
| } |
| +// servesBelow reports whether c serves names below its host right now: a |
| +// verified claim with both Wildcard and Catchall (the box derives the |
| +// catch-all row only for those, domains/aliases.go). A pending claim, or |
| +// one with Catchall but not Wildcard, serves nothing below it. |
| +func servesBelow(c *domains.Claim) bool { |
| + return c != nil && !c.Pending && c.Wildcard && c.Catchall |
| +} |
| + |
| // namespaceCreateRefusal is a door's decision for a write at host, given |
| -// the claim the door read there (nil when there is none). A claim account |
| -// already holds at host is not a new host, whoever's label it sits under; |
| -// wantCatchall asks for coverage below host, which only a claim that has it |
| -// on already does not add. nil means the write may go ahead as far as the |
| -// namespace is concerned. |
| -func (s *Server) namespaceCreateRefusal(v namespaceView, host, account string, cur *domains.Claim, wantCatchall bool) *doorRefusal { |
| +// the claim the door read there (nil when there is none) and whether the |
| +// claim will serve names below host once the write lands (coverageAfter). |
| +// A claim account already holds at host is not a new host, whoever's label |
| +// it sits under; coverage it does not serve before the write and does |
| +// after is new, and is a create under the label (createExpandsCoverage) |
| +// however it comes about: Catchall turned on, Wildcard turned on beside a |
| +// Catchall, or a pending claim with both verified. nil means the write may |
| +// go ahead as far as the namespace is concerned. |
| +func (s *Server) namespaceCreateRefusal(v namespaceView, host, account string, cur *domains.Claim, coverageAfter bool) *doorRefusal { |
| held := cur != nil && cur.Account == account |
| if !held && s.createRefusal(v, host, account, createNewHost) { |
| return s.createDoorRefusal(v, host, account) |
| } |
| - if wantCatchall && !(held && cur.Catchall) && s.createRefusal(v, host, account, createExpandsCoverage) { |
| + if coverageAfter && !(held && servesBelow(cur)) && s.createRefusal(v, host, account, createExpandsCoverage) { |
| return s.createDoorRefusal(v, host, account) |
| } |
| return nil |
| } |
| -// attachCreateRefusal is namespaceCreateRefusal for the attach doors, which |
| -// hold no claim read of their own at this point: it reads host's claim only |
| -// when the label is not the account's, so the common case (the account's |
| -// own sqid, or a host outside the apps domain) costs nothing. A read that |
| -// fails refuses, retryably. |
| +// attachCreateRefusal is namespaceCreateRefusal for the attach doors. It |
| +// reads host's claim only when the label is not the account's (the common |
| +// case, the account's own sqid or a host outside the apps domain, costs |
| +// nothing); a read that fails refuses, retryably. The attach itself never |
| +// sets a capability, but it can verify a pending claim, which activates the |
| +// Wildcard+Catchall that claim already carries, so that is coverage after |
| +// too; wantCatchall is a door's request to turn Catchall on in the same |
| +// call. |
| // |
| -// The read and the attach's create-only write are not one step. The only |
| -// claim that admits here is one the account already holds, so what can slip |
| -// between them is that same account detaching it and the attach writing it |
| -// back: a host the account held a moment before. |
| -func (s *Server) attachCreateRefusal(ctx context.Context, v namespaceView, host, account string, wantCatchall bool) *doorRefusal { |
| - if !s.createRefusal(v, host, account, createNewHost) && |
| - !(wantCatchall && s.createRefusal(v, host, account, createExpandsCoverage)) { |
| +// When the decision rested on that read, the attach must write against |
| +// exactly what was read: the returned pin is handed to the claim write |
| +// (withClaimPin), which refuses if the claim has gone or changed since, |
| +// and never creates in its place. Without it, the account detaching its |
| +// own claim between this read and the write would let the attach create a |
| +// fresh claim under a label that is not its own. |
| +func (s *Server) attachCreateRefusal(ctx context.Context, v namespaceView, host, account string, wantCatchall bool) (*claimPin, *doorRefusal) { |
| + if !s.createRefusal(v, host, account, createNewHost) && !s.createRefusal(v, host, account, createExpandsCoverage) { |
| + return nil, nil |
| + } |
| + label, _ := s.appsLabel(host) |
| + unreadable := &doorRefusal{Status: http.StatusBadGateway, Msg: fmt.Sprintf(subdomainCreateUnreadableCopy, label+"."+s.appsDomain())} |
| + cur, etag, err := domains.GetClaimETag(ctx, s.cfg.Releases, host) |
| + switch { |
| + case errors.Is(err, os.ErrNotExist): |
| + cur, etag = nil, "" |
| + case err != nil: |
| + log.Printf("console: namespace: claim read for %s: %v", host, err) |
| + return nil, unreadable |
| + } |
| + held := cur != nil && cur.Account == account |
| + coverageAfter := wantCatchall || (held && cur.Wildcard && cur.Catchall) |
| + if ref := s.namespaceCreateRefusal(v, host, account, cur, coverageAfter); ref != nil { |
| + return nil, ref |
| + } |
| + return &claimPin{host: host, etag: etag, present: cur != nil, |
| + gone: s.createDoorRefusal(v, host, account), moved: unreadable}, nil |
| +} |
| + |
| +// claimPin is the revision of host's claim (or its absence) that a door's |
| +// namespace decision was made on, and the answers the write gives when the |
| +// claim is no longer that: gone (the decision admitted an existing claim |
| +// that has since been removed: writing now would be a create, which the |
| +// label does not allow) and moved (it changed: judged on a stale read, so |
| +// try again). |
| +type claimPin struct { |
| + host, etag string |
| + present bool |
| + gone *doorRefusal |
| + moved *doorRefusal |
| +} |
| + |
| +// claimPinError is a pinned claim write refused because the claim is not |
| +// what the decision read. claimRefusal answers it with its refusal. |
| +type claimPinError struct{ ref *doorRefusal } |
| + |
| +func (e *claimPinError) Error() string { return "console: namespace: " + e.ref.Msg } |
| + |
| +type claimPinKey struct{} |
| + |
| +// withClaimPin carries p to the claim write of this request |
| +// (attachDomainClaim). A nil p carries nothing. |
| +func withClaimPin(ctx context.Context, p *claimPin) context.Context { |
| + if p == nil { |
| + return ctx |
| + } |
| + return context.WithValue(ctx, claimPinKey{}, p) |
| +} |
| + |
| +// claimPinFor is the pin ctx carries for host, or nil. |
| +func claimPinFor(ctx context.Context, host string) *claimPin { |
| + p, _ := ctx.Value(claimPinKey{}).(*claimPin) |
| + if p == nil || p.host != host { |
| return nil |
| } |
| - cur, err := domains.GetClaim(ctx, s.cfg.Releases, host) |
| + return p |
| +} |
| + |
| +// pinnedClaimStore is a release.Store whose one claim key answers only as |
| +// the pin read it. A Get of the key that finds it gone, changed, or present |
| +// where it was absent fails with the pin's refusal, so the claim writer |
| +// (domains.AttachClaimProven, which reads before it writes and re-reads |
| +// after a lost CAS) stops instead of creating or converging; a Put of the |
| +// key is admitted only conditional on the pinned revision. Every other key |
| +// passes through. |
| +type pinnedClaimStore struct { |
| + release.Store |
| + key string |
| + pin *claimPin |
| +} |
| + |
| +func (p pinnedClaimStore) Get(ctx context.Context, key string) ([]byte, string, error) { |
| + body, etag, err := p.Store.Get(ctx, key) |
| + if key != p.key { |
| + return body, etag, err |
| + } |
| switch { |
| + case errors.Is(err, os.ErrNotExist) && p.pin.present: |
| + return nil, "", &claimPinError{p.pin.gone} |
| case errors.Is(err, os.ErrNotExist): |
| - cur = nil |
| + return body, etag, err |
| case err != nil: |
| - log.Printf("console: namespace: claim read for %s: %v", host, err) |
| - label, _ := s.appsLabel(host) |
| - return &doorRefusal{Status: http.StatusBadGateway, Msg: fmt.Sprintf(subdomainCreateUnreadableCopy, label+"."+s.appsDomain())} |
| + return body, etag, err |
| + case !p.pin.present || etag != p.pin.etag: |
| + return nil, "", &claimPinError{p.pin.moved} |
| } |
| - return s.namespaceCreateRefusal(v, host, account, cur, wantCatchall) |
| + return body, etag, nil |
| +} |
| + |
| +func (p pinnedClaimStore) Put(ctx context.Context, key string, body []byte, ifMatch string) (string, error) { |
| + if key == p.key { |
| + want := "" |
| + if p.pin.present { |
| + want = p.pin.etag |
| + } |
| + if ifMatch != want { |
| + if p.pin.present && ifMatch == "" { |
| + return "", &claimPinError{p.pin.gone} |
| + } |
| + return "", &claimPinError{p.pin.moved} |
| + } |
| + } |
| + return p.Store.Put(ctx, key, body, ifMatch) |
| +} |
| + |
| +// claimStoreFor is the store the claim write for host goes through: the |
| +// deployment bucket, pinned when the request's namespace decision rested on |
| +// the claim's revision. |
| +func (s *Server) claimStoreFor(ctx context.Context, host string) release.Store { |
| + if p := claimPinFor(ctx, host); p != nil { |
| + return pinnedClaimStore{Store: s.cfg.Releases, key: domains.ClaimKey(host), pin: p} |
| + } |
| + return s.cfg.Releases |
| } |
| // doorNamespaces loads the view for a door that may create host. A host |
diff --git a/internal/console/subdomains_test.go b/internal/console/subdomains_test.go| index ed13f0873..adbbb768e 100644 |
| --- a/internal/console/subdomains_test.go |
| +++ b/internal/console/subdomains_test.go |
| @@ -29,7 +29,53 @@ import ( |
| "github.com/carlosframework/platform/internal/release" |
| ) |
| -const nsApps = "oncarlos.com" |
| +const ( |
| + nsApps = "oncarlos.com" |
| + nsActor = "owner@example.com" |
| +) |
| + |
| +// nsShopFixture is the base console with app shop in the fixture account |
| +// (bab, the ops account), the apps domain oncarlos.com, a member |
| +// owner@example.com and an operator ops@example.com (an owner of the ops |
| +// account, so the platform door admits it), each with a CLI token. Neutral |
| +// names throughout, for the doors the attach fixture cannot reach. |
| +func nsShopFixture(t *testing.T, code string) (fx *consoleFixture, member, operator string) { |
| + t.Helper() |
| + fx = newConsoleFixture(t) |
| + fx.srv.cfg.AppsDomain = nsApps |
| + now := time.Now() |
| + if _, err := fx.st.CreateAppIn(OpsAccountID, "shop", nsActor, now); err != nil { |
| + t.Fatal(err) |
| + } |
| + if err := fx.st.AddMember(OpsAccountID, nsActor, RoleMember, now); err != nil { |
| + t.Fatal(err) |
| + } |
| + if err := fx.st.AddMember(OpsAccountID, "ops@example.com", RoleOwner, now); err != nil { |
| + t.Fatal(err) |
| + } |
| + return fx, cliToken(t, fx, nsActor, code), cliToken(t, fx, "ops@example.com", code+"-ops") |
| +} |
| + |
| +// 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 |
| +// use the account's own label or a custom domain; any other label gets the |
| +// one that says to have it assigned. |
| +func nsNobodysCopy(label string) string { |
| + switch label { |
| + case "team", "www": |
| + return fmt.Sprintf(subdomainCreateUnassignableCopy, label+"."+nsApps) |
| + } |
| + return fmt.Sprintf(subdomainCreateUnassignedCopy, label+"."+nsApps) |
| +} |
| + |
| +// nsShopManifest is shop's instance manifest on domain. |
| +func nsShopManifest(domain string) provision.Manifest { |
| + return provision.Manifest{Schema: 1, App: "shop", Domain: domain, Channel: "stable", Regions: []string{"ie"}} |
| +} |
| + |
| +// nsShopRoute is shop's platform address, the route the alias attaches name. |
| +func nsShopRoute(fx *consoleFixture) string { return "shop." + fx.sqid + "." + nsApps } |
| // nsAccount creates the account whose sqid is Sqid(id), with its bucket |
| // manifest, so the record walk knows it too. |
| @@ -227,8 +273,8 @@ func TestCreateUnderUnassignedLabelRefused(t *testing.T) { |
| for _, label := range []string{"team", "marina"} { |
| host := "blog." + label + "." + nsApps |
| - _, ref := fx.srv.attachDomain(ctx, acct, "story", host, "", "", "paul@keymail.dev") |
| - if want := fmt.Sprintf(subdomainCreateUnassignedCopy, label+"."+nsApps); ref == nil || ref.Msg != want { |
| + _, ref := fx.srv.attachDomain(ctx, acct, "story", host, "", "", nsActor) |
| + if want := nsNobodysCopy(label); ref == nil || ref.Msg != want { |
| t.Errorf("attach %s under an unassigned label = %+v, want %q", host, ref, want) |
| } |
| noClaim(t, fx, host) |
| @@ -236,7 +282,7 @@ func TestCreateUnderUnassignedLabelRefused(t *testing.T) { |
| host := "blog.marina." + nsApps |
| nsHold(t, fx, "marina", fx.sqid) |
| - res, ref := fx.srv.attachDomain(ctx, acct, "story", host, "", "", "paul@keymail.dev") |
| + res, ref := fx.srv.attachDomain(ctx, acct, "story", host, "", "", nsActor) |
| if ref != nil || !res.FirstRoute { |
| t.Fatalf("attach %s once marina is the account's = %+v %+v, want a first route", host, res, ref) |
| } |
| @@ -247,21 +293,21 @@ func TestCreateUnderUnassignedLabelRefused(t *testing.T) { |
| // re-attached (declaring its record), and its existing alias converges. |
| first := "x.dock." + nsApps |
| seedClaim(t, fx, domains.Claim{Schema: 1, Host: first, Account: fx.sqid, App: "story", CreatedAt: "2026-11-11T00:00:00Z"}) |
| - if res, ref := fx.srv.attachDomain(ctx, acct, "story", first, "", "", "paul@keymail.dev"); ref != nil || !res.FirstRoute { |
| + if res, ref := fx.srv.attachDomain(ctx, acct, "story", first, "", "", nsActor); ref != nil || !res.FirstRoute { |
| t.Errorf("re-attach of the account's own %s = %+v %+v, want its first route", first, res, ref) |
| } |
| alias := "y.dock." + nsApps |
| seedClaim(t, fx, domains.Claim{Schema: 1, Host: alias, Account: fx.sqid, App: "story", Route: "old.story.example.com", CreatedAt: "2026-11-11T00:00:00Z"}) |
| ready := "story." + fx.sqid + "." + nsApps |
| fx.srv.cfg.Registry = attachRegistry(t, registry.Route{Host: ready, Kind: "static", App: "story", Account: fx.sqid, Channel: "canary/live", Status: "ready"}) |
| - if _, ref := fx.srv.attachDomain(ctx, acct, "story", alias, "", "", "paul@keymail.dev"); ref != nil { |
| + if _, ref := fx.srv.attachDomain(ctx, acct, "story", alias, "", "", nsActor); ref != nil { |
| t.Errorf("re-pointing the account's own %s = %+v, want it changed", alias, ref) |
| } |
| if c, err := domains.GetClaim(ctx, fx.rel, alias); err != nil || c.Route != ready { |
| t.Errorf("claim %s = %+v, %v; want it pointing at %s", alias, c, err, ready) |
| } |
| // A new host beside them is still refused. |
| - if _, ref := fx.srv.attachDomain(ctx, acct, "story", "z.dock."+nsApps, "", "", "paul@keymail.dev"); ref == nil { |
| + if _, ref := fx.srv.attachDomain(ctx, acct, "story", "z.dock."+nsApps, "", "", nsActor); ref == nil { |
| t.Error("a new host under dock was accepted") |
| } |
| noClaim(t, fx, "z.dock."+nsApps) |
| @@ -273,12 +319,11 @@ func TestCreateUnderUnassignedLabelRefused(t *testing.T) { |
| // sqid keep their text; instance create, which did not, answers with the |
| // approved other-account copy. |
| func TestCreateUnderOtherAccountsNameRefused(t *testing.T) { |
| - fx, member := instanceFixture(t, "code-ns-other") |
| - fx.srv.cfg.AppsDomain = nsApps |
| - operator := cliToken(t, fx, "paul@keymail.dev", "code-ns-other-paul") |
| + fx, member, operator := nsShopFixture(t, "code-ns-other") |
| + route := nsShopRoute(fx) |
| nsAccount(t, fx, 82, "bdq") |
| nsHold(t, fx, "harbour", "bdq") |
| - enableInstances(t, fx, "titogo", titoManifest()) |
| + enableInstances(t, fx, "shop", nsShopManifest("shop.example.com")) |
| acct, err := fx.st.AccountBySqid(fx.sqid) |
| if err != nil { |
| t.Fatal(err) |
| @@ -287,22 +332,22 @@ func TestCreateUnderOtherAccountsNameRefused(t *testing.T) { |
| host := "x.harbour." + nsApps |
| // The browser form's core, and the first-route core. |
| - if _, ref := fx.srv.attachDomain(ctx, acct, "titogo", host, "", "", "paul@keymail.dev"); ref == nil || ref.Msg != "that hostname is platform-managed" { |
| + if _, ref := fx.srv.attachDomain(ctx, acct, "shop", host, "", "", nsActor); ref == nil || ref.Msg != "that hostname is platform-managed" { |
| t.Errorf("attach core = %+v, want the platform-managed refusal", ref) |
| } |
| - if _, ref := fx.srv.attachDomain(ctx, acct, "titogo", host, "static", "", "paul@keymail.dev"); ref == nil { |
| + if _, ref := fx.srv.attachDomain(ctx, acct, "shop", host, "static", "", nsActor); ref == nil { |
| t.Error("first-route core accepted") |
| } |
| - u := domainsURL(fx, "bab", "titogo") |
| + u := domainsURL(fx, "bab", "shop") |
| for _, c := range []struct { |
| door, token, body string |
| want int |
| }{ |
| - {"API alias", member, attachBody(host, "go.tito.io"), http.StatusBadRequest}, |
| + {"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":"go.tito.io","wildcard":true,"catchall":true}`, http.StatusBadRequest}, |
| - {"platform door", operator, platformAttachBody(host, "go.tito.io"), http.StatusBadRequest}, |
| - {"one-label platform door", operator, platformAttachBody("harbour."+nsApps, "go.tito.io"), http.StatusBadRequest}, |
| + {"API wildcard and catchall", member, `{"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}, |
| } { |
| @@ -312,14 +357,12 @@ func TestCreateUnderOtherAccountsNameRefused(t *testing.T) { |
| } |
| // Instance create: the host's own label decides. |
| - m := titoManifest() |
| - m.Domain = "harbour." + nsApps |
| - enableInstances(t, fx, "titogo", m) |
| - code, _, out := rawReq(t, http.MethodPost, instancesURL(fx, "bab", "titogo"), member, `{"host":"`+host+`","region":"ie"}`) |
| + enableInstances(t, fx, "shop", nsShopManifest("harbour."+nsApps)) |
| + code, _, out := rawReq(t, http.MethodPost, instancesURL(fx, "bab", "shop"), member, `{"host":"`+host+`","region":"ie"}`) |
| if want := fmt.Sprintf(subdomainCreateOtherAccountCopy, "harbour."+nsApps); code != http.StatusUnprocessableEntity || cutoverErrorOf(out) != want { |
| t.Errorf("instance create = %d %s, want 422 %q", code, out, want) |
| } |
| - if _, _, err := fx.rel.Get(ctx, provision.RecordKey(fx.sqid, "titogo", host)); !errors.Is(err, os.ErrNotExist) { |
| + if _, _, err := fx.rel.Get(ctx, provision.RecordKey(fx.sqid, "shop", host)); !errors.Is(err, os.ErrNotExist) { |
| t.Errorf("a record at %s (err %v)", host, err) |
| } |
| for _, h := range []string{host, "harbour." + nsApps, "*.x.harbour." + nsApps} { |
| @@ -345,7 +388,7 @@ func TestPlacementsUnderOtherAccountsNameRefused(t *testing.T) { |
| noClaim(t, w.fx, host) |
| unassigned := "x.team." + nsApps |
| code, out := w.put(t, unassigned, rdBoth()) |
| - if want := fmt.Sprintf(subdomainCreateUnassignedCopy, "team."+nsApps); code != http.StatusUnprocessableEntity || cutoverErrorOf(out) != want { |
| + if want := nsNobodysCopy("team"); code != http.StatusUnprocessableEntity || cutoverErrorOf(out) != want { |
| t.Errorf("placements under an unassigned label = %d %s, want 422 %q", code, out, want) |
| } |
| noClaim(t, w.fx, unassigned) |
| @@ -367,16 +410,16 @@ 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 := instanceFixture(t, "code-ns-catchall") |
| - fx.srv.cfg.AppsDomain = nsApps |
| - enableInstances(t, fx, "titogo", titoManifest()) |
| + fx, member, _ := nsShopFixture(t, "code-ns-catchall") |
| + route := nsShopRoute(fx) |
| + enableInstances(t, fx, "shop", nsShopManifest("shop.example.com")) |
| ctx := context.Background() |
| - u := domainsURL(fx, "bab", "titogo") |
| + u := domainsURL(fx, "bab", "shop") |
| for _, label := range []string{"team", "marina"} { |
| parent := label + "." + nsApps |
| - unassigned := fmt.Sprintf(subdomainCreateUnassignedCopy, parent) |
| - code, _, out := rawReq(t, http.MethodPost, u, member, `{"host":"`+parent+`","route":"go.tito.io","wildcard":true,"catchall":true}`) |
| + unassigned := nsNobodysCopy(label) |
| + code, _, out := rawReq(t, http.MethodPost, u, member, `{"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) |
| } |
| @@ -392,17 +435,17 @@ func TestCatchallUnderUnassignedLabelRefused(t *testing.T) { |
| // off. |
| parent := "marina." + nsApps |
| unassigned := fmt.Sprintf(subdomainCreateUnassignedCopy, parent) |
| - seedClaim(t, fx, domains.Claim{Schema: 1, Host: parent, Account: fx.sqid, App: "titogo", Route: "go.tito.io", CreatedAt: "2026-11-11T00:00:00Z"}) |
| - if _, err := domains.SetClaimCapabilities(ctx, fx.rel, parent, fx.sqid, "titogo", true, false); err != nil { |
| + seedClaim(t, fx, domains.Claim{Schema: 1, Host: parent, Account: fx.sqid, App: "shop", Route: route, CreatedAt: "2026-11-11T00:00:00Z"}) |
| + 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":"go.tito.io","catchall":true}`) |
| + code, _, out := rawReq(t, http.MethodPost, u, member, `{"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) |
| } |
| for _, body := range []string{ |
| - `{"host":"` + parent + `","route":"go.tito.io","wildcard":true}`, |
| - `{"host":"` + parent + `","route":"go.tito.io"}`, |
| + `{"host":"` + parent + `","route":"` + route + `","wildcard":true}`, |
| + `{"host":"` + parent + `","route":"` + route + `"}`, |
| } { |
| if code, _, out := rawReq(t, http.MethodPost, u, member, body); code != http.StatusOK { |
| t.Errorf("re-attach unchanged %s = %d %s, want 200", body, code, out) |
| @@ -420,8 +463,8 @@ func TestCatchallUnderUnassignedLabelRefused(t *testing.T) { |
| } |
| yes := true |
| rec := httptest.NewRecorder() |
| - if fx.srv.setDomainCapabilities(rec, httptest.NewRequest(http.MethodPost, "/", nil), ctx, nsView(t, fx.srv), acct, "titogo", |
| - Principal{Kind: PrincipalUser, Address: "alice@keymail.dev"}, parent, nil, &yes) { |
| + if fx.srv.setDomainCapabilities(rec, httptest.NewRequest(http.MethodPost, "/", nil), ctx, nsView(t, fx.srv), acct, "shop", |
| + Principal{Kind: PrincipalUser, Address: nsActor}, parent, nil, &yes) { |
| t.Error("setDomainCapabilities turned the catch-all on under an unassigned label") |
| } |
| if rec.Code != http.StatusUnprocessableEntity { |
| @@ -430,7 +473,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":"go.tito.io","catchall":true}`); code != http.StatusOK { |
| + if code, _, out := rawReq(t, http.MethodPost, u, member, `{"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 { |
| @@ -450,7 +493,7 @@ func TestDoorRefusesWhenNamespacesUnreadable(t *testing.T) { |
| nsAccount(t, fx, 49, "bcd") |
| nsHold(t, fx, "harbour", "bcd") |
| - if _, ref := fx.srv.attachDomain(ctx, acct, "story", "harbour."+nsApps, "", "", "paul@keymail.dev"); ref == nil { |
| + if _, ref := fx.srv.attachDomain(ctx, acct, "story", "harbour."+nsApps, "", "", nsActor); ref == nil { |
| t.Error("a one-label attach of bcd's harbour was accepted") |
| } |
| noClaim(t, fx, "harbour."+nsApps) |
| @@ -458,7 +501,7 @@ func TestDoorRefusesWhenNamespacesUnreadable(t *testing.T) { |
| fx.srv.cfg.Releases = &nsFaultStore{Store: fx.rel, failList: domains.ClaimsPrefix} |
| fx.srv.claims.Reset() |
| own := "blog." + fx.sqid + "." + nsApps |
| - _, ref := fx.srv.attachDomain(ctx, acct, "story", own, "", "", "paul@keymail.dev") |
| + _, ref := fx.srv.attachDomain(ctx, acct, "story", own, "", "", nsActor) |
| if want := fmt.Sprintf(subdomainCreateUnreadableCopy, fx.sqid+"."+nsApps); ref == nil || ref.Msg != want || ref.Status != http.StatusBadGateway { |
| t.Errorf("attach %s with the listing down = %+v, want 502 %q", own, ref, want) |
| } |
| @@ -467,7 +510,7 @@ func TestDoorRefusesWhenNamespacesUnreadable(t *testing.T) { |
| t.Error("loadNamespaces answered with the listing down") |
| } |
| // A host outside the apps domain needs no namespace and still attaches. |
| - if _, ref := fx.srv.attachDomain(ctx, acct, "story", "story.example.com", "", "", "paul@keymail.dev"); ref != nil { |
| + if _, ref := fx.srv.attachDomain(ctx, acct, "story", "story.example.com", "", "", nsActor); ref != nil { |
| t.Errorf("attach outside the apps domain with the listing down = %+v, want it attached", ref) |
| } |
| } |
| @@ -479,16 +522,15 @@ func TestDoorRefusesWhenNamespacesUnreadable(t *testing.T) { |
| // until marina is the account's, and one pinned to another account's sqid |
| // cannot create there at all. |
| func TestInstanceCreateChecksHostLabel(t *testing.T) { |
| - fx, member := instanceFixture(t, "code-ns-instance") |
| - fx.srv.cfg.AppsDomain = nsApps |
| + fx, member, _ := nsShopFixture(t, "code-ns-instance") |
| nsAccount(t, fx, 82, "bdq") |
| - m := titoManifest() |
| - u := instancesURL(fx, "bab", "titogo") |
| + m := nsShopManifest("") |
| + u := instancesURL(fx, "bab", "shop") |
| for _, label := range []string{"team", "marina"} { |
| m.Domain = label + "." + nsApps |
| - enableInstances(t, fx, "titogo", m) |
| + enableInstances(t, fx, "shop", m) |
| code, _, out := rawReq(t, http.MethodPost, u, member, `{"host":"a.`+label+`.`+nsApps+`","region":"ie"}`) |
| - if want := fmt.Sprintf(subdomainCreateUnassignedCopy, label+"."+nsApps); code != http.StatusUnprocessableEntity || cutoverErrorOf(out) != want { |
| + if want := nsNobodysCopy(label); code != http.StatusUnprocessableEntity || cutoverErrorOf(out) != want { |
| t.Errorf("create a.%s = %d %s, want 422 %q", label, code, out, want) |
| } |
| } |
| @@ -498,7 +540,7 @@ func TestInstanceCreateChecksHostLabel(t *testing.T) { |
| } |
| m.Domain = "bdq." + nsApps |
| - enableInstances(t, fx, "titogo", m) |
| + enableInstances(t, fx, "shop", m) |
| code, _, out := rawReq(t, http.MethodPost, u, member, `{"host":"a.bdq.`+nsApps+`","region":"ie"}`) |
| if want := fmt.Sprintf(subdomainCreateOtherAccountCopy, "bdq."+nsApps); code != http.StatusUnprocessableEntity || cutoverErrorOf(out) != want { |
| t.Errorf("create a.bdq = %d %s, want 422 %q", code, out, want) |
| @@ -530,7 +572,7 @@ func TestUnreadNamespaceRefusesEveryone(t *testing.T) { |
| } |
| want := fmt.Sprintf(subdomainCreateUnreadableCopy, "marketx."+nsApps) |
| for _, host := range []string{"x.marketx." + nsApps, "marketx." + nsApps} { |
| - if _, ref := fx.srv.attachDomain(ctx, acct, "story", host, "", "", "paul@keymail.dev"); ref == nil || ref.Msg != want { |
| + if _, ref := fx.srv.attachDomain(ctx, acct, "story", host, "", "", nsActor); ref == nil || ref.Msg != want { |
| t.Errorf("attach %s = %+v, want %q", host, ref, want) |
| } |
| noClaim(t, fx, host) |
| @@ -539,7 +581,7 @@ func TestUnreadNamespaceRefusesEveryone(t *testing.T) { |
| t.Errorf("assigning marketx = %q, want %q", got, domains.SubdomainUnreadable) |
| } |
| // Other labels are untouched. |
| - if _, ref := fx.srv.attachDomain(ctx, acct, "story", "blog."+fx.sqid+"."+nsApps, "", "", "paul@keymail.dev"); ref != nil { |
| + if _, ref := fx.srv.attachDomain(ctx, acct, "story", "blog."+fx.sqid+"."+nsApps, "", "", nsActor); ref != nil { |
| t.Errorf("attach under the account's own sqid = %+v, want it attached", ref) |
| } |
| } |
| @@ -660,7 +702,7 @@ func TestRemovedNameStopsProtecting(t *testing.T) { |
| if got := fx.srv.domainHostPolicy(nsView(t, fx.srv), "x.harbour."+nsApps, fx.sqid); got != hostReserved { |
| t.Errorf("policy under bdq's harbour = %v, want reserved", got) |
| } |
| - if _, ref := fx.srv.attachDomain(ctx, acct, "story", "harbour."+nsApps, "", "", "paul@keymail.dev"); ref == nil { |
| + if _, ref := fx.srv.attachDomain(ctx, acct, "story", "harbour."+nsApps, "", "", nsActor); ref == nil { |
| t.Error("harbour.<apps> attached while bdq holds harbour") |
| } |
| @@ -668,10 +710,10 @@ func TestRemovedNameStopsProtecting(t *testing.T) { |
| if got := fx.srv.domainHostPolicy(nsView(t, fx.srv), "x.harbour."+nsApps, fx.sqid); got != hostOpen { |
| t.Errorf("policy under the removed harbour = %v, want open", got) |
| } |
| - if _, ref := fx.srv.attachDomain(ctx, acct, "story", "harbour."+nsApps, "", "", "paul@keymail.dev"); ref != nil { |
| + if _, ref := fx.srv.attachDomain(ctx, acct, "story", "harbour."+nsApps, "", "", nsActor); ref != nil { |
| t.Errorf("harbour.<apps> after removal = %+v, want it attached", ref) |
| } |
| - _, ref := fx.srv.attachDomain(ctx, acct, "story", "x.harbour."+nsApps, "", "", "paul@keymail.dev") |
| + _, ref := fx.srv.attachDomain(ctx, acct, "story", "x.harbour."+nsApps, "", "", nsActor) |
| if want := fmt.Sprintf(subdomainCreateUnassignedCopy, "harbour."+nsApps); ref == nil || ref.Msg != want { |
| t.Errorf("attach under the removed harbour = %+v, want %q", ref, want) |
| } |
| @@ -700,3 +742,270 @@ func TestNamespaceClaimOnSqidLabelIgnored(t *testing.T) { |
| t.Error("bcd has a name from a claim on a sqid label") |
| } |
| } |
| + |
| +// nsDetachOnReadStore removes victim's claim the first time trigger is read: |
| +// a concurrent detach landing between a door's namespace decision and its |
| +// claim write. Every attach reads the instance catch-all key of host's |
| +// parent (heldElsewhere) after that decision and before the write. |
| +type nsDetachOnReadStore struct { |
| + release.Store |
| + trigger, victim string |
| + fired bool |
| +} |
| + |
| +func (s *nsDetachOnReadStore) Get(ctx context.Context, key string) ([]byte, string, error) { |
| + if key == s.trigger && !s.fired { |
| + s.fired = true |
| + if err := s.Store.Delete(ctx, s.victim); err != nil { |
| + return nil, "", err |
| + } |
| + } |
| + return s.Store.Get(ctx, key) |
| +} |
| + |
| +// TestAttachExemptionHoldsThroughTheWrite (Task 5 round 1, I1): the |
| +// account's own claim under an unassigned label admits a re-attach, and the |
| +// claim write is held to the claim that decision read. Detached between the |
| +// decision and the write, the attach is refused and writes nothing: no |
| +// fresh claim, no record. Both branches: an alias converge and a first |
| +// route. |
| +func TestAttachExemptionHoldsThroughTheWrite(t *testing.T) { |
| + for _, branch := range []string{"alias", "first route"} { |
| + t.Run(branch, func(t *testing.T) { |
| + fx, acct := attachFixture(t) |
| + shipVersion(t, fx, "story", "v1") |
| + seedChannel(t, fx, "story", "canary/live", "v1") |
| + ctx := context.Background() |
| + host := "y.dock." + nsApps |
| + c := domains.Claim{Schema: 1, Host: host, Account: fx.sqid, App: "story", CreatedAt: "2026-11-11T00:00:00Z"} |
| + if branch == "alias" { |
| + fx.srv.cfg.Registry = attachRegistry(t, registry.Route{Host: "story." + fx.sqid + "." + nsApps, Kind: "static", |
| + App: "story", Account: fx.sqid, Channel: "canary/live", Status: "ready"}) |
| + c.Route = "old.story.example.com" |
| + } |
| + seedClaim(t, fx, c) |
| + pause := &nsDetachOnReadStore{Store: fx.rel, |
| + trigger: domains.ClaimKey(domains.InstanceCatchallHost("dock." + nsApps)), victim: domains.ClaimKey(host)} |
| + fx.srv.cfg.Releases = pause |
| + _, ref := fx.srv.attachDomain(ctx, acct, "story", host, "", "", nsActor) |
| + if !pause.fired { |
| + t.Fatal("the attach never reached the read between its decision and its write") |
| + } |
| + if want := nsNobodysCopy("dock"); ref == nil || ref.Msg != want { |
| + t.Errorf("attach after the claim was detached = %+v, want %q", ref, want) |
| + } |
| + noClaim(t, fx, host) |
| + if _, _, err := fx.rel.Get(ctx, provision.RecordKey(fx.sqid, "story", host)); !errors.Is(err, os.ErrNotExist) { |
| + t.Errorf("a record at %s (err %v)", host, err) |
| + } |
| + }) |
| + } |
| +} |
| + |
| +// nsPutClaim writes c as stored, bypassing every writer's rules: a legacy |
| +// claim, or one a direct bucket write left. |
| +func nsPutClaim(t *testing.T, fx *consoleFixture, c domains.Claim) { |
| + t.Helper() |
| + body, err := json.Marshal(c) |
| + if err != nil { |
| + t.Fatal(err) |
| + } |
| + putFixtureObject(t, fx.rel, domains.ClaimKey(c.Host), body) |
| +} |
| + |
| +// TestPendingCatchallClaimNotVerifiedUnderUnassignedLabel (round 1, I2): a |
| +// legacy pending claim carrying Wildcard and Catchall serves nothing; a |
| +// plain re-attach would verify it, and then it would serve every name below |
| +// it. Under a label that is not the account's that is a create, refused, |
| +// and the claim stays pending. A pending claim with no catch-all verifies |
| +// as before. |
| +func TestPendingCatchallClaimNotVerifiedUnderUnassignedLabel(t *testing.T) { |
| + fx, acct := attachFixture(t) |
| + shipVersion(t, fx, "story", "v1") |
| + seedChannel(t, fx, "story", "canary/live", "v1") |
| + ready := "story." + fx.sqid + "." + nsApps |
| + fx.srv.cfg.Registry = attachRegistry(t, registry.Route{Host: ready, Kind: "static", App: "story", Account: fx.sqid, Channel: "canary/live", Status: "ready"}) |
| + ctx := context.Background() |
| + until := time.Now().Add(time.Hour).UTC().Format(time.RFC3339) |
| + for _, host := range []string{"marina." + nsApps, "x.marina." + nsApps} { |
| + nsPutClaim(t, fx, domains.Claim{Schema: 1, Host: host, Account: fx.sqid, App: "story", Route: ready, |
| + CreatedAt: "2026-11-11T00:00:00Z", Wildcard: true, Catchall: true, Pending: true, PendingUntil: until}) |
| + if _, ref := fx.srv.attachDomain(ctx, acct, "story", host, "", "", nsActor); ref == nil || ref.Msg != nsNobodysCopy("marina") { |
| + t.Errorf("re-attach of the pending catch-all %s = %+v, want %q", host, ref, nsNobodysCopy("marina")) |
| + } |
| + if c, err := domains.GetClaim(ctx, fx.rel, host); err != nil || !c.Pending { |
| + t.Errorf("claim %s = %+v, %v; want it still pending", host, c, err) |
| + } |
| + } |
| + plain := "y.marina." + nsApps |
| + nsPutClaim(t, fx, domains.Claim{Schema: 1, Host: plain, Account: fx.sqid, App: "story", Route: ready, |
| + CreatedAt: "2026-11-11T00:00:00Z", Pending: true, PendingUntil: until}) |
| + if _, ref := fx.srv.attachDomain(ctx, acct, "story", plain, "", "", nsActor); ref != nil { |
| + t.Errorf("re-attach of a pending claim with no catch-all = %+v, want it verified", ref) |
| + } |
| + if c, err := domains.GetClaim(ctx, fx.rel, plain); err != nil || c.Pending { |
| + t.Errorf("claim %s = %+v, %v; want it verified", plain, c, err) |
| + } |
| +} |
| + |
| +// TestWildcardBesideLegacyCatchallRefused (round 1, I2): a legacy claim |
| +// with Catchall on and Wildcard off serves nothing below it; turning |
| +// Wildcard on would make it serve every name below it, so under a label |
| +// 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") |
| + route := nsShopRoute(fx) |
| + ctx := context.Background() |
| + // The wildcard gate would pass: a delegation zone and the right CNAME |
| + // for every host. Only the namespace rule can refuse. |
| + lookups := 0 |
| + fx.srv.delegationZone = "acme.example.net" |
| + fx.srv.lookupCNAME = func(_ context.Context, name string) (string, error) { |
| + lookups++ |
| + return name + ".acme.example.net.", nil |
| + } |
| + u := domainsURL(fx, "bab", "shop") |
| + 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}`) |
| + 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) |
| + } |
| + if c, err := domains.GetClaim(ctx, fx.rel, host); err != nil || c.Wildcard || !c.Catchall { |
| + t.Errorf("claim %s = %+v, %v; want it unchanged", host, c, err) |
| + } |
| + } |
| + if lookups != 0 { |
| + t.Errorf("CNAME lookups = %d; the refusal comes before the wildcard gate", lookups) |
| + } |
| +} |
| + |
| +// TestInstanceCreateOneLabelOtherAccountRefused (round 1, Fable minor 1): an |
| +// app whose manifest is pinned to the apps domain itself cannot create a |
| +// one-label host that is another account's namespace: a name it holds or |
| +// its sqid. A one-label host nobody holds is created as before. |
| +func TestInstanceCreateOneLabelOtherAccountRefused(t *testing.T) { |
| + fx, member, _ := nsShopFixture(t, "code-ns-onelabel") |
| + nsAccount(t, fx, 82, "bdq") |
| + nsHold(t, fx, "harbour", "bdq") |
| + enableInstances(t, fx, "shop", nsShopManifest(nsApps)) |
| + u := instancesURL(fx, "bab", "shop") |
| + for _, label := range []string{"harbour", "bdq"} { |
| + code, _, out := rawReq(t, http.MethodPost, u, member, `{"host":"`+label+`.`+nsApps+`","region":"ie"}`) |
| + if want := fmt.Sprintf(subdomainCreateOtherAccountCopy, label+"."+nsApps); code != http.StatusUnprocessableEntity || cutoverErrorOf(out) != want { |
| + t.Errorf("create %s.%s = %d %s, want 422 %q", label, nsApps, code, out, want) |
| + } |
| + } |
| + if code, _, out := rawReq(t, http.MethodPost, u, member, `{"host":"lighthouse.`+nsApps+`","region":"ie"}`); code != http.StatusCreated { |
| + t.Errorf("create lighthouse.%s = %d %s, want 201", nsApps, code, out) |
| + } |
| +} |
| + |
| +// TestUnassignableLabelAnswer (round 1, Fable minor 2): a label §4.2 refuses |
| +// as a name, short sqid-shaped or reserved, gets the answer that says to use |
| +// the account's own label or a custom domain, not the one that says to have |
| +// it assigned. |
| +func TestUnassignableLabelAnswer(t *testing.T) { |
| + fx, acct := attachFixture(t) |
| + shipVersion(t, fx, "story", "v1") |
| + seedChannel(t, fx, "story", "canary/live", "v1") |
| + for _, label := range []string{"team", "www"} { |
| + host := "blog." + label + "." + nsApps |
| + _, ref := fx.srv.attachDomain(context.Background(), acct, "story", host, "", "", nsActor) |
| + if want := fmt.Sprintf(subdomainCreateUnassignableCopy, label+"."+nsApps); ref == nil || ref.Msg != want { |
| + t.Errorf("attach %s = %+v, want %q", host, ref, want) |
| + } |
| + } |
| +} |
| + |
| +// TestOwnClaimReadFailureRefuses (round 1, Fable minor 4): under a label |
| +// that is not the account's, the attach reads host's claim to see whether |
| +// it is the account's own; that read failing refuses, retryably. |
| +func TestOwnClaimReadFailureRefuses(t *testing.T) { |
| + fx, acct := attachFixture(t) |
| + host := "x.dock." + nsApps |
| + fx.srv.cfg.Releases = &nsFaultStore{Store: fx.rel, failGet: domains.ClaimKey(host)} |
| + _, ref := fx.srv.attachDomain(context.Background(), acct, "story", host, "", "", nsActor) |
| + if want := fmt.Sprintf(subdomainCreateUnreadableCopy, "dock."+nsApps); ref == nil || ref.Status != http.StatusBadGateway || ref.Msg != want { |
| + t.Errorf("attach with the claim unreadable = %+v, want 502 %q", ref, want) |
| + } |
| +} |
| + |
| +// TestCreateDoorsRefuseWhenNamespacesUnreadable (round 1, Fable minor 4): |
| +// the instance create and placements doors refuse, retryably, when the |
| +// namespace listing fails. |
| +func TestCreateDoorsRefuseWhenNamespacesUnreadable(t *testing.T) { |
| + fx, member, _ := nsShopFixture(t, "code-ns-instance-unread") |
| + enableInstances(t, fx, "shop", nsShopManifest("marina."+nsApps)) |
| + nsHold(t, fx, "marina", fx.sqid) |
| + fx.srv.cfg.Releases = &nsFaultStore{Store: fx.rel, failList: domains.ClaimsPrefix} |
| + fx.srv.claims.Reset() |
| + code, _, out := rawReq(t, http.MethodPost, instancesURL(fx, "bab", "shop"), member, `{"host":"a.marina.`+nsApps+`","region":"ie"}`) |
| + if want := fmt.Sprintf(subdomainCreateUnreadableCopy, "marina."+nsApps); code != http.StatusBadGateway || cutoverErrorOf(out) != want { |
| + t.Errorf("instance create with the listing down = %d %s, want 502 %q", code, out, want) |
| + } |
| + |
| + w := newRegionalWorld(t, "code-ns-placements-unread") |
| + w.fx.srv.cfg.AppsDomain = nsApps |
| + nsHold(t, w.fx, "marina", w.fx.sqid) |
| + w.fx.srv.cfg.Releases = &nsFaultStore{Store: w.fx.rel, failList: domains.ClaimsPrefix} |
| + w.fx.srv.claims.Reset() |
| + code, out = w.put(t, "x.marina."+nsApps, rdBoth()) |
| + if want := fmt.Sprintf(subdomainCreateUnreadableCopy, "marina."+nsApps); code != http.StatusBadGateway || cutoverErrorOf(out) != want { |
| + t.Errorf("placements with the listing down = %d %s, want 502 %q", code, out, want) |
| + } |
| + noClaim(t, w.fx, "x.marina."+nsApps) |
| +} |
| + |
| +// TestRestoreUnderUnassignedLabelRefused (round 1, Fable minor 4; ruling: a |
| +// restore is a create): an eligible restore of a deleted instance whose host |
| +// sits under a label that is not the account's is refused, after its own |
| +// ownership answer, and writes nothing. |
| +func TestRestoreUnderUnassignedLabelRefused(t *testing.T) { |
| + d := newDoorFx(t) |
| + // one.shop.example.com, the deleted instance, now sits under the label |
| + // shop of the apps domain example.com, which nobody holds. |
| + d.fx.srv.cfg.AppsDomain = "example.com" |
| + code, out := d.restore(t, "") |
| + if want := fmt.Sprintf(subdomainCreateUnassignedCopy, "shop.example.com"); code != http.StatusUnprocessableEntity || ltErr(out) != want { |
| + t.Errorf("restore under an unassigned label = %d %s, want 422 %q", code, out, want) |
| + } |
| + d.requireNoRecord(t) |
| +} |
| + |
| +// TestCapabilityChangeUnderOtherAccountsNameRefused (round 1, Fable minor |
| +// 4): a legacy claim of the fixture account under bdq's harbour cannot turn |
| +// 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") |
| + route := nsShopRoute(fx) |
| + nsAccount(t, fx, 82, "bdq") |
| + nsHold(t, fx, "harbour", "bdq") |
| + ctx := context.Background() |
| + 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}`) |
| + 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) |
| + } |
| + acct, err := fx.st.AccountBySqid(fx.sqid) |
| + if err != nil { |
| + t.Fatal(err) |
| + } |
| + yes := true |
| + rec := httptest.NewRecorder() |
| + if fx.srv.setDomainCapabilities(rec, httptest.NewRequest(http.MethodPost, "/", nil), ctx, nsView(t, fx.srv), acct, "shop", |
| + Principal{Kind: PrincipalUser, Address: nsActor}, host, nil, &yes) { |
| + t.Error("setDomainCapabilities turned the catch-all on under bdq's name") |
| + } |
| + if want := fmt.Sprintf(subdomainCreateOtherAccountCopy, "harbour."+nsApps); rec.Code != http.StatusUnprocessableEntity || cutoverErrorOf(rec.Body.String()) != want { |
| + t.Errorf("setDomainCapabilities = %d %s, want 422 %q", rec.Code, rec.Body, want) |
| + } |
| + if c, err := domains.GetClaim(ctx, fx.rel, host); err != nil || c.Catchall { |
| + t.Errorf("claim %s = %+v, %v; want catchall still off", host, c, err) |
| + } |
| +} |
diff --git a/internal/domains/namespace.go b/internal/domains/namespace.go| index 0c2536476..6ba176999 100644 |
| --- a/internal/domains/namespace.go |
| +++ b/internal/domains/namespace.go |
| @@ -216,6 +216,11 @@ func namespaceHostChecked(name, appsDomain, account string) (string, error) { |
| // under appsDomain, name a valid account and carry nothing a namespace claim |
| // never has (an App, Route, Wildcard, Catchall, Paths, Instances or |
| // Placements: no door writes such a claim, so it is not trusted to be one). |
| +// A name SubdomainRuleRefusal refuses (a bad shape, a reserved label, a |
| +// sqid-shaped word shorter than the floor) is skipped too: the console door |
| +// never assigns one, so a claim at *.bdq.<apps> or *.www.<apps> is a direct |
| +// bucket write, and honouring it would serve another account's apps inside |
| +// bdq's own sqid namespace, or under a platform label. |
| // |
| // The door leaves an account at most one name. Should a store-mode write |
| // leave it two, byName keeps both and byAccount keeps the lexically first, |
| @@ -228,7 +233,7 @@ func AccountNamespaces(claims []Claim, appsDomain string) (byName, byAccount map |
| continue |
| } |
| name, ok := ParseNamespaceHost(c.Host, appsDomain) |
| - if !ok { |
| + if !ok || SubdomainRuleRefusal(name) != "" { |
| continue |
| } |
| byName[name] = c.Account |
diff --git a/internal/domains/namespace_test.go b/internal/domains/namespace_test.go| index f1ca51589..93fd744d8 100644 |
| --- a/internal/domains/namespace_test.go |
| +++ b/internal/domains/namespace_test.go |
| @@ -212,7 +212,9 @@ func TestAccountNamespacesSkipsPendingAndOtherKinds(t *testing.T) { |
| func TestAccountNamespacesTwoNamesOneAccountIsStable(t *testing.T) { |
| // The door never leaves an account two names, but a store-mode write |
| // can. byName keeps both; byAccount picks the same one whatever the order. |
| - a := Claim{Schema: 1, Host: "*.quay.apps.test", Account: "bdq", AccountNamespace: true} |
| + // pier, not quay: quay is sqid-shaped and shorter than the floor, so it |
| + // can never be a name and AccountNamespaces skips it (Task 5 round 1). |
| + a := Claim{Schema: 1, Host: "*.pier.apps.test", Account: "bdq", AccountNamespace: true} |
| b := Claim{Schema: 1, Host: "*.harbour.apps.test", Account: "bdq", AccountNamespace: true} |
| for _, claims := range [][]Claim{{a, b}, {b, a}} { |
| byName, byAccount := AccountNamespaces(claims, "apps.test") |
| @@ -249,3 +251,23 @@ func TestParseNamespaceHost(t *testing.T) { |
| t.Error("empty apps domain parsed") |
| } |
| } |
| + |
| +// TestAccountNamespacesSkipsNamesTheRulesRefuse (Task 5 round 1): a claim no |
| +// door writes, at the key of a label §4.2 refuses as a name, holds nothing: |
| +// another account's sqid (bdq), a reserved label (www), a short sqid-shaped |
| +// word (team). A 7-letter frozen-alphabet name is allowed. |
| +func TestAccountNamespacesSkipsNamesTheRulesRefuse(t *testing.T) { |
| + claims := []Claim{ |
| + {Schema: 1, Host: "*.bdq.apps.test", Account: "bcd", AccountNamespace: true}, |
| + {Schema: 1, Host: "*.www.apps.test", Account: "bcd", AccountNamespace: true}, |
| + {Schema: 1, Host: "*.team.apps.test", Account: "bcd", AccountNamespace: true}, |
| + {Schema: 1, Host: "*.marketx.apps.test", Account: "bdq", AccountNamespace: true}, |
| + } |
| + byName, byAccount := AccountNamespaces(claims, "apps.test") |
| + if len(byName) != 1 || byName["marketx"] != "bdq" { |
| + t.Errorf("byName = %v, want only marketx→bdq", byName) |
| + } |
| + if len(byAccount) != 1 || byAccount["bdq"] != "marketx" { |
| + t.Errorf("byAccount = %v, want only bdq→marketx", byAccount) |
| + } |
| +} |
diff --git a/internal/domains/namespacealiases_test.go b/internal/domains/namespacealiases_test.go| index 0e9ee0bb5..cc75aa4c1 100644 |
| --- a/internal/domains/namespacealiases_test.go |
| +++ b/internal/domains/namespacealiases_test.go |
| @@ -646,3 +646,29 @@ func TestExactClaimUnderKeptNameIsPointing(t *testing.T) { |
| t.Fatalf("kept row = %+v; want pointing", a) |
| } |
| } |
| + |
| +// TestNamespaceClaimOnRefusedLabelDerivesNothing (Task 5 round 1): a |
| +// namespace claim written straight to the bucket at *.bdq.apps.test or |
| +// *.www.apps.test, held by bcd, derives no alias and records no name: bcd's |
| +// apps never answer inside bdq's sqid namespace or under a platform label. |
| +func TestNamespaceClaimOnRefusedLabelDerivesNothing(t *testing.T) { |
| + for _, label := range []string{"bdq", "www"} { |
| + t.Run(label, func(t *testing.T) { |
| + s := release.NewDirStore(t.TempDir()) |
| + reg := aliasRegWith(t) |
| + // AttachAccountNamespace checks shape only, as a direct write would. |
| + holdNamespace(t, s, label, "bcd") |
| + addInstance(t, reg, "shop.bcd.apps.test", "shop", "bcd", "shop") |
| + addPlatformRoute(t, reg, "site.bcd.apps.test", "bcd", "site") |
| + if rep := reconcileNS(t, s, reg, nsApps); !rep.Complete { |
| + t.Fatal("pass incomplete") |
| + } |
| + if got := aliasMap(t, reg); len(got) != 0 { |
| + t.Errorf("aliases = %v; want none", aliasTargets(got)) |
| + } |
| + if got := namespaces(t, reg); len(got) != 0 { |
| + t.Errorf("account_namespaces = %v; want none", got) |
| + } |
| + }) |
| + } |
| +} |
diff --git a/internal/provision/account_subdomains_census_test.go b/internal/provision/account_subdomains_census_test.go| index 67b1a60dc..cf10bb661 100644 |
| --- a/internal/provision/account_subdomains_census_test.go |
| +++ b/internal/provision/account_subdomains_census_test.go |
| @@ -51,11 +51,31 @@ package provision |
| // names (ParseRecordKey); keys only, refuses an empty suffix, writes |
| // nothing. The console's walk of what lives under an account |
| // subdomain. key-site / key:ParseRecordKey. |
| +// |
| +// Task 5 fix round 1 re-digests the same two console units and adds one; no |
| +// record write is added and no class or kind changes: |
| +// - Server.handleAPIDomainAttach (re-pinned again): attachCreateRefusal |
| +// now also returns a pin of the claim revision its decision read, which |
| +// the door puts on the request context (withClaimPin) for the alias |
| +// claim write, and a pinned write refused because the claim went or |
| +// changed answers with the pin's refusal. Refusals only. key-site / |
| +// lit:instances, as before. |
| +// - Server.attachDomainAs (re-pinned again): the same pin on the context |
| +// for its claim writes, and the host-claim first route refused when the |
| +// decision rested on an existing claim (that path cannot carry the |
| +// pin). The CreateRecord path is unchanged. record-writer / |
| +// key:CreateRecord, as before. |
| +// - pinnedClaimStore.Put (new): the release.Store wrapper the attach's |
| +// claim write goes through when pinned. Its one key is the claim key |
| +// (domains.ClaimKey(host)); a Put there is admitted only conditional |
| +// on the pinned ETag (or create-only when the pin read no claim), any |
| +// other is refused; other keys pass through unchanged. Never a record |
| +// key. nonrecord / def:Put,sel:Put, the class of checkedStore.Put. |
| func accountSubdomainsWriteCensusInventory() []censusEntry { |
| entries := append([]censusEntry(nil), linkedDeploymentsSlice1WriteCensusInventory()...) |
| repins := []censusEntry{ |
| - {"internal/console/apidomains.go", "Server.handleAPIDomainAttach", "key-site", "lit:instances", "b7103016f07b19fe1158d9d13994f02fdc6bb30189a7762f2492692f198d83f9"}, |
| - {"internal/console/domainattach.go", "Server.attachDomainAs", "record-writer", "key:CreateRecord", "49a9a28a7929f4262d3b73d3cb68d7d263f453202bf9d8a09d20e1c7bbc237c4"}, |
| + {"internal/console/apidomains.go", "Server.handleAPIDomainAttach", "key-site", "lit:instances", "3e0501dbc4e79c6f51274c3e02ac34853d20557474e57dbcae8d30e7742e9b9d"}, |
| + {"internal/console/domainattach.go", "Server.attachDomainAs", "record-writer", "key:CreateRecord", "cad4da6801d2d1fae6381a9420beda4b881ffdc237c84c05877ac68ba509f609"}, |
| } |
| // The one classification change, stated as such rather than slipped |
| // through a re-pin: the kinds narrow, the class stays. |
| @@ -94,5 +114,6 @@ func accountSubdomainsWriteCensusInventory() []censusEntry { |
| censusEntry{"internal/domains/namespace.go", "AttachAccountNamespace", "nonrecord", "sel:Put", "cca934a1385e98ad1decbf49f968a447a54f6983f4d277da7706b16773acd486"}, |
| censusEntry{"internal/provision/recordhost.go", "declaredRecordKeys", "key-site", "lit:instances", "f396f0bd46328f209ff9f0d966d735a9c25fc3f691298e8815cd29e2ee47c2cf"}, |
| censusEntry{"internal/provision/recordhost.go", "RecordHostDeclaredUnder", "key-site", "key:ParseRecordKey", "d465d7382b20167ed49b28f4c9c59f45bfe3debea6882aefb4233a443fc9f162"}, |
| + censusEntry{"internal/console/subdomains.go", "pinnedClaimStore.Put", "nonrecord", "def:Put,sel:Put", "a7d301a0ea7fd1f7b48bfa8cd2687a000b38f311715d3458acba4fc35e6500b2"}, |
| ) |
| } |
diff --git a/internal/provision/testdata/plan14-root-reads-account-subdomains.tsv b/internal/provision/testdata/plan14-root-reads-account-subdomains.tsv| index bc4466d00..5ab154750 100644 |
| --- a/internal/provision/testdata/plan14-root-reads-account-subdomains.tsv |
| +++ b/internal/provision/testdata/plan14-root-reads-account-subdomains.tsv |
| @@ -28,7 +28,7 @@ internal/domains/aliases.go deriveInstanceAliases legacy accepted-legacy accepte |
| internal/domains/reconcile.go StampHealth legacy accepted-legacy accepted-legacy;rev3=J1;basis=root-route;rev3=census-ruling-dns-fresh-lookup-724;basis=section 4 now computes every cached verdict first, then freshUpgrade gives up to 64 randomly ordered names that could have a public zone (not under the apps domain, not special-use like .internal) and whose verdict is "" or "elsewhere" an uncached lookup (30 s pass budget) that may only upgrade to "pointing", then stamps; the extra sites are the indexed loops over the same rows (#724);rev3=census-ruling-no-negative-prime-724;basis=section 4 now hands each route and alias, with its previous stamp (the two new registry:DNSStatus reads, rt.DNSStatus and a.DNSStatus, same rows already listed), to dnsVerdicts, which first hands the pass's hostnames to Config.FreshRetain (the resolver forgets its in-memory backoff and strike for names no longer carried) and then decides each hostname once per pass and applies the verdict to every row carrying it: a name not "pointing" before this pass and eligible for a fresh lookup (public name, not under the apps domain, ResolveFresh set) is looked at uncached first within the same 64-lookup/30 s budget (shared, with previously "pointing" names' upgrade looks serviced before any fresh-first name so new names cannot starve a published one) and stamped from it (edge address, A or AAAA, "pointing", other "elsewhere", authoritative not-found "", authoritative NODATA for A and AAAA with the zone's SOA "" with no cached query), falling back to the cached lookup past the budget or on the second fresh failure in a row; the first fresh failure in a row is held (stamp and check time untouched, the resolver forgives it so the next pass asks fresh again); a previously "pointing" name keeps cached-first plus the upgrade-only fresh look (ResolveUpgrade, nearest zones first), so the fresh path still never unpublishes; a fresh-first name that ends the pass "pointing" (fresh or cached) has its fresh failure backoff cleared through Config.FreshForget, so an onboarding failure never suppresses the upgrade look that keeps it published; new names are ordered never-checked first then oldest check, and lookups answered from the backoff do not count against the budget; StampHealth's own body is unchanged by the last round; no new file, path or command input; the dropped Alias/Host/Route/RouteAlias sites are the old indexed loops folded into the candidate build (#724);rev3=census-ruling-account-subdomains;basis=reads the box's own account_namespaces table (only when DNS stamping runs) and leaves out of the DNS loop the alias rows isNamespaceDerived names (an alias under a held name, of that name's account, pointing at its sqid twin); if that read fails it logs and leaves out every alias two or more labels under the apps domain, still stamping every other alias, every route and all TLS expiry (fix round 1); the added RouteAlias sites are that filter over rows already listed; stamps less, never more; TLS stamping unchanged registry:Alias@1972,registry:Alias@4450,registry:Alias@5039,registry:Alias@5129,registry:Alias@5563,registry:Alias@5627,registry:Alias@5715,registry:DNSCheckedAt@4325,registry:DNSCheckedAt@4472,registry:DNSStatus@4311,registry:DNSStatus@4459,registry:DNSStatus@4664,registry:DNSStatus@4963,registry:Host@4302,registry:Host@4736,registry:Host@4820,registry:Host@5332,registry:Host@5391,registry:Host@5473,whole:Route@199,whole:Route@236,whole:Route@4126,whole:Route@4242,whole:Route@4571,whole:Route@5286,whole:RouteAlias@1680,whole:RouteAlias@1906,whole:RouteAlias@2058,whole:RouteAlias@2106,whole:RouteAlias@2126,whole:RouteAlias@2138,whole:RouteAlias@4172,whole:RouteAlias@4386,whole:RouteAlias@4866,whole:RouteAlias@5516,whole:RouteAlias@780 5288387d1eac4611bc4b1acc30569011009192e7210127001c27174e1e1cfa43 |
| internal/registry/registry.go Registry.Fingerprint legacy accepted-legacy accepted-legacy;rev3=census-ruling-self-serve-moves-1;basis=the registry's SQLite side, as carlos: in the agent (/opt/carlos/carlos agent, carlos-edge.service) and in the registry child (carlos __registry-child, which a root pass forks as the service user); the remote arm, unchanged, in the process that holds a remote handle: census-ruling-seeded-instances's body with the row's lifetime pair (incarnation, serving_seq) folded into the edge's change poll, each only when non-zero, so a registry with no pair digests as before; self-serve moves 1 Task 7;rev3=census-ruling-regional-domains-447;basis=#447 Task 4: hashes regional_domains (host, target, account, app, region; created_at not) over the same fresh connection, with a section marker written only when a row exists, so a registry with no regional rows digests as before; the one added site is that SELECT (+file:Query) on the box's own registry database, as carlos; no file path read;rev3=census-ruling-fleet-public-routes;basis=fleet public routes (spec 2026-10-29 rev 4, §4.2 writer rule): review R1 finding 1: the routes SELECT also reads host, kind, account, app, platform and fingerprintForwardInert (one CASE over the ForwardForbidden columns), and every row folds host, kind, account and app (tagged, quoted), platform when set, and forward_inert=0 for a forward row that is not inert, so a rowid reused by another hostname, an in-place account or app rewrite, or a stray forbidden column moves the edge's change poll. Same one SELECT per table on the same fresh connection to the box's own registry database, as carlos; no table, file or bucket read added; a digest, never a decision.;rev3=census-ruling-managed-fleets-1b;basis=managed fleets 1b (Task 5): the SELECT also reads fleet_label and, only when it is set, hashes "fleet_label=<q>" into the digest, so labelling a row moves the edge's reload fingerprint. Read sites unchanged (33). Registry side, not root; an unlabelled registry's digest is byte-identical.;rev3=census-ruling-stateless-replicas-1;basis=Read the additive stateless projection in the existing registry SELECT and hash only when set; no new read source.;rev3=census-ruling-agent-start-demo-1;basis=Existing SELECT reads four more demo columns; only a marked row adds them to the hash, so ordinary hashes remain unchanged.;rev3=census-ruling-stateless-replicas-2;basis=Four additive projection columns join the existing routes SELECT and hash only when nonzero; no new query or file read. merge of origin/main 6be08467: Union main demo identity and expiry with replica columns in the same SELECT and hash; merge-only body change.;rev3=census-ruling-agent-start-demo-3;basis=Hash moved-notice wire bytes so notice-only changes invalidate an edge route snapshot. Census read-site delta: +file:QueryRow.;rev3=census-ruling-edge-page-cache-1;basis=selects the new pages_off column with the rest and folds "pages_off=1" into the hash only when set, as assets_off, so a registry that never sets it fingerprints as before; same routes SELECT, no new table; read sites unchanged (34); no read added;rev3=census-ruling-linked-deployments-slice1;basis=linked deployments slice 1 Task 1: hashes link_channels (link_id, account, token_hash, status, generation; connected, seen_at, seq and created_at not) over the same fresh connection, with a section marker written only when a row exists, so a registry with no links digests as before; the one added site is that SELECT (+file:Query) on the box's own registry database, as carlos; a digest, never a decision; linked deployments slice 1 Task 7: also folds home_link (id, serving_url, tunnel_url, the token's sha256 never the token, account, apps_domain, box_label, conn_gen; state and created_at not) and home_link_apps (name, home_account, home_app, home_host) through fingerprintHomeLink over the same fresh connection, each section marker written only when a row exists, so a registry with no link digests as before; no file path read; a digest, never a decision;rev3=census-ruling-account-subdomains;basis=hashes account_namespaces (name, account) over the same fresh connection, with a section marker written only when a row exists, so a registry with no held names digests as before; the one added site is that SELECT (+file:Query) on the box's own registry database, as carlos; a digest, never a decision file:Exec@284,file:Open@188,file:Query@10785,file:Query@11707,file:Query@12810,file:Query@368,file:Query@6655,file:Query@7134,file:Query@8120,file:Query@8816,file:Query@9728,file:QueryRow@13727,registry:ClaimIncarnation@1729,registry:ClaimIncarnation@5563,registry:ClaimIncarnation@5640,registry:ClaimOwner@1773,registry:ClaimOwner@5764,registry:ClaimOwner@5829,registry:ClaimRowID@1792,registry:ClaimRowID@5856,registry:ClaimRowID@5922,registry:ClaimStamp@1754,registry:ClaimStamp@5673,registry:ClaimStamp@5737,registry:Incarnation@1848,registry:Incarnation@6143,registry:Incarnation@6207,registry:ServingSeq@1867,registry:ServingSeq@6234,registry:ServingSeq@6297,registry:Text@158,registry:path@207,registry:remote@55,registry:remote@87,whole:remoteClient@57,whole:remoteClient@89 a52e0bc25d555bbf22f35655c54c0fa3aca6cedec5f0b6b80157d9d95f921a29 |
| internal/registry/registry.go Registry.migrate legacy accepted-legacy accepted-legacy;rev3=census-ruling-self-serve-moves-1;basis=the registry's SQLite side, as carlos: in the agent (/opt/carlos/carlos agent, carlos-edge.service) and in the registry child (carlos __registry-child, which a root pass forks as the service user), on every registry open; a box CLI verb that opens the registry directly runs it as whoever runs the verb: census-ruling-seeded-instances's body with two more columns added to routes (incarnation and serving_seq, INTEGER NOT NULL DEFAULT 0, idempotent through the duplicate-column rule); self-serve moves 1 Task 7;rev3=census-ruling-rootfs-apps-2;basis=one more ALTER TABLE, routes ADD COLUMN runtime TEXT NOT NULL DEFAULT '', beside main's rate_limit, assets_off, asset_gen, incarnation and serving_seq (the last four from the merges of origin/main 3c33f2eb and 953b9fda); the same sixteen sites, no read added;rev3=census-ruling-instance-egress-sizes-328-329;basis=#328/#329 plan 1 Task 4: three more ALTER TABLE statements in the existing loop, routes ADD COLUMN egress_allow, size and policy_expires_at, each TEXT NOT NULL DEFAULT '' and idempotent through the duplicate-column rule; the same sixteen sites, no read added.;rev3=census-ruling-region-ha-p1a;basis=one more ALTER TABLE in the existing loop: routes ADD COLUMN ha INTEGER NOT NULL DEFAULT 0, idempotent through the duplicate-column rule; the same sixteen sites, no read added;rev3=census-ruling-ha-p1a-433;basis=the registry's SQLite side as carlos (agent, registry child; a box CLI verb that opens the registry directly runs it as whoever runs it), on every registry open: the ALTER TABLE routes statements are now built from the one migration definition routeAddedColumns (addedColumn name, type, default; review r1 P2): for each entry without the Claim mark, "ALTER TABLE routes ADD COLUMN " + spec(), byte for byte the statements main runs, in main's order, under the same duplicate-column rule. +registry:Claim is that mark, +whole:addedColumn the struct. Every name, type and default is an in-binary literal; no statement added, removed or changed; no read added.;rev3=census-ruling-regional-domains-447;basis=#447 Task 4: one more CREATE TABLE IF NOT EXISTS regional_domains (host TEXT PRIMARY KEY, target, account, app, region TEXT NOT NULL DEFAULT '', created_at INTEGER NOT NULL DEFAULT 0), beside wildcard_domains; the added sites are that statement (+file:Exec, +registry:sql), an in-binary literal; additive, no existing statement changed;rev3=census-ruling-region-ha-p1b3b-t;basis=Create local HA duty/replay tables and revision triggers in the existing registry connection; no new database path.;rev3=census-ruling-agent-start-demo-3;basis=Create moved-notice storage as a single (id, wire) row; fingerprints include the stored wire bytes. Census read-site delta: +file:Exec, +registry:sql.;rev3=census-ruling-linked-deployments-slice1;basis=linked deployments slice 1 Task 1: calls migrateLinks after migrateHADuties (one CREATE TABLE IF NOT EXISTS link_channels, an in-binary literal); additive, no existing statement changed; linked deployments slice 1 Task 7: also runs migrateHomeLink (CREATE TABLE IF NOT EXISTS home_link and home_link_apps) after migrateLinks; additive, the box's own registry database, as carlos;rev3=census-ruling-account-subdomains;basis=one more CREATE TABLE IF NOT EXISTS account_namespaces (name TEXT PRIMARY KEY, account TEXT NOT NULL), an in-binary literal (+file:Exec, +registry:sql); additive, no existing statement changed file:Exec@1124,file:Exec@1855,file:Exec@212,file:Exec@2409,file:Exec@3057,file:Exec@3822,file:Exec@4101,file:Exec@4964,file:Exec@51,file:Exec@5140,file:Exec@761,registry:Claim@686,registry:sql@1124,registry:sql@1855,registry:sql@212,registry:sql@2409,registry:sql@3057,registry:sql@3822,registry:sql@4101,registry:sql@4964,registry:sql@51,registry:sql@5140,registry:sql@761,whole:addedColumn@661 0c5fdaf1215e8f81c156a1fc1576cb075c2a52238bde75fc8320d49472fd117d |
| -@coverage internal/domains fc681633c98fd7dedee47dca8862a0295c84dee2534a3e3d4403c7fd21b83438 |
| +@coverage internal/domains be259af4d007f9f06e6d827eb2fa775710788821cc1bbac3215ec1c9b67780fc |
| @coverage internal/edge 9b9f642f53505bd73aad991d29b75b68abba48b6eb9d242a6634bea069dc421c |
| @coverage internal/host aa8f6c1a0b8dd200cb7656622d1fb6004ea0e1bbac292459b4eafa463da7f9bb |
| @coverage internal/provision 8b7747ecb67234457618a5ab9f2454823520065ddac23360be60fd93d26ec131 |