caddy/caddyconfig/httpcaddyfile
Islam Elsayed 5ee9a2d424
httpcaddyfile: new tls_automate_names global option (#8015)
* httpcaddyfile: new tls_automate_names global option

Provisioning a certificate for a name that is not served requires giving
it a site block of its own:

    *.example.com {
    }

    foo.example.com {
            respond "Real site"
    }

That asks the tls app for the wildcard, but it also adds a route to the
http app, so every name pointed at the server that has no site block of
its own -- bar.example.com here -- gets an empty but valid response
rather than no match at all. Wanting a certificate and wanting to serve
a name are separate things, and the Caddyfile had no way to say only the
first.

Name them in the new global option instead:

    {
            tls_automate_names *.example.com
    }

    foo.example.com {
            respond "Real site"
    }

The names are added to the automate certificate loader and to an
automation policy built from the global options, so a name listed here
is managed exactly as it would be from a site block, with the same
issuers; the only difference in the adapted config is that no route is
added for it. Repeating the option appends rather than replaces, so a
long list can be split over several lines.

Names that cannot get a public certificate are given the internal
issuer, the same treatment a site block gives them. Names that already
appear in the automate list are skipped, but a name that also has a site
block is left listed here as well: a site block for http:// only is not
managed by auto-HTTPS, so dropping the name because a block exists could
silently leave it without a certificate.

The option needs no http app at all, so a config consisting only of
global options now adapts to a tls app on its own -- enough to keep
certificates renewed for a mail or XMPP server, or for names served by a
layer 4 app.

Closes #7122

* httpcaddyfile: reuse an existing policy for an automated name

A name given to tls_automate_names may already have an automation policy
from its own site block. Adding a second policy for the same subject is
not just redundant: the adapter rejects overlapping subjects, so

    {
            email nobody@example.com
            tls_automate_names foo.example.com
    }

    foo.example.com {
            tls {
                    ca https://acme.example.test/directory
            }
    }

failed to adapt at all, with "hostname appears in more than one
automation policy, making certificate management ambiguous".

Keep such a name in the automate loader but leave its policy alone. The
site block's policy is the more specific of the two, and the loader entry
is still wanted, since a site block served only over HTTP is not managed
by auto-HTTPS.

* Pin that tls_automate_names overrides auto_https off

The names given to the option are managed whether or not auto-HTTPS is
disabled: unlike the hostless-key block above it, that code is not gated
on auto_https, because naming a subject explicitly is a stronger signal
than the general switch. Nothing enforced it, so add the adaptation
fixture @steadytao asked for.
2026-09-30 06:49:46 -04:00
..
testdata caddyfile: Do not replace import tokens if they are part of a snippet (#5539) 2023-05-22 15:36:55 -06:00
addresses.go core: addresses.go funcs renames (#6622) 2024-10-21 08:02:29 -06:00
addresses_fuzz.go core: Windows service integration (#4790) 2022-07-29 14:06:54 -06:00
addresses_test.go httpcaddyfile: Preserve IPv6 addresses through normalization (fix #4381) 2021-10-20 10:27:59 -06:00
builtins.go httpcaddyfile: give each adaptation its own directive order (#7995) 2026-09-06 09:20:44 -04:00
builtins_test.go log: don't allow overwriting singly-assigned vals (#7927) 2026-08-08 00:59:12 +03:00
directives.go httpcaddyfile: give each adaptation its own directive order (#7995) 2026-09-06 09:20:44 -04:00
directives_test.go httpcaddyfile: give each adaptation its own directive order (#7995) 2026-09-06 09:20:44 -04:00
httptype.go httpcaddyfile: give each adaptation its own directive order (#7995) 2026-09-06 09:20:44 -04:00
httptype_test.go httpcaddyfile: fix incorrect error message on duplicate matchers (#7780) 2026-05-30 07:05:41 +10:00
options.go httpcaddyfile: new tls_automate_names global option (#8015) 2026-09-30 06:49:46 -04:00
options_test.go httpcaddyfile: inherit global ACME issuer settings in tls shortcuts (#7617) 2026-04-26 23:39:57 +10:00
pkiapp.go pki: honor skip_install_trust for explicit tls internal issuers (#7894) 2026-08-25 14:19:33 +10:00
pkiapp_test.go pki: honor skip_install_trust for explicit tls internal issuers (#7894) 2026-08-25 14:19:33 +10:00
serveroptions.go caddyhttp: mitigate slowloris via idle read/write deadlines (#7913) 2026-08-21 21:17:26 -06:00
shorthands.go caddyhttp: add replacer placeholders for escaped values (#7181) 2025-08-25 09:07:51 -06:00
tlsapp.go httpcaddyfile: new tls_automate_names global option (#8015) 2026-09-30 06:49:46 -04:00
tlsapp_test.go caddyfile: preserve implicit TLS issuer semantics (#7743) 2026-05-20 12:48:37 -04:00