Skip to content

Renew gateway TLS certificates from the gateway app - #4386

Open
vitostrokov wants to merge 1 commit into
dstackai:masterfrom
vitostrokov:issue_4383_k8s_gateway_cert_renewal
Open

vitostrokov wants to merge 1 commit into
dstackai:masterfrom
vitostrokov:issue_4383_k8s_gateway_cert_renewal

Conversation

@vitostrokov

Copy link
Copy Markdown

Fixes #4383

Gateways on the Kubernetes backend have nothing that runs certbot renew, so their certificates
expire. This makes the gateway app renew certificates itself:

  • Nginx.renew_certificates() runs certbot renew under the lock that register() already
    holds around run_certbot, so a renewal never overlaps an issuance.
  • It passes --no-random-sleep-on-renew and
    --deploy-hook "systemctl reload nginx.service", the reload command the gateway already
    uses. The hook runs only when a certificate was renewed.
  • The app lifespan starts a task that waits a random time of up to 12 hours, then renews every
    12 hours. Failures are logged and retried on the next run. The task is cancelled on shutdown.

On VM gateways this runs alongside the snap's renewal timer, which is harmless: certbot renews
only certificates that are due.

Testing:

  • uv run pytest src/tests/_internal/proxy/gateway/: 63 passed.
  • New tests: services/test_nginx.py (renew command and deploy hook, failure, waiting for the
    lock) and test_app.py::test_renews_certificates_periodically_despite_errors.
  • uv run ruff check and uv run ruff format --check on the changed files: clean.

🤖 Generated with Claude Code

Gateways on the Kubernetes backend install certbot with pip into a venv
and run docker-systemctl-replacement as PID 1, so nothing ever runs
`certbot renew`, and their certificates expire after 90 days. VM
gateways get a renewal timer from the certbot snap.

Run `certbot renew` from the gateway app twice a day, after a random
first delay, under the lock that certificate issuance already uses. A
deploy hook reloads nginx when a certificate is renewed. On VM gateways
this duplicates the snap timer, which is harmless: certbot renews only
certificates that are due.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
@peterschmidt85
peterschmidt85 requested a review from jvstme October 18, 2026 08:14
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.

[Bug]: Gateway TLS certificates are never renewed on the Kubernetes backend

1 participant