carlos / platform Public

host: publish an alias early when its imported cert is usable (#1429)

edgesFileWriteClaims now also publishes a not-pointing alias, marked
dns_pointing false, when the edge's cert cache holds a usable
<alias>+import bound to the alias row's account, beside the DNS-01
pre-issue rule (49bcf97). Tests cover a matching account, another
account, no import, an expired import, and a fleet app's alias on a
hub's forward row.
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
claude agent, operated by paul@keymail.dev pushed by paul@keymail.dev 50895e9834572b2612b91ade22442ab1df7b3958 parent 7f3d75a
2 files changed, +188 −2
  • internal/host/edgesfile.go +11 −2
  • internal/host/edgesfile_import_test.go +177 −0
diff --git a/internal/host/edgesfile.go b/internal/host/edgesfile.go
index 0ab56dd44..70c6ea0fe 100644
--- a/internal/host/edgesfile.go
+++ b/internal/host/edgesfile.go
@@ -830,7 +830,15 @@ func edgesFileWriteClaims(ctx context.Context, s release.Store, reg *registry.Re
// keeps it out of the issuer's HTTP-01 warm set, and the issuer's
// HostPolicy refuses to order for a name published only this way
// (edge homeMap.AliasNotPointing), so it adds nothing to the
- // envelope above; the name is the operator's, not a tenant's;
+ // envelope above; the name is the operator's, not a tenant's.
+ // The same early publication, with the same false mark, holds for
+ // an alias whose imported certificate (#1429) sits in this box's
+ // cache (domains.UsableImportedCert: a regular <alias>+import file
+ // whose key matches, which names the alias, is in date, and whose
+ // binding Account is the alias row's account). An import is an
+ // operator's act on a claim they belong to, and the issuer's
+ // HostPolicy refuses to order for an imported name until a box
+ // publishes it pointing, so it adds nothing to the envelope either;
// - never platform-class: a customer's name derives no wildcard parent;
// - marked alias: the reader lets a real route on another box beat it;
// - no "*.parent" catch-all alias: a remote edge could dial it but has
@@ -877,7 +885,8 @@ func edgesFileWriteClaims(ctx context.Context, s release.Store, reg *registry.Re
continue
}
pointing := a.DNSStatus == "pointing"
- preIssued := !pointing && dns01.Allows(a.Alias, a.Account) && domains.UsablePerHostCert(acmeDir, a.Alias, now)
+ preIssued := !pointing && ((dns01.Allows(a.Alias, a.Account) && domains.UsablePerHostCert(acmeDir, a.Alias, now)) ||
+ domains.UsableImportedCert(acmeDir, a.Alias, a.Account, now))
if !pointing && !preIssued {
// Withheld, and said so ONCE per name per process: an alias
// whose DNS resolves to an address outside PLATFORM_EDGE_IPS
diff --git a/internal/host/edgesfile_import_test.go b/internal/host/edgesfile_import_test.go
new file mode 100644
index 000000000..f9e4241de
--- /dev/null
+++ b/internal/host/edgesfile_import_test.go
@@ -0,0 +1,177 @@
+package host
+
+import (
+ "context"
+ "crypto/ecdsa"
+ "crypto/elliptic"
+ "crypto/rand"
+ "crypto/x509"
+ "crypto/x509/pkix"
+ "encoding/json"
+ "math/big"
+ "os"
+ "path/filepath"
+ "sync"
+ "testing"
+ "time"
+
+ "github.com/carlosframework/platform/internal/domains"
+ "github.com/carlosframework/platform/internal/registry"
+ "github.com/carlosframework/platform/internal/release"
+)
+
+// writeImportEntry writes an imported-certificate entry (#1429) for host into
+// acmeDir, as the edge's mirror copies it from control/certs/<host>+import:
+// the binding (bound to account), the PKCS#8 key, then the leaf, valid until
+// notAfter.
+func writeImportEntry(t *testing.T, acmeDir, host, account string, notAfter time.Time) {
+ t.Helper()
+ key, err := ecdsa.GenerateKey(elliptic.P256(), rand.Reader)
+ if err != nil {
+ t.Fatal(err)
+ }
+ tmpl := &x509.Certificate{SerialNumber: big.NewInt(1), Subject: pkix.Name{CommonName: host}, DNSNames: []string{host},
+ NotBefore: time.Now().Add(-48 * time.Hour), NotAfter: notAfter}
+ der, err := x509.CreateCertificate(rand.Reader, tmpl, tmpl, &key.PublicKey, key)
+ if err != nil {
+ t.Fatal(err)
+ }
+ pkcs8, err := x509.MarshalPKCS8PrivateKey(key)
+ if err != nil {
+ t.Fatal(err)
+ }
+ body := domains.EncodeImport(domains.ImportBinding{Host: host, Account: account, App: "app", ClaimCreated: "2026-11-25T09:00:00Z"}, pkcs8, [][]byte{der})
+ if err := os.MkdirAll(acmeDir, 0o700); err != nil {
+ t.Fatal(err)
+ }
+ if err := os.WriteFile(filepath.Join(acmeDir, domains.ImportName(host)), body, 0o600); err != nil {
+ t.Fatal(err)
+ }
+}
+
+type importHostView struct {
+ Role string `json:"role"`
+ Alias bool `json:"alias"`
+ TargetHost string `json:"target_host"`
+ DNSPointing *bool `json:"dns_pointing"`
+}
+
+func publishedHosts(t *testing.T, s release.Store, box string) map[string]importHostView {
+ t.Helper()
+ body, _, err := s.Get(context.Background(), edgesFileKey(box))
+ if err != nil {
+ t.Fatal(err)
+ }
+ var f struct {
+ Hosts map[string]importHostView `json:"hosts"`
+ }
+ if err := json.Unmarshal(body, &f); err != nil {
+ t.Fatal(err)
+ }
+ return f.Hosts
+}
+
+// #1429: an alias whose imported certificate sits in the edge's cache, bound
+// to the alias row's account, is published before its DNS points here,
+// marked dns_pointing false, with no DNS-01 scope configured at all. Another
+// account's import, no import, or an expired one publishes nothing early.
+func TestEdgesFilePublishesImportedAliasesBeforeDNS(t *testing.T) {
+ withheldAliasSaid = sync.Map{}
+ t.Setenv("PLATFORM_APPS_DOMAIN", "apps.test")
+ t.Setenv("CARLOS_DNS01_ZONES", "")
+ t.Setenv("CARLOS_DNS01_ACCOUNTS", "")
+ s, reg := release.NewDirStore(t.TempDir()), edgesTestRegistry(t)
+ if err := reg.Upsert(registry.Route{Host: "app.acct.apps.test", Kind: "service", Addr: "10.0.0.1:3000", Status: "ready", Platform: true}); err != nil {
+ t.Fatal(err)
+ }
+ acme := filepath.Join(t.TempDir(), "acme")
+ future, past := time.Now().Add(60*24*time.Hour), time.Now().Add(-time.Minute)
+ for _, a := range []struct {
+ alias, aliasAccount, importAccount string
+ notAfter time.Time
+ }{
+ {"billing.customer.example", "acct", "acct", future}, // the case
+ {"otheracct.customer.example", "acct", "zzz", future}, // bound to another account
+ {"noimport.customer.example", "acct", "", future}, // no import
+ {"expired.customer.example", "acct", "acct", past}, // expired
+ {"wrongrow.customer.example", "zzz", "acct", future}, // the alias row is another account's
+ } {
+ if err := reg.UpsertAlias(registry.RouteAlias{Alias: a.alias, Host: "app.acct.apps.test", Account: a.aliasAccount, App: "app", DNSStatus: "elsewhere"}); err != nil {
+ t.Fatal(err)
+ }
+ if a.importAccount != "" {
+ writeImportEntry(t, acme, a.alias, a.importAccount, a.notAfter)
+ }
+ }
+ publish := func() map[string]importHostView {
+ t.Helper()
+ var last []byte
+ if err := edgesFilePass(context.Background(), s, reg, edgesFile{Box: "annie", AcmeDir: acme}, "1.2.3.4", &last); err != nil {
+ t.Fatal(err)
+ }
+ return publishedHosts(t, s, "annie")
+ }
+ hosts := publish()
+ if h, ok := hosts["billing.customer.example"]; !ok || h.Role != "home" || !h.Alias || h.TargetHost != "app.acct.apps.test" || h.DNSPointing == nil || *h.DNSPointing {
+ t.Errorf("billing.customer.example = %+v (published %v); want home, alias, dns_pointing false", h, ok)
+ }
+ for _, absent := range []string{"otheracct.customer.example", "noimport.customer.example", "expired.customer.example", "wrongrow.customer.example"} {
+ if _, ok := hosts[absent]; ok {
+ t.Errorf("%s must not be published before it points here", absent)
+ }
+ }
+
+ // The mirror removing the disk copy takes the name back out.
+ if err := os.Remove(filepath.Join(acme, domains.ImportName("billing.customer.example"))); err != nil {
+ t.Fatal(err)
+ }
+ if _, ok := publish()["billing.customer.example"]; ok {
+ t.Error("billing.customer.example still published after its import was removed")
+ }
+}
+
+// The real use (#1429): a fleet app's custom domain. The hub holds the fleet
+// app's forward row and its alias, and publishes them in its own edges file;
+// region edges terminate TLS from control/certs and relay to the hub. A
+// usable import in the hub's cache publishes the alias early, marked
+// dns_pointing false, served by the forward row.
+func TestEdgesFileHubPublishesAFleetAliasWithAnImportBeforeDNS(t *testing.T) {
+ setHubEnv(t, fpTunnel, "")
+ t.Setenv("PLATFORM_APPS_DOMAIN", "example.com")
+ t.Setenv("CARLOS_DNS01_ZONES", "")
+ withheldAliasSaid = sync.Map{}
+ reg := fpRegistry(t)
+ fpPutForward(t, reg, fpForward(fpEligible, "home", fpOwner))
+ const alias = "shop.customer.example"
+ if err := reg.UpsertAlias(registry.RouteAlias{Alias: alias, Host: fpEligible, Account: fpOwner, App: "shop", DNSStatus: "elsewhere"}); err != nil {
+ t.Fatal(err)
+ }
+ acme := filepath.Join(t.TempDir(), "acme")
+ s := release.NewDirStore(t.TempDir())
+ write := func() map[string]importHostView {
+ t.Helper()
+ var last []byte
+ if err := edgesFileWriteClaims(context.Background(), s, reg, edgesFile{Box: "hub", AcmeDir: acme}, "198.51.100.7", &last, false, nil, false, nil, nil); err != nil {
+ t.Fatal(err)
+ }
+ return publishedHosts(t, s, "hub")
+ }
+ if _, ok := write()[alias]; ok {
+ t.Fatal("without an import the fleet alias must wait for the pointing stamp")
+ }
+ writeImportEntry(t, acme, alias, fpOwner, time.Now().Add(60*24*time.Hour))
+ hosts := write()
+ if _, ok := hosts[fpEligible]; !ok {
+ t.Fatal("test bug: the hub must publish the eligible forward row")
+ }
+ h, ok := hosts[alias]
+ if !ok || h.Role != "home" || !h.Alias || h.TargetHost != fpEligible || h.DNSPointing == nil || *h.DNSPointing {
+ t.Fatalf("%s = %+v (published %v); want home, alias of %s, dns_pointing false", alias, h, ok, fpEligible)
+ }
+
+ // An import bound to another account publishes nothing early.
+ writeImportEntry(t, acme, alias, fpOther, time.Now().Add(60*24*time.Hour))
+ if _, ok := write()[alias]; ok {
+ t.Fatal("an import bound to another account published the fleet alias")
+ }
+}