console: custom domains CNAME at the app's own host
Where the deployment publishes app hosts (steering armed: the CARLOS_STEERING_ZONE_ID + PLATFORM_APPS_DOMAIN pair), a non-apex custom domain is now told to CNAME at its app host, configured ingress or not: the claim's route when it is a name under the apps domain (an instance's own name), else <app>.<sqid>.<apps-domain>. The A alternative follows from the same address set as before. Apexes, regional claims and deployments without published app hosts keep today's wording. One source for the app page, Settings and the domains doors; the list and per-host answers gain cname_target. Tests drive the domains verifier and the cert-warm gate through a real resolver against a CNAME chain. Copy approved by Paul (review h6ervmdazwch2d5zj5pnrotnne).
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
docs/site/cli.md+2 −3internal/console/apidomains.go+10 −2internal/console/apphost_guidance_test.go+284 −0internal/console/appsettings.go+1 −1internal/console/domaincatchall.go+6 −3internal/console/domainstate.go+6 −7internal/console/remoteinstances.go+1 −1internal/console/server.go+9 −2internal/console/view.go+92 −1internal/domains/cname_apphost_test.go+114 −0internal/edge/cname_apphost_test.go+104 −0
CI failed — run details
Intent
<paseo-system version="1" kind="agent-message" source-agent-id="8a3d302a-eac7-407c-b61c-f5ccc66b5544" message-id="12aa1a9b-23af-4af7-a947-06ffc5fbeb4c"> Agent manager 8a3d302: plan approved. Two notes appended to ~/.cache/cname-app-host/REPORT.md (show Paul the advice with and without the A-record alternative; prove app and instance hosts resolve publicly on dev and flagship). </paseo-system>
<task-notification> <task-id>bx5p78gmt</task-id> <tool-use-id>toolu_01GPqqB96VqMhymb1kkmkUt4</tool-use-id> <output-file>/home/paulca/.cache/tmp/claude-1001/-home-paulca-amadan-net-carlos-platform/2fb16e46-9bb8-4bb3-8017-2fbbed1305eb/tasks/bx5p78gmt.output</output-file> <status>completed</status> <summary>Background command "Run full console test package" completed (exit code 0)</summary> </task-notification>
<task-notification> <task-id>bs92h1fs1</task-id> <tool-use-id>toolu_01WMVEcfxx3xUVNUaLzKcvhh</tool-use-id> <output-file>/home/paulca/.cache/tmp/claude-1001/-home-paulca-amadan-net-carlos-platform/2fb16e46-9bb8-4bb3-8017-2fbbed1305eb/tasks/bs92h1fs1.output</output-file> <status>completed</status> <summary>Background command "Wait in background for copy review" completed (exit code 0)</summary> </task-notification>
Attributed to this commit: 24.2 g CO₂e (2,883,034 tokens). This is an attribution, not a measurement — usage counted from this commit's own marker forward to the next one on cname-app-host, 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/docs/site/cli.md b/docs/site/cli.md| index c5a22399a..c289a7d63 100644 |
| --- a/docs/site/cli.md |
| +++ b/docs/site/cli.md |
| @@ -1372,8 +1372,7 @@ created** — you do not have to ask. Static is the one kind every edge can |
| serve on its own, straight from the channel pointer, so there is no reason |
| for one edge to answer for all of them. `off` turns it back off if you want |
| a single answer, and nothing re-applies the default to a host that already |
| -exists. Custom domains are not steered for you, because their DNS is yours: |
| -point them at the steering hostname the app's Settings page names. |
| +exists. A custom domain's DNS is yours, so steering cannot change it for you. Point a CNAME for it at the app's own hostname, which the app's Settings page names, and it follows that hostname's steering. |
| ### carlos routes |
| @@ -1517,7 +1516,7 @@ When the deployment uses configured regional ingress, set `CONSOLE_REGION_INGRES |
| Before rolling the console, validate the complete `CONSOLE_REGION_INGRESS` value. Verify that the agents accept the same addresses through `PLATFORM_EDGE_IPS` before setting `CONSOLE_REGION_INGRESS`. Set the console ingress before any group box publishes an edges file. |
| -With configured ingress, DNS guidance uses A records for both apexes and subdomains. `carlos domains placements` refuses configured high availability placements while regional placement readiness is unavailable. The refusal names the configured public ingress addresses and does not list member addresses. |
| +With configured ingress, an apex domain's advice names the configured public ingress addresses for its A records. A subdomain's advice is still a CNAME to the app's own hostname. `carlos domains placements` refuses configured high availability placements while regional placement readiness is unavailable. The refusal names the configured public ingress addresses and does not list member addresses. |
| The root CLI help still says that `carlos domains placements` shows the addresses to point DNS at for each region. That help remains unchanged. The configured-ingress refusal limits that promise until regional placement readiness is available. |
diff --git a/internal/console/apidomains.go b/internal/console/apidomains.go| index e127ee3d3..44e991d90 100644 |
| --- a/internal/console/apidomains.go |
| +++ b/internal/console/apidomains.go |
| @@ -1266,6 +1266,12 @@ type domainListItem struct { |
| DNSStatus string `json:"dns_status,omitempty"` |
| CertExpiresAt int64 `json:"cert_expires_at,omitempty"` |
| Guidance string `json:"guidance,omitempty"` |
| + // CNAMETarget is the name Guidance tells the member to CNAME this host |
| + // at: the app's own host (view.go's appHostFor) where the deployment |
| + // publishes app hosts, else the legacy steering hostname. Set exactly |
| + // when Records carries the CNAME alternative; omitted for an apex, for |
| + // A-record-only advice and when there is nothing to do. Additive. |
| + CNAMETarget string `json:"cname_target,omitempty"` |
| // Wildcard and Catchall (Task 5) copy the claim's own capability bits |
| // verbatim — always present, true or false, the same "known state" |
| // convention Created/Removed use on the attach/detach answers (never |
| @@ -1457,11 +1463,13 @@ 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": |
| - item.Guidance = domainGuidance(c.Host, targets) |
| + bound := targets.forApp(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 |
| // anything for the member to do. |
| - item.Records = domainRecords(c.Host, targets, c.Wildcard, s.delegationZone) |
| + item.Records = domainRecords(c.Host, bound, c.Wildcard, s.delegationZone) |
| + item.CNAMETarget = cnameTarget(c.Host, bound) |
| } |
| if c.Pending { |
| // The proof record, in BOTH forms, under the same lockstep rule as |
diff --git a/internal/console/apphost_guidance_test.go b/internal/console/apphost_guidance_test.go| new file mode 100644 |
| index 000000000..6cdc7e72d |
| --- /dev/null |
| +++ b/internal/console/apphost_guidance_test.go |
| @@ -0,0 +1,284 @@ |
| +package console |
| + |
| +import ( |
| + "context" |
| + "encoding/json" |
| + "net/http" |
| + "strings" |
| + "testing" |
| + "time" |
| + |
| + "github.com/carlosframework/platform/internal/domains" |
| + "github.com/carlosframework/platform/internal/registry" |
| + "github.com/carlosframework/platform/internal/release" |
| +) |
| + |
| +// Which name a custom domain is told to CNAME at. The claim's own route wins |
| +// when it is a name under the apps domain (the exact host serving it: an |
| +// instance's own name, HA or regional or not); otherwise the app's platform |
| +// apex, which reconcile mints for every app with a route. Nothing is named |
| +// when the deployment does not publish app hosts, or when the name asking is |
| +// already one of ours. |
| +func TestAppHostFor(t *testing.T) { |
| + const d = "oncarlos.test" |
| + for _, c := range []struct { |
| + name, domain, host, acct, app, route, want string |
| + }{ |
| + {"unpublished deployment names nothing", "", "shop.example.com", "bab", "blog", "", ""}, |
| + {"route under the apps domain is the app host", d, "shop.example.com", "bab", "blog", "eu.blog.bab.oncarlos.test", "eu.blog.bab.oncarlos.test"}, |
| + {"route case and trailing dot fold", d, "shop.example.com", "bab", "blog", "EU.Blog.bab.oncarlos.test.", "eu.blog.bab.oncarlos.test"}, |
| + {"first-route claim falls back to the apex", d, "shop.example.com", "bab", "blog", "", "blog.bab.oncarlos.test"}, |
| + {"route that is another custom name falls back to the apex", d, "www.example.com", "bab", "blog", "shop.example.com", "blog.bab.oncarlos.test"}, |
| + {"sidecar member name is never public", d, "shop.example.com", "bab", "blog", "m1.blog.sidecar.internal", "blog.bab.oncarlos.test"}, |
| + {"a wildcard route is never a target", d, "shop.example.com", "bab", "blog", "*.bab.oncarlos.test", "blog.bab.oncarlos.test"}, |
| + {"the apps domain itself is not an app host", d, "shop.example.com", "bab", "blog", "oncarlos.test", "blog.bab.oncarlos.test"}, |
| + {"catch-all head uses the apex", d, "*.example.com", "bab", "teams", "", "teams.bab.oncarlos.test"}, |
| + {"a name already under the apps domain gets nothing", d, "www.bab.oncarlos.test", "bab", "blog", "", ""}, |
| + {"no app, no apex", d, "shop.example.com", "bab", "", "", ""}, |
| + {"no account, no apex", d, "shop.example.com", "", "blog", "", ""}, |
| + {"an unusable app name gives no apex", d, "shop.example.com", "bab", "Not A Label", "", ""}, |
| + {"a route equal to the host is not a target", d, "blog.bab.oncarlos.test", "bab", "blog", "blog.bab.oncarlos.test", ""}, |
| + } { |
| + t.Run(c.name, func(t *testing.T) { |
| + if got := appHostFor(c.domain, c.host, c.acct, c.app, c.route); got != c.want { |
| + t.Errorf("appHostFor(%q, %q, %q, %q, %q) = %q, want %q", c.domain, c.host, c.acct, c.app, c.route, got, c.want) |
| + } |
| + }) |
| + } |
| +} |
| + |
| +// The deployment publishes app hosts exactly when it steers: the converger |
| +// that keeps their records is armed by the same pair (CARLOS_STEERING_ZONE_ID |
| +// and PLATFORM_APPS_DOMAIN) that gives the console its steering hostname. |
| +// Configured ingress does not change that. |
| +func TestDNSTargetsPublishAppHostsWhenSteering(t *testing.T) { |
| + for _, c := range []struct { |
| + name string |
| + s *Server |
| + want string |
| + ingress bool |
| + steering string |
| + }{ |
| + {"self-hosted: no apps domain", &Server{}, "", false, ""}, |
| + {"apps domain without steering", &Server{cfg: Config{AppsDomain: "oncarlos.test"}}, "", false, ""}, |
| + {"steering armed", &Server{cfg: Config{AppsDomain: " OnCarlos.test "}, steeringHost: "edge.oncarlos.test"}, "oncarlos.test", false, "edge.oncarlos.test"}, |
| + {"steering armed with configured ingress", &Server{cfg: Config{AppsDomain: "oncarlos.test", RegionIngress: []string{ingressIP}}, steeringHost: "edge.oncarlos.test"}, "oncarlos.test", true, ""}, |
| + } { |
| + t.Run(c.name, func(t *testing.T) { |
| + c.s.foldEdgeIPs = func(context.Context) []string { return nil } |
| + got := c.s.dnsTargets(context.Background()) |
| + if got.AppsDomain != c.want || got.ConfiguredIngress != c.ingress || got.SteeringHost != c.steering || got.AppHost != "" { |
| + t.Errorf("dnsTargets = %+v, want apps domain %q, ingress %v, steering %q, no row host", got, c.want, c.ingress, c.steering) |
| + } |
| + }) |
| + } |
| +} |
| + |
| +// A subdomain is told to CNAME at its app host on every published |
| +// deployment, configured ingress or not. The sentence and the records say |
| +// the same thing, and the A alternative is the same IP set as before. |
| +// Apexes keep exactly today's advice. |
| +func TestGuidanceNamesTheAppHost(t *testing.T) { |
| + ips := []string{"203.0.113.7", "198.51.100.9"} |
| + const appHost = "blog.bab.oncarlos.test" |
| + steered := DNSTargets{EdgeIPs: ips, SteeringHost: "edge.oncarlos.test", AppsDomain: "oncarlos.test"} |
| + ingress := DNSTargets{EdgeIPs: []string{ingressIP}, ConfiguredIngress: true, AppsDomain: "oncarlos.test"} |
| + for name, base := range map[string]DNSTargets{"steered": steered, "configured ingress": ingress} { |
| + t.Run(name, func(t *testing.T) { |
| + bound := base.forApp("shop.example.com", "bab", "blog", "") |
| + if bound.AppHost != appHost { |
| + t.Fatalf("bound app host = %q", bound.AppHost) |
| + } |
| + g := domainGuidance("shop.example.com", bound) |
| + if !strings.HasPrefix(g, "Point a CNAME for shop.example.com at "+appHost+",") { |
| + t.Errorf("guidance = %q, want the CNAME to the app host first", g) |
| + } |
| + if strings.Contains(g, "edge.oncarlos.test") { |
| + t.Errorf("guidance still names the steering host: %q", g) |
| + } |
| + if got := cnameTarget("shop.example.com", bound); got != appHost { |
| + t.Errorf("cnameTarget = %q, want %q", got, appHost) |
| + } |
| + var cname []dnsRecord |
| + for _, r := range domainRecords("shop.example.com", bound, false, "") { |
| + switch r.Type { |
| + case "CNAME": |
| + cname = append(cname, r) |
| + case "A": |
| + if r.Set != "a" || !strings.Contains(strings.Join(base.EdgeIPs, ","), r.Value) { |
| + t.Errorf("A record %+v is not from the deployment's set %v", r, base.EdgeIPs) |
| + } |
| + } |
| + } |
| + if len(cname) != 1 || cname[0].Value != appHost || cname[0].Set != "cname" || cname[0].TTL != domainRecordTTL { |
| + t.Errorf("CNAME records = %+v, want one at %s", cname, appHost) |
| + } |
| + // The apex keeps today's advice, byte for byte. |
| + apexBound := base.forApp("example.com", "bab", "blog", "") |
| + unbound := base |
| + if got, want := domainGuidance("example.com", apexBound), domainGuidance("example.com", unbound); got != want { |
| + t.Errorf("apex guidance changed:\n got %q\n want %q", got, want) |
| + } |
| + if got := cnameTarget("example.com", apexBound); got != "" { |
| + t.Errorf("apex offered a CNAME target %q", got) |
| + } |
| + for _, r := range domainRecords("example.com", apexBound, false, "") { |
| + if r.Type == "CNAME" { |
| + t.Errorf("apex offered a CNAME: %+v", r) |
| + } |
| + } |
| + }) |
| + } |
| +} |
| + |
| +// A deployment that does not publish app hosts (self-hosted, devbox) keeps |
| +// exactly today's wording even when a row binds an app. |
| +func TestGuidanceUnpublishedDeploymentUnchanged(t *testing.T) { |
| + ips := []string{"203.0.113.7"} |
| + for _, base := range []DNSTargets{{EdgeIPs: ips}, {}, {EdgeIPs: ips, SteeringHost: "edge.oncarlos.test"}, {EdgeIPs: ips, ConfiguredIngress: true}} { |
| + for _, host := range []string{"shop.example.com", "example.com"} { |
| + bound := base.forApp(host, "bab", "blog", "blog.bab.oncarlos.test") |
| + if got, want := domainGuidance(host, bound), domainGuidance(host, base); got != want { |
| + t.Errorf("%+v %s: guidance %q, want unchanged %q", base, host, got, want) |
| + } |
| + if bound.AppHost != "" { |
| + t.Errorf("%+v: bound an app host %q on an unpublished deployment", base, bound.AppHost) |
| + } |
| + } |
| + } |
| + if got := cnameTarget("shop.example.com", DNSTargets{SteeringHost: "edge.oncarlos.test"}); got != "edge.oncarlos.test" { |
| + t.Errorf("legacy steering CNAME target = %q", got) |
| + } |
| + if got := cnameTarget("shop.example.com", DNSTargets{EdgeIPs: ips}); got != "" { |
| + t.Errorf("no steering, no app host: cname target %q", got) |
| + } |
| +} |
| + |
| +// The domains API, the Settings page and the app page all name the same app |
| +// host for the same claim, with configured ingress on: the route's own name |
| +// when it is under the apps domain, the app's apex for a first-route claim. |
| +func TestDomainSurfacesAgreeOnTheAppHost(t *testing.T) { |
| + fx, member := instanceFixture(t, "code-dom-apphost") |
| + 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" |
| + ctx := context.Background() |
| + sqid := release.OpsAccount |
| + acct, err := fx.st.AccountBySqid(sqid) |
| + if err != nil || acct == nil { |
| + t.Fatalf("account: %v %v", acct, err) |
| + } |
| + instHost := "eu." + "titogo." + sqid + ".oncarlos.test" |
| + apex := "titogo." + sqid + ".oncarlos.test" |
| + attachShopClaim(t, fx, sqid, "titogo", "shop.example.com", instHost) |
| + attachShopClaim(t, fx, sqid, "titogo", "first.example.com", "") |
| + attachShopClaim(t, fx, sqid, "titogo", "example.com", instHost) |
| + want := map[string]string{"shop.example.com": instHost, "first.example.com": apex, "example.com": ""} |
| + |
| + 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"` |
| + Records []dnsRecord `json:"records"` |
| + } `json:"domains"` |
| + Deployment struct { |
| + SteeringHost string `json:"steering_host"` |
| + EdgeIPs []string `json:"edge_ips"` |
| + } `json:"deployment"` |
| + } |
| + if err := json.Unmarshal([]byte(out), &got); err != nil { |
| + t.Fatal(err) |
| + } |
| + seen := 0 |
| + for _, d := range got.Domains { |
| + w, ok := want[d.Host] |
| + if !ok { |
| + continue |
| + } |
| + seen++ |
| + if d.CNAMETarget != w { |
| + t.Errorf("%s cname_target = %q, want %q", d.Host, d.CNAMETarget, w) |
| + } |
| + if w != "" && !strings.HasPrefix(d.Guidance, "Point a CNAME for "+d.Host+" at "+w+",") { |
| + t.Errorf("%s guidance = %q", d.Host, d.Guidance) |
| + } |
| + if w == "" && strings.Contains(d.Guidance, "CNAME for") { |
| + t.Errorf("apex %s guidance offers a CNAME: %q", d.Host, d.Guidance) |
| + } |
| + for _, r := range d.Records { |
| + if r.Type == "CNAME" && r.Value != w { |
| + t.Errorf("%s CNAME record %+v, want %q", d.Host, r, w) |
| + } |
| + } |
| + } |
| + if seen != len(want) { |
| + t.Fatalf("saw %d of %d claims in %s", seen, len(want), out) |
| + } |
| + if len(got.Deployment.EdgeIPs) == 0 { |
| + t.Errorf("deployment block lost edge_ips: %s", out) |
| + } |
| + |
| + // The per-host door answers the same. |
| + code, _, out = rawReq(t, http.MethodGet, domainGetURL(fx, "bab", "titogo", "first.example.com"), member, "") |
| + if code != http.StatusOK || !strings.Contains(out, `"cname_target":"`+apex+`"`) { |
| + t.Errorf("per-host door = %d %s, want cname_target %s", code, out, apex) |
| + } |
| + |
| + // Settings rows for claims with no registry row yet. |
| + views := fx.srv.settingsDomains(withReqMemo(ctx), acct, "titogo", nil) |
| + for _, dv := range views { |
| + w, ok := want[dv.Domain] |
| + if !ok { |
| + continue |
| + } |
| + if w != "" && !strings.HasPrefix(dv.Guidance, "Point a CNAME for "+dv.Domain+" at "+w+",") { |
| + t.Errorf("settings %s guidance = %q", dv.Domain, dv.Guidance) |
| + } |
| + } |
| + |
| + // A registry custom route (the app page's Domains rows) names the apex. |
| + dv := domainView(registry.Route{Host: "www.example.com", App: "titogo", Account: sqid}, fx.srv.dnsTargets(ctx)) |
| + if !strings.HasPrefix(dv.Guidance, "Point a CNAME for www.example.com at "+apex+",") { |
| + t.Errorf("app page guidance = %q", dv.Guidance) |
| + } |
| +} |
| + |
| +// An instance catch-all's head ("*.<parent>") names the app's apex: no one |
| +// instance's name can stand for every label under it. |
| +func TestCatchallHeadNamesTheAppApex(t *testing.T) { |
| + fx, _ := instanceFixture(t, "code-dom-apphost-catchall") |
| + fx.srv.cfg.AppsDomain = "oncarlos.test" |
| + fx.srv.cfg.RegionIngress = []string{ingressIP} |
| + fx.srv.steeringHost = "edge.oncarlos.test" |
| + ctx := withReqMemo(context.Background()) |
| + acct, err := fx.st.AccountBySqid(release.OpsAccount) |
| + if err != nil || acct == nil { |
| + t.Fatalf("account: %v %v", acct, err) |
| + } |
| + c := domains.Claim{Host: "*.example.com", Instances: true, Account: acct.Sqid, App: "titogo"} |
| + items := fx.srv.catchallListItems(ctx, acct, "titogo", c, map[string]bool{}, nil, nil, fx.srv.dnsTargets(ctx), time.Now()) |
| + apex := "titogo." + acct.Sqid + ".oncarlos.test" |
| + if len(items) == 0 || items[0].CNAMETarget != apex || !strings.HasPrefix(items[0].Guidance, "Point a CNAME for *.example.com at "+apex+",") { |
| + t.Fatalf("catch-all head = %+v, want CNAME at %s", items, apex) |
| + } |
| +} |
| + |
| +// The approved wording (copy review 2026-11-08), with and without a known |
| +// address set. |
| +func TestAppHostGuidanceWording(t *testing.T) { |
| + t.Parallel() |
| + bound := DNSTargets{EdgeIPs: []string{"203.0.113.10", "203.0.113.11"}, ConfiguredIngress: true, AppsDomain: "oncarlos.com"}.forApp("shop.example.com", "k3x", "blog", "") |
| + if got, want := domainGuidance("shop.example.com", bound), "Point a CNAME for shop.example.com at blog.k3x.oncarlos.com, your app's own address. Visitors then reach the nearest edge, and the record keeps working if the app moves. An A record for shop.example.com at 203.0.113.10, 203.0.113.11 also works, but it sends visitors to fixed addresses that may change later. Checks run every few minutes."; got != want { |
| + t.Errorf("with addresses:\n got %q\n want %q", got, want) |
| + } |
| + bare := DNSTargets{SteeringHost: "edge.oncarlos.com", AppsDomain: "oncarlos.com"}.forApp("shop.example.com", "k3x", "blog", "") |
| + if got, want := domainGuidance("shop.example.com", bare), "Point a CNAME for shop.example.com at blog.k3x.oncarlos.com, your app's own address. Visitors then reach the nearest edge, and the record keeps working if the app moves. Checks run every few minutes."; got != want { |
| + t.Errorf("without addresses:\n got %q\n want %q", got, want) |
| + } |
| +} |
diff --git a/internal/console/appsettings.go b/internal/console/appsettings.go| index 8984a5dbc..21a5a25b2 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)) |
| + dv := claimDomainView(c.Host, s.dnsTargets(ctx).forApp(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..488f2e195 100644 |
| --- a/internal/console/domaincatchall.go |
| +++ b/internal/console/domaincatchall.go |
| @@ -349,7 +349,7 @@ func (s *Server) catchallListItems(ctx context.Context, acct *Account, app strin |
| rows := make([]domainListItem, 0, len(derived)) |
| pointing := false |
| for _, d := range derived { |
| - item := s.domainItem(ctx, domains.Claim{Host: d.Host, Route: d.Route}, readings, warm[d.Host], targets, now, false) |
| + item := s.domainItem(ctx, domains.Claim{Host: d.Host, Route: d.Route, Account: acct.Sqid, App: app}, readings, warm[d.Host], targets, now, false) |
| item.Via = c.Host |
| rows = append(rows, item) |
| pointing = pointing || d.Reading.DNSStatus == "pointing" |
| @@ -361,8 +361,11 @@ 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: no one instance's name can stand for every label. |
| + bound := targets.forApp(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/domainstate.go b/internal/console/domainstate.go| index 27bd52aa4..1cfd1f4ba 100644 |
| --- a/internal/console/domainstate.go |
| +++ b/internal/console/domainstate.go |
| @@ -213,16 +213,15 @@ const domainRecordTTL = 300 |
| // disagreed, an app would create records that contradict the sentence shown |
| // to the person operating it. |
| // |
| -// The alias/CNAME alternative is emitted ONLY when steering is armed. |
| -// edge.<apps-domain> exists only where the steering converger maintains its |
| -// records; on a non-steering deployment naming it would hand out a hostname |
| -// with no records behind it. |
| +// The CNAME alternative is emitted ONLY when steering is armed (cnameTarget): |
| +// the row's app host where one is bound, else edge.<apps-domain>. Both exist |
| +// only where the steering converger maintains its records; on a non-steering |
| +// deployment naming either would hand out a hostname nobody keeps. |
| func domainRecords(host string, t DNSTargets, wildcard bool, delegationZone string) []dnsRecord { |
| var out []dnsRecord |
| - steering := t.SteeringHost != "" && !isApexDomain(host) |
| - if steering { |
| + if target := cnameTarget(host, t); target != "" { |
| out = append(out, dnsRecord{ |
| - Type: "CNAME", Name: host, Value: t.SteeringHost, |
| + Type: "CNAME", Name: host, Value: target, |
| TTL: domainRecordTTL, Set: "cname", |
| }) |
| } |
diff --git a/internal/console/remoteinstances.go b/internal/console/remoteinstances.go| index 75b548883..5bcf3cba5 100644 |
| --- a/internal/console/remoteinstances.go |
| +++ b/internal/console/remoteinstances.go |
| @@ -466,7 +466,7 @@ func remoteRoute(rec provision.Record, rep *hostReport, f appFacts, acct string, |
| // domainView's rule: guidance only for a reading that says the |
| // member's record is missing or wrong. No reading is not that. |
| if rd.DNSStatus != "" && rd.DNSStatus != "pointing" && rd.DNSStatus != "unresolved" { |
| - dv.Guidance = domainGuidance(rec.Host, dns) |
| + dv.Guidance = domainGuidance(rec.Host, dns.forApp(rec.Host, rec.Account, rec.App, "")) |
| } |
| } |
| case f.complete() && !fleetPlaced && !f.seen(rec.Host): |
diff --git a/internal/console/server.go b/internal/console/server.go| index 42670a55c..b1f11c4e5 100644 |
| --- a/internal/console/server.go |
| +++ b/internal/console/server.go |
| @@ -1630,10 +1630,17 @@ func (s *Server) chrome(p *page) { |
| // point DNS. ctx is the caller's request: a fold refresh it waits for is |
| // counted against that request (see foldedEdgeIPs). |
| func (s *Server) dnsTargets(ctx context.Context) DNSTargets { |
| + // App hosts are published where the deployment steers: steeringHost is |
| + // set only when CARLOS_STEERING_ZONE_ID and PLATFORM_APPS_DOMAIN both |
| + // are, and the converger they arm keeps the app hosts' records. |
| + var apps string |
| + if s.steeringHost != "" { |
| + apps = strings.ToLower(strings.TrimSuffix(strings.TrimSpace(s.cfg.AppsDomain), ".")) |
| + } |
| if len(s.cfg.RegionIngress) > 0 { |
| - return DNSTargets{EdgeIPs: s.edgeIPs(ctx), ConfiguredIngress: true} |
| + return DNSTargets{EdgeIPs: s.edgeIPs(ctx), ConfiguredIngress: true, AppsDomain: apps} |
| } |
| - return DNSTargets{EdgeIPs: s.edgeIPs(ctx), SteeringHost: s.steeringHost} |
| + return DNSTargets{EdgeIPs: s.edgeIPs(ctx), SteeringHost: s.steeringHost, AppsDomain: apps} |
| } |
| // edgeIPs is the DNS address union. Configured ingress is deployment-wide: |
diff --git a/internal/console/view.go b/internal/console/view.go| index 297fdcbde..11796f127 100644 |
| --- a/internal/console/view.go |
| +++ b/internal/console/view.go |
| @@ -22,6 +22,7 @@ import ( |
| "github.com/carlosframework/platform/internal/metrics" |
| "github.com/carlosframework/platform/internal/perf" |
| + "github.com/carlosframework/platform/internal/provision" |
| "github.com/carlosframework/platform/internal/regionlabel" |
| "github.com/carlosframework/platform/internal/registry" |
| "github.com/carlosframework/platform/internal/release" |
| @@ -171,6 +172,81 @@ type DNSTargets struct { |
| // deployment that does not set CARLOS_STEERING_ZONE_ID, which is all of |
| // them today — keeps the guidance byte-for-byte what it has always been. |
| SteeringHost string |
| + // AppsDomain is set only where the deployment publishes its app hosts in |
| + // public DNS: where it steers (CARLOS_STEERING_ZONE_ID plus |
| + // PLATFORM_APPS_DOMAIN, the pair the converger that keeps their records |
| + // needs). Unlike SteeringHost it stays set under configured ingress: an |
| + // app host's records are the deployment's to steer, so a customer CNAME |
| + // to one follows us wherever its traffic goes next. "" (self-hosted, |
| + // devbox) keeps today's wording. |
| + AppsDomain string |
| + // AppHost is the one row's CNAME target, bound by forApp: the name a |
| + // non-apex custom domain is told to CNAME at. "" until a row binds it. |
| + AppHost string |
| +} |
| + |
| +// forApp binds the row's app host (see appHostFor). Every surface that shows |
| +// a custom domain's guidance binds it from the same claim or route facts, so |
| +// the app page, Settings and the domains door name the same host. |
| +func (t DNSTargets) forApp(host, acct, app, route string) DNSTargets { |
| + t.AppHost = appHostFor(t.AppsDomain, host, acct, app, route) |
| + return t |
| +} |
| + |
| +// appHostFor is the name under the apps domain a custom domain host should |
| +// CNAME at, or "" when there is none to name: |
| +// |
| +// 1. the claim's route, when it is a name under the apps domain: the exact |
| +// host serving the custom domain. For an instance (HA, in another |
| +// region, or a sidecar's primary) that is the instance's own public |
| +// name; member and sidecar names (*.sidecar.internal) are never under |
| +// the apps domain, so they are never named; |
| +// 2. otherwise the app's platform apex, <app>.<sqid>.<apps-domain>, which |
| +// reconcile mints for every app with a route. |
| +// |
| +// A host that is itself under the apps domain is ours already and is told |
| +// nothing new, and nothing is named on a deployment that does not publish |
| +// app hosts (domain ""). |
| +func appHostFor(domain, host, acct, app, route string) string { |
| + domain = strings.ToLower(strings.TrimSuffix(strings.TrimSpace(domain), ".")) |
| + if domain == "" { |
| + return "" |
| + } |
| + norm := func(h string) string { return strings.ToLower(strings.TrimSuffix(strings.TrimSpace(h), ".")) } |
| + h := norm(host) |
| + ours := func(n string) bool { |
| + return strings.HasSuffix(n, "."+domain) && provision.ValidHostShape(n) |
| + } |
| + if h == domain || strings.HasSuffix(h, "."+domain) { |
| + return "" |
| + } |
| + if r := norm(route); ours(r) && r != h { |
| + return r |
| + } |
| + if acct == "" || app == "" { |
| + return "" |
| + } |
| + if apex := norm(app) + "." + norm(acct) + "." + domain; ours(apex) { |
| + return apex |
| + } |
| + return "" |
| +} |
| + |
| +// 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 |
| +// sentence and the records can never name two different targets. |
| +func cnameTarget(host string, t DNSTargets) string { |
| + if isApexDomain(host) { |
| + return "" |
| + } |
| + if t.AppHost != "" { |
| + return t.AppHost |
| + } |
| + if t.ConfiguredIngress { |
| + return "" |
| + } |
| + return t.SteeringHost |
| } |
| // domainGuidance is shared by routed and claim-only custom domains. Ingress |
| @@ -184,6 +260,8 @@ func domainGuidance(host string, t DNSTargets) string { |
| } |
| aRecord := "Point an A record for " + host + " at " + target + "." |
| switch { |
| + case t.AppHost != "" && !isApexDomain(host): |
| + aRecord = appHostGuidance(host, t.AppHost, target, len(t.EdgeIPs) > 0) |
| case t.ConfiguredIngress: |
| if isApexDomain(host) { |
| return fmt.Sprintf("%s is an apex domain and cannot use a CNAME. Point its A record at the configured public ingress addresses: %s. Checks run every few minutes.", host, target) |
| @@ -266,7 +344,7 @@ func domainView(rt registry.Route, dns DNSTargets) DomainView { |
| // the member's record is missing or wrong, so telling them to (re)point |
| // it would blame them for our outage. |
| if !rt.Platform && rt.DNSStatus != "pointing" && rt.DNSStatus != "unresolved" { |
| - dv.Guidance = domainGuidance(rt.Host, dns) |
| + dv.Guidance = domainGuidance(rt.Host, dns.forApp(rt.Host, release.RouteAccount(rt), rt.App, "")) |
| } |
| return dv |
| } |
| @@ -1108,3 +1186,16 @@ func versionsPage(ctx context.Context, s release.Store, acct, app string, page i |
| } |
| return out, newest, more, nil |
| } |
| + |
| +// appHostGuidance is the subdomain advice where the deployment publishes |
| +// app hosts (copy review 2026-11-08: both forms approved). The A-record |
| +// alternative follows only when the deployment knows its addresses (the |
| +// same set as before); otherwise the CNAME stands alone rather than |
| +// naming "this deployment's edge IP". |
| +func appHostGuidance(host, appHost, target string, withA bool) string { |
| + cname := "Point a CNAME for " + host + " at " + appHost + ", your app's own address. Visitors then reach the nearest edge, and the record keeps working if the app moves." |
| + if withA { |
| + return cname + " An A record for " + host + " at " + target + " also works, but it sends visitors to fixed addresses that may change later." |
| + } |
| + return cname |
| +} |
diff --git a/internal/domains/cname_apphost_test.go b/internal/domains/cname_apphost_test.go| new file mode 100644 |
| index 000000000..4283fd840 |
| --- /dev/null |
| +++ b/internal/domains/cname_apphost_test.go |
| @@ -0,0 +1,114 @@ |
| +package domains |
| + |
| +import ( |
| + "context" |
| + "net" |
| + "strings" |
| + "testing" |
| + "time" |
| + |
| + "golang.org/x/net/dns/dnsmessage" |
| +) |
| + |
| +// A custom domain CNAMEd at its app's own host (the console's advice where |
| +// the deployment publishes app hosts) reads "pointing" when that host |
| +// resolves into the edge set, configured public ingress included, and |
| +// "elsewhere" when it does not. dnsStatus is fed the production resolver |
| +// shape, so the CNAME is followed by LookupHost exactly as on a box. |
| +func TestDNSStatusFollowsACNAMEToTheAppHost(t *testing.T) { |
| + const ingress = "192.0.2.90" |
| + chain := []string{"shop.example.com", "eu.blog.bab.oncarlos.test"} |
| + resolve := cnameDNS(t, chain, []string{ingress}) |
| + if got := dnsStatus(resolve, "shop.example.com", map[string]bool{"192.0.2.1": true, ingress: true}); got != "pointing" { |
| + t.Errorf("CNAME to the app host, app host on configured ingress: %q, want pointing", got) |
| + } |
| + if got := dnsStatus(resolve, "shop.example.com", map[string]bool{"192.0.2.1": true}); got != "elsewhere" { |
| + t.Errorf("CNAME to an address outside the edge set: %q, want elsewhere", got) |
| + } |
| + if got := dnsStatus(resolve, "missing.example.com", map[string]bool{ingress: true}); got != "" { |
| + t.Errorf("no record yet: %q, want empty", got) |
| + } |
| + // Two hops (a customer CNAME to their own name, then to the app host). |
| + two := cnameDNS(t, []string{"www.example.com", "shop.example.com", "blog.bab.oncarlos.test"}, []string{ingress}) |
| + if got := dnsStatus(two, "www.example.com", map[string]bool{ingress: true}); got != "pointing" { |
| + t.Errorf("two-hop CNAME: %q, want pointing", got) |
| + } |
| +} |
| + |
| +// cnameDNS is a one-zone authoritative fake for the CNAME tests: it answers |
| +// every A query for a name in chain with the whole CNAME chain to the end |
| +// name plus that name's A records, the way a recursive resolver hands a |
| +// stub the answer. AAAA gets the chain alone. Anything else is NXDOMAIN. |
| +// It is reached through a real net.Resolver (PreferGo, dialing it), so |
| +// the lookup under test is the production LookupHost, CNAME-following and |
| +// all, with only the network swapped. |
| +func cnameDNS(t *testing.T, chain []string, ips []string) func(string) ([]string, error) { |
| + t.Helper() |
| + pc, err := net.ListenPacket("udp", "127.0.0.1:0") |
| + if err != nil { |
| + t.Fatal(err) |
| + } |
| + t.Cleanup(func() { pc.Close() }) |
| + fq := func(n string) string { return strings.TrimSuffix(strings.ToLower(n), ".") + "." } |
| + go func() { |
| + buf := make([]byte, 1500) |
| + for { |
| + n, addr, err := pc.ReadFrom(buf) |
| + if err != nil { |
| + return |
| + } |
| + var p dnsmessage.Parser |
| + h, err := p.Start(buf[:n]) |
| + if err != nil { |
| + continue |
| + } |
| + q, err := p.Question() |
| + if err != nil { |
| + continue |
| + } |
| + b := dnsmessage.NewBuilder(nil, dnsmessage.Header{ID: h.ID, Response: true, Authoritative: true, RecursionAvailable: true}) |
| + b.EnableCompression() |
| + _ = b.StartQuestions() |
| + _ = b.Question(q) |
| + _ = b.StartAnswers() |
| + start := -1 |
| + for i, name := range chain { |
| + if fq(name) == strings.ToLower(q.Name.String()) { |
| + start = i |
| + } |
| + } |
| + if start < 0 { |
| + b = dnsmessage.NewBuilder(nil, dnsmessage.Header{ID: h.ID, Response: true, Authoritative: true, RCode: dnsmessage.RCodeNameError}) |
| + _ = b.StartQuestions() |
| + _ = b.Question(q) |
| + } else { |
| + for i := start; i+1 < len(chain); i++ { |
| + _ = b.CNAMEResource(dnsmessage.ResourceHeader{Name: dnsmessage.MustNewName(fq(chain[i])), Class: dnsmessage.ClassINET, TTL: 60}, |
| + dnsmessage.CNAMEResource{CNAME: dnsmessage.MustNewName(fq(chain[i+1]))}) |
| + } |
| + if q.Type == dnsmessage.TypeA { |
| + for _, ip := range ips { |
| + var a [4]byte |
| + copy(a[:], net.ParseIP(ip).To4()) |
| + _ = b.AResource(dnsmessage.ResourceHeader{Name: dnsmessage.MustNewName(fq(chain[len(chain)-1])), Class: dnsmessage.ClassINET, TTL: 60}, |
| + dnsmessage.AResource{A: a}) |
| + } |
| + } |
| + } |
| + msg, err := b.Finish() |
| + if err != nil { |
| + continue |
| + } |
| + _, _ = pc.WriteTo(msg, addr) |
| + } |
| + }() |
| + r := &net.Resolver{PreferGo: true, Dial: func(ctx context.Context, _, _ string) (net.Conn, error) { |
| + var d net.Dialer |
| + return d.DialContext(ctx, "udp", pc.LocalAddr().String()) |
| + }} |
| + return func(host string) ([]string, error) { |
| + ctx, cancel := context.WithTimeout(context.Background(), 3*time.Second) |
| + defer cancel() |
| + return r.LookupHost(ctx, host) |
| + } |
| +} |
diff --git a/internal/edge/cname_apphost_test.go b/internal/edge/cname_apphost_test.go| new file mode 100644 |
| index 000000000..bd38d13b2 |
| --- /dev/null |
| +++ b/internal/edge/cname_apphost_test.go |
| @@ -0,0 +1,104 @@ |
| +package edge |
| + |
| +import ( |
| + "context" |
| + "net" |
| + "strings" |
| + "testing" |
| + "time" |
| + |
| + "golang.org/x/net/dns/dnsmessage" |
| +) |
| + |
| +// The cert warm only orders for a host whose DNS lands wholly on this |
| +// deployment. A custom domain CNAMEd at its app's own host passes when that |
| +// host resolves into the edge set (configured public ingress is part of it |
| +// through PLATFORM_EDGE_IPS), and fails when it does not. |
| +func TestCertWarmGateFollowsACNAMEToTheAppHost(t *testing.T) { |
| + const ingress = "192.0.2.90" |
| + resolve := cnameDNS(t, []string{"shop.example.com", "eu.blog.bab.oncarlos.test"}, []string{ingress}) |
| + if !dnsGate(resolve, func() []string { return []string{"192.0.2.1", ingress} })("shop.example.com") { |
| + t.Error("CNAME to an app host on configured ingress was refused a certificate") |
| + } |
| + if dnsGate(resolve, func() []string { return []string{"192.0.2.1"} })("shop.example.com") { |
| + t.Error("CNAME to an address outside the edge set was offered a certificate") |
| + } |
| +} |
| + |
| +// cnameDNS is a one-zone authoritative fake for the CNAME tests: it answers |
| +// every A query for a name in chain with the whole CNAME chain to the end |
| +// name plus that name's A records, the way a recursive resolver hands a |
| +// stub the answer. AAAA gets the chain alone. Anything else is NXDOMAIN. |
| +// It is reached through a real net.Resolver (PreferGo, dialing it), so |
| +// the lookup under test is the production LookupHost, CNAME-following and |
| +// all, with only the network swapped. |
| +func cnameDNS(t *testing.T, chain []string, ips []string) func(string) ([]string, error) { |
| + t.Helper() |
| + pc, err := net.ListenPacket("udp", "127.0.0.1:0") |
| + if err != nil { |
| + t.Fatal(err) |
| + } |
| + t.Cleanup(func() { pc.Close() }) |
| + fq := func(n string) string { return strings.TrimSuffix(strings.ToLower(n), ".") + "." } |
| + go func() { |
| + buf := make([]byte, 1500) |
| + for { |
| + n, addr, err := pc.ReadFrom(buf) |
| + if err != nil { |
| + return |
| + } |
| + var p dnsmessage.Parser |
| + h, err := p.Start(buf[:n]) |
| + if err != nil { |
| + continue |
| + } |
| + q, err := p.Question() |
| + if err != nil { |
| + continue |
| + } |
| + b := dnsmessage.NewBuilder(nil, dnsmessage.Header{ID: h.ID, Response: true, Authoritative: true, RecursionAvailable: true}) |
| + b.EnableCompression() |
| + _ = b.StartQuestions() |
| + _ = b.Question(q) |
| + _ = b.StartAnswers() |
| + start := -1 |
| + for i, name := range chain { |
| + if fq(name) == strings.ToLower(q.Name.String()) { |
| + start = i |
| + } |
| + } |
| + if start < 0 { |
| + b = dnsmessage.NewBuilder(nil, dnsmessage.Header{ID: h.ID, Response: true, Authoritative: true, RCode: dnsmessage.RCodeNameError}) |
| + _ = b.StartQuestions() |
| + _ = b.Question(q) |
| + } else { |
| + for i := start; i+1 < len(chain); i++ { |
| + _ = b.CNAMEResource(dnsmessage.ResourceHeader{Name: dnsmessage.MustNewName(fq(chain[i])), Class: dnsmessage.ClassINET, TTL: 60}, |
| + dnsmessage.CNAMEResource{CNAME: dnsmessage.MustNewName(fq(chain[i+1]))}) |
| + } |
| + if q.Type == dnsmessage.TypeA { |
| + for _, ip := range ips { |
| + var a [4]byte |
| + copy(a[:], net.ParseIP(ip).To4()) |
| + _ = b.AResource(dnsmessage.ResourceHeader{Name: dnsmessage.MustNewName(fq(chain[len(chain)-1])), Class: dnsmessage.ClassINET, TTL: 60}, |
| + dnsmessage.AResource{A: a}) |
| + } |
| + } |
| + } |
| + msg, err := b.Finish() |
| + if err != nil { |
| + continue |
| + } |
| + _, _ = pc.WriteTo(msg, addr) |
| + } |
| + }() |
| + r := &net.Resolver{PreferGo: true, Dial: func(ctx context.Context, _, _ string) (net.Conn, error) { |
| + var d net.Dialer |
| + return d.DialContext(ctx, "udp", pc.LocalAddr().String()) |
| + }} |
| + return func(host string) ([]string, error) { |
| + ctx, cancel := context.WithTimeout(context.Background(), 3*time.Second) |
| + defer cancel() |
| + return r.LookupHost(ctx, host) |
| + } |
| +} |