carlos / platform Public

#162: publish the replica alias as role replica, stamp or no stamp

Co-Authored-By: Claude Opus 5 <noreply@anthropic.com>
claude agent, operated by paul@keymail.dev 112f5e0720c2eed38f66f0996043e252c86b21f5 parent e5c8887
2 files changed, +112 −1
  • internal/host/edgesfile.go +30 −1
  • internal/host/edgesfile_test.go +82 −0
diff --git a/internal/host/edgesfile.go b/internal/host/edgesfile.go
index 8a6aab585..2037f2674 100644
--- a/internal/host/edgesfile.go
+++ b/internal/host/edgesfile.go
@@ -245,6 +245,19 @@ func edgesFilePass(ctx context.Context, s release.Store, reg *registry.Registry,
if err != nil {
return fmt.Errorf("edges: list aliases: %w", err)
}
+ // byHost is the primary-route lookup the replica test below needs:
+ // whether an alias's PRIMARY route (a.Host) is itself a replica route
+ // (routes.replica_of set), never whether the alias's own NAME matches
+ // ReplicaOf. With custom domains in scope (#162 revision 2), a replica
+ // alias's name can be a tenant's own domain — the row is
+ // `claim.Host -> replica.Host` — while ReplicaOf always names the
+ // account's public host, so an equality test against a.Alias would
+ // match only the account-host alias and silently withhold every
+ // custom-domain one.
+ byHost := make(map[string]registry.Route, len(routes))
+ for _, r := range routes {
+ byHost[r.Host] = r
+ }
for _, a := range aliases {
if a.Alias == "" || strings.HasPrefix(a.Alias, "*.") {
continue
@@ -252,7 +265,15 @@ func edgesFilePass(ctx context.Context, s release.Store, reg *registry.Registry,
if _, served := hosts[a.Host]; !served {
continue
}
- if a.DNSStatus != "pointing" {
+ // A replica alias (#162) is a platform row: the domains pass
+ // derived it from a route THIS box wrote (routes.replica_of), and
+ // the name it publishes is already issued and mirrored for its
+ // home. Published without waiting for a dns_status stamp — that
+ // stamp answers a question about a tenant-chosen name, and
+ // withholding a replica alias would withhold exactly the rows this
+ // feature exists to publish, silently.
+ replica := byHost[a.Host].ReplicaOf != ""
+ if !replica && a.DNSStatus != "pointing" {
// Withheld, and said so ONCE per name per process: an alias
// whose DNS resolves to an address outside PLATFORM_EDGE_IPS
// (a region EIP missing from that list is the usual cause) is
@@ -266,6 +287,14 @@ func edgesFilePass(ctx context.Context, s release.Store, reg *registry.Registry,
if _, taken := hosts[a.Alias]; taken {
continue
}
+ if replica {
+ // Role "replica", never "home": every home-map reader drops an
+ // unknown role (foldHomes), which is what keeps the account's
+ // host single-valued fleet-wide. A "home" entry here would give
+ // a third box two dial targets settled by sort order.
+ hosts[a.Alias] = edgeHost{Role: "replica", Alias: true}
+ continue
+ }
hosts[a.Alias] = edgeHost{Role: "home", Alias: true}
}
diff --git a/internal/host/edgesfile_test.go b/internal/host/edgesfile_test.go
index 31c61feec..f107b5772 100644
--- a/internal/host/edgesfile_test.go
+++ b/internal/host/edgesfile_test.go
@@ -744,6 +744,88 @@ func TestEdgesFilePublishesPointingAliasesOfServedPrimaries(t *testing.T) {
}
}
+// #162: a replica alias — the account's own public host, derived by
+// domains.ReconcileAliases from a route's ReplicaOf — is a platform row, not
+// a tenant-chosen name, so it publishes regardless of dns_status. It is
+// marked role "replica" (never "home": foldHomes must drop it fleet-wide so
+// the account host stays single-valued), while the replica's own route
+// keeps role "home" so ordinary backhaul can still reach it.
+func TestEdgesFilePublishesReplicaAliasWithoutADNSStamp(t *testing.T) {
+ s, reg := release.NewDirStore(t.TempDir()), edgesTestRegistry(t)
+ if err := reg.Upsert(registry.Route{
+ Host: "r7x2k9m4qa.go.tito.io", Kind: "instance", Status: "ready",
+ Socket: "/run/carlos/r7x2k9m4qa.go.tito.io.sock", Provisioned: true,
+ Account: "bab", App: "tito", ReplicaOf: "acme.go.tito.io",
+ }); err != nil {
+ t.Fatal(err)
+ }
+ if err := reg.UpsertAlias(registry.RouteAlias{
+ Alias: "acme.go.tito.io", Host: "r7x2k9m4qa.go.tito.io",
+ Account: "bab", App: "tito", // deliberately unstamped
+ }); err != nil {
+ t.Fatal(err)
+ }
+ var lastBody []byte
+ if err := edgesFilePass(context.Background(), s, reg,
+ edgesFile{Box: "uk-1", Placement: "uk"}, "203.0.113.9", &lastBody); err != nil {
+ t.Fatal(err)
+ }
+ got, _, err := s.Get(context.Background(), "control/edges/uk-1.json")
+ if err != nil {
+ t.Fatal(err)
+ }
+ var f edgesFile
+ if err := json.Unmarshal(got, &f); err != nil {
+ t.Fatal(err)
+ }
+ if h, ok := f.Hosts["acme.go.tito.io"]; !ok || h.Role != "replica" || !h.Alias {
+ t.Fatalf("public host entry = %+v, want role replica alias true: %+v", h, f.Hosts)
+ }
+ if h, ok := f.Hosts["r7x2k9m4qa.go.tito.io"]; !ok || h.Role != "home" {
+ t.Fatalf("the replica's own host must stay role home: %+v", f.Hosts)
+ }
+}
+
+// #162 revision 2: with custom domains in scope, a replica alias's NAME can
+// be a custom domain rather than the account host — the alias row is
+// `claim.Host -> replica.Host`, and `ReplicaOf` names the account host, not
+// the alias. The replica test must therefore key off the PRIMARY route's
+// ReplicaOf (byHost[a.Host].ReplicaOf != ""), never off a.Alias equality,
+// or every custom-domain replica alias is silently withheld exactly like an
+// unstamped tenant name.
+func TestEdgesFilePublishesReplicaCustomDomainAliasWithoutADNSStamp(t *testing.T) {
+ s, reg := release.NewDirStore(t.TempDir()), edgesTestRegistry(t)
+ if err := reg.Upsert(registry.Route{
+ Host: "r7x2k9m4qa.go.tito.io", Kind: "instance", Status: "ready",
+ Socket: "/run/carlos/r7x2k9m4qa.go.tito.io.sock", Provisioned: true,
+ Account: "bab", App: "tito", ReplicaOf: "acme.go.tito.io",
+ }); err != nil {
+ t.Fatal(err)
+ }
+ if err := reg.UpsertAlias(registry.RouteAlias{
+ Alias: "tickets.example.com", Host: "r7x2k9m4qa.go.tito.io",
+ Account: "bab", App: "tito", // deliberately unstamped
+ }); err != nil {
+ t.Fatal(err)
+ }
+ var lastBody []byte
+ if err := edgesFilePass(context.Background(), s, reg,
+ edgesFile{Box: "uk-1", Placement: "uk"}, "203.0.113.9", &lastBody); err != nil {
+ t.Fatal(err)
+ }
+ got, _, err := s.Get(context.Background(), "control/edges/uk-1.json")
+ if err != nil {
+ t.Fatal(err)
+ }
+ var f edgesFile
+ if err := json.Unmarshal(got, &f); err != nil {
+ t.Fatal(err)
+ }
+ if h, ok := f.Hosts["tickets.example.com"]; !ok || h.Role != "replica" || !h.Alias {
+ t.Fatalf("custom-domain replica alias = %+v, want role replica alias true: %+v", h, f.Hosts)
+ }
+}
+
// #305: delegated customer wildcard parents publish as "*.<parent>" in their
// own class — never platform, never over an existing key.
func TestEdgesFilePublishesDelegatedWildcardParents(t *testing.T) {