caddytls: Log error if ask request fails

Errors returned from the DecisionFunc (whether to get a cert on-demand)
are used as a signal whether to allow a cert or not; *any* error
will forbid cert issuance.

We bubble up the error all the way to the caller, but that caller is the
Go standard library which might gobble it up.
Now we explicitly log connection errors so sysadmins can
ensure their ask endpoints are working.

Thanks to our sponsor AppCove for reporting this!
This commit is contained in:
Matthew Holt 2022-08-23 22:28:11 -06:00
parent bbc923d66b
commit 3aabbc49a2
2 changed files with 37 additions and 24 deletions

View file

@ -16,6 +16,7 @@ package caddytls
import (
"encoding/json"
"errors"
"fmt"
"net/http"
"time"
@ -23,6 +24,7 @@ import (
"github.com/caddyserver/caddy/v2"
"github.com/caddyserver/certmagic"
"github.com/mholt/acmez"
"go.uber.org/zap"
)
// AutomationConfig governs the automated management of TLS certificates.
@ -174,6 +176,13 @@ func (ap *AutomationPolicy) Provision(tlsApp *TLS) error {
tlsApp.Automation.OnDemand.Ask != "" {
err := onDemandAskRequest(tlsApp.Automation.OnDemand.Ask, name)
if err != nil {
// distinguish true errors from denials, because it's important to log actual errors
if !errors.Is(err, errAskDenied) {
tlsApp.logger.Error("request to 'ask' endpoint failed",
zap.Error(err),
zap.String("endpoint", tlsApp.Automation.OnDemand.Ask),
zap.String("domain", name))
}
return err
}
}