carlos / platform Public

cert import (#1429): design rev 2 after spec round 1

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
claude agent, operated by paul@keymail.dev pushed by paul@keymail.dev 20b0dc8c2c1464a1b09c112e7426335fead966e7 parent b467495
4 files changed, +428 −139
  • docs/superpowers/reviews/cert-import-1429/ASTRA-FINDINGS-SPEC-R1.md +53 −0
  • docs/superpowers/reviews/cert-import-1429/FABLE-FINDINGS-SPEC-R1.md +72 −0
  • docs/superpowers/reviews/cert-import-1429/REVIEW-BRIEF-SPEC-R2.md +102 −0
  • docs/superpowers/specs/2026-11-25-cert-import-1429-design.md +201 −139

CI cancelled — superseded by a newer push — run details

CI log
=== gate ===
go: downloading go1.26.10 (linux/arm64)
go version go1.26.10 linux/arm64
opentofu: arm64, tofu 1.13.9, aws 6.73.0, archive 2.8.1
  tofu: downloading https://carlos-ci-mirror-640012953448.s3.eu-west-1.amazonaws.com/opentofu/tofu_1.13.9_linux_arm64.tar.gz
  tofu: downloaded, digest verified
  aws: downloading https://carlos-ci-mirror-640012953448.s3.eu-west-1.amazonaws.com/opentofu/terraform-provider-aws_6.73.0_linux_arm64.zip
  aws: downloaded, digest verified
  archive: downloading https://carlos-ci-mirror-640012953448.s3.eu-west-1.amazonaws.com/opentofu/terraform-provider-archive_2.8.1_linux_arm64.zip
  archive: downloaded, digest verified
  installed in /tmp/carlos-opentofu-G2uFh7
.amadan/test-gate.sh
go: downloading github.com/aws/aws-sdk-go-v2 v1.44.0
go: downloading github.com/aws/aws-sdk-go-v2/service/cloudwatch v1.68.0
go: downloading github.com/aws/aws-sdk-go-v2/service/costexplorer v1.67.5
go: downloading github.com/aws/aws-sdk-go-v2/service/s3 v1.105.0
go: downloading github.com/aws/smithy-go v1.28.1
go: downloading github.com/benbjohnson/litestream v0.5.14
go: downloading github.com/superfly/ltx v0.5.1
go: downloading golang.org/x/net v0.62.0
go: downloading modernc.org/sqlite v1.55.0
go: downloading golang.org/x/crypto v0.58.0
go: downloading github.com/aws/aws-sdk-go-v2/service/acm v1.45.0
go: downloading github.com/aws/aws-sdk-go-v2/service/ec2 v1.324.0
go: downloading github.com/aws/aws-sdk-go-v2/service/iam v1.58.2
go: downloading github.com/aws/aws-sdk-go-v2/service/resourcegroupstaggingapi v1.37.0
go: downloading github.com/aws/aws-sdk-go-v2/service/route53 v1.64.1
go: downloading golang.org/x/sys v0.49.0
go: downloading golang.org/x/mod v0.41.0
go: downloading github.com/aws/aws-sdk-go-v2/service/sesv2 v1.66.6
go: downloading github.com/pion/logging v0.2.4
go: downloading github.com/pion/stun/v3 v3.1.5
go: downloading github.com/pion/turn/v4 v4.1.4
go: downloading github.com/pierrec/lz4/v4 v4.1.22
go: downloading github.com/pion/randutil v0.1.0
go: downloading github.com/pion/transport/v4 v4.0.2
go: downloading github.com/pion/dtls/v3 v3.1.4
go: downloading github.com/klauspost/compress v1.20.2
go: downloading github.com/prometheus/client_golang v1.17.0
go: downloading github.com/lmittmann/tint v1.1.3
go: downloading github.com/aws/aws-sdk-go-v2/feature/s3/manager v1.20.18
go: downloading golang.org/x/sync v0.24.0
go: downloading github.com/wlynxg/anet v0.0.5
go: downloading github.com/prometheus/client_model v0.5.0
go: downloading github.com/prometheus/procfs v0.12.0
go: downloading github.com/prometheus/common v0.45.0
go: downloading google.golang.org/protobuf v1.36.10
go: downloading golang.org/x/text v0.43.0
go: downloading github.com/matttproud/golang_protobuf_extensions/v2 v2.0.0
go: downloading golang.org/x/crypto/x509roots/fallback v0.0.0-20260209214922-2f26647a795e
go: downloading github.com/klauspost/compress v1.20.2
go: downloading modernc.org/sqlite v1.55.0
go: downloading github.com/aws/aws-sdk-go-v2/service/ecs v1.91.0
go: downloading github.com/pierrec/lz4/v4 v4.1.22
go: downloading modernc.org/libc v1.74.1
go: downloading modernc.org/libc v1.74.1
go: downloading modernc.org/mathutil v1.7.1
go: downloading modernc.org/mathutil v1.7.1

amadan: job cancelled — a newer push superseded it
diff --git a/docs/superpowers/reviews/cert-import-1429/ASTRA-FINDINGS-SPEC-R1.md b/docs/superpowers/reviews/cert-import-1429/ASTRA-FINDINGS-SPEC-R1.md
new file mode 100644
index 000000000..926e7aa1e
--- /dev/null
+++ b/docs/superpowers/reviews/cert-import-1429/ASTRA-FINDINGS-SPEC-R1.md
@@ -0,0 +1,53 @@
+Reviewed commit `b467495d7cc9a074b27580eccab66023c7143b1c`, spec round 1. No files edited or test suites run.
+
+1. **P1 — Removal: the post-write claim check cannot prevent an orphaned import.**
+
+ **Evidence:** The [removal protocol](/home/paulca/amadan.net/carlos/platform-cert-import-1429/docs/superpowers/specs/2026-11-25-cert-import-1429-design.md:175) deletes the claim before the import and checks ownership after publishing. [`putCAS`](/home/paulca/amadan.net/carlos/platform-cert-import-1429/internal/edge/certsync.go:388) conditions only the certificate object’s revision. The proposed serving and early-publication checks carry no claim identity.
+
+ **Failure scenario:** An import validates account A’s claim, then pauses. A detaches completely, and B attaches the name. The original import resumes and writes its certificate. If the console stops before the re-read or cleanup succeeds, the import remains indefinitely. B’s alias can then use A’s import to obtain early relay without an operator authorizing B. Separately, delayed detach cleanup can delete a subsequent owner’s replacement import.
+
+ **Fix:** Bind each import to a specific claim acquisition and require that binding at serving and early-publication time. Make cleanup conditional on the observed import revision, and define recovery for interrupted operations; a post-write check alone is insufficient.
+
+ **Fault family:** Certificate authority must remain bound to the claim acquisition that authorized it.
+
+2. **P1 — Serving: incompatible-client fallback can order before DNS points.**
+
+ **Evidence:** The [handshake rule](/home/paulca/amadan.net/carlos/platform-cert-import-1429/docs/superpowers/specs/2026-11-25-cert-import-1429-design.md:123) passes through when the client cannot use the import. [`issuerHostPolicyAt`](/home/paulca/amadan.net/carlos/platform-cert-import-1429/internal/edge/certsync.go:222) applies `AliasNotPointing` only when `!e.Allowed(host)`. [`Allowed`](/home/paulca/amadan.net/carlos/platform-cert-import-1429/internal/edge/edge.go:1795) accepts a local exact alias.
+
+ **Failure scenario:** The issuer also hosts the alias. An ECDSA import exists, DNS still points elsewhere, and an RSA-only client connects. The import wrapper falls through; the local alias passes HostPolicy; autocert orders an RSA certificate. If an ordinary cached certificate exists instead, autocert can load it and arm renewal before pointing.
+
+ **Fix:** Enforce the pre-pointing issuance refusal for local aliases as well as remote ones, before autocert can load or order a certificate. Test an issuer that is also the home box, including incompatible hellos and ordinary cached entries.
+
+ **Fault family:** Pre-pointing imports must not allow handshakes to initiate issuance or arm renewal.
+
+3. **P1 — Retirement: one ordinary certificate does not replace every supported import key type.**
+
+ **Evidence:** The [retirement rule](/home/paulca/amadan.net/carlos/platform-cert-import-1429/docs/superpowers/specs/2026-11-25-cert-import-1429-design.md:151) accepts either ordinary cache entry. [`warmHello`](/home/paulca/amadan.net/carlos/platform-cert-import-1429/internal/edge/certwarm.go:689) deliberately obtains ECDSA. The mirror’s [`certificate`](/home/paulca/amadan.net/carlos/platform-cert-import-1429/internal/edge/certsync.go:1682) tries both cache names, while [`usableFor`](/home/paulca/amadan.net/carlos/platform-cert-import-1429/internal/edge/certsync.go:1708) checks expiry and hostname, not client compatibility.
+
+ **Failure scenario:** An RSA import successfully serves RSA-only clients. After DNS moves, the warm obtains ECDSA, and the sweep removes the import. An RSA-only client reaching a non-issuer receives the ECDSA fallback and fails TLS; that edge cannot order the missing RSA certificate. The design’s unconditional CARLOS preference can cause the same failure even before retirement.
+
+ **Fix:** Select certificates using compatibility with the actual hello. Keep the import until compatible CARLOS replacements exist; when replacing an RSA import, proactively obtain the necessary RSA entry before retirement. Test the transition on a non-issuer.
+
+ **Fault family:** Retirement must preserve the client coverage provided by the import.
+
+4. **P2 — Serving: the import wrapper needs an explicit ACME challenge bypass.**
+
+ **Evidence:** The [new wrapper’s rules](/home/paulca/amadan.net/carlos/platform-cert-import-1429/docs/superpowers/specs/2026-11-25-cert-import-1429-design.md:120) omit ALPN challenge handling. Both the existing [wildcard wrapper](/home/paulca/amadan.net/carlos/platform-cert-import-1429/internal/edge/wildcard.go:1107) and [mirror wrapper](/home/paulca/amadan.net/carlos/platform-cert-import-1429/internal/edge/certsync.go:1609) explicitly preserve it. Autocert v0.58.0 [tries `tls-alpn-01` first](/home/paulca/go/pkg/mod/golang.org/x/crypto@v0.58.0/acme/autocert/autocert.go:770).
+
+ **Failure scenario:** During the first post-move order, a compatible ACME validation hello meets the import wrapper before the mirror. It receives the imported leaf instead of the challenge certificate. Validation fails and autocert must attempt another order using HTTP-01.
+
+ **Fix:** Pass an `acme-tls/1`-only hello directly to the inner chain before ordinary certificate selection. Add a challenge-handshake test while an import is present.
+
+ **Fault family:** Ordinary TLS certificate selection must not intercept ACME validation.
+
+5. **P2 — Replacement: ordinary mirror reconciliation can retain a superseded import on disk.**
+
+ **Evidence:** The [mirror changes](/home/paulca/amadan.net/carlos/platform-cert-import-1429/docs/superpowers/specs/2026-11-25-cert-import-1429-design.md:115) treat imports like other entries, while [re-import replaces the object](/home/paulca/amadan.net/carlos/platform-cert-import-1429/docs/superpowers/specs/2026-11-25-cert-import-1429-design.md:163). [`reconcileLocal`](/home/paulca/amadan.net/carlos/platform-cert-import-1429/internal/edge/certsync.go:1539) preserves the existing local certificate whenever its expiry is equal or later.
+
+ **Failure scenario:** An operator replaces an import with a different key or chain whose expiry is unchanged or earlier. The mirror serves the replacement from memory but retains the previous import on disk. After a restart during a bucket outage, fallback serves the superseded material.
+
+ **Fix:** Reconcile `+import` entries by authoritative object identity, not maximum expiry. Replace differing local bytes and invalidate any parsed local cache. Test equal-expiry and shorter-expiry replacements followed by restart with the bucket unavailable.
+
+ **Fault family:** Local fallback must preserve the latest accepted import replacement.
+
+**NOT READY**
\ No newline at end of file
diff --git a/docs/superpowers/reviews/cert-import-1429/FABLE-FINDINGS-SPEC-R1.md b/docs/superpowers/reviews/cert-import-1429/FABLE-FINDINGS-SPEC-R1.md
new file mode 100644
index 000000000..065b5c41f
--- /dev/null
+++ b/docs/superpowers/reviews/cert-import-1429/FABLE-FINDINGS-SPEC-R1.md
@@ -0,0 +1,72 @@
+# Review: imported certificates design (#1429), spec round 1
+
+No P1. Six P2s and six P3s. The mixed-fleet backfill claim, the warm's blindness to the import and the old sweep leaving `+import` alone all check out against the code.
+
+## P2
+
+**P2-1. Handshake layer swallows tls-alpn-01 validations (How edges serve it §2; After the DNS move)**
+- **Problem:** the layer sits outside `mirror.wrapGetCertificate` and serves the import for "an exact SNI with no usable CARLOS entry". The `acme-tls/1` pass-through lives inside the mirror wrap, so the CA's validation hello gets the import instead of the token cert.
+- **Evidence:** `internal/edge/certsync.go:1609-1621` (ALPN branch), `internal/edge/edge.go:5160-5176` (chain order), autocert v0.58.0 `autocert.go:770-777` (tls-alpn-01 is tried first), `certsync.go:1911-1915` (a failed validation is a whole failed order).
+- **Failure:** after the move, the warm's first order for each of the ~70 names fails tls-alpn-01 on every edge and only then falls back to HTTP-01. That is one burned validation per name against the shared account, and slower issuance.
+- **Fix:** the layer passes through first when `SupportedProtos` is exactly `[acme.ALPNProto]`. Add that case to the handshake tests and make the end-to-end test's CA use tls-alpn-01.
+- **Family:** the import must be invisible to issuance.
+
+**P2-2. An import is bound to a hostname, not to the claim that authorized it (Removal; Who may import)**
+- **Problem:** only "the detach door" deletes the import, after the claim, with no retry. The claim is deleted through several other paths, and neither the edges-file writer nor the handshake layer checks who holds the name now.
+- **Evidence:** claim deletes at `internal/console/apidomains.go:1285-1289`, `internal/console/appdomains.go:136` → `domainattach.go:498`, `domainattach.go:716` and `:834` (attach rollbacks), `domaincatchall.go:179`; the unconditional delete at `internal/domains/claims.go:858`. The writer's early-publish test is by name and disk only, `internal/host/edgesfile.go:880`.
+- **Failure:** a browser detach, or an API detach whose second delete fails, or an import door that dies between its write and its re-read, leaves `control/certs/<host>+import` behind. Account B then attaches the name: every edge serves the old operator's certificate for B's host and B's alias is relayed before pointing, though no operator imported for B.
+- **Fix:**
+ - Delete the import in the shared claim-delete core (`detachDomainClaim` and `DetachClaimAt`), not in one door.
+ - Have a newly created claim delete any `<host>+import`.
+ - Have the issuer sweep delete an import whose host has been outside `DeployedHosts` for N passes.
+ - Have the writer require the alias row's account to match an account recorded with the import.
+- **Family:** authorization follows the claim (brief check 1 and check 5).
+
+**P2-3. Three different meanings of "usable CARLOS entry" (gate 4, handshake layer, retirement)**
+- **Problem:** gate 4 refuses only if a CARLOS entry is in date for more than 7 days (spec lines 42-46). The layer yields to any in-date entry (lines 123-126). The sweep retires on any usable entry (lines 151-153).
+- **Evidence:** autocert never deletes, and the sweep keeps entries until 30 days past expiry (`internal/edge/certsweep.go:158-173`), so a leftover `<host>` entry from an earlier attachment with a few days left is realistic.
+- **Failure:** such an entry passes gate 4, then beats the import at the handshake, and the sweep deletes the import on its next pass. Days later the leftover expires with DNS still elsewhere and nothing serves the name.
+- **Second case:** retirement can land in the same listing in which a gated edge first sees the new CARLOS entry. If that one Get fails there is no previous copy to carry (`certsync.go:932-944`), so that edge has neither certificate for a poll.
+- **Fix:** one shared predicate. Retire only when the alias is pointing, the CARLOS leaf outlasts the 7-day floor (or the import), and the CARLOS object is at least a few minutes old (`ListMod` already gives the stamp, `certsweep.go:112`).
+- **Family:** never delete the only thing serving a name (check 6).
+
+**P2-4. The local-delete rule needs its mechanism stated (How edges serve it §1; Removal; Rollout)**
+- **Problem:** "absent from a successful listing" is right, but the spec does not say what the rule reads, and its rollout paragraph understates what old boxes do with `+import` objects.
+- **Evidence:**
+ - A key that is listed but whose Get failed with no previous copy is absent from the snapshot (`certsync.go:932-944`). A rule keyed on `snap.entries` deletes a live import.
+ - `m.synced` is empty after a restart (`certsync.go:668`), so only a scan of the cache directory for `*+import` finds stale files.
+ - An old box does more than "parse into a map nothing old reads": `syncLocal` writes the key to its disk and never deletes it (`certsync.go:1467-1486`).
+ - With the change watch armed, a mirror only lists when the `control/certs` generation moves (`certsync.go:787-794`). A lost bump delays a removal to the 30-minute backstop (`internal/release/changewatch.go:17`), not "30 s".
+- **Failure:** a removed key lingers on old boxes' disks until they upgrade, and an upgraded box that boots during a bucket outage serves it from the local fallback.
+- **Fix:** key the delete on the listing's key set, by directory scan, on every successful listing (full and changed-only). Say in Rollout that old boxes persist the key and when it goes. Have the remove door retry or surface a failed bump.
+- **Family:** removal sticks everywhere (check 4).
+
+**P2-5. Apps homed on a box with no cert mirror are not addressed**
+- **Problem:** the design assumes the home box mirrors `control/certs/`.
+- **Evidence:** a box with no deployment store has no mirror and no gate (`certsync.go:128-142`, `:604-607`), so it never holds `<host>+import` and its writer can never early-publish (`edgesfile.go:868-880`).
+- **Failure:** if the Tito Pro app is homed on a fleet box without the bucket, the import returns 200 and does nothing before the move. I did not trace how fleet-homed aliases reach the shared edges, so this is a gap in the spec rather than a proven break.
+- **Fix:** say where the home box must be, and have the door refuse (or `domains get` report) when it cannot serve the import.
+- **Family:** an accepted import must take effect.
+
+**P2-6. Mixed fleet is not inert once an operator imports (Rollout)**
+- **Problem:** the listed properties hold, but an old edge does not serve the import and an old home agent does not publish early (`edgesfile.go:880`).
+- **Failure:** an import during a roll gives TLS errors on whichever old edges DNS lands on, which is the outage the feature exists to prevent.
+- **Fix:** state the precondition (every edge and the home agent on the new version) and show per-edge serving in `domains get`, or gate the door on fleet version.
+- **Family:** rollout (check 7).
+
+## P3
+
+- **Overclaim in §2.** "Autocert is never asked about the name by a real handshake" is false for hellos the import cannot serve (RSA-only client with an ECDSA import, expired import) on a home box that is also the issuer. `Allowed(host)` is true there, so `certsync.go:222` does not refuse. This is today's behaviour for any not-pointing alias; reword the sentence.
+- **Lookup order.** Look the import up in the snapshot first. As written, every unknown SNI pays the local-cache read before the import map is consulted.
+- **Key-type test.** Use `hello.SupportsCertificate` for "key type the client supports". `helloSupportsECDSA` only knows P-256 (`certsync.go:1734-1744`), and P-384 imports are allowed.
+- **Stored bytes.** Store the re-encoded verified chain and key, not the operator's bytes, so unused certificates and stray text never reach `control/certs/`.
+- **RSA size.** Cap RSA at 4096. An 8192-bit key is a per-handshake CPU cost on every edge.
+- **Console as a writer.** The console becomes a new writer of `control/certs/`. I found no IAM for the prefix under `infra/` to check; confirm put and delete rights and amend the writer map.
+
+Verified as claimed:
+- Old-binary backfill never republishes `<host>+import` (`certsync.go:1321`, `:1368-1372`).
+- The warm calls `perHostCert` and its set excludes not-pointing names (`edge.go:5167`, `:5212`; `internal/edge/homemap.go:762`).
+- The old sweep leaves `+import` alone until 30 days past expiry (`certsweep.go:131-135`).
+- `golang.org/x/crypto/x509roots/fallback/bundle` is already in `go.mod:32`.
+
+**Verdict: READY AFTER FIXES**
diff --git a/docs/superpowers/reviews/cert-import-1429/REVIEW-BRIEF-SPEC-R2.md b/docs/superpowers/reviews/cert-import-1429/REVIEW-BRIEF-SPEC-R2.md
new file mode 100644
index 000000000..5fb02604e
--- /dev/null
+++ b/docs/superpowers/reviews/cert-import-1429/REVIEW-BRIEF-SPEC-R2.md
@@ -0,0 +1,102 @@
+# Review brief: imported certificates design (#1429), spec round 2 of 3
+
+Repo carlos/platform, branch `cert-import-1429`. Under review:
+`docs/superpowers/specs/2026-11-25-cert-import-1429-design.md` at the
+commit named in your prompt. Authorities, all MERGED on main: #1293's
+DNS-01 pre-issue (internal/edge/precert.go, dns01scope.go) and its
+alias-before-pointing follow-up 49bcf97 (internal/host/edgesfile.go
+edgesFileWriteClaims, internal/edge/homemap.go AliasNotPointing,
+internal/edge/certsync.go issuerHostPolicyAt, internal/domains/certusable.go);
+the cert mirror and backfill (internal/edge/certsync.go), the cert warm
+and sweep (internal/edge/certwarm.go, certsweep.go), the console domains
+doors (internal/console/apidomains.go, domainpolicy.go
+principalPlatformOperator), autocert in golang.org/x/crypto v0.58.0.
+
+You are an independent reviewer. Read the spec, then the code it names,
+and check every claim against that code. Two reviewers (Astra and
+Fable) read this independently.
+
+## Context
+
+Tito Pro moves ~70 customer-owned custom domains (customers' DNS zones,
+so no DNS-01) from Kubernetes cert-manager to CARLOS by repointing one
+shared CNAME target. Without an import, each name has minutes of TLS
+errors. Private keys are involved, so security is the first concern.
+Tito asked for an operator-only import; Paul approved the work.
+
+## Fixed: do not re-argue
+
+- Operator-only (platform operator, a person) and inside an account the
+ operator is a member of.
+- Storage at the same at-rest protection as CARLOS-issued keys in
+ control/certs/ (SSE-S3 bucket default, 0600 on disk); no new envelope
+ encryption.
+- No revocation checking.
+
+## What to check
+
+1. Authorization: can anyone other than a platform operator who is a
+ member of the claim's account get an imported certificate served, or
+ cause one to be served for a name they don't hold? Races between
+ import, detach and re-attach by another account.
+2. Validation: anything that lets a certificate that should not be
+ served (wrong name, broader wildcard without the flag, CA cert,
+ untrusted chain, mismatched key, expired) through, or any parse path
+ that could echo key bytes into a log, error, audit row or response.
+3. Serving: is the handshake layer's placement right? Check against
+ edge.go's chain (around the perHostCert capture), wrapGetCertificate,
+ the wildcard wrapper, and the warm. Can a real handshake still make
+ autocert order or arm a renewal timer for an imported name before it
+ points? Does a CARLOS-issued entry always win?
+4. Removal: does a removal stick on every box (mirror memory, local
+ disk, backfill on new AND old binaries, autocert's in-memory state)?
+ Does the local-delete rule ever delete on a failed or partial listing?
+5. The relay-before-pointing extension: does adding "usable +import on
+ disk" to the edges-file writer's early-publish rule widen what a
+ tenant can make the issuer do, or what any edge relays, beyond what
+ 49bcf97 reviewed?
+6. After the move: does the warm actually order for the name (its set,
+ the dns_pointing filter, the HostPolicy, the order budget), and does
+ the sweep's retirement rule ever delete an import while nothing else
+ serves the name?
+7. Mixed-version fleet during a roll: old boxes meeting +import objects.
+
+## Round 2
+
+Earlier rounds: round 1 by Astra (`ASTRA-FINDINGS-SPEC-R1.md`, NOT READY,
+3 P1) and Fable (`FABLE-FINDINGS-SPEC-R1.md`, READY AFTER FIXES), both in
+this directory. Rev 2's dispositions are at the end of the spec.
+
+First give one line per P1 and P2 from BOTH round-1 files: resolved,
+partly, or not. Carry every unresolved or partly resolved finding forward
+at its current severity, then add new findings, especially any the rev 2
+changes introduced (the binding block, the issuer reconcile, the
+HostPolicy refusal for imported names, SupportsCertificate selection,
+memory-only serving, identity reconcile of disk copies, no retirement).
+The verdict covers everything outstanding.
+
+## Severity
+
+- **P1**: unsafe, would not compile, a test fails, or it would not work.
+ Blocks merge.
+- **P2**: wrong or missing. Fixed without reopening this review.
+- **P3**: clarity or polish. Goes on a follow-up list; never a reason for
+ another round.
+
+A P1 states its failure scenario and the evidence (file:line). Do not
+raise a P2 to P1 to keep the review open.
+
+## Output
+
+Findings ranked P1, P2, P3. Each gives the section, the problem, the
+evidence (file:line, verified), the failure scenario, a concrete fix and
+the invariant or trust boundary it breaks (that is its fault family).
+End with exactly one verdict:
+
+- **READY**: no P1 and no P2.
+- **READY AFTER FIXES**: no P1. The listed P2s are fixed without another
+ round.
+- **NOT READY**: one or more P1s, listed.
+
+Do not edit files. Do not spawn reviewers or subagents of your own. Do
+not run the full test suites.
diff --git a/docs/superpowers/specs/2026-11-25-cert-import-1429-design.md b/docs/superpowers/specs/2026-11-25-cert-import-1429-design.md
index 991752431..d0643a06a 100644
--- a/docs/superpowers/specs/2026-11-25-cert-import-1429-design.md
+++ b/docs/superpowers/specs/2026-11-25-cert-import-1429-design.md
@@ -1,8 +1,10 @@
# Imported certificates for custom domains before a DNS move (#1429)
-Rev 1, 2026-11-25. Discussion: amadan carlos/platform #1429 (ask), #1293
+Rev 2, 2026-11-25. Discussion: amadan carlos/platform #1429 (ask), #1293
(DNS-01 pre-issue, merged 042e1af and 49bcf97). Review budget: at most
three rounds each for Astra and Fable (AGENTS.md "Stopping rules").
+Round 1: Astra NOT READY (3 P1, 2 P2), Fable READY AFTER FIXES (6 P2,
+6 P3); dispositions at the end.
## Why
@@ -17,7 +19,19 @@ customers'.
An operator who already holds a valid certificate and key for the name
imports them. Every edge serves the import from that moment, the alias
is relayed by every edge before DNS points here, and once DNS has moved
-CARLOS orders its own certificate and the import retires.
+CARLOS orders its own certificate, which takes over for every client it
+suits. The import is served to the clients only it suits until it
+expires.
+
+## Preconditions
+
+- Every box of the deployment runs a release with this change, and
+ runs with the deployment bucket (the normal multi-edge shape; a box
+ without one has no cert mirror and no edges file). An old edge does
+ not serve imports and an old home box does not publish early, so an
+ import before the roll finishes gives TLS errors on old edges. The docs
+ and the import's answer say to check with `curl --resolve` on a
+ non-hub edge before moving DNS.
## Who may import, and for which account
@@ -28,25 +42,20 @@ in this order, else refused:
1. `domainsGate`: signed in, a member of `{account}` with `{app}`
(the domains family's byte-identical 404 for anyone else), rate
- limited, deployment bucket configured.
-2. `principalPlatformOperator`: a person (not a service or app
- credential) who is an ops account owner or on
- `CARLOS_SYSTEM_OPERATORS`. Members who are not operators get 403
- with the platform-operator message. So an import is the deployment
- operator's act, done inside an account they belong to, the same
- rule as `domains attach --platform`.
+ limited, deployment bucket configured. Route declaration
+ `Allow: svcrole.Set{}` (no service credential) and refused for linked
+ credentials, like the other domain writes.
+2. `principalPlatformOperator`: a person who is an ops account owner or
+ on `CARLOS_SYSTEM_OPERATORS`. Anyone else: 403 with the
+ platform-operator message. An import is the deployment operator's
+ act, inside an account they belong to, the rule
+ `domains attach --platform` already uses.
3. The claim `domains/<host>.json` exists, is held by `{account}` and
`{app}`, is not pending (#215), and is an exact name (no `*.` claim,
- no instance catch-all). Otherwise the door's neutral 404/409, as
- detach answers.
-4. No usable CARLOS certificate already serves the name: a `<host>` or
- `<host>+rsa` entry in `control/certs/` that is in date for more than
- 7 days and names the host. Then 409 "already has a certificate from
- CARLOS; nothing to import". An import exists to bridge a gap, not to
- replace our own.
+ no instance catch-all). Otherwise the neutral 404, as detach answers.
-`DELETE` on the same path removes an import (same gates 1 to 3). Detach
-removes it too (any holder may detach, as today).
+`DELETE` on the same path removes the import (gates 1 to 3; a missing
+import is 200 with `removed: false`).
## Validation (console, before any write)
@@ -54,166 +63,219 @@ The request carries the two PEM texts. The body is capped at 64 KiB.
- **Key**: exactly one unencrypted private key block (PKCS#8, PKCS#1 RSA
or SEC 1 EC). Encrypted PEM, a second key, or any other block in the
- key text is refused. RSA 2048 to 8192 bits; ECDSA P-256 or P-384.
- Anything else (Ed25519, DSA, small RSA) is refused.
+ key text is refused. RSA 2048 to 4096 bits; ECDSA P-256 or P-384.
+ Anything else is refused.
- **Chain**: one to five CERTIFICATE blocks, leaf first, nothing else.
-- **Key matches leaf** (`tls.X509KeyPair` on the pair).
+- **Key matches leaf** (`tls.X509KeyPair`).
- **Chain is valid**: `leaf.Verify` with the supplied intermediates,
`KeyUsage` server auth, `DNSName` = host, against the Mozilla root set
- vendored as `golang.org/x/crypto/x509roots/fallback/bundle` (not the
- console host's store, so the answer doesn't depend on where the
- console runs). A self-signed or private-CA certificate is refused: no
- visitor would trust it.
+ from `golang.org/x/crypto/x509roots/fallback/bundle` (already in
+ go.mod), not the console host's store. Self-signed and private-CA
+ certificates are refused.
- **Not a CA**: the leaf has no `IsCA`.
-- **SAN covers the name**: implied by `Verify(DNSName: host)`. If the
- only SAN that matches is a wildcard (`*.example.com` for
- `shop.example.com`), refused unless `--allow-wildcard`. With it, the
- import is still served for this one exact host only.
+- **SAN covers the name**: implied by `Verify(DNSName: host)`. If no SAN
+ names the host exactly and only a wildcard matches, refused unless
+ `--allow-wildcard`. With it, the import is still served for this one
+ exact host only.
- **Dates**: `NotBefore` ≤ now, and `NotAfter` more than 7 days away.
- **Not revoked**: not checked (Let's Encrypt no longer runs OCSP). Said
in the docs.
-Every refusal names the failed check by kind ("the key does not match
-the certificate", "the certificate does not cover shop.example.com"),
-never echoes input bytes, and is a 400 (409 for gate 4).
-
-The CLI reads the two files, refuses a key file readable by group or
-other with a warning only (it's the operator's disk), and sends both
-over the console's HTTPS connection. It runs the same parse locally
-first only for a friendlier message; the console decides.
+Refusals are 400s that name the failed check by kind ("the key does not
+match the certificate"), never echo input bytes. The CLI reads the two
+files and sends both over the console's HTTPS connection.
## Storage
-One object, `control/certs/<host>+import`, in autocert's entry format
-(the key block, then the chain), written by the console with the
-existing create-or-replace CAS (`putCAS` shape). Nothing else is stored
-anywhere: the audit row and the API answers carry the leaf's SHA-256,
-issuer, SANs count and `NotAfter`, derived from the object when needed.
+One object, `control/certs/<host>+import`, written by the console with
+the create-or-replace CAS (`putCAS` shape). The console writes it from
+what it verified, not the operator's bytes: a binding block, the key
+re-encoded as PKCS#8, then the leaf and the intermediates `Verify`
+used. The binding block is a PEM block of type `CARLOS IMPORT BINDING`
+whose headers are `Host`, `Account` (sqid), `App` and `Claim-Created`
+(the claim's `created_at`, which a detach and re-attach changes).
+`tls.X509KeyPair` skips it, and autocert never reads `+import` names.
- **At rest**: the deployment bucket's default encryption (SSE-S3,
- AES256, infra/modules/deployment-buckets/main.tf), exactly as every
- CARLOS-issued key in `control/certs/` is stored, and on each box's
- disk in the edge's cert cache directory, mode 0600, as autocert's own
- entries are. An imported key gets no weaker and no stronger treatment
- than the keys we mint, so it adds no new kind of secret to protect.
-- **Never logged**: no log line, error, audit row, API answer or
- activity entry carries key or certificate bytes. The handler never
- logs the request body; parse errors are mapped to fixed sentences.
-- **Why its own name** (`+import`, not `<host>`/`<host>+rsa`): autocert
- never reads it (so no autocert renewal timer and no hello-time order
- ever starts from an import), the backfill never republishes it (so a
- removal sticks without a tombstone; certsync.go backfill notes that a
- purge of an ordinary name would be resurrected by any box's disk
- copy), and a CARLOS-issued certificate under the ordinary names is
- told apart from an import by name alone.
+ AES256, infra/modules/deployment-buckets/main.tf), as every
+ CARLOS-issued key in `control/certs/` is stored; on box disks, mode
+ 0600 in the edge's cert cache directory, as autocert's entries are.
+- **Never logged**: no log line, error, audit row or API answer carries
+ key or certificate bytes. The handler never logs the body; parse
+ errors map to fixed sentences. Answers and audit rows carry the leaf's
+ SHA-256, issuer CN, SAN count and `NotAfter`.
+- **Its own name** (`+import`): autocert never reads it, so no autocert
+ renewal timer and no order starts from an import; the backfill never
+ republishes it (old binaries too: `ownsCertName` trims only `+rsa`,
+ certsync.go:1368), so a deletion sticks without a tombstone; and a
+ CARLOS certificate is told from an import by name.
+- The console becomes a writer of `control/certs/` (imports only). The
+ writer-map note in certsync.go is amended to say so.
+
+## Binding to the claim
+
+An import authorizes a name for one claim acquisition: the binding's
+account, app and `Claim-Created`. Three places enforce it.
+
+- **The issuer reconciles** every minute (`importReconcileInterval`),
+ from the mirror's snapshot and the claims it already reads through a
+ `ClaimCache`: an import whose binding is unreadable, whose claim is
+ gone, pending, or held by another account, app or acquisition, is
+ deleted with `release.DeleteIfMatch` on the revision it read (a
+ refusal deletes nothing and is retried). This is the one cleanup for
+ every detach path (API, browser, attach rollbacks, catch-alls, claim
+ lapses) and for an import door that died mid-write. At most five
+ deletes a pass, one log line each.
+- **Early publication** (below) requires the alias row's account to
+ equal the binding's `Account`.
+- **Serving** requires the name to be a deployment host (exact, some box
+ publishes it or this box routes it), so a detached name stops being
+ served at the next home map refresh even before the reconcile.
+
+Between a detach and the reconcile (up to a minute) a re-attach by
+another account can see the old import served for its name. The
+certificate is valid for the name and its key never leaves our edges;
+the new holder gets no early relay (account check) and the import is
+gone within the minute.
## How edges serve it
-Every edge's cert mirror already lists and parses all of
-`control/certs/`. Changes:
-
-1. **Mirror**: `<host>+import` is parsed like any cert entry and written
- to the local cache (bucket-outage fallback, and for check 3). The
- backfill skips the `+import` suffix. A local `+import` file whose name
- is absent from a successful listing of the prefix is deleted (a
- failed listing deletes nothing).
-2. **Handshake**: a new layer, between the mirror's
- `wrapGetCertificate` and the wildcard wrapper, so the cert warm (which
- calls the chain below it, `perHostCert`) never sees it. For an exact
- SNI with no usable CARLOS entry (mirror snapshot, then local cache)
- and a usable import (in date, names the host, key type the client
- supports), it serves the import without calling autocert. Otherwise it
- passes through. So a CARLOS certificate always wins, and before one
- exists autocert is never asked about the name by a real handshake.
-3. **Relay before DNS points**: the home box's edges-file writer already
- publishes a not-pointing alias, marked `dns_pointing: false`, when it
- is in the operator's DNS-01 scope and has a usable pre-issued
- certificate (49bcf97). It now also does so when the edge's cert cache
- holds a usable `<host>+import` for the alias (same checks as
- `domains.UsablePerHostCert`: regular file, key matches, names the
- host, in date). The issuer's `AliasNotPointing` refusal and the warm
- set's `dns_pointing` filter then apply unchanged: no box orders
- HTTP-01 for the name until it points. The operator's import is the
- authorization here, as the DNS-01 settings are for pre-issue.
+1. **Mirror.** `<host>+import` is parsed like any cert entry (the snapshot
+ keeps the binding beside it). Locally it is reconciled by identity,
+ not by expiry: the disk copy is rewritten whenever its bytes differ
+ from the bucket's, and on every successful listing (full or
+ changed-only) a scan of the cache directory deletes any `*+import`
+ file whose key the listing did not return. A failed listing deletes
+ nothing; a listed key whose Get failed is not deleted. The backfill
+ skips `+import`.
+2. **Handshake layer**, a new wrapper between the mirror's
+ `wrapGetCertificate` and the wildcard wrapper, so the warm (which
+ calls `perHostCert`, below it) never sees it. In order:
+ - a hello offering only `acme-tls/1` goes straight to the inner
+ chain (a tls-alpn-01 validation must reach its token);
+ - if the mirror snapshot holds a usable CARLOS entry (`<host>` or
+ `<host>+rsa`, in date, names the host) that the hello supports
+ (`hello.SupportsCertificate`), pass through;
+ - else, if it holds a usable import the hello supports, for a
+ deployment host, serve the import;
+ - else pass through.
+ Imports are served from mirror memory only, never from the local
+ disk fallback, so a removed import is never served by a box that has
+ not listed since.
+3. **No order before DNS points.** The issuer's HostPolicy refuses a
+ name for which the mirror holds a usable import unless some box,
+ this one included, publishes it pointing (the warm set's own source:
+ `homes.OwnServedHosts()` and `homes.ServedHosts()`). This covers the
+ issuer as home box (Astra R1 P1-2): an incompatible hello that falls
+ through to autocert neither orders nor loads a cached entry nor arms
+ a timer.
+4. **Relay before DNS points.** The home box's edges-file writer already
+ publishes a not-pointing alias, `dns_pointing: false`, when it is in
+ the DNS-01 scope with a usable pre-issued certificate (49bcf97). It
+ now also does so when the edge's cert cache directory holds a usable
+ `<host>+import` (regular file, key matches, names the host, in date)
+ whose binding `Account` equals the alias row's account. The issuer's
+ `AliasNotPointing` refusal and the warm set's `dns_pointing` filter
+ then apply unchanged.
Before the move, `curl --resolve <host>:443:<edge IP>` on any edge shows
the imported certificate and a relayed answer.
-## After the DNS move: CARLOS issues its own
+## After the DNS move
The home box stamps the alias pointing on its next DNS sweep (5 to 7
minutes; the import serves throughout). The alias joins the warm set,
-and the issuer's warm orders a certificate over HTTP-01 as for any
-custom domain, within its normal order budget. From then on the handshake
-layer sees a usable CARLOS entry and passes through to autocert, which
-renews as usual.
+the HostPolicy stops refusing it, and the warm orders an ECDSA
+certificate over HTTP-01 within its normal budget. From then on every
+client that supports ECDSA gets CARLOS's certificate. An RSA import keeps
+serving RSA-only clients until it expires; after that they get what
+every other custom domain gives them today (the issuer orders an RSA
+certificate on such a hello, now that the name points).
-The issuer retires the import: on its cert sweep pass, a `<host>+import`
-entry is deleted once `control/certs/` holds a usable `<host>` or
-`<host>+rsa` entry for the same host. Every box drops it on its next
-listing.
+There is no early retirement: an import stays until it expires and the
+existing sweep removes it 30 days later, or until an operator removes
+it or the reconcile does.
## Expiry and replacement
-- An import is served while its leaf is in date, never after
- (`usableFor`'s `NotAfter` check).
-- CARLOS cannot renew an import before DNS points (no DNS-01 on a
- customer's zone, HTTP-01 can't validate). If the move is delayed past
- the import's expiry, the operator imports the renewed cert-manager
- certificate again. A re-import replaces the object.
+- An import is served while its leaf is in date, never after.
+- CARLOS cannot renew an import before DNS points. If the move is
+ delayed past its expiry, the operator imports the renewed cert-manager
+ certificate; a re-import replaces the object, and every box's disk
+ copy follows by identity.
- `carlos domains get <host>` shows an import's issuer, SHA-256 and
- expiry, and says whether CARLOS has issued its own yet. The sweep's
- existing expired-plus-30-days rule removes a forgotten one.
+ expiry.
## Removal
-`carlos domains cert remove <host>` (DELETE above), or detaching the
-name, deletes `control/certs/<host>+import`. Every mirror stops serving
-it on its next listing (30 s poll, sooner on the change index) and
-deletes its local copy; the home box stops publishing the alias before
-it points on its next edges-file pass. Nothing republishes it. The
-detach door deletes the import after the claim; the import door
-re-reads the claim after writing and deletes its own write if the claim
-is gone or no longer held by `{account}`/`{app}` (409), so an import
-and a detach racing each other leave no import behind.
+`carlos domains cert remove <host>` deletes the object; detaching the
+name gets it deleted by the reconcile. Every mirror stops serving it on
+its next listing (seconds, through the `control/certs` change index; at
+worst the mirror's full-rebuild backstop) and deletes its disk copy; the
+home box stops publishing the alias early on its next edges-file pass.
+Nothing republishes it. An old box keeps a disk copy it never serves or
+publishes, deleted when it upgrades.
## Audit
`domain-cert-import` and `domain-cert-remove` rows on the app's
Activity, as the operator: host, leaf SHA-256, issuer CN, `NotAfter`,
-`--allow-wildcard` if used. Detach's row adds "and its imported
-certificate" when it removed one. The issuer's retirement logs one line
-per host (no bytes).
+and `--allow-wildcard` if used. The reconcile logs one line per deleted
+import (host and reason, no bytes).
## Not in scope
-- Imports for wildcard claims, catch-alls, or names under the apps
- domain's account namespaces.
-- Revocation checking, or importing into a deployment without a bucket.
-- A browser door. CLI and API only.
-- Automatic re-import from Kubernetes.
+Imports for wildcard claims, catch-alls or names under the apps domain's
+account namespaces; revocation checking; a browser door; automatic
+re-import from Kubernetes.
## Tests (built first)
-- Console door: each gate and each validation refusal (a fixture CA and
- intermediates; real roots exercised through an injected pool), the
- wildcard flag, the CARLOS-cert-present 409, no key bytes in any
- response, log or audit row, the claim re-read race, detach removes.
-- Mirror: `+import` parsed and synced locally, never backfilled, local
- copy deleted on withdrawal and kept on a failed listing.
-- Handshake layer: import served when no CARLOS entry, CARLOS entry wins,
- expired import not served, ECDSA import not served to an RSA-only
- hello, warm path does not see the import (orders as before).
-- Edges file: an alias with a usable import publishes with
- `dns_pointing: false`; without, or with an unusable one, it doesn't.
-- Sweep: import retired once a CARLOS entry exists, kept otherwise.
-- An end-to-end test across two edges and an issuer: import, relay
- before pointing, then pointing, the warm's order, retirement.
-
-## Rollout
-
-Additive wire shapes: an old box ignores `+import` objects (the mirror
-parses them into a map nothing old reads; the backfill on an old box
-doesn't own the name `<host>+import`, since `ownsCertName` trims only
-`+rsa`, so it never republishes one). Inert until an operator imports.
-Release and any production use are Paul's go.
+- Console door: each gate and validation refusal (fixture CA with an
+ injected root pool), the wildcard flag, RSA 8192 refused, re-encoded
+ storage with the binding, no key bytes in any response, log or audit
+ row; remove.
+- Mirror: `+import` parsed and synced; replaced on equal or earlier
+ expiry; disk copy deleted when unlisted; kept on a failed listing and
+ on a failed Get; never backfilled.
+- Handshake: ALPN pass-through with an import present; CARLOS wins when
+ compatible; RSA import serves an RSA-only hello beside an ECDSA CARLOS
+ cert; expired import not served; import not served for a non-deployed
+ name; warm path never sees it.
+- HostPolicy: refuses an imported name homed on the issuer before
+ pointing, for an incompatible hello and with an ordinary cached
+ entry; allows it once published pointing.
+- Edges file: early publication with a matching account; none with
+ another account, no import, or an unusable one.
+- Reconcile: deletes on claim gone, other account, re-acquired claim,
+ pending; keeps a matching one; conditional delete refused deletes
+ nothing.
+- End to end across an issuer and a second edge: import, relay before
+ pointing, pointing, the warm's order, CARLOS preferred, removal.
+
+## Round 1 dispositions
+
+Astra R1:
+- P1-1 (orphaned import, binding): accepted. Binding block, issuer
+ reconcile with conditional deletes, account check on early
+ publication, deployed-host check on serving.
+- P1-2 (order before pointing on the issuer as home): accepted. HostPolicy
+ refusal for imported names until published pointing, own file
+ included.
+- P1-3 (retirement drops RSA coverage): accepted by cutting retirement
+ and selecting by `SupportsCertificate`.
+- P2-4 (ALPN): accepted.
+- P2-5 (disk copy by expiry): accepted. Identity reconcile, and imports
+ served from memory only.
+
+Fable R1:
+- P2-1 (ALPN): accepted, as above.
+- P2-2 (binding by hostname): accepted, as Astra P1-1. Deleting in every
+ detach path is replaced by the one issuer reconcile.
+- P2-3 (three meanings of "usable"): gone with gate 4 and retirement.
+- P2-4 (local-delete mechanism, rollout wording, change-index latency):
+ accepted.
+- P2-5 (home box without a mirror): stated as a precondition.
+- P2-6 (mixed fleet): stated as a precondition, with the curl check.
+- P3s: `SupportsCertificate`, snapshot-only lookup, re-encoded storage,
+ RSA cap 4096 and the console as a writer all taken.