carlos / platform Public

console: an owner's namespace claim no longer blocks its placements

Astra final review P2-2. regionalOverlapRefusal refused any object at
*.P, so an account holding harbour could not create a regional
shop.harbour.<apps>, nor update a regional claim under harbour made
before the name was assigned. The *.P read now passes the asking
account's own namespace claim in force (ownNamespaceClaim: schema 1, at
that host, trusted by AccountNamespaces, the name the account's). A
foreign, retired, untrusted, unparseable or unread object still refuses
as before.
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
claude agent, operated by paul@keymail.dev pushed by paul@keymail.dev d064559e1e31ce01b3ee8c410296337db3efee91 parent 754023e
2 files changed, +120 −5
  • internal/console/apiplacements.go +30 −5
  • internal/console/subdomain_placements_test.go +90 −0
diff --git a/internal/console/apiplacements.go b/internal/console/apiplacements.go
index 7ac0ca7f1..0c269395d 100644
--- a/internal/console/apiplacements.go
+++ b/internal/console/apiplacements.go
@@ -629,7 +629,7 @@ func (s *Server) handleAPIDomainPlacementsPut(w http.ResponseWriter, r *http.Req
jsonError(w, ref.Status, ref.Msg)
return
}
- if ref := s.regionalOverlapRefusal(ctx, host, snap, boxes, now); ref != nil {
+ if ref := s.regionalOverlapRefusal(ctx, host, acct.Sqid, snap, boxes, now); ref != nil {
jsonError(w, ref.Status, ref.Msg)
return
}
@@ -853,13 +853,18 @@ func (s *Server) regionalEvidenceRefusal(ctx context.Context, host string, snap
// body, refuses;
// - when P has an interior dot (so a claim can exist there):
// domains/P.json with Catchall, of any schema (a body that does not
-// parse refuses), and domains/*.P.json, any object;
+// parse refuses), and domains/*.P.json, any object but one: the
+// account namespace claim (account subdomains §4.4) that account holds
+// on P, in force (ownNamespaceClaim). It is not a catch-all: it serves
+// nothing at X, and a box derives no name over an exact claim, so it
+// does not stop the name's own holder from placing hosts under it. A
+// foreign, retired, malformed or unreadable one refuses as before;
// - a fresh edges file publishing *.P under role home;
// - a fresh heartbeat listing *.P.
//
// A not-found GET passes; any other GET error is 503 RD-22. Every refusal
// is the neutral 409.
-func (s *Server) regionalOverlapRefusal(ctx context.Context, host string, snap edgesfile.Snapshot, boxes []status.Box, now time.Time) *doorRefusal {
+func (s *Server) regionalOverlapRefusal(ctx context.Context, host, account string, snap edgesfile.Snapshot, boxes []status.Box, now time.Time) *doorRefusal {
taken := &doorRefusal{Status: http.StatusConflict, Msg: hostUnavailableMsg}
unreadable := &doorRefusal{Status: http.StatusServiceUnavailable, Msg: placementsUnreadableMsg}
parent := parentOf(host)
@@ -899,14 +904,34 @@ func (s *Server) regionalOverlapRefusal(ctx context.Context, host string, snap e
return taken
}
}
- if _, found, ref := get("*." + parent); ref != nil {
+ if raw, found, ref := get("*." + parent); ref != nil {
return ref
- } else if found {
+ } else if found && !s.ownNamespaceClaim(raw, "*."+parent, account) {
return taken
}
return nil
}
+// ownNamespaceClaim reports whether raw, the object at claim host
+// "*.<parent>", is account's namespace claim for parent's label, in force:
+// it parses, sits at that host, and domains.AccountNamespaces trusts it
+// (verified, nothing but the namespace, a nameable label under this
+// deployment's apps domain) and gives the name to account. A retired one is
+// not in force. Anything else is not.
+func (s *Server) ownNamespaceClaim(raw []byte, claimHost, account string) bool {
+ domain := s.appsDomain()
+ name, ok := domains.ParseNamespaceHost(claimHost, domain)
+ if !ok || account == "" {
+ return false
+ }
+ var c domains.Claim
+ if err := json.Unmarshal(raw, &c); err != nil || c.Schema != 1 || c.Host != claimHost {
+ return false
+ }
+ byName, _ := domains.AccountNamespaces([]domains.Claim{c}, domain)
+ return byName[name] == account
+}
+
// regionalDescendantRefusal is the descendant scan (spec §6.7): a claim on
// any "<label>.<parent>" that is regional, or that the listing shows but
// could not read, makes a catch-all on parent impossible. A listing error
diff --git a/internal/console/subdomain_placements_test.go b/internal/console/subdomain_placements_test.go
new file mode 100644
index 000000000..36eba2ab4
--- /dev/null
+++ b/internal/console/subdomain_placements_test.go
@@ -0,0 +1,90 @@
+package console
+
+// Account subdomains, final review fix (Astra P2-2): the owner's own
+// namespace claim does not block its regional placements under the name.
+// Neutral names: bab (the ops account), bdq, the name harbour, the apps
+// domain oncarlos.com.
+
+import (
+ "context"
+ "net/http"
+ "testing"
+ "time"
+
+ "github.com/carlosframework/platform/internal/domains"
+ "github.com/carlosframework/platform/internal/edgesfile"
+)
+
+// TestPlacementsUnderOwnName: bab holds harbour. It creates a regional
+// shop.harbour.<apps>, and updates a regional claim under harbour that it
+// made before the name was assigned (a legacy claim); the namespace claim
+// at *.harbour.<apps> is not an overlapping catch-all for its own holder.
+func TestPlacementsUnderOwnName(t *testing.T) {
+ w := newRegionalWorld(t, "code-ns-placements-own")
+ w.fx.srv.cfg.AppsDomain = nsApps
+ legacy := "old.harbour." + nsApps
+ nsPutClaim(t, w.fx, domains.Claim{Schema: 2, Host: legacy, Account: w.fx.sqid, App: "shop", Route: rdIE,
+ Placements: []domains.Placement{{Region: "", Host: rdIE}}, CreatedAt: time.Now().UTC().Format(time.RFC3339)})
+ nsHold(t, w.fx, "harbour", w.fx.sqid)
+
+ host := "shop.harbour." + nsApps
+ w.mustPut(t, host, rdBoth())
+ if c := w.claim(t, host); !c.Regional() || len(c.Placements) != 2 || c.Account != w.fx.sqid {
+ t.Errorf("created claim = %+v, want bab's, both regions", c)
+ }
+ w.mustPut(t, legacy, rdBoth())
+ if c := w.claim(t, legacy); len(c.Placements) != 2 {
+ t.Errorf("updated legacy claim = %+v, want both regions", c)
+ }
+}
+
+// TestPlacementsOverlapNamespaceClaim: regionalOverlapRefusal's *.P read
+// passes only the asking account's own namespace claim in force; it still
+// refuses another account's, a retired one, one that does not parse and
+// one that does not read.
+func TestPlacementsOverlapNamespaceClaim(t *testing.T) {
+ w := newRegionalWorld(t, "code-ns-placements-overlap")
+ w.fx.srv.cfg.AppsDomain = nsApps
+ nsAccount(t, w.fx, 82, "bdq")
+ ctx := context.Background()
+ host := "shop.harbour." + nsApps
+ key := domains.ClaimKey(nsHarbourHost)
+ overlap := func() *doorRefusal {
+ return w.fx.srv.regionalOverlapRefusal(ctx, host, w.fx.sqid, edgesfile.Snapshot{}, nil, time.Now())
+ }
+ if ref := overlap(); ref != nil {
+ t.Fatalf("no claim at *.harbour: %+v, want none", ref)
+ }
+ nsHold(t, w.fx, "harbour", w.fx.sqid)
+ if ref := overlap(); ref != nil {
+ t.Errorf("bab's own namespace claim: %+v, want none", ref)
+ }
+ _, etag, err := domains.GetClaimETag(ctx, w.fx.rel, nsHarbourHost)
+ if err != nil {
+ t.Fatal(err)
+ }
+ if _, ok, err := domains.RetireAccountNamespace(ctx, w.fx.rel, "harbour", nsApps, w.fx.sqid, etag, time.Now()); err != nil || !ok {
+ t.Fatalf("retire = %v, %v", ok, err)
+ }
+ if ref := overlap(); ref == nil || ref.Status != http.StatusConflict {
+ t.Errorf("bab's retired namespace claim: %+v, want 409", ref)
+ }
+ nsPutClaim(t, w.fx, domains.Claim{Schema: 1, Host: nsHarbourHost, Account: "bdq", AccountNamespace: true, CreatedAt: time.Now().UTC().Format(time.RFC3339)})
+ if ref := overlap(); ref == nil || ref.Status != http.StatusConflict {
+ t.Errorf("bdq's namespace claim: %+v, want 409", ref)
+ }
+ nsPutClaim(t, w.fx, domains.Claim{Schema: 1, Host: nsHarbourHost, Account: w.fx.sqid, AccountNamespace: true, Pending: true, CreatedAt: time.Now().UTC().Format(time.RFC3339)})
+ if ref := overlap(); ref == nil || ref.Status != http.StatusConflict {
+ t.Errorf("bab's pending (untrusted) namespace claim: %+v, want 409", ref)
+ }
+ putFixtureObject(t, w.fx.rel, key, []byte("not json"))
+ if ref := overlap(); ref == nil || ref.Status != http.StatusConflict {
+ t.Errorf("a namespace key that does not parse: %+v, want 409", ref)
+ }
+ nsPutClaim(t, w.fx, domains.Claim{Schema: 1, Host: nsHarbourHost, Account: w.fx.sqid, AccountNamespace: true, CreatedAt: time.Now().UTC().Format(time.RFC3339)})
+ st := w.wrap()
+ st.failGet[key] = true
+ if ref := overlap(); ref == nil || ref.Status != http.StatusServiceUnavailable {
+ t.Errorf("a namespace key that does not read: %+v, want 503", ref)
+ }
+}