Mutual TLS — where the server validates the client’s certificate, not just the other way around — is how internal APIs, IoT fleets, and zero-trust gateways prove who is connecting before any payload is sent. Caddy supports mTLS via the client_auth block under tls. This article is the production configuration we deploy at clients: trust pool wiring, validation modes, header forwarding for upstream consumption, and the rotation pattern that keeps the fleet operable.
How to verify
A working mTLS endpoint behaves like this:
curl -I https://api.example.com/ # rejected, no client cert
curl --cert /path/to/client.crt --key /path/to/client.key \
-I https://api.example.com/ # accepts
openssl s_client -connect api.example.com:443 -servername api.example.com \
-cert /path/to/client.crt -key /path/to/client.key < /dev/null
sudo journalctl -u caddy --since '5m ago' | grep -i 'client.cert\|verif'
Without a client cert, Caddy returns a TLS alert. With a valid cert, the handshake completes and the request reaches the application. The upstream sees the cert details in forwarded headers — X-Client-Subject, X-Client-Issuer, etc.
What’s happening
mTLS extends the standard TLS handshake by adding a client side. After the server presents its cert, the server sends a CertificateRequest to the client. The client responds with its own certificate chain and proves possession of the private key by signing the handshake transcript. The server validates the client chain against a configured trust pool (a set of trusted root CAs) and accepts or rejects the connection.
Caddy’s client_auth block controls this:
mode— one ofrequest,require,verify_if_given,require_and_verify. The mode determines whether a missing or invalid client cert is fatal.trusted_ca_cert_fileortrusted_ca_cert— the CA(s) Caddy will accept client certs from. This is the trust anchor.trusted_leaf_cert_file— pinned individual client certs, bypassing CA-based validation. Useful when you have a small fixed set of clients.
After validation, Caddy exposes the cert details to the request handler through placeholders: {tls_client_subject}, {tls_client_issuer}, {tls_client_serial}, {tls_client_fingerprint}. You forward these to the upstream as headers so the application can authorize based on identity, not just connection.
The procedure
-
Prepare the trust pool. Use your internal CA’s root certificate, or assemble a bundle of trusted CAs:
# Internal CA root sudo cp /etc/pki/ca-trust/source/anchors/internal-ca.crt /etc/caddy/clients/ca.crt sudo chown caddy:caddy /etc/caddy/clients/ca.crt sudo chmod 644 /etc/caddy/clients/ca.crtThe file is PEM-encoded. Concatenate multiple PEM blocks if you have multiple CAs.
-
Enable mTLS on the site. The minimum config:
api.example.com { tls { client_auth { mode require_and_verify trusted_ca_cert_file /etc/caddy/clients/ca.crt } } reverse_proxy localhost:3000 }require_and_verifyis the strict mode: the client MUST present a cert AND the cert MUST validate against the trust pool. Anything else is rejected at the handshake — the application never sees the request. -
Forward cert details to the upstream. The application needs to know which client is connected:
api.example.com { tls { client_auth { mode require_and_verify trusted_ca_cert_file /etc/caddy/clients/ca.crt } } reverse_proxy localhost:3000 { header_up X-Client-Subject {tls_client_subject} header_up X-Client-Issuer {tls_client_issuer} header_up X-Client-Serial {tls_client_serial} header_up X-Client-Fingerprint {tls_client_fingerprint} } }The application code reads
X-Client-Subjectto identify the caller. The fingerprint header is the most stable identifier for revocation lookups. -
Mixed-mode site — some paths require mTLS, others do not. Common for an API that has a public health endpoint and authenticated routes:
api.example.com { tls { client_auth { mode verify_if_given trusted_ca_cert_file /etc/caddy/clients/ca.crt } } @authenticated { not path /health /version /docs/* } handle @authenticated { @no_cert vars {tls_client_subject} "" respond @no_cert "Client certificate required" 401 reverse_proxy localhost:3000 { header_up X-Client-Subject {tls_client_subject} } } handle { reverse_proxy localhost:3000 } }verify_if_givenaccepts the connection without a client cert, validates if one is presented. The handler then enforces the cert presence per-path. -
Pinned leaf certificates. When you have a known small set of clients and want to bypass CA-based trust:
internal-api.example.com { tls { client_auth { mode require_and_verify trusted_leaf_cert_file /etc/caddy/clients/leaf-bundle.pem } } reverse_proxy localhost:3000 }leaf-bundle.pemis a concatenation of every individual client cert that should be accepted. Add or remove a cert, reload Caddy. No CA, no chain — just the leaf. -
Revocation. Caddy does not natively check CRLs or OCSP for client certs. The two operational patterns:
- Rebuild the trust pool. Issue a new internal CA, re-issue every client cert, swap the trust file. Heavy-handed but airtight.
- Pin leaf certs. Maintain the
trusted_leaf_cert_fileas the source of truth and remove revoked certs from the bundle. - Authorize in the application. Caddy validates the chain; the application checks the cert serial against a revocation list pulled from your CA’s database.
Common pitfalls
mode requestis not the same asmode verify_if_given.requestasks for a cert and allows the connection regardless;verify_if_givenvalidates if presented.requestis almost never what you want — useverify_if_givenorrequire_and_verify.- Self-signed client certs do not validate against a CA. If your CA file is just the self-signed cert itself, it works only for that one cert — that is leaf pinning in disguise.
- The placeholder
{tls_client_subject}is the cert’s distinguished name as a string likeCN=client01,O=Example,C=US. Your application code should parse it or use the fingerprint instead for stable identifiers. - Browsers cache client cert selections per-session. A user testing different certs sees stale behavior — they must close and reopen the browser, or hit a different hostname.
- A bad CA file (wrong format, missing newlines between PEM blocks, expired root) makes Caddy fail to start. Validate with
openssl x509 -in /etc/caddy/clients/ca.crt -noout -textbefore reload.
Stack Harbor runs mTLS endpoints for clients whose internal services need to prove identity beyond IP allowlisting — internal CA infrastructure under management, client cert lifecycle integrated with the customer’s identity provider, and Caddy trust pools rotated on schedule. If you have an internal API or zero-trust gateway that needs the certificate plane operated for you, this is the kind of work covered by our Managed Operations practice.