Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Upgrade: ACMEz v2, CertMagic, and ZeroSSL issuer #6229

Merged
merged 9 commits into from
Apr 14, 2024
Merged
Show file tree
Hide file tree
Changes from 4 commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 0 additions & 1 deletion admin.go
Original file line number Diff line number Diff line change
Expand Up @@ -474,7 +474,6 @@ func manageIdentity(ctx Context, cfg *Config) error {
// import the caddytls package -- but it works
if cfg.Admin.Identity.IssuersRaw == nil {
cfg.Admin.Identity.IssuersRaw = []json.RawMessage{
json.RawMessage(`{"module": "zerossl"}`),
json.RawMessage(`{"module": "acme"}`),
}
}
Expand Down
28 changes: 16 additions & 12 deletions caddyconfig/httpcaddyfile/builtins.go
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ import (
"time"

"github.com/caddyserver/certmagic"
"github.com/mholt/acmez/acme"
"github.com/mholt/acmez/v2/acme"
"go.uber.org/zap/zapcore"

"github.com/caddyserver/caddy/v2"
Expand Down Expand Up @@ -107,7 +107,6 @@ func parseTLS(h Helper) ([]ConfigValue, error) {
var onDemand bool
var reusePrivateKeys bool

// file certificate loader
firstLine := h.RemainingArgs()
switch len(firstLine) {
case 0:
Expand All @@ -117,13 +116,13 @@ func parseTLS(h Helper) ([]ConfigValue, error) {
} else if !strings.Contains(firstLine[0], "@") {
return nil, h.Err("single argument must either be 'internal' or an email address")
} else {
if acmeIssuer == nil {
acmeIssuer = new(caddytls.ACMEIssuer)
acmeIssuer = &caddytls.ACMEIssuer{
Email: firstLine[0],
}
acmeIssuer.Email = firstLine[0]
}

case 2:
// file certificate loader
certFilename := firstLine[0]
keyFilename := firstLine[1]

Expand Down Expand Up @@ -488,19 +487,24 @@ func parseTLS(h Helper) ([]ConfigValue, error) {

case acmeIssuer != nil:
// implicit ACME issuers (from various subdirectives) - use defaults; there might be more than one
defaultIssuers := caddytls.DefaultIssuers()
defaultIssuers := caddytls.DefaultIssuers(acmeIssuer.Email)

// if a CA endpoint was set, override multiple implicit issuers since it's a specific one
// if an ACME CA endpoint was set, the user expects to use that specific one,
// not any others that may be defaults, so replace all defaults with that ACME CA
if acmeIssuer.CA != "" {
defaultIssuers = []certmagic.Issuer{acmeIssuer}
}

for _, issuer := range defaultIssuers {
switch iss := issuer.(type) {
case *caddytls.ACMEIssuer:
issuer = acmeIssuer
case *caddytls.ZeroSSLIssuer:
iss.ACMEIssuer = acmeIssuer
// apply settings from the implicitly-configured ACMEIssuer to any
// default ACMEIssuers, but preserve each default issuer's CA endpoint,
// because, for example, if you configure the DNS challenge, it should
// apply to any of the default ACMEIssuers, but you don't want to trample
// out their unique CA endpoints
if iss, ok := issuer.(*caddytls.ACMEIssuer); ok && iss != nil {
acmeCopy := *acmeIssuer
acmeCopy.CA = iss.CA
issuer = &acmeCopy
}
configVals = append(configVals, ConfigValue{
Class: "tls.cert_issuer",
Expand Down
6 changes: 3 additions & 3 deletions caddyconfig/httpcaddyfile/options.go
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ import (
"strconv"

"github.com/caddyserver/certmagic"
"github.com/mholt/acmez/acme"
"github.com/mholt/acmez/v2/acme"

"github.com/caddyserver/caddy/v2"
"github.com/caddyserver/caddy/v2/caddyconfig"
Expand Down Expand Up @@ -212,9 +212,9 @@ func parseOptACMEDNS(d *caddyfile.Dispenser, _ any) (any, error) {
if err != nil {
return nil, err
}
prov, ok := unm.(certmagic.ACMEDNSProvider)
prov, ok := unm.(certmagic.DNSProvider)
if !ok {
return nil, d.Errf("module %s (%T) is not a certmagic.ACMEDNSProvider", modID, unm)
return nil, d.Errf("module %s (%T) is not a certmagic.DNSProvider", modID, unm)
}
return prov, nil
}
Expand Down
21 changes: 14 additions & 7 deletions caddyconfig/httpcaddyfile/tlsapp.go
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ import (
"strings"

"github.com/caddyserver/certmagic"
"github.com/mholt/acmez/acme"
"github.com/mholt/acmez/v2/acme"

"github.com/caddyserver/caddy/v2"
"github.com/caddyserver/caddy/v2/caddyconfig"
Expand Down Expand Up @@ -378,15 +378,12 @@ func (st ServerType) buildTLSApp(
if len(ap.Issuers) == 0 && automationPolicyHasAllPublicNames(ap) {
// for public names, create default issuers which will later be filled in with configured global defaults
// (internal names will implicitly use the internal issuer at auto-https time)
ap.Issuers = caddytls.DefaultIssuers()
emailStr, _ := globalEmail.(string)
ap.Issuers = caddytls.DefaultIssuers(emailStr)

// if a specific endpoint is configured, can't use multiple default issuers
if globalACMECA != nil {
if strings.Contains(globalACMECA.(string), "zerossl") {
ap.Issuers = []certmagic.Issuer{&caddytls.ZeroSSLIssuer{ACMEIssuer: new(caddytls.ACMEIssuer)}}
} else {
ap.Issuers = []certmagic.Issuer{new(caddytls.ACMEIssuer)}
}
ap.Issuers = []certmagic.Issuer{new(caddytls.ACMEIssuer)}
}
}
}
Expand Down Expand Up @@ -666,6 +663,16 @@ func automationPolicyShadows(i int, aps []*caddytls.AutomationPolicy) int {
// subjectQualifiesForPublicCert is like certmagic.SubjectQualifiesForPublicCert() except
// that this allows domains with multiple wildcard levels like '*.*.example.com' to qualify
// if the automation policy has OnDemand enabled (i.e. this function is more lenient).
//
// IP subjects are considered as non-qualifying for public certs. Technically, there are
// now public ACME CAs as well as non-ACME CAs that issue IP certificates. But this function
// is used solely for implicit automation (defaults), where it gets really complicated to
// keep track of which issuers support IP certificates in which circumstances. Currently,
// issuers that support IP certificates are very few, and all require some sort of config
// from the user anyway (such as an account credential). Since we cannot implicitly and
// automatically get public IP certs without configuration from the user, we treat IPs as
// not qualifying for public certificates. Users should expressly configure an issuer
// that supports IP certs for that purpose.
func subjectQualifiesForPublicCert(ap *caddytls.AutomationPolicy, subj string) bool {
return !certmagic.SubjectIsIP(subj) &&
!certmagic.SubjectIsInternal(subj) &&
Expand Down
8 changes: 4 additions & 4 deletions caddytest/integration/acme_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -13,8 +13,8 @@ import (

"github.com/caddyserver/caddy/v2"
"github.com/caddyserver/caddy/v2/caddytest"
"github.com/mholt/acmez"
"github.com/mholt/acmez/acme"
"github.com/mholt/acmez/v2"
"github.com/mholt/acmez/v2/acme"
smallstepacme "github.com/smallstep/certificates/acme"
"go.uber.org/zap"
)
Expand Down Expand Up @@ -77,7 +77,7 @@ func TestACMEServerWithDefaults(t *testing.T) {
return
}

certs, err := client.ObtainCertificate(ctx, account, certPrivateKey, []string{"localhost"})
certs, err := client.ObtainCertificateForSANs(ctx, account, certPrivateKey, []string{"localhost"})
if err != nil {
t.Errorf("obtaining certificate: %v", err)
return
Expand Down Expand Up @@ -146,7 +146,7 @@ func TestACMEServerWithMismatchedChallenges(t *testing.T) {
return
}

certs, err := client.ObtainCertificate(ctx, account, certPrivateKey, []string{"localhost"})
certs, err := client.ObtainCertificateForSANs(ctx, account, certPrivateKey, []string{"localhost"})
if len(certs) > 0 {
t.Errorf("expected '0' certificates, but received '%d'", len(certs))
}
Expand Down
15 changes: 5 additions & 10 deletions caddytest/integration/acmeserver_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -9,8 +9,8 @@ import (
"testing"

"github.com/caddyserver/caddy/v2/caddytest"
"github.com/mholt/acmez"
"github.com/mholt/acmez/acme"
"github.com/mholt/acmez/v2"
"github.com/mholt/acmez/v2/acme"
"go.uber.org/zap"
)

Expand Down Expand Up @@ -105,12 +105,7 @@ func TestACMEServerAllowPolicy(t *testing.T) {
return
}
{
certs, err := client.ObtainCertificate(
ctx,
account,
certPrivateKey,
[]string{"localhost"},
)
certs, err := client.ObtainCertificateForSANs(ctx, account, certPrivateKey, []string{"localhost"})
if err != nil {
t.Errorf("obtaining certificate for allowed domain: %v", err)
return
Expand All @@ -126,7 +121,7 @@ func TestACMEServerAllowPolicy(t *testing.T) {
}
}
{
_, err := client.ObtainCertificate(ctx, account, certPrivateKey, []string{"not-matching.localhost"})
_, err := client.ObtainCertificateForSANs(ctx, account, certPrivateKey, []string{"not-matching.localhost"})
if err == nil {
t.Errorf("obtaining certificate for 'not-matching.localhost' domain")
} else if err != nil && !strings.Contains(err.Error(), "urn:ietf:params:acme:error:rejectedIdentifier") {
Expand Down Expand Up @@ -199,7 +194,7 @@ func TestACMEServerDenyPolicy(t *testing.T) {
return
}
{
_, err := client.ObtainCertificate(ctx, account, certPrivateKey, []string{"deny.localhost"})
_, err := client.ObtainCertificateForSANs(ctx, account, certPrivateKey, []string{"deny.localhost"})
if err == nil {
t.Errorf("obtaining certificate for 'deny.localhost' domain")
} else if err != nil && !strings.Contains(err.Error(), "urn:ietf:params:acme:error:rejectedIdentifier") {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -40,12 +40,6 @@ example.com
"preferred_chains": {
"smallest": true
}
},
{
"module": "zerossl",
"preferred_chains": {
"smallest": true
}
}
]
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -70,8 +70,9 @@ c.example.com {
"module": "acme"
},
{
"ca": "https://acme.zerossl.com/v2/DV90",
"email": "abc@example.com",
"module": "zerossl"
"module": "acme"
}
]
},
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -131,8 +131,9 @@ abc.de {
"module": "acme"
},
{
"ca": "https://acme.zerossl.com/v2/DV90",
"email": "my.email@example.com",
"module": "zerossl"
"module": "acme"
}
]
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -86,8 +86,9 @@ http://localhost:8081 {
"module": "acme"
},
{
"ca": "https://acme.zerossl.com/v2/DV90",
"email": "abc@example.com",
"module": "zerossl"
"module": "acme"
}
]
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -54,8 +54,9 @@ example.com {
"module": "acme"
},
{
"ca": "https://acme.zerossl.com/v2/DV90",
"email": "foo@bar",
"module": "zerossl"
"module": "acme"
}
]
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -58,14 +58,6 @@ tls {
}
},
"module": "acme"
},
{
"challenges": {
"dns": {
"ttl": 310000000000
}
},
"module": "zerossl"
}
]
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ tls {
issuer acme {
dns_ttl 5m10s
}
issuer zerossl {
issuer zerossl api_key {
dns_ttl 10m20s
}
}
Expand Down Expand Up @@ -65,10 +65,9 @@ tls {
"module": "acme"
},
{
"challenges": {
"dns": {
"ttl": 620000000000
}
"api_key": "api_key",
"cname_validation": {
"ttl": 620000000000
},
"module": "zerossl"
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ tls {
propagation_delay 5m10s
propagation_timeout 10m20s
}
issuer zerossl {
issuer zerossl api_key {
propagation_delay 5m30s
propagation_timeout -1
}
Expand Down Expand Up @@ -68,11 +68,10 @@ tls {
"module": "acme"
},
{
"challenges": {
"dns": {
"propagation_delay": 330000000000,
"propagation_timeout": -1
}
"api_key": "api_key",
"cname_validation": {
"propagation_delay": 330000000000,
"propagation_timeout": -1
},
"module": "zerossl"
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -60,15 +60,6 @@ tls {
}
},
"module": "acme"
},
{
"challenges": {
"dns": {
"propagation_delay": 310000000000,
"propagation_timeout": 620000000000
}
},
"module": "zerossl"
}
]
}
Expand Down
15 changes: 7 additions & 8 deletions go.mod
Original file line number Diff line number Diff line change
@@ -1,22 +1,21 @@
module github.com/caddyserver/caddy/v2

go 1.21

toolchain go1.21.4
go 1.22.0

require (
github.com/BurntSushi/toml v1.3.2
github.com/Masterminds/sprig/v3 v3.2.3
github.com/alecthomas/chroma/v2 v2.13.0
github.com/aryann/difflib v0.0.0-20210328193216-ff5ff6dc229b
github.com/caddyserver/certmagic v0.20.0
github.com/caddyserver/certmagic v0.20.1-0.20240411182353-f7ea6fb698e2
github.com/caddyserver/zerossl v0.1.2
github.com/dustin/go-humanize v1.0.1
github.com/go-chi/chi/v5 v5.0.12
github.com/google/cel-go v0.20.0
github.com/google/uuid v1.6.0
github.com/klauspost/compress v1.17.0
github.com/klauspost/cpuid/v2 v2.2.5
github.com/mholt/acmez v1.2.0
github.com/klauspost/cpuid/v2 v2.2.7
github.com/mholt/acmez/v2 v2.0.0-beta.2
github.com/prometheus/client_golang v1.19.0
github.com/quic-go/quic-go v0.42.0
github.com/smallstep/certificates v0.25.3-rc5
Expand Down Expand Up @@ -112,12 +111,12 @@ require (
github.com/jackc/pgservicefile v0.0.0-20221227161230-091c0ba34f0a // indirect
github.com/jackc/pgtype v1.14.0 // indirect
github.com/jackc/pgx/v4 v4.18.3 // indirect
github.com/libdns/libdns v0.2.1 // indirect
github.com/libdns/libdns v0.2.2 // indirect
github.com/manifoldco/promptui v0.9.0 // indirect
github.com/mattn/go-colorable v0.1.13 // indirect
github.com/mattn/go-isatty v0.0.20 // indirect
github.com/mgutz/ansi v0.0.0-20200706080929-d51e80ef957d // indirect
github.com/miekg/dns v1.1.55 // indirect
github.com/miekg/dns v1.1.58 // indirect
github.com/mitchellh/copystructure v1.2.0 // indirect
github.com/mitchellh/go-ps v1.0.0 // indirect
github.com/mitchellh/reflectwalk v1.0.2 // indirect
Expand Down
Loading
Loading