carlos / platform Public

console: a domain's records to set are the CLI list's advice

domainRecordsToSet built every address's records with no wildcard and no
regional case, so a wildcard lost its _acme-challenge delegation and a
regional claim was given single-edge A records. domainAddress now carries
the claim (and its Wildcard and Regional), and both the page and the CLI
list's domainItem read one helper, claimDNSAdvice: pointing records with
the delegation, a regional claim's delegation alone, a pending claim's
proof.
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
claude agent, operated by paul@keymail.dev pushed by paul@keymail.dev d5cf8651bc2a0992f73f34d69a5ba63820e47a96 parent 66cb5b2
4 files changed, +190 −38
  • internal/console/accountdomains.go +6 −1
  • internal/console/accountdomainspage.go +27 −19
  • internal/console/accountdomainspage_test.go +125 −0
  • internal/console/apidomains.go +32 −18
diff --git a/internal/console/accountdomains.go b/internal/console/accountdomains.go
index d0a893a17..f98279b70 100644
--- a/internal/console/accountdomains.go
+++ b/internal/console/accountdomains.go
@@ -17,6 +17,10 @@ type domainAddress struct {
Host, App string
AppInTrash bool
State string // the attach state (live, pending-dns, ...), as the app's Domains tab shows it
+ // Wildcard and Regional are the claim's: a wildcard needs its
+ // certificate's delegation record, a regional claim points per region.
+ Wildcard, Regional bool
+ claim domains.Claim // the claim the address is, for its DNS advice (claimDNSAdvice)
}
// domainCard is one registrable domain the account uses (spec §11.3): bought
@@ -173,7 +177,8 @@ func (s *Server) domainCardAddresses(ctx context.Context, acct *Account, only st
continue
}
cd := card(d)
- cd.Addresses = append(cd.Addresses, domainAddress{Host: host, App: c.App, AppInTrash: !live[c.App]})
+ cd.Addresses = append(cd.Addresses, domainAddress{Host: host, App: c.App, AppInTrash: !live[c.App],
+ Wildcard: c.Wildcard, Regional: c.Regional(), claim: c})
byApp[c.App] = append(byApp[c.App], slot{cd, len(cd.Addresses) - 1})
}
for app, rows := range byApp {
diff --git a/internal/console/accountdomainspage.go b/internal/console/accountdomainspage.go
index 62ad24f5f..12567e9d1 100644
--- a/internal/console/accountdomainspage.go
+++ b/internal/console/accountdomainspage.go
@@ -394,7 +394,7 @@ func (s *Server) domainPage(ctx context.Context, acct *Account, owner bool, c do
if t := domainLiveTile(cv.live, cv.total); t != nil {
v.Tiles = append(v.Tiles, *t)
}
- v.Records, v.Guidance = s.domainRecordsToSet(ctx, acct, c.Addresses)
+ v.Records, v.Guidance = s.domainRecordsToSet(ctx, c.Addresses)
v.RecordsNote = domainsFill(domainsPageCopy.RecordsNote, "{domain}", c.Domain)
return v
}
@@ -440,39 +440,47 @@ func domainExpiresTile(c domainCardView, now time.Time) domainTile {
return t
}
-// domainNeedsRecords is a state whose records may still be missing at the
-// other registrar: DNS not seen pointing here yet, or not checked yet.
-func domainNeedsRecords(state string) bool {
+// domainDNSStatus is the DNS answer an attach state implies, for
+// claimDNSAdvice: the page has each address's state, not its reading.
+// Pointing states list nothing to point; a failed lookup blames nobody;
+// every other state (no answer, a wrong answer, not checked yet, awaiting
+// its proof) is told what to create.
+func domainDNSStatus(state string) string {
switch state {
- case StateLive, StateIssuingCert, StateFailed, StateRegional:
- return false
+ case StateLive, StateIssuingCert, StateFailed:
+ return "pointing"
+ case StateUnknown:
+ return "unresolved"
+ case StateMisdirected:
+ return "elsewhere"
}
- return true
+ return ""
}
// domainRecordsToSet is the records a domain registered elsewhere still
-// needs, for its addresses not yet live: domainRecords, the structured form
-// of domainGuidance, from the deployment's own targets, with an unproven
-// address's proof first. A host whose advice has no records (no edge
-// addresses known) gets domainGuidance's sentence instead.
-func (s *Server) domainRecordsToSet(ctx context.Context, acct *Account, addrs []domainAddress) ([]domainRecordRow, []string) {
+// needs at the other registrar: each address's claimDNSAdvice, the advice
+// the CLI's domains list gives for the same claim (pointing records with a
+// wildcard's delegation, or for a regional claim its delegation alone, and
+// a pending claim's proof). An address whose advice is a sentence with no
+// records (no edge addresses known), or a regional one (its pointing is per
+// region), also gets the sentence.
+func (s *Server) domainRecordsToSet(ctx context.Context, addrs []domainAddress) ([]domainRecordRow, []string) {
var rows []domainRecordRow
var guidance []string
var targets *DNSTargets
for _, a := range addrs {
- if a.AppInTrash || !domainNeedsRecords(a.State) {
+ if a.AppInTrash {
continue
}
if targets == nil {
t := s.dnsTargets(ctx)
targets = &t
}
- recs := domainRecords(a.Host, *targets, false, "")
- if len(recs) == 0 {
- guidance = append(guidance, domainGuidance(a.Host, *targets))
- }
- if a.State == StateUnverified {
- recs = append([]dnsRecord{s.domainChallenge(a.Host, acct.Sqid)}, recs...)
+ c := a.claim
+ c.Host = a.Host
+ sentence, _, recs, _ := s.claimDNSAdvice(ctx, c, domainDNSStatus(a.State), *targets)
+ if sentence != "" && (len(recs) == 0 || c.Regional()) {
+ guidance = append(guidance, sentence)
}
first, last := "", ""
for _, r := range recs {
diff --git a/internal/console/accountdomainspage_test.go b/internal/console/accountdomainspage_test.go
index e657e6e05..8fcfdb254 100644
--- a/internal/console/accountdomainspage_test.go
+++ b/internal/console/accountdomainspage_test.go
@@ -5,11 +5,15 @@ package console
import (
"context"
+ "encoding/json"
"net/http"
"regexp"
+ "slices"
"strings"
"testing"
"time"
+
+ "github.com/carlosframework/platform/internal/domains"
)
// adSignIn is a fresh browser signed in as address.
@@ -521,3 +525,124 @@ func TestDomainPageMemberSeesRegistrantNameOnly(t *testing.T) {
}
}
}
+
+// adPutClaim stores c (Account and App already set) as written.
+func adPutClaim(t *testing.T, fx *consoleFixture, c domains.Claim) {
+ t.Helper()
+ c.CreatedAt = time.Now().UTC().Format(time.RFC3339)
+ b, err := json.Marshal(c)
+ if err != nil {
+ t.Fatal(err)
+ }
+ if _, err := fx.rel.Put(context.Background(), domains.ClaimKey(c.Host), b, ""); err != nil {
+ t.Fatal(err)
+ }
+}
+
+// adRecordsTable is the domain page's records-to-set table, one
+// "name type value" line per row.
+func adRecordsTable(t *testing.T, fx *consoleFixture, c *http.Client, acct *Account, domain string) []string {
+ t.Helper()
+ status, body := adGet(t, fx, c, acct, "/domains/"+domain)
+ if status != http.StatusOK {
+ t.Fatalf("GET %s = %d", domain, status)
+ }
+ _, after, ok := strings.Cut(mainOf(t, body), "<h2>"+domainsPageCopy.RecordsToSet+"</h2>")
+ if !ok {
+ t.Fatalf("no records to set:\n%s", mainOf(t, body))
+ }
+ table, _, _ := strings.Cut(after, "</table>")
+ row := regexp.MustCompile(`<td>(?:<span class="small">` + domainsPageCopy.Or + `</span> )?<code>([^<]*)</code></td>\s*<td>([^<]*)</td>\s*<td><code>([^<]*)</code></td>`)
+ var out []string
+ for _, m := range row.FindAllStringSubmatch(table, -1) {
+ out = append(out, m[1]+" "+m[2]+" "+m[3])
+ }
+ return out
+}
+
+// adCLIRecords is what the CLI's domains list tells the member to create
+// for c, unread (no box has reported on it).
+func adCLIRecords(t *testing.T, fx *consoleFixture, c domains.Claim) []string {
+ t.Helper()
+ ctx := context.Background()
+ item := fx.srv.domainItem(ctx, c, nil, nil, fx.srv.dnsTargets(ctx), time.Now(), false)
+ var out []string
+ for _, r := range item.Records {
+ out = append(out, r.Name+" "+r.Type+" "+r.Value)
+ }
+ return out
+}
+
+// A wildcard claim's certificate needs the _acme-challenge delegation, so
+// the page lists it with the pointing records, as the CLI list does.
+func TestDomainPageWildcardListsAcmeDelegation(t *testing.T) {
+ fx, acct := adFixture(t, consoleFixtureOptions{})
+ fx.srv.cfg.EdgeIPs = []string{"192.0.2.10"}
+ fx.srv.delegationZone = "acme.oncarlos.test"
+ adApp(t, fx, acct, "a")
+ claim := domains.Claim{Schema: 1, Host: "docs.example.org", Account: acct.Sqid, App: "a", Route: "r.a", Wildcard: true}
+ adPutClaim(t, fx, claim)
+ c := adSignIn(t, fx, adOwner(acct))
+
+ got := adRecordsTable(t, fx, c, acct, "example.org")
+ want := []string{
+ "docs.example.org A 192.0.2.10",
+ "_acme-challenge.docs.example.org CNAME _acme-challenge.docs.example.org.acme.oncarlos.test",
+ }
+ if !slices.Equal(got, want) {
+ t.Fatalf("records = %q, want %q", got, want)
+ }
+ if cli := adCLIRecords(t, fx, claim); !slices.Equal(got, cli) {
+ t.Errorf("page records %q differ from the CLI list's %q", got, cli)
+ }
+}
+
+// A regional claim points per region (the placements read), so the page
+// lists only its delegation, and a pending one its proof, never the
+// single-edge records, as the CLI list does. A stored regional claim is
+// never pending (ValidPlacements refuses one, and SetClaimPlacements clears
+// the flag), so the page is driven with a stored wildcard regional claim
+// and the pending case through the page's own record builder.
+func TestDomainPageRegionalPendingListsDelegationOnly(t *testing.T) {
+ fx, acct := adFixture(t, consoleFixtureOptions{})
+ fx.srv.cfg.EdgeIPs = []string{"192.0.2.10"}
+ fx.srv.delegationZone = "acme.oncarlos.test"
+ adApp(t, fx, acct, "a")
+ ctx := context.Background()
+ if _, err := domains.SetClaimPlacements(ctx, fx.rel, domains.Claim{Host: "shop.example.org", Account: acct.Sqid, App: "a",
+ Route: "a-ie.oncarlos.test", Wildcard: true, CreatedAt: time.Now().UTC().Format(time.RFC3339),
+ Placements: []domains.Placement{{Region: "", Host: "a-ie.oncarlos.test"}}}, nil, ""); err != nil {
+ t.Fatal(err)
+ }
+ stored, err := domains.GetClaim(ctx, fx.rel, "shop.example.org")
+ if err != nil || !stored.Regional() || !stored.Wildcard {
+ t.Fatalf("stored claim %+v %v", stored, err)
+ }
+ c := adSignIn(t, fx, adOwner(acct))
+ delegation := "_acme-challenge.shop.example.org CNAME _acme-challenge.shop.example.org.acme.oncarlos.test"
+
+ got := adRecordsTable(t, fx, c, acct, "example.org")
+ if want := []string{delegation}; !slices.Equal(got, want) {
+ t.Fatalf("records = %q, want %q", got, want)
+ }
+ if cli := adCLIRecords(t, fx, *stored); !slices.Equal(got, cli) {
+ t.Errorf("page records %q differ from the CLI list's %q", got, cli)
+ }
+
+ // Pending: the delegation and the proof, still no pointing record.
+ pending := *stored
+ pending.Pending = true
+ rows, _ := fx.srv.domainRecordsToSet(ctx, []domainAddress{{Host: pending.Host, App: "a", State: StateUnverified,
+ Wildcard: true, Regional: true, claim: pending}})
+ proof := fx.srv.domainChallenge(pending.Host, acct.Sqid)
+ var built []string
+ for _, r := range rows {
+ built = append(built, r.Name+" "+r.Type+" "+r.Value)
+ }
+ if want := []string{delegation, proof.Name + " TXT " + proof.Value}; !slices.Equal(built, want) {
+ t.Fatalf("pending regional records = %q, want %q", built, want)
+ }
+ if cli := adCLIRecords(t, fx, pending); !slices.Equal(built, cli) {
+ t.Errorf("pending records %q differ from the CLI list's %q", built, cli)
+ }
+}
diff --git a/internal/console/apidomains.go b/internal/console/apidomains.go
index 18bd3d167..503f47511 100644
--- a/internal/console/apidomains.go
+++ b/internal/console/apidomains.go
@@ -1507,6 +1507,28 @@ func (s *Server) domainItem(ctx context.Context, c domains.Claim, readings map[s
}
item.State, item.Reason, item.Detail = claimState(c, reading, seen, warm, now)
item.Verified = !c.Pending
+ var regionalDetail string
+ item.Guidance, regionalDetail, item.Records, item.CNAMETarget = s.claimDNSAdvice(ctx, c, item.DNSStatus, targets)
+ if c.Regional() {
+ item.Detail = regionalDetail
+ }
+ if delegation {
+ if s.delegationCNAMEDelegated(ctx, c.Host) {
+ item.DelegationStatus = "delegated"
+ } else {
+ item.DelegationStatus = "missing"
+ }
+ }
+ return item
+}
+
+// claimDNSAdvice is what a claim's member is told to create in DNS, as a
+// sentence and as the same advice in records, for a claim whose DNS answer
+// is dnsStatus (an alias reading's DNSStatus; "" when none). The domains
+// list (domainItem) and a domain's own page (domainRecordsToSet) both read
+// it, so they never tell a member two different things. regionalDetail is
+// a regional claim's state detail, "" otherwise.
+func (s *Server) claimDNSAdvice(ctx context.Context, c domains.Claim, dnsStatus string, targets DNSTargets) (guidance, regionalDetail string, records []dnsRecord, cname string) {
// "unresolved" means the lookup FAILED (our resolver, not the customer's
// record) — pointing them at "create this record" guidance would blame
// them for our outage. Only "" (no answer yet) and "elsewhere" (a real,
@@ -1517,34 +1539,26 @@ func (s *Server) domainItem(ctx context.Context, c domains.Claim, readings map[s
// gives: the single-edge advice and its records would send every
// region's visitors to every edge. A wildcard's delegation CNAME is
// not a pointing record, and stays: without it the delegation check
- // below can say "missing" with nothing to create.
- 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)
+ // can say "missing" with nothing to create.
+ guidance, regionalDetail = s.configuredRegionalGuidance(ctx, c)
+ records = delegationRecords(c.Host, c.Wildcard, s.delegationZone)
+ case dnsStatus != "pointing" && dnsStatus != "unresolved":
+ guidance = domainGuidance(c.Host, targets)
// 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.CNAMETarget = cnameTarget(c.Host, targets)
+ records = domainRecords(c.Host, targets, c.Wildcard, s.delegationZone)
+ cname = cnameTarget(c.Host, targets)
}
if c.Pending {
// The proof record, in BOTH forms, under the same lockstep rule as
// the pointing advice above: a member reading the sentence and an
// app reading the records must be told to create the same thing.
v := s.domainChallenge(c.Host, c.Account)
- item.Guidance = verifyGuidance(v) + " " + item.Guidance
- item.Guidance = strings.TrimSpace(item.Guidance)
- item.Records = append(item.Records, v)
- }
- if delegation {
- if s.delegationCNAMEDelegated(ctx, c.Host) {
- item.DelegationStatus = "delegated"
- } else {
- item.DelegationStatus = "missing"
- }
+ guidance = strings.TrimSpace(verifyGuidance(v) + " " + guidance)
+ records = append(records, v)
}
- return item
+ return guidance, regionalDetail, records, cname
}
// handleAPIDomainGet answers ONE hostname — the per-host read (#299 §2e).