Actively maintained certificate extractor

Hi All,

nice to be part of the community :slight_smile:

we've had a long standing requirement to extract certificates from traefiks acme.json so they can be used by the services which require them (postfix, simplerisk, as well as a few others).

however it has been increasingly difficult to find projects with sufficient development, and community backing.

our organisation is not allowed to use software which is not actively maintained or contains security flaws that have patches available.

is anyone aware of a certificate extractor that is actively maintained?

Thanks in advance :slight_smile:

Maintained by a Traefik maintainer :slight_smile:

traefik-certs-dumper is the usual answer, and it can also handle the part that tends to break in these setups: getting the consuming services to pick up renewed certificates. Run it in watch mode with a post hook:

traefik-certs-dumper file --version v2 --watch \
  --source /letsencrypt/acme.json --dest /certs \
  --domain-subdir --crt-ext .pem --key-ext .pem \
  --post-hook "/usr/local/bin/reload-certs.sh"

--version v2 refers to the acme.json format and is also the right value for Traefik v3. With --domain-subdir you get stable per-domain paths (e.g. /certs/mail.example.com/certificate.pem and privatekey.pem), so Postfix and the other services can point at fixed files. Postfix won't notice a changed cert file on its own, so the hook should run postfix reload (or restart that container).

If your policy makes any extra tool a problem, the other route is to take those hostnames out of Traefik and issue them separately with certbot or lego using a DNS challenge, so each service owns its certificate and renewal. For a mail server that's often the cleaner setup anyway, since it no longer depends on Traefik being up.

If the concern is depending on a third-party project at all, you don't strictly need an extractor. acme.json stores each certificate and key as base64-encoded PEM, so jq and base64 are enough:

RESOLVER=letsencrypt        # your certificatesResolvers name
DOMAIN=mail.example.com
OUT=/etc/ssl/traefik

jq -r --arg r "$RESOLVER" --arg d "$DOMAIN" \
  '.[$r].Certificates[] | select(.domain.main == $d) | .certificate' \
  acme.json | base64 -d > "$OUT/$DOMAIN.crt"

jq -r --arg r "$RESOLVER" --arg d "$DOMAIN" \
  '.[$r].Certificates[] | select(.domain.main == $d) | .key' \
  acme.json | base64 -d > "$OUT/$DOMAIN.key"
chmod 600 "$OUT/$DOMAIN.key"

The certificate field already contains the full chain, so the .crt works directly for Postfix (smtpd_tls_chain_files or the cert/key pair). If a domain was requested as a SAN rather than the main domain, select on .domain.sans instead.

Run it from a daily cron job or a systemd path unit watching acme.json, compare a checksum before overwriting, and only reload Postfix/other services when the file actually changed. Since Let's Encrypt certificates are renewed well before expiry, daily is plenty.

That said, traefik-certs-dumper above is the same idea packaged, with a watch mode and post-hook, and it is maintained by ldez who also works on Traefik, so it should satisfy most "actively maintained" policies.