cert import (#1429): design rev 1 and review brief
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
2 files changed,
+307
−0
docs/superpowers/reviews/cert-import-1429/REVIEW-BRIEF-SPEC-R1.md+88 −0docs/superpowers/specs/2026-11-25-cert-import-1429-design.md+219 −0
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-kx83gB .amadan/test-gate.sh 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/benbjohnson/litestream v0.5.14 go: downloading github.com/superfly/ltx v0.5.1 go: downloading modernc.org/sqlite v1.55.0 go: downloading golang.org/x/net v0.62.0 go: downloading golang.org/x/sys v0.49.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 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/stun/v3 v3.1.5 go: downloading github.com/pierrec/lz4/v4 v4.1.22 go: downloading github.com/klauspost/compress v1.20.2 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/aws/aws-sdk-go-v2/service/internal/s3shared v1.19.31 go: downloading github.com/aws/aws-sdk-go-v2/service/internal/checksum v1.9.23 go: downloading github.com/aws/aws-sdk-go-v2/aws/protocol/eventstream v1.7.14 go: downloading github.com/wlynxg/anet v0.0.5 go: downloading github.com/prometheus/client_golang v1.17.0 go: downloading github.com/aws/aws-sdk-go-v2/feature/s3/manager v1.20.18 go: downloading github.com/prometheus/client_model v0.5.0 go: downloading github.com/prometheus/procfs v0.12.0 go: downloading google.golang.org/protobuf v1.36.10 go: downloading github.com/prometheus/common v0.45.0 go: downloading golang.org/x/text v0.43.0 go: downloading github.com/matttproud/golang_protobuf_extensions/v2 v2.0.0 go: downloading github.com/klauspost/compress v1.20.2 go: downloading modernc.org/sqlite v1.55.0 go: downloading golang.org/x/crypto/x509roots/fallback v0.0.0-20260209214922-2f26647a795e 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 github.com/google/uuid v1.6.0 go: downloading modernc.org/mathutil v1.7.1 go: downloading modernc.org/memory v1.11.0 go: downloading github.com/dustin/go-humanize v1.0.1 go: downloading github.com/dustin/go-humanize v1.0.1 go: downloading modernc.org/memory v1.11.0 go: downloading github.com/google/uuid v1.6.0 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/REVIEW-BRIEF-SPEC-R1.md b/docs/superpowers/reviews/cert-import-1429/REVIEW-BRIEF-SPEC-R1.md| new file mode 100644 |
| index 000000000..194d793d3 |
| --- /dev/null |
| +++ b/docs/superpowers/reviews/cert-import-1429/REVIEW-BRIEF-SPEC-R1.md |
| @@ -0,0 +1,88 @@ |
| +# Review brief: imported certificates design (#1429), spec round 1 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. |
| + |
| +## 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| new file mode 100644 |
| index 000000000..991752431 |
| --- /dev/null |
| +++ b/docs/superpowers/specs/2026-11-25-cert-import-1429-design.md |
| @@ -0,0 +1,219 @@ |
| +# Imported certificates for custom domains before a DNS move (#1429) |
| + |
| +Rev 1, 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"). |
| + |
| +## Why |
| + |
| +A custom domain whose zone we don't control can only get a CARLOS |
| +certificate over HTTP-01, after its DNS points at us. Tito Pro has about |
| +70 such names, each with a valid cert-manager certificate on Kubernetes, |
| +all reached through one Tito-controlled CNAME target. Moving that target |
| +gives every name minutes of TLS errors (the 5 to 7 minute DNS stamp, then |
| +the order). DNS-01 pre-issue (#1293) can't help: the zones are the |
| +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. |
| + |
| +## Who may import, and for which account |
| + |
| +`carlos domains cert import <host> --cert fullchain.pem --key key.pem |
| +[--allow-wildcard]`, sent to a new console door, |
| +`PUT /api/cli/apps/{account}/{app}/domains/{host}/cert`. All of these, |
| +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`. |
| +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. |
| + |
| +`DELETE` on the same path removes an import (same gates 1 to 3). Detach |
| +removes it too (any holder may detach, as today). |
| + |
| +## Validation (console, before any write) |
| + |
| +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. |
| +- **Chain**: one to five CERTIFICATE blocks, leaf first, nothing else. |
| +- **Key matches leaf** (`tls.X509KeyPair` on the pair). |
| +- **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. |
| +- **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. |
| +- **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. |
| + |
| +## 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. |
| + |
| +- **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. |
| + |
| +## 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. |
| + |
| +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 |
| + |
| +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 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. |
| + |
| +## 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. |
| +- `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. |
| + |
| +## 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. |
| + |
| +## 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). |
| + |
| +## 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. |
| + |
| +## 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. |