fix(traefik): load uploaded custom certificates from top-level dynamic dir#4595
Open
ravindu0823 wants to merge 2 commits into
Open
fix(traefik): load uploaded custom certificates from top-level dynamic dir#4595ravindu0823 wants to merge 2 commits into
ravindu0823 wants to merge 2 commits into
Conversation
…c dir Traefik's file.directory provider (directory: /etc/dokploy/traefik/dynamic, watch: true) is non-recursive, so the per-certificate registration YAML written to certificates/<certificatePath>/certificate.yml was never loaded and uploaded custom certificates were never presented over SNI. Write the registration YAML to the TOP LEVEL of the dynamic Traefik directory as <certificatePath>-certificate.yml via a new exported pure helper getCertificateConfigPath. The PEM files (chain.crt/privkey.key) stay in the per-certificate subdirectory since the YAML references them by absolute path. removeCertificateById now also deletes the top-level YAML in addition to the subdirectory. Fixes Dokploy#4503 Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
Address review: certificatePath is user-supplied (apiCreateCertificate does not
omit it), so interpolating it unquoted into the remote shell commands widened a
pre-existing injection/word-splitting surface. Quote ${certDir} and ${configFile}
in the create (mkdir) and remove (rm) commands, matching the already-quoted PEM
path redirects.
Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
What
Uploaded custom certificates (e.g. Cloudflare Origin CA) were never presented by Traefik over SNI, even though they appeared in the Dokploy UI under Certificates.
Root cause
The per-certificate Traefik registration YAML was written into a subdirectory:
But Traefik's file provider is configured with
directory: /etc/dokploy/traefik/dynamicandwatch: true. Thefile.directoryprovider is non-recursive, so it never reads files nested in subdirectories. As a result the cert YAML was never loaded into Traefik's TLS store and SNI matching never picked it up.Fix
getCertificateConfigPath(dynamicTraefikPath, certificatePath)that returns the registration YAML path at the top level of the dynamic Traefik directory:<dynamicTraefikPath>/<certificatePath>-certificate.yml.createCertificateFilesnow pullsDYNAMIC_TRAEFIK_PATHfrompaths()and writes the YAML to the top-level path. The PEM files (chain.crt/privkey.key) stay in the per-certificate subdirectory — the YAML references them by absolute path, so this keeps working. The subdirmkdirfor PEMs is unchanged.removeCertificateByIdnow also deletes the top-level YAML (rm -ffor remote servers,fs.rmSyncif it exists for local) in addition to removing the per-cert subdirectory.Test
New test
apps/dokploy/__test__/traefik/certificate.test.tscovers thegetCertificateConfigPathcontract: the path is top-level, is not under acertificates/subdirectory, and is unique percertificatePath(expected values built withpath.jointo avoid Windows separator flakiness).RED (before adding the helper):
getCertificateConfigPath is not a function— 3 failed.GREEN (after fix):
Both typechecks clean:
pnpm --filter=@dokploy/server run typecheckandpnpm --filter=dokploy run typecheck.Fixes #4503
🤖 Generated with Claude Code