The TLS Certificate That Refused to Rotate
TL;DR — Key Takeaways
- A supposedly automated TLS rotation pipeline left some Traefik instances serving an old certificate for 19 days because single-file bind mounts pinned stale inodes.
- A SHA-256 fingerprint hidden in a YAML comment failed as a reload trigger because Traefik compares parsed configuration and discards comments.
- The durable fix was to inline the certificate and private key directly into Traefik’s dynamic config, making certificate changes part of the watched configuration itself.
We renew a wildcard certificate every night at 00:48. acme.sh answers a DNS challenge, ZeroSSL signs, and a deploy hook pushes the new PEM into three Consul clusters, one per environment. On the other end of that pipe sits Traefik, seven instances of it: Two allocations in each of the three environments under Nomad, plus one standalone container on an ops host. consul-template renders the certificate and a small dynamic config for Traefik’s file provider, and the template block runs with change_mode set to noop, which is a deliberate choice, because a certificate rotation should never restart an ingress.
And inside the migration commit that set all of this up, from day one, lived a clever trick. The dynamic config carried a YAML comment with the sha256 of the certificate: The idea was that when the cert rotates in Consul, the fingerprint changes, the watched file changes, and Traefik hot-reloads. The comment above it said, in our own words, “Keep it as a comment — Traefik ignores it.” It looked like this:
# fingerprint changes whenever the wildcard rotates in Consul, which
# mutates this watched dynamic-config file and triggers a hot reload
# (no restart). Keep it as a comment — Traefik ignores it.
# cert-fingerprint: {{ key “certs/*.example.com/fullchain.pem” | sha256Hex }}
tls:
stores:
default:
defaultCertificate:
certFile: /tls/wildcard.pem
keyFile: /tls/wildcard.key
We shipped it, the review passed, and nobody thought about this comment again.
The first crack showed five weeks later, and it was not about certificates at all. An oauth2-proxy allocation got rescheduled, and every route behind its forwardauth middleware started returning 500 with an empty body, because Traefik was still dialing the dead allocation’s address. Which was strange, because the address lives in the same watched config file, and the file on disk was correct. The investigation came down to one line: consul-template rewrites the file by atomic rename, and our container mounted that file as a single-file bind mount. A single-file bind mount pins the inode. The rename replaces the file with a new inode, and the container keeps reading the old one, which by then is deleted and held open, nlink 0, frozen forever. So Traefik had been reading a snapshot of the config from the day its container started. The fix was six lines in one file:
# BEFORE — pins the pre-rename inode forever:
volumes = [“local/traefik.yaml:/traefik/traefik.yaml”]
args = [ …, “–providers.file.filename=/traefik/traefik.yaml” ]
# AFTER — read through the directory mount Nomad already provides:
args = [ …, “–providers.file.filename=/local/traefik.yaml” ]
On August 5, the wildcard rotated in Consul, the way it does every sixty-odd days. Nobody noticed anything, and we took that as normal. On August 24 we found the ops host and one of the edge nodes still serving the June certificate. The replacement had happened nineteen days earlier. There was no outage and no alert. We caught it only because somebody looked at the certificate dates by hand.
The diagnosis this time had two layers stacked on top of each other. The first layer was the same inode pin, still alive in stage and prod, so those instances had never even seen the new bytes. And the second layer was the interesting one, because dev HAD seen the new bytes, and dev was serving the old certificate anyway. The fingerprint comment turned out to do nothing at all. Traefik’s file provider compares parsed configurations, and comments do not survive parsing, so a config whose only change is a comment parses to the same thing as before. Traefik logs “Skipping unchanged configuration” and moves on, and it keeps the default certificate it already loaded in memory. We verified this on a throwaway Traefik container: swapping the certificate file on disk changes nothing which is served, and changing any parsed field of the config triggers the reload. So the trick which we shipped on day one could never have worked, not once, and it had been reviewed and believed by everyone, including me.
The first repair moved the fingerprint into something which survives parsing, a middleware attached to no router, carrying the hash in a response header nobody would ever see. Its only purpose was to be different after a rotation. That version lived for 37 minutes, and then we replaced it with a cleaner one. Traefik’s certFile and keyFile accept content, not only paths. So the final config inlines the PEM directly:
tls:
stores:
default:
defaultCertificate:
certFile: |
{{ key “certs/*.example.com/fullchain.pem” | trimSpace | indent 20 }}
keyFile: |
{{ key “certs/*.example.com/cert.key” | trimSpace | indent 20 }}
After this change the certificate itself is a part of the config. A rotation in Consul re-renders the template, the parsed config now genuinely differs, and the hot reload fires. The template renders with perms 0600, because the file now contains the private key. The commit that did this removed the two certificate templates, the /tls mount and the whole fingerprint machinery, and it came out at 49 lines added against 80 removed.
The ops host got a twin of the same idea in systemd terms. A path unit fires when the renamed fullchain lands, and a timer backstops it 22 minutes after the renewal cron:
[Path]
# PathChanged fires on rename-into-place, which is how acme.sh deploys
PathChanged=/var/storage/acme/fullchain.pem
[Timer]
# safety net: 22 minutes after the 00:48 renewal cron
OnCalendar=*-*-* 01:10:00
Both trigger the same script, which builds the same inline-PEM config into a directory mount. The script writes through a temp file with an extension that Traefik’s directory provider does not read, and then renames it, because the rename is what the watcher sees.
The whole story cost us eight weeks between the migration and the last fix, and nineteen days of serving a certificate which had already been replaced. A few things from it went into our internal notes. A rotation pipeline which ends at “the new file is on disk” has not actually ended, because the process which serves the certificate decides for itself when to look at that file, and it may decide never. Anything which parsing throws away cannot work as a change signal, and a comment is the first thing which parsing throws away. And a mechanism which only gets exercised every sixty days should be tested on the day it is built, with a forced rotation, watched end to end, because otherwise it can stay in the believed-working state for months.
Frequently Asked Questions
Why didn’t Traefik detect the renewed TLS certificate?
Two separate issues were involved. Some Traefik instances were reading files through single-file bind mounts that remained attached to an old inode after consul-template performed an atomic rename. Other instances saw the new file but did not reload because the only configuration change was a YAML comment.
Why didn’t the certificate fingerprint comment trigger a hot reload?
Traefik compares parsed configurations rather than raw file contents. YAML comments disappear during parsing, so changing a SHA-256 fingerprint stored only in a comment did not make the effective configuration different.
What ultimately fixed the certificate rotation problem?
The certificate and private key were embedded directly into Traefik’s dynamic configuration. When Consul delivered new certificate material, the parsed configuration itself changed, allowing Traefik to hot-reload the updated certificate without restarting ingress.

