Lesson 5 of 9 · 24m
TLS Beyond the Happy Path: Internal CA, DNS, Wildcards, On-Demand
The four TLS designs Caddy operators actually use, with validation requirements and failure modes for each.
Automatic HTTPS feels like one feature until the first real constraint arrives: the service is private, the wildcard cannot use HTTP validation, or customers bring their own domains. Caddy supports these designs cleanly, but they are different designs. Choosing one before understanding validation usually produces a working demo and an operational incident.
Internal names: use Caddy's local CA deliberately
grafana.internal
reverse_proxy 10.0.5.22:3000For names that are not publicly resolvable, Caddy can issue from its internal CA. That means the server side is easy and the client side becomes the work: every browser, script, or monitoring probe must trust the local root certificate. This is excellent inside controlled networks and miserable for unmanaged devices. Do not confuse "certificate exists" with "clients trust it."
DNS validation: required for wildcards, useful when ports are hostile
*.apps.sudosecurity.org {
tls {
dns cloudflare {env.CLOUDFLARE_API_TOKEN}
}
reverse_proxy 127.0.0.1:9000
}Public wildcard certificates require the DNS-01 challenge. That means Caddy needs a DNS provider plugin and an API credential able to create TXT records. It also means issuance can work even when inbound ports are restricted — valuable for split-horizon services and networks where port 80 is unavailable.
The credential becomes high-value. Scope it to the smallest DNS zone permissions your provider supports. An edge credential that can rewrite every domain you own turns a proxy compromise into organization-wide identity theft.
On-demand TLS: customers' domains, not magic
{
on_demand_tls {
ask http://127.0.0.1:8081/tls-allowed
}
}
:443 {
tls {
on_demand
}
reverse_proxy 127.0.0.1:8080
}On-demand TLS obtains a certificate the first time a hostname connects, rather than requiring every hostname in the config. This is how SaaS platforms can support customer-controlled domains. It is also a denial-of-service amplifier unless you gate it. The ask endpoint is not optional decoration — it is your authorization layer deciding whether this tenant/domain is allowed to trigger issuance.
Without that control, an attacker can point unlimited throwaway domains at your edge and force certificate attempts, storage growth, and ACME rate-limit pressure.
Know where state lives
Certificates and ACME account material live under Caddy's storage directory. Back it up, monitor disk usage, and plan restores. Rebuilding state is often possible, but re-issuing hundreds of names can hit rate limits and takes time. Certificate automation reduces routine toil; it does not abolish inventory management.
Field notes
caddy trustinstalls the local root for a machine/browser context where appropriate; it is not a substitute for enterprise certificate distribution.- DNS plugin configuration belongs in protected config or secrets injection. Do not paste API tokens into public repositories.
- A wildcard cert does not make routing safer. Hostname authorization and application tenancy are separate problems.
- Test renewals by checking logs and certificate expiry over time, not by deleting production certificates for fun.
Was this lesson helpful?