carlos / platform Public

console: route-less claims CNAME at a routed app apex

Manager check before merge: first-route claims, claims aliasing another
custom name and catch-alls would otherwise keep A-record advice under
configured ingress. They now name the app's platform apex when the
console's registry holds it as that app's own platform route (memoized
per request); with no such route they keep today's advice. Re-pins the
record-write census digest for catchallListItems: the edit binds DNS
guidance only and adds no record write.
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
claude agent, operated by paul@keymail.dev pushed by paul@keymail.dev e891b488a01772fa7c4b31ea555343ed4603b21a parent 3ae9113
6 files changed, +131 −7
  • internal/console/apidomains.go +1 −1
  • internal/console/apphost_guidance_test.go +78 −0
  • internal/console/appsettings.go +1 −1
  • internal/console/domaincatchall.go +6 −2
  • internal/console/view.go +44 −2
  • internal/provision/plan9_b8_census_test.go +1 −1

CI passed — run details

diff --git a/internal/console/apidomains.go b/internal/console/apidomains.go
index d1bf9e2ca..ba3c6bf25 100644
--- a/internal/console/apidomains.go
+++ b/internal/console/apidomains.go
@@ -1463,7 +1463,7 @@ func (s *Server) domainItem(ctx context.Context, c domains.Claim, readings map[s
item.Guidance, item.Detail = s.configuredRegionalGuidance(ctx, c)
item.Records = delegationRecords(c.Host, c.Wildcard, s.delegationZone)
case item.DNSStatus != "pointing" && item.DNSStatus != "unresolved":
- bound := targets.forApp(c.Host, c.Route)
+ bound := s.bindAppHost(ctx, targets, c.Host, c.Account, c.App, c.Route)
item.Guidance = domainGuidance(c.Host, bound)
// The structured form of the SAME advice, emitted under exactly the
// same condition so the two can never disagree about whether there is
diff --git a/internal/console/apphost_guidance_test.go b/internal/console/apphost_guidance_test.go
index 86b5d693f..3a689c3c7 100644
--- a/internal/console/apphost_guidance_test.go
+++ b/internal/console/apphost_guidance_test.go
@@ -6,7 +6,9 @@ import (
"net/http"
"strings"
"testing"
+ "time"
+ "github.com/carlosframework/platform/internal/domains"
"github.com/carlosframework/platform/internal/registry"
"github.com/carlosframework/platform/internal/release"
)
@@ -286,3 +288,79 @@ func TestAppHostGuidanceWording(t *testing.T) {
t.Errorf("without addresses:\n got %q\n want %q", got, want)
}
}
+
+// A claim with no served route of its own (a first-route claim, a claim
+// aliasing another custom name, an instance catch-all) names the app's apex
+// once, and only once, the apex is that app's own platform route in the
+// registry. Until then, or when another app holds the name, it keeps
+// today's advice.
+func TestRoutelessClaimsNameTheRoutedApex(t *testing.T) {
+ fx, member := instanceFixture(t, "code-dom-apphost-apex")
+ fx.srv.cfg.AppsDomain = "oncarlos.test"
+ fx.srv.cfg.EdgeIPs = []string{"192.0.2.1"}
+ fx.srv.cfg.RegionIngress = []string{ingressIP}
+ fx.srv.steeringHost = "edge.oncarlos.test"
+ sqid := release.OpsAccount
+ apex := "titogo." + sqid + ".oncarlos.test"
+ attachShopClaim(t, fx, sqid, "titogo", "first.example.com", "")
+ attachShopClaim(t, fx, sqid, "titogo", "raw.example.com", "example.com")
+ if _, _, err := domains.AttachClaim(context.Background(), fx.rel, domains.Claim{
+ Host: "*.app.example.com", Account: sqid, App: "titogo", Instances: true,
+ CreatedAt: time.Now().UTC().Format(time.RFC3339),
+ }); err != nil {
+ t.Fatal(err)
+ }
+ targets := func() map[string]string {
+ t.Helper()
+ code, _, out := rawReq(t, http.MethodGet, domainsURL(fx, "bab", "titogo"), member, "")
+ if code != http.StatusOK {
+ t.Fatalf("list = %d %s", code, out)
+ }
+ var got struct {
+ Domains []struct {
+ Host string `json:"host"`
+ Guidance string `json:"guidance"`
+ CNAMETarget string `json:"cname_target"`
+ } `json:"domains"`
+ }
+ if err := json.Unmarshal([]byte(out), &got); err != nil {
+ t.Fatal(err)
+ }
+ m := map[string]string{}
+ for _, d := range got.Domains {
+ m[d.Host] = d.CNAMETarget
+ if d.CNAMETarget != "" && !strings.HasPrefix(d.Guidance, "Point a CNAME for "+d.Host+" at "+d.CNAMETarget+",") {
+ t.Errorf("%s guidance %q disagrees with cname_target %q", d.Host, d.Guidance, d.CNAMETarget)
+ }
+ }
+ return m
+ }
+ hosts := []string{"first.example.com", "raw.example.com", "*.app.example.com"}
+ for _, h := range hosts {
+ if got := targets()[h]; got != "" {
+ t.Errorf("unrouted apex: %s cname_target = %q, want none", h, got)
+ }
+ }
+ fx.addRoute(t, registry.Route{Host: apex, Kind: "instance", Status: "ready", App: "other", Platform: true, Account: sqid})
+ for _, h := range hosts {
+ if got := targets()[h]; got != "" {
+ t.Errorf("apex held by another app: %s cname_target = %q, want none", h, got)
+ }
+ }
+ fx.addRoute(t, registry.Route{Host: apex, Kind: "instance", Status: "ready", App: "titogo", Platform: true, Account: sqid})
+ got := targets()
+ for _, h := range hosts {
+ if got[h] != apex {
+ t.Errorf("routed apex: %s cname_target = %q, want %q", h, got[h], apex)
+ }
+ }
+ acct, err := fx.st.AccountBySqid(sqid)
+ if err != nil || acct == nil {
+ t.Fatal(err)
+ }
+ for _, dv := range fx.srv.settingsDomains(withReqMemo(context.Background()), acct, "titogo", nil) {
+ if dv.Domain == "first.example.com" && !strings.HasPrefix(dv.Guidance, "Point a CNAME for first.example.com at "+apex+",") {
+ t.Errorf("settings first.example.com guidance = %q", dv.Guidance)
+ }
+ }
+}
diff --git a/internal/console/appsettings.go b/internal/console/appsettings.go
index 1d8366a5a..64f72452b 100644
--- a/internal/console/appsettings.go
+++ b/internal/console/appsettings.go
@@ -763,7 +763,7 @@ func (s *Server) settingsDomains(ctx context.Context, acct *Account, app string,
}
continue
}
- dv := claimDomainView(c.Host, s.dnsTargets(ctx).forApp(c.Host, c.Route))
+ dv := claimDomainView(c.Host, s.bindAppHost(ctx, s.dnsTargets(ctx), c.Host, c.Account, c.App, c.Route))
dv.State, dv.Reason, dv.Detail = state(c)
if c.Regional() {
dv.Guidance, dv.Detail = s.configuredRegionalGuidance(ctx, c)
diff --git a/internal/console/domaincatchall.go b/internal/console/domaincatchall.go
index 60130c380..19962af71 100644
--- a/internal/console/domaincatchall.go
+++ b/internal/console/domaincatchall.go
@@ -361,8 +361,12 @@ func (s *Server) catchallListItems(ctx context.Context, acct *Account, app strin
if !pointing {
// The wildcard record is what makes every label resolve here; the
// guidance for "*.<parent>" says exactly that.
- head.Guidance = domainGuidance(c.Host, targets)
- head.Records = domainRecords(c.Host, targets, false, "")
+ // The app's apex, when it is routed: no one instance's name can
+ // stand for every label.
+ bound := s.bindAppHost(ctx, targets, c.Host, acct.Sqid, app, "")
+ head.Guidance = domainGuidance(c.Host, bound)
+ head.Records = domainRecords(c.Host, bound, false, "")
+ head.CNAMETarget = cnameTarget(c.Host, bound)
}
// Whether the catch-all reserves every label, or only its instances'
// (catchallInstanceName). Said on every listing, with the record to
diff --git a/internal/console/view.go b/internal/console/view.go
index 74f058dcd..b7e141c65 100644
--- a/internal/console/view.go
+++ b/internal/console/view.go
@@ -199,8 +199,8 @@ func (t DNSTargets) forApp(host, route string) DNSTargets {
// route is always a host the deployment SERVES under its own name: a
// domain claim's route (the instance or app the custom name aliases; for an
// HA instance, or one in another region, that is the instance's own public
-// name), or on the app page the app's platform apex when it is a route in
-// the registry. That is what makes it a safe target: its visitors already
+// name), or the app's platform apex when it is a route in the registry
+// (Server.bindAppHost, and the app page's own route fold). That is what makes it a safe target: its visitors already
// reach it by that name, so its public DNS is maintained (steering records
// or the apps-domain wildcards). A name merely SPELLED like an apex is never
// named: one that is no route may have no address at all (Astra R1 P1).
@@ -224,6 +224,48 @@ func appHostFor(domain, host, route string) string {
return ""
}
+// bindAppHost binds a claim row's app host: the claim's route when that is
+// a served name under the apps domain, else the app's platform apex when it
+// is a route of that app and account in this console's registry (a
+// first-route claim, a claim aliasing another custom name, a catch-all).
+// No served name means no CNAME: the row keeps today's advice.
+func (s *Server) bindAppHost(ctx context.Context, t DNSTargets, host, acct, app, route string) DNSTargets {
+ if b := t.forApp(host, route); b.AppHost != "" || t.AppsDomain == "" {
+ return b
+ }
+ return t.forApp(host, s.routedApex(ctx, acct, app))
+}
+
+// routedApex is app's platform apex when the console's registry holds it as
+// that app's own platform route in acct, else "". A failed read is "": the
+// row keeps today's advice rather than naming a host nobody confirmed.
+// Memoized per request, so a list of claims reads each apex once.
+func (s *Server) routedApex(ctx context.Context, acct, app string) string {
+ host := s.apexHost(acct, app)
+ if host == "" || app == "" || acct == "" || s.cfg.Registry == "" {
+ return ""
+ }
+ h, err := memoize(ctx, "routed-apex:"+host, func() (string, error) {
+ reg, err := openRegistry(s.cfg.Registry)
+ if err != nil {
+ return "", err
+ }
+ rt, err := reg.Get(host)
+ if err != nil || rt == nil {
+ return "", err
+ }
+ if !rt.Platform || rt.Canary || rt.App != app || release.RouteAccount(*rt) != acct {
+ return "", nil
+ }
+ return host, nil
+ })
+ if err != nil {
+ log.Printf("console: apex route %s: %v", host, err)
+ return ""
+ }
+ return h
+}
+
// cnameTarget is the name a non-apex host is told to CNAME at, or "" when
// the advice is A records only: the bound app host, else the legacy
// steering hostname. domainGuidance and domainRecords both read it, so the
diff --git a/internal/provision/plan9_b8_census_test.go b/internal/provision/plan9_b8_census_test.go
index 5f3d95215..ebea2696e 100644
--- a/internal/provision/plan9_b8_census_test.go
+++ b/internal/provision/plan9_b8_census_test.go
@@ -722,7 +722,7 @@ var plan9B8CensusInventory = []censusEntry{
{"internal/console/claim_retire_helpers.go", "claimRetireRecordKey", "key-site", "key:RecordKey,key:SidecarRecordKey,key:claimRetireRecordKey", "4a84350fc30ad6866855f785e40bea690655daf6399acad853c4e61871ee82a5"},
{"internal/console/claim_store_effects.go", "claimEffectStore.Put", "record-transport", "def:Put,sel:Put", "679406564fa1f9816a4fe2fe9bd454ed6fdde1e16a3e7c5060c22fdb933e7b9e"},
{"internal/console/domainattach.go", "Server.attachDomainAs", "record-writer", "key:CreateRecord", "c99691f92daab087137bb607a89f3dc7ef4202e83431e61ebee56553756f7f4f"},
- {"internal/console/domaincatchall.go", "Server.catchallListItems", "key-site", "lit:instances", "365ead1d588dfbe9397a86510c386940545bf853f77294601575f1f39c48e989"},
+ {"internal/console/domaincatchall.go", "Server.catchallListItems", "key-site", "lit:instances", "107fa9a9639422616195f1892f619fc1f5ddecf1dd3effa2361ff19717567a8f"},
{"internal/console/economicspass.go", "Server.upsertBill", "nonrecord", "sel:Put", "2af1ed6992d6856f5273d5ce6305fa4b9d434f94b25c9843c5cd45a6c69362b1"},
{"internal/console/economicspass.go", "Server.putScenario", "nonrecord", "sel:Put", "80557ccbb43b60fe9e8a54a4aaf3be1e7982a92a9ba2d6e33be43ddf51329ab5"},
{"internal/console/economicspass.go", "Server.putActiveScenario", "nonrecord", "sel:Put", "0711f7092a78e391af67eca8c4a5b30224297bbddb8c7a92add8c375faef3bff"},