do not try to get a tls cert for autoconfig.<domain> at startup if there is no listener with autoconfig enabled

reduces needless logging in setups that don't use autoconfig.
This commit is contained in:
Mechiel Lukkien 2024-12-07 20:28:52 +01:00
parent cbe418ec59
commit 35af7e30a6
No known key found for this signature in database

View file

@ -821,32 +821,38 @@ func portServes(l config.Listener) map[int]*serve {
} }
if l.TLS != nil && l.TLS.ACME != "" { if l.TLS != nil && l.TLS.ACME != "" {
hosts := map[dns.Domain]struct{}{ m := mox.Conf.Static.ACME[l.TLS.ACME].Manager
mox.Conf.Static.HostnameDomain: {}, if ensureManagerHosts[m] == nil {
ensureManagerHosts[m] = map[dns.Domain]struct{}{}
} }
hosts := ensureManagerHosts[m]
hosts[mox.Conf.Static.HostnameDomain] = struct{}{}
if l.HostnameDomain.ASCII != "" { if l.HostnameDomain.ASCII != "" {
hosts[l.HostnameDomain] = struct{}{} hosts[l.HostnameDomain] = struct{}{}
} }
// All domains are served on all listeners. Gather autoconfig hostnames to ensure
// presence of TLS certificates for.
for _, name := range mox.Conf.Domains() {
if dom, err := dns.ParseDomain(name); err != nil {
pkglog.Errorx("parsing domain from config", err)
} else if d, _ := mox.Conf.Domain(dom); d.ReportsOnly {
// Do not gather autoconfig name if we aren't accepting email for this domain.
continue
}
autoconfdom, err := dns.ParseDomain("autoconfig." + name) // All domains are served on all listeners. Gather autoconfig hostnames to ensure
if err != nil { // presence of TLS certificates. Fetching a certificate on-demand may be too slow
pkglog.Errorx("parsing domain from config for autoconfig", err) // for the timeouts of clients doing autoconfig.
} else {
hosts[autoconfdom] = struct{}{} if l.AutoconfigHTTPS.Enabled && !l.AutoconfigHTTPS.NonTLS {
for _, name := range mox.Conf.Domains() {
if dom, err := dns.ParseDomain(name); err != nil {
pkglog.Errorx("parsing domain from config", err)
} else if d, _ := mox.Conf.Domain(dom); d.ReportsOnly {
// Do not gather autoconfig name if we aren't accepting email for this domain.
continue
}
autoconfdom, err := dns.ParseDomain("autoconfig." + name)
if err != nil {
pkglog.Errorx("parsing domain from config for autoconfig", err)
} else {
hosts[autoconfdom] = struct{}{}
}
} }
} }
m := mox.Conf.Static.ACME[l.TLS.ACME].Manager
ensureManagerHosts[m] = hosts
} }
for _, srv := range portServe { for _, srv := range portServe {