Skip to content

fix(traefik): remove stale acme.json certificates on domain/app deletion - #4921

Open
scthakuri wants to merge 1 commit into
Dokploy:canaryfrom
klixsoft:fix/acme-cleanup-on-delete
Open

fix(traefik): remove stale acme.json certificates on domain/app deletion#4921
scthakuri wants to merge 1 commit into
Dokploy:canaryfrom
klixsoft:fix/acme-cleanup-on-delete

Conversation

@scthakuri

Copy link
Copy Markdown

Summary

  • Deleting a domain, application, or preview deployment removed the Traefik routing config but never touched acme.json, leaving stale Let's Encrypt certificate entries behind.
  • Traefik then retries ACME renewal indefinitely for domains that no longer exist, producing repeated NXDOMAIN renewal errors in the logs.
  • Added removeAcmeCertificate(host, serverId) in packages/server/src/utils/traefik/domain.ts that prunes the matching certificate entry (by domain.main or any sans) from acme.json, safely for both local and remote (SSH) servers, only writing back when something actually changed.
  • Wired this into the three places a Let's Encrypt domain can disappear: domain delete, application delete, and preview deployment cleanup.

Test plan

  • pnpm --filter=@dokploy/server run typecheck
  • pnpm --filter=dokploy run typecheck
  • biome check on all changed files
  • Added apps/dokploy/__test__/traefik/acme-certificate.test.ts (5 new tests: host match, SAN match, case-insensitivity, no-op when unrelated, no-op when acme.json is missing)
  • Full existing test suite (vitest run) — 72 files / 660 tests passing

Fixes #4920

Deleting a domain, application, or preview deployment removed the Traefik
routing config but left the Let's Encrypt certificate entry in acme.json,
causing Traefik to retry ACME renewal indefinitely for domains that no
longer exist.

Fixes Dokploy#4920
@scthakuri
scthakuri requested a review from Siumauricio as a code owner July 28, 2026 04:28
@dosubot dosubot Bot added the size:M This PR changes 30-99 lines, ignoring generated files. label Jul 28, 2026
@IPreferToEatDinner

Copy link
Copy Markdown

This is really quite an important task. I've been worried about it for a long time because otherwise there’s always so much useless information left over, and it’s really annoying to look at the logs. It would be great if this could be solved.

@djsisson

Copy link
Copy Markdown

traefik only reads acme.json at startup, from then on it only writes to the file on changes, it does not read from it, so this would not change anything, it is also advised not to alter this file whilst traefik is running.

the recommended path would be to stop traefik, then edit file, then restart traefik.

however, i would recommend using dns challenge with a wildcard, this prevents unnecessary ca certificate generation

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

size:M This PR changes 30-99 lines, ignoring generated files.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Traefik domains are not deleted when services/domains are deleted

3 participants