carlos / platform Public

host: early publication needs the import's app to match too (#1429)

An alias with an imported certificate is published before it points
only when the binding names the alias row's account AND app. The app is
checked in host from the entry's binding (domains.ParseImport), after
domains.UsableImportedCert's file, key, name, date and account checks,
reading only the file that check examined. Tests add another app's
import, for a custom domain and for a fleet alias on a hub.
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
claude agent, operated by paul@keymail.dev pushed by paul@keymail.dev 49ff83e0c10d9737d8d085e5afcbf54a8a11e957 parent 86082f4
3 files changed, +74 −18
  • internal/host/edgesfile.go +4 −4
  • internal/host/edgesfile_import.go +45 −0
  • internal/host/edgesfile_import_test.go +25 −14
diff --git a/internal/host/edgesfile.go b/internal/host/edgesfile.go
index 70c6ea0fe..f7849e24f 100644
--- a/internal/host/edgesfile.go
+++ b/internal/host/edgesfile.go
@@ -833,9 +833,9 @@ func edgesFileWriteClaims(ctx context.Context, s release.Store, reg *registry.Re
// 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
+ // cache (importBoundTo: a regular <alias>+import file whose key
+ // matches, which names the alias, is in date, and whose binding
+ // Account and App are the alias row's). 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;
@@ -886,7 +886,7 @@ func edgesFileWriteClaims(ctx context.Context, s release.Store, reg *registry.Re
}
pointing := a.DNSStatus == "pointing"
preIssued := !pointing && ((dns01.Allows(a.Alias, a.Account) && domains.UsablePerHostCert(acmeDir, a.Alias, now)) ||
- domains.UsableImportedCert(acmeDir, a.Alias, a.Account, now))
+ importBoundTo(acmeDir, a.Alias, a.Account, a.App, 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.go b/internal/host/edgesfile_import.go
new file mode 100644
index 000000000..de291d493
--- /dev/null
+++ b/internal/host/edgesfile_import.go
@@ -0,0 +1,45 @@
+package host
+
+import (
+ "io"
+ "os"
+ "path/filepath"
+ "time"
+
+ "github.com/carlosframework/platform/internal/domains"
+)
+
+// importBoundTo reports whether acmeDir holds an imported certificate for
+// alias (#1429) that would serve right now and whose binding names both the
+// alias row's account AND its app: the edges-file writer's test for
+// publishing an alias before its DNS points here.
+//
+// domains.UsableImportedCert checks the file (a regular <alias>+import, not
+// a symlink), the key, the name, the dates and the account; the app is
+// checked here from the same entry's binding. The second read is opened
+// only if it is still the file that check examined, so a swap between the
+// two reads publishes nothing (the next pass decides again).
+func importBoundTo(acmeDir, alias, account, app string, now time.Time) bool {
+ if app == "" || !domains.UsableImportedCert(acmeDir, alias, account, now) {
+ return false
+ }
+ p := filepath.Join(acmeDir, domains.ImportName(alias))
+ before, err := os.Lstat(p)
+ if err != nil || !before.Mode().IsRegular() {
+ return false
+ }
+ f, err := os.Open(p)
+ if err != nil {
+ return false
+ }
+ defer f.Close()
+ if opened, err := f.Stat(); err != nil || !os.SameFile(before, opened) {
+ return false
+ }
+ raw, err := io.ReadAll(io.LimitReader(f, 1<<20))
+ if err != nil {
+ return false
+ }
+ b, _, err := domains.ParseImport(raw)
+ return err == nil && b.Account == account && b.App == app
+}
diff --git a/internal/host/edgesfile_import_test.go b/internal/host/edgesfile_import_test.go
index f9e4241de..99996d4a5 100644
--- a/internal/host/edgesfile_import_test.go
+++ b/internal/host/edgesfile_import_test.go
@@ -22,9 +22,9 @@ import (
// 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) {
+// the binding (bound to account and app), the PKCS#8 key, then the leaf,
+// valid until notAfter.
+func writeImportEntry(t *testing.T, acmeDir, host, account, app string, notAfter time.Time) {
t.Helper()
key, err := ecdsa.GenerateKey(elliptic.P256(), rand.Reader)
if err != nil {
@@ -40,7 +40,7 @@ func writeImportEntry(t *testing.T, acmeDir, host, account string, notAfter time
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})
+ 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)
}
@@ -89,18 +89,24 @@ func TestEdgesFilePublishesImportedAliasesBeforeDNS(t *testing.T) {
for _, a := range []struct {
alias, aliasAccount, importAccount string
notAfter time.Time
+ importApp string
}{
- {"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
+ {"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
+ {"otherapp.customer.example", "acct", "acct", future, "other"}, // bound to another app
} {
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)
+ app := a.importApp
+ if app == "" {
+ app = "app"
+ }
+ writeImportEntry(t, acme, a.alias, a.importAccount, app, a.notAfter)
}
}
publish := func() map[string]importHostView {
@@ -115,7 +121,7 @@ func TestEdgesFilePublishesImportedAliasesBeforeDNS(t *testing.T) {
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"} {
+ for _, absent := range []string{"otheracct.customer.example", "noimport.customer.example", "expired.customer.example", "wrongrow.customer.example", "otherapp.customer.example"} {
if _, ok := hosts[absent]; ok {
t.Errorf("%s must not be published before it points here", absent)
}
@@ -159,7 +165,7 @@ func TestEdgesFileHubPublishesAFleetAliasWithAnImportBeforeDNS(t *testing.T) {
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))
+ writeImportEntry(t, acme, alias, fpOwner, "shop", 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")
@@ -169,9 +175,14 @@ func TestEdgesFileHubPublishesAFleetAliasWithAnImportBeforeDNS(t *testing.T) {
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))
+ // An import bound to another account, or to another app of the same
+ // account, publishes nothing early.
+ writeImportEntry(t, acme, alias, fpOther, "shop", time.Now().Add(60*24*time.Hour))
if _, ok := write()[alias]; ok {
t.Fatal("an import bound to another account published the fleet alias")
}
+ writeImportEntry(t, acme, alias, fpOwner, "other", time.Now().Add(60*24*time.Hour))
+ if _, ok := write()[alias]; ok {
+ t.Fatal("an import bound to another app published the fleet alias")
+ }
}