Lesson 8 of 9 · 21m
Extending Caddy: Modules, xcaddy, and Plugin Discipline
When a plugin is the right answer, how to build one with xcaddy, and why plugins change your patching and threat model.
Caddy's module system is one of its best traits and one of its easiest ways to hurt yourself. Core Caddy covers a huge amount of infrastructure. Plugins add DNS providers, storage backends, authentication systems, observability integrations, and niche protocol behavior. The question is never merely "does a plugin exist?" It is "do I want this code in my edge process for the next three years?"
The canonical example: DNS validation
The stock Caddy binary cannot speak every DNS provider API. If you need DNS-01 validation for a wildcard or a locked-down host, install the relevant DNS plugin:
xcaddy build --with github.com/caddy-dns/cloudflareThen configure the provider:
tls {
dns cloudflare {env.CLOUDFLARE_API_TOKEN}
}That plugin now participates in certificate issuance — a critical security path. Treat it accordingly.
Understand the build tradeoff
xcaddy compiles a custom binary with the requested modules. That is simple and powerful, but it means your package manager no longer owns the complete artifact. You now need a process for rebuilding when Caddy or the plugin has a security release.
A sane pattern is:
upstream Caddy release
+
pinned plugin versions
|
v
reproducible build pipeline -> test binary -> deploy artifactPin versions. Record the exact build command. Test the binary in staging before replacing the edge. Downloading a random plugin in a panic during an incident is how supply-chain risk enters through the front door.
Plugins are process residents, not config decorators
A module runs inside the Caddy process with access to whatever that process can access. It can see traffic metadata, manipulate requests, read configured credentials, and crash or slow the entire edge. Popularity of the core project does not transfer automatically to every community plugin.
Before adopting one, inspect maintenance activity, issue handling, dependency quality, and whether the feature belongs at the edge at all. Sometimes authentication or tenant logic belongs in the application, not inside the web server. Putting every concern in Caddy because it is programmable creates a distributed monolith in the worst possible place.
Prefer standard config before custom code
Caddy already supports rich matchers, rewrites, templates, rate limiting through modules, forward auth integrations through external systems, and multiple certificate strategies. Write the standard version first. If it becomes contorted, that is evidence — not proof — that a module or external service is justified.
Field notes
- Keep a copy of the exact
xcaddy buildcommand in infrastructure code, not shell history. - Treat plugin upgrades like dependency upgrades anywhere else: changelog, test, staged rollout.
- Do not install plugins because they are convenient in a blog post; install them because a named requirement demands them.
- If a plugin handles credentials, review token scope and file permissions before the first certificate is issued.
Was this lesson helpful?