Skip to content

fix(certbot): bound the zone listing, write keys owner-only, publish the live pair atomically, and rotate on renewal - #1241

Merged
kvinwang merged 10 commits into
nextfrom
fix/certbot-hardening
Sep 24, 2026
Merged

kvinwang merged 10 commits into
nextfrom
fix/certbot-hardening

Conversation

@kvinwang

@kvinwang kvinwang commented Sep 20, 2026 •

Copy link
Copy Markdown
Collaborator

Six defects in the certbot crate. Item 1 also affects the gateway; items 2–6 affect the standalone certbot-cli only.

  1. Cloudflare calls had no timeout, and zone listing looped on a provider-supplied total_pages. Zone discovery runs under the cluster-wide ACME lock. Now: 30 s timeout on every call, zone listing capped at 100 pages (warns when truncated).
  2. Account credentials and certificate keys were written with default permissions (0664). Now safe_write_with_mode(.., 0o600).
  3. The live pair was published non-atomically. ln_force was remove-then-symlink, so live/cert.pem could be missing, and cert and key flipped separately. Now both live names resolve through one .current symlink that is swapped with a single rename(2). Existing layouts migrate on the next publish.
  4. The standalone certbot never rotated the certificate key. It reused live/key.pem for every renewal. It now issues each certificate under a new key, as the gateway's distributed_certbot already does. Past keys stay in the archive.
  5. The renewed hook blocked the runtime without a timeout. It used std::process::Command::status() inside the async loop. Now it uses tokio::process with kill_on_drop, bounded by renew_timeout.
  6. The tries: u8 DNS poll counter could overflow. Changed to u32.

Verification

Regression tests fail on next:

  • zone_discovery_stops_at_the_page_cap (Elapsed(()) after 10 s)
  • a_stored_certificate_key_is_owner_only / stored_account_credentials_are_owner_only (436 != 384)
  • a_reader_never_catches_the_live_pair_half_published (cert Err(NotFound))
  • a_hook_that_never_returns_gives_the_renewal_loop_back (held 30 s)

Checks run:

  • cargo test -p certbot: pass
  • cargo clippy -p certbot -p certbot-cli --all-targets -- -D warnings: clean
  • cargo check -p dstack-gateway: clean

@kvinwang
kvinwang merged commit 7c7ea53 into next Sep 24, 2026
12 checks passed
@kvinwang
kvinwang deleted the fix/certbot-hardening branch September 24, 2026 15:26
kvinwang added a commit that referenced this pull request Sep 25, 2026
…n and bounded hooks

PR #1241 writes account and certificate keys owner-only, publishes the
live pair through one .current link, issues every renewal under a new key,
bounds the renewed hook by renew_timeout and caps Cloudflare zone
discovery. tc-gw-certbot-006 checks the first four against the real CLI
and tc-gw-certbot-003 runs the zone-cap test.

Signed-off-by: Kevin Wang <wy721@qq.com>
kvinwang added a commit that referenced this pull request Nov 8, 2026
…n and bounded hooks

PR #1241 writes account and certificate keys owner-only, publishes the
live pair through one .current link, issues every renewal under a new key,
bounds the renewed hook by renew_timeout and caps Cloudflare zone
discovery. tc-gw-certbot-006 checks the first four against the real CLI
and tc-gw-certbot-003 runs the zone-cap test.

Signed-off-by: Kevin Wang <wy721@qq.com>
kvinwang added a commit that referenced this pull request Nov 8, 2026
…n and bounded hooks

PR #1241 writes account and certificate keys owner-only, publishes the
live pair through one .current link, issues every renewal under a new key,
bounds the renewed hook by renew_timeout and caps Cloudflare zone
discovery. tc-gw-certbot-006 checks the first four against the real CLI
and tc-gw-certbot-003 runs the zone-cap test.

Signed-off-by: Kevin Wang <wy721@qq.com>
kvinwang added a commit that referenced this pull request Nov 10, 2026
…n and bounded hooks

PR #1241 writes account and certificate keys owner-only, publishes the
live pair through one .current link, issues every renewal under a new key,
bounds the renewed hook by renew_timeout and caps Cloudflare zone
discovery. tc-gw-certbot-006 checks the first four against the real CLI
and tc-gw-certbot-003 runs the zone-cap test.

Signed-off-by: Kevin Wang <wy721@qq.com>
kvinwang added a commit that referenced this pull request Nov 11, 2026
…n and bounded hooks

PR #1241 writes account and certificate keys owner-only, publishes the
live pair through one .current link, issues every renewal under a new key,
bounds the renewed hook by renew_timeout and caps Cloudflare zone
discovery. tc-gw-certbot-006 checks the first four against the real CLI
and tc-gw-certbot-003 runs the zone-cap test.

Signed-off-by: Kevin Wang <wy721@qq.com>
kvinwang added a commit that referenced this pull request Nov 11, 2026
…n and bounded hooks

PR #1241 writes account and certificate keys owner-only, publishes the
live pair through one .current link, issues every renewal under a new key,
bounds the renewed hook by renew_timeout and caps Cloudflare zone
discovery. tc-gw-certbot-006 checks the first four against the real CLI
and tc-gw-certbot-003 runs the zone-cap test.

Signed-off-by: Kevin Wang <wy721@qq.com>
kvinwang added a commit that referenced this pull request Nov 16, 2026
…n and bounded hooks

PR #1241 writes account and certificate keys owner-only, publishes the
live pair through one .current link, issues every renewal under a new key,
bounds the renewed hook by renew_timeout and caps Cloudflare zone
discovery. tc-gw-certbot-006 checks the first four against the real CLI
and tc-gw-certbot-003 runs the zone-cap test.

Signed-off-by: Kevin Wang <wy721@qq.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant