carlos / platform Public

cert import (#1429): round 3 findings

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
claude agent, operated by paul@keymail.dev pushed by paul@keymail.dev 040fb42797f02139fb2f1b0ab9e46aa18c308544 parent b54e417
2 files changed, +160 −0
  • docs/superpowers/reviews/cert-import-1429/ASTRA-FINDINGS-R3.md +96 −0
  • docs/superpowers/reviews/cert-import-1429/FABLE-FINDINGS-R3.md +64 −0
diff --git a/docs/superpowers/reviews/cert-import-1429/ASTRA-FINDINGS-R3.md b/docs/superpowers/reviews/cert-import-1429/ASTRA-FINDINGS-R3.md
new file mode 100644
index 000000000..a36fde8d4
--- /dev/null
+++ b/docs/superpowers/reviews/cert-import-1429/ASTRA-FINDINGS-R3.md
@@ -0,0 +1,96 @@
+- **Astra R2 P1-1 — Partly resolved:** fresh-read CAS attempts protect successor imports; failed withdrawal still breaks the stated invariant.
+- **Astra R2 P1-2 — Resolved:** cleanup reads the claim afresh and preserves an import when that read fails.
+- **Astra R2 P1-3 — Resolved:** the generic sweep skips imports; expiry cleanup uses conditional deletion.
+- **Astra R2 P1-4 — Partly resolved:** the inner-mirror selection bug is fixed; the outer wildcard wrapper can still bypass compatible-certificate selection.
+- **Fable R2 P2-1 — Resolved:** unread claims are no longer sufficient authority to delete.
+- **Fable R2 P2-2 — Resolved:** the spec identifies the hub’s fleet-forward role, and the host test covers early publication through it.
+
+Reviewed `8c5bdfd48d1916c5588a7edf2beabfc55e26c4c5`, spec rev 3, and the branch diff against `ce9fb958`.
+
+1. **P1 — Invariant 2 / handshake composition: a wildcard can bypass the selector.**
+
+ **Problem and evidence:** The import wrapper is installed at [edge.go:5173](/home/paulca/amadan.net/carlos/platform-cert-import-1429/internal/edge/edge.go:5173), then wrapped by the wildcard selector at line 5183. That outer wrapper returns its certificate without checking `SupportsCertificate` at [wildcard.go:1113](/home/paulca/amadan.net/carlos/platform-cert-import-1429/internal/edge/wildcard.go:1113). The import gate does not exclude exact names covered by configured or delegated wildcard parents.
+
+ **Failure scenario:** An exact custom name has a usable RSA import and is also covered by a CARLOS ECDSA wildcard. An RSA-only client receives the wildcard and fails TLS despite the compatible import. The randomized selector test never exercises this outer wrapper; the claimed whole-chain regression test also omits it.
+
+ **Fix:** Include wildcard candidates in the compatibility decision for imported names, preserving the existing path for names without imports. Alternatively, explicitly refuse this overlap and prevent wildcard configuration from introducing it later.
+
+ **Fault family:** Certificate selection must preserve the client coverage provided by the import—the recurring R1/R2 family.
+
+2. **P2 — Invariant 1 / failure handling: withdrawal is best-effort, but the invariant and simulation assume success.**
+
+ **Problem and evidence:** After publishing, `WriteImport` confirms and withdraws using the same context at [certimport_invariant.go:138](/home/paulca/amadan.net/carlos/platform-cert-import-1429/internal/domains/certimport_invariant.go:138). It neither checks conditional-delete support before writing nor preserves recovery state when withdrawal fails. The simulation’s [DeleteIfMatch:109](/home/paulca/amadan.net/carlos/platform-cert-import-1429/internal/domains/certimport_sim_test.go:109) injects no storage failure and ignores context cancellation.
+
+ **Failure scenario:** A claim changes after the writer’s authorization read. The write succeeds, confirmation fails or observes the change, and withdrawal fails because the request was cancelled, storage failed, or conditional deletion is unsupported. The function returns with its nonmatching entry still present—the exact condition S2 claims to exclude. Moreover, the joined withdrawal error matches `ErrImportNoClaim`, so [apidomaincert.go:392](/home/paulca/amadan.net/carlos/platform-cert-import-1429/internal/console/apidomaincert.go:392) returns 404 before logging the cleanup failure.
+
+ **Fix:** Refuse unsupported stores before publication; give cleanup a separate bounded context; expose failed cleanup and define its recovery. Extend the simulation with cancellation and failed mutations, and reconcile the unconditional spec claim with that recovery behavior.
+
+ **Fault family:** Acquisition-bound authority must survive failed or interrupted writes.
+
+3. **P2 — Early publication / census: the file checks do not establish the declared guarantees.**
+
+ **Problem and evidence:** [importBoundTo:23](/home/paulca/amadan.net/carlos/platform-cert-import-1429/internal/host/edgesfile_import.go:23) checks usability through one read, then performs another. Its `SameFile` comparison covers only the second `Lstat`/open pair; it never compares that file with the first read. The second parse checks account/app alone and reads up to **1 MiB**, despite the census basis claiming 64 KiB.
+
+ Separately, [UsableImportedCert:133](/home/paulca/amadan.net/carlos/platform-cert-import-1429/internal/domains/certimport.go:133) uses `Lstat` followed by ordinary `Open`, allowing a symlink or FIFO swap. [reconcileLocalImport:206](/home/paulca/amadan.net/carlos/platform-cert-import-1429/internal/edge/certimport.go:206) calls `local.Get` even after discovering a nonregular file; production `autocert.DirCache.Get` follows symlinks.
+
+ **Failure scenario:** Replacing the file between the two publication reads can combine usability from one entry with app binding from another, including an expired or wrong-host replacement. A symlink/FIFO can also be followed or opened despite the recorded refusal guarantees. Production runs this agent as `carlos`; I am not asserting a demonstrated root privilege escalation.
+
+ **Fix:** Open one bounded, no-follow regular-file descriptor and validate hostname, dates, account, and app from those same bytes. Avoid reading nonregular local-cache entries before replacing them. Update the census basis to match the implemented checks.
+
+ **Fault family:** Publication authority must come from one validated cache entry.
+
+4. **P2 — Reconcile scheduling: five persistent failures can starve every later name.**
+
+ **Problem and evidence:** [certimport.go:342](/home/paulca/amadan.net/carlos/platform-cert-import-1429/internal/edge/certimport.go:342) sorts names on every pass, starts at the beginning, and spends the five-call budget on attempts, including failures. Only successful deletions receive a skip memo.
+
+ **Failure scenario:** The first five suspect names have persistently unreadable claims or failed deletes. Every pass retries those five; a sixth detached or long-expired import is never examined even when its storage operations would succeed. The simulation has one hostname and does not exercise this scheduler.
+
+ **Fix:** Rotate the starting position or retain a cursor across passes, preserving the five-call limit. Test persistent failures ahead of a deletable name.
+
+ **Fault family:** Cleanup failures for one hostname must not prevent cleanup of unrelated names.
+
+5. **P2 — Removal documentation: the published timing contradicts the spec.**
+
+ **Problem and evidence:** [cli.md:2030](/home/paulca/amadan.net/carlos/platform-cert-import-1429/docs/site/cli.md:2030) promises removal within a minute. The remove section says “usually within seconds” but omits the 30-minute backstop explicitly required by [spec:247](/home/paulca/amadan.net/carlos/platform-cert-import-1429/docs/superpowers/specs/2026-11-25-cert-import-1429-design.md:247).
+
+ **Failure scenario:** An operator removing a compromised key reasonably assumes withdrawal has completed while mirrors still serve it. The five-attempt queue also prevents a one-minute detach guarantee.
+
+ **Fix:** Document cleanup cadence separately from propagation, include the backstop, and explain that storage failures can extend withdrawal.
+
+ **Fault family:** Documented withdrawal guarantees must match observed state.
+
+No P3 findings.
+
+The census verdicts concern the submitted dispositions and their stated bases:
+
+| Unit or envelope | Verdict | Basis |
+|---|---|---|
+| [`certMirror.backfill`](/home/paulca/amadan.net/carlos/platform-cert-import-1429/internal/edge/certsync.go:1346) | APPROVED | Imports are excluded; existing read authority is unchanged. |
+| [`RunWithActivatorReady`](/home/paulca/amadan.net/carlos/platform-cert-import-1429/internal/edge/edge.go:5167) | APPROVED | No new root reader; functional selection defect is finding 1. |
+| [`edgesFileWriteClaims`](/home/paulca/amadan.net/carlos/platform-cert-import-1429/internal/host/edgesfile.go:887) | REJECTED | Its new publication basis depends on checks not established by `importBoundTo`. |
+| [`readCertFile`](/home/paulca/amadan.net/carlos/platform-cert-import-1429/domains_cert_cli.go:95) | APPROVED | Bounded operator-selected CLI input; no root authority. |
+| [`UsableImportedCert`](/home/paulca/amadan.net/carlos/platform-cert-import-1429/internal/domains/certimport.go:128) | REJECTED | The stated no-symlink guarantee is not enforced across open. |
+| [`certMirror.pruneLocalImports`](/home/paulca/amadan.net/carlos/platform-cert-import-1429/internal/edge/certimport.go:171) | APPROVED | Removes regular import-cache entries absent from a successful listing. |
+| [`certMirror.reconcileLocalImport`](/home/paulca/amadan.net/carlos/platform-cert-import-1429/internal/edge/certimport.go:203) | REJECTED | Its basis says no symlink is followed; `local.Get` does follow one. |
+| [`importBoundTo`](/home/paulca/amadan.net/carlos/platform-cert-import-1429/internal/host/edgesfile_import.go:22) | REJECTED | Neither same-entry validation nor the recorded 64-KiB bound holds. |
+| Envelope `.` | APPROVED | CLI registration, bounded reads, and API calls introduce no root authority. |
+| Envelope `internal/domains` | REJECTED | `UsableImportedCert` basis is unproven. |
+| Envelope `internal/edge` | REJECTED | `reconcileLocalImport` contradicts its recorded basis. |
+| Envelope `internal/host` | REJECTED | Early-publication validation is incomplete. |
+
+Record-write census verdicts:
+
+| Entry | Verdict |
+|---|---|
+| [`routeDecls`](/home/paulca/amadan.net/carlos/platform-cert-import-1429/internal/console/routedecls.go:909) | APPROVED: existing key-site classification retained; person-only, host-claim-gated routes. |
+| [`linkedPolicies`](/home/paulca/amadan.net/carlos/platform-cert-import-1429/internal/console/linkedpolicy.go:92) | APPROVED: existing key-site classification retained; linked credentials refused. |
+| [`WriteImport`](/home/paulca/amadan.net/carlos/platform-cert-import-1429/internal/domains/certimport_invariant.go:130) | APPROVED as `nonrecord`: writes only the import object; finding 2 remains. |
+| [`reconcileLocalImport`](/home/paulca/amadan.net/carlos/platform-cert-import-1429/internal/edge/certimport.go:217) | APPROVED as `nonrecord`: writes the certificate cache, not provision records; its read-census rejection remains. |
+
+**Overall census verdict: REJECTED.**
+
+Domains import tests, the socket-free edge subset—including the randomized selector—and console validation tests passed. Broader edge/console selections were blocked by sandbox socket restrictions. No full suites, census tests, or subagents were run. Tracked files are unchanged; test-generated `go.mod` normalization was restored.
+
+Round 3 is exhausted. The sole P1 belongs to the recurring client-coverage family. Refusing and preventing wildcard/import overlap would remove that case; cutting imported-certificate support would also remove it. Further work on that family needs Paul’s scope decision, not an automatic fourth round.
+
+**NOT READY**
\ No newline at end of file
diff --git a/docs/superpowers/reviews/cert-import-1429/FABLE-FINDINGS-R3.md b/docs/superpowers/reviews/cert-import-1429/FABLE-FINDINGS-R3.md
new file mode 100644
index 000000000..d59c6409b
--- /dev/null
+++ b/docs/superpowers/reviews/cert-import-1429/FABLE-FINDINGS-R3.md
@@ -0,0 +1,64 @@
+# Round 3 review: cert-import-1429 at 8c5bdfd4 (spec rev 3 and code)
+
+No P1, one P2, seven P3s. No files edited, no subagents; census skipped as instructed.
+
+**Tests run:**
+- Pass: `go build ./...`, `go vet` on the four packages, `./internal/domains -run Import`, `./internal/edge -run Import`, `./internal/console -run 'Cert|Import'`, `./internal/host -run 'TestEdgesFile.*Import'`.
+- One failure, not attributed to this branch: a broader `./internal/host -run Import` also matched `TestS1ProbeNeverWakesAGatedImport`, which failed at `movesprobe_test.go:239`. The branch does not touch that file, and I did not check whether it fails on main or only in my sandbox.
+
+## Round-2 dispositions
+
+**Astra R2**
+- **P1-1 (binding authority, stale writer): resolved.** `WriteImport` reads the entry, then the claim, does a conditional Put, confirms, and withdraws its own write (`internal/domains/certimport_invariant.go:117-149`). `RemoveImport` is conditional only (`:174-200`). Publication checks account and app (`internal/host/edgesfile_import.go:44`). Serving stays unbound until the reconcile, as the spec states.
+- **P1-2 (unread claim read as gone): resolved.** `ReconcileImport` reads the claim fresh and an unread claim keeps the entry (`certimport_invariant.go:265-271`, `:236`). The cached listing is only a prefilter (`internal/edge/certimport.go:353`).
+- **P1-3 (sweep deletes a replacement): resolved.** The sweep skips imports (`internal/edge/certsweep.go:137`); expiry goes through the conditional reconcile (`certimport_invariant.go:233`, `:273`).
+- **P1-4 (inner chain picks): resolved.** `wrapImported` returns `chooseCert`'s answer and never consults the inner chain for a served import (`internal/edge/certimport.go:131-135`, `:146-156`).
+
+**Fable R2**
+- **P2-1 (unread claim): resolved**, as Astra P1-2.
+- **P2-2 (home box class): partly.** The fleet-via-hub case is a stated precondition with a passing test (`TestEdgesFileHubPublishesAFleetAliasWithAnImportBeforeDNS`). The suggested "has the home box published it" readout was not built; the operator still relies on `curl --resolve`.
+
+## P1
+
+None.
+
+## P2
+
+**P2-1. A re-import can destroy the working import on a transient claim-read failure (Invariant 1, `WriteImport`)**
+- **Problem:** the confirm step treats a failed claim re-read like a mismatch and withdraws the write. By then the Put has already replaced the previous good entry.
+- **Evidence:** `certimport_invariant.go:130` (replace), `:138-148` (any `err != nil` leads to `withdrawImport`). The door answers "could not save the certificate. Try again" (`internal/console/domaincert_copy.go:42`), which does not say the old import is gone.
+- **Failure:** an operator re-imports a renewed certificate for a name the import is actively serving (after the DNS move and before the CARLOS certificate, or for RSA-only clients). One S3 hiccup on the confirm read deletes the new entry, and the old one is already overwritten. Mirrors drop the import within seconds, and the name has TLS errors until someone retries.
+- **Fix:** retry the confirm read (two or three times, short backoff) before withdrawing, and withdraw only on a confirmed mismatch or absence or when the retries run out. State in the spec that a failed re-import can leave no import. Add entry-read and Put/Delete error injection to the simulation so this path runs.
+- **Family:** an unreadable claim must not cause a destructive act, the same family as R2 P1-2, on the writer side.
+
+## P3 (follow-up list)
+
+1. **Reconcile budget can starve.** The pass sorts names and returns after five `ReconcileImport` calls whether or not they deleted (`internal/edge/certimport.go:342-359`). Five persistently suspect-but-kept names at the head of the order (a claim listed but unreadable, for example a newer schema) block cleanup of every later name indefinitely. Rotate the start offset, or cap deletes and bound calls separately.
+2. **The file-swap comment overstates.** `importBoundTo` says its second read is "the file that check examined", but `before` is a fresh `Lstat` taken after `UsableImportedCert` returned (`internal/host/edgesfile_import.go:23-34`). A swap between the two is undetected, and the second read rechecks only account and app, not dates or host. The harm is one early `dns_pointing:false` publication for one pass. Have `UsableImportedCert` return the binding and read once.
+3. **The simulation is narrower than the spec says.**
+ - It injects claim-Get and List failures only (`internal/domains/certimport_sim_test.go:72`, `:126`): no entry-read failure, no Put or delete error, no store without conditional delete.
+ - Spec line 158's "no write leaves a non-matching binding of its own behind" is false when the withdraw itself fails (`certimport_invariant.go:142-144`). The reconcile bounds it; say so.
+ - "Each rule is mutation-checked" has nothing in the tree to reproduce it.
+ - `TestChooseCertInvariant`'s oracle restates the implementation (`internal/edge/certimport_test.go:1081-1090`). The TLS 1.3 chain test is the real guard.
+4. **Content-hash ETags allow one ABA.** If two identical imports run concurrently and the first then fails its confirm, its withdraw deletes the second's confirmed, byte-identical entry (`certimport_invariant.go:155-160`). The second caller was told success. P2-1's retry shrinks the window; note it in the spec.
+5. **Apps-domain names are "not in scope" but not refused.** The door's gate 3 checks only exact, not pending, not catch-all (`internal/console/apidomaincert.go:343-344`). An import for a wildcard-covered name is accepted and never served, because the wildcard wrapper sits above it. Refuse it, or say so in the spec.
+6. **"Rewritten when the bytes differ" holds only against the mirror's memo.** `syncLocal` skips a name whose bucket bytes are unchanged (`internal/edge/certsync.go:1548`), so a disk copy changed or deleted out of band is not repaired until a restart or a bucket change. This is existing behaviour for certificates; align the spec wording.
+7. **Validation order.** A claim with no `created_at` gets validation errors (400) before the 404, because that check lives in `WriteImport`, not `certDoorGate` (`apidomaincert.go:343`, `:379-394`). Operator-only, so no leak; the spec lists it under gate 3.
+
+## Verified as claimed
+
+- **Writers and deleters (check 1):** nothing else touches `control/certs/*+import`. The backfill skips imports (`certsync.go:1346`), the sweep skips them (`certsweep.go:137`), and no code outside `internal/edge` and `domains.ImportKey` builds a `control/certs/` key. Put with `""` is create-only (`internal/release/store.go:47`). Without conditional delete the code errors and never falls back (`internal/release/conditional_delete.go:29-37`).
+- **Selection (check 2):**
+ - The `acme-tls/1` bypass matches autocert's own test (`certimport.go:121`).
+ - Names with no usable import, or not deployment hosts, go to the inner chain untouched (`:128`).
+ - `perHostCert` is captured before the wrap, so the warm still reaches autocert (`internal/edge/edge.go:5167-5173`).
+ - The HostPolicy refusal covers the issuer as home (`certsync.go:257`).
+- **Console door (check 3):**
+ - Both routes carry `gateNoHostClaim`, `svcrole.Set{}` and `linkedRefuseDomains` (`internal/console/routedecls.go:909-910`, `linkedpolicy.go:92-93`).
+ - The operator check precedes any body read, the 64 KiB cap is in place, and refusals are fixed sentences.
+ - Logs and audit rows carry only store errors and the certificate summary.
+ - Root constraints are kept (`apidomaincert.go:84`).
+- **Mirror (check 4):** imports get their own map, and pruning runs only from `publish`, after a successful listing, with read-failed keys kept (`certsync.go:1015`, `certimport.go:171-197`). Both Put and conditional delete bump the change index at the store.
+- **Host (check 5):** account and app are both required (`edgesfile.go:888-889`); the hub fleet-forward test passes.
+
+**Verdict: READY AFTER FIXES**