@marcel91200 / caddy Mirror · read-only / commits / 38677aaa
Fork 0

Fast and extensible multi-platform HTTP/1-2-3 web server with automatic HTTPS

Mirrored from https://github.com/Slazee/caddy.git

Synced Nov 14, 05:15 UTC

caddytls: Support tags for manually-loaded certificates

Matthew Holt committed Jun 24, 2019 at 12:16 UTC 38677aaa58eb76a416fa42146956f3e3a5981e75
6 files changed +33 -20
go.mod
+4 -3
@@ -6,7 +6,7 @@ require (
6 github.com/DataDog/zstd v1.4.0 // indirect
7 github.com/Masterminds/goutils v1.1.0 // indirect
8 github.com/Masterminds/semver v1.4.2 // indirect
9 - github.com/Masterminds/sprig v2.20.0+incompatible // indirect
9 + github.com/Masterminds/sprig v2.20.0+incompatible
10 github.com/andybalholm/brotli v0.0.0-20190430215306-5c318f9037cb
11 github.com/dustin/go-humanize v1.0.0
12 github.com/go-acme/lego v2.6.0+incompatible
@@ -16,14 +16,15 @@ require (
16 github.com/imdario/mergo v0.3.7 // indirect
17 github.com/klauspost/compress v1.7.1-0.20190613161414-0b31f265a57b
18 github.com/klauspost/cpuid v1.2.1
19 - github.com/mholt/certmagic v0.6.2-0.20190621004807-be4f86a2eb60
19 + github.com/mholt/certmagic v0.6.2-0.20190624175158-6a42ef9fe8c2
20 github.com/rs/cors v1.6.0
21 github.com/shurcooL/sanitized_anchor_name v1.0.0 // indirect
22 github.com/starlight-go/starlight v0.0.0-20181207205707-b06f321544f3
23 go.starlark.net v0.0.0-20190604130855-6ddc71c0ba77
24 golang.org/x/net v0.0.0-20190603091049-60506f45cf65
25 - golang.org/x/time v0.0.0-20190308202827-9d24e82272b4 // indirect
25 + golang.org/x/time v0.0.0-20190308202827-9d24e82272b4
26 gopkg.in/russross/blackfriday.v2 v2.0.1
27 + gopkg.in/yaml.v2 v2.2.2 // indirect
28 )
29
30 replace gopkg.in/russross/blackfriday.v2 v2.0.1 => github.com/russross/blackfriday/v2 v2.0.1
go.sum
+6 -6
@@ -32,12 +32,8 @@ github.com/klauspost/compress v1.7.1-0.20190613161414-0b31f265a57b/go.mod h1:RyI
32 github.com/klauspost/cpuid v1.2.0/go.mod h1:Pj4uuM528wm8OyEC2QMXAi2YiTZ96dNQPGgoMS4s3ek=
33 github.com/klauspost/cpuid v1.2.1 h1:vJi+O/nMdFt0vqm8NZBI6wzALWdA2X+egi0ogNyrC/w=
34 github.com/klauspost/cpuid v1.2.1/go.mod h1:Pj4uuM528wm8OyEC2QMXAi2YiTZ96dNQPGgoMS4s3ek=
35 -github.com/mholt/certmagic v0.5.2-0.20190605043235-e49d0d405641 h1:wNqOQ0DFxcZDNpPChhHfL8KscFMnxARN6Q2FiX4/VKI=
36 -github.com/mholt/certmagic v0.5.2-0.20190605043235-e49d0d405641/go.mod h1:g4cOPxcjV0oFq3qwpjSA30LReKD8AoIfwAY9VvG35NY=
37 -github.com/mholt/certmagic v0.6.0 h1:gZwuBuONw2v8/fZh2nd39kvjFNjnSF2uIR4GzKaaryw=
38 -github.com/mholt/certmagic v0.6.0/go.mod h1:g4cOPxcjV0oFq3qwpjSA30LReKD8AoIfwAY9VvG35NY=
39 -github.com/mholt/certmagic v0.6.2-0.20190621004807-be4f86a2eb60 h1:SALetD3LrWGNvna2JIwY1dG4W6rBKtoBehQtHjEKTpo=
40 -github.com/mholt/certmagic v0.6.2-0.20190621004807-be4f86a2eb60/go.mod h1:g4cOPxcjV0oFq3qwpjSA30LReKD8AoIfwAY9VvG35NY=
35 +github.com/mholt/certmagic v0.6.2-0.20190624175158-6a42ef9fe8c2 h1:xKE9kZ5C8gelJC3+BNM6LJs1x21rivK7yxfTZMAuY2s=
36 +github.com/mholt/certmagic v0.6.2-0.20190624175158-6a42ef9fe8c2/go.mod h1:g4cOPxcjV0oFq3qwpjSA30LReKD8AoIfwAY9VvG35NY=
37 github.com/miekg/dns v1.1.3 h1:1g0r1IvskvgL8rR+AcHzUA+oFmGcQlaIm4IqakufeMM=
38 github.com/miekg/dns v1.1.3/go.mod h1:W1PPwlIAgtquWBMBEV9nkV9Cazfe8ScdGz/Lj7v3Nrg=
39 github.com/pmezard/go-difflib v1.0.0 h1:4DBwDE0NGyQoBHbLQYPwSUPoCMWR5BEzIk/f1lZbAQM=
@@ -70,5 +66,9 @@ golang.org/x/text v0.3.0 h1:g61tztE5qeGQ89tm6NTjjM9VPIm088od1l6aSorWRWg=
66 golang.org/x/text v0.3.0/go.mod h1:NqM8EUOU14njkJ3fqMW+pc6Ldnwhi/IjpwHt7yyuwOQ=
67 golang.org/x/time v0.0.0-20190308202827-9d24e82272b4 h1:SvFZT6jyqRaOeXpc5h/JSfZenJ2O330aBsf7JfSUXmQ=
68 golang.org/x/time v0.0.0-20190308202827-9d24e82272b4/go.mod h1:tRJNPiyCQ0inRvYxbN9jk5I+vvW/OXSQhTDSoE431IQ=
69 +gopkg.in/check.v1 v0.0.0-20161208181325-20d25e280405 h1:yhCVgyC4o1eVCa2tZl7eS0r+SDo693bJlVdllGtEeKM=
70 +gopkg.in/check.v1 v0.0.0-20161208181325-20d25e280405/go.mod h1:Co6ibVJAznAaIkqp8huTwlJQCZ016jof/cbN4VW5Yz0=
71 gopkg.in/square/go-jose.v2 v2.2.2 h1:orlkJ3myw8CN1nVQHBFfloD+L3egixIa4FvUP6RosSA=
72 gopkg.in/square/go-jose.v2 v2.2.2/go.mod h1:M9dMgbHiYLoDGQrXy7OpJDJWiKiU//h+vD76mk0e1AI=
73 +gopkg.in/yaml.v2 v2.2.2 h1:ZCJp+EgiOT7lHqUV2J862kp8Qj64Jo6az82+3Td9dZw=
74 +gopkg.in/yaml.v2 v2.2.2/go.mod h1:hI93XBmqTisBFMUTm0b8Fm+jr3Dg1NNxqwp+5A1VGuI=
modules/caddyhttp/caddyhttp.go
+1
@@ -243,6 +243,7 @@ func (app *App) automaticHTTPS() error {
243 })
244
245 // manage their certificates
246 + log.Printf("[INFO] Enabling automatic HTTPS for %v", domains)
247 err := tlsApp.Manage(domains)
248 if err != nil {
249 return fmt.Errorf("%s: managing certificate for %s: %s", srvName, domains, err)
modules/caddytls/fileloader.go
+7 -6
@@ -21,14 +21,15 @@ type fileLoader []CertKeyFilePair
21 // CertKeyFilePair pairs certificate and key file names along with their
22 // encoding format so that they can be loaded from disk.
23 type CertKeyFilePair struct {
24 - Certificate string `json:"certificate"`
25 - Key string `json:"key"`
26 - Format string `json:"format,omitempty"` // "pem" is default
24 + Certificate string `json:"certificate"`
25 + Key string `json:"key"`
26 + Format string `json:"format,omitempty"` // "pem" is default
27 + Tags []string `json:"tags,omitempty"`
28 }
29
30 // LoadCertificates returns the certificates to be loaded by fl.
30 -func (fl fileLoader) LoadCertificates() ([]tls.Certificate, error) {
31 - var certs []tls.Certificate
31 +func (fl fileLoader) LoadCertificates() ([]Certificate, error) {
32 + var certs []Certificate
33 for _, pair := range fl {
34 certData, err := ioutil.ReadFile(pair.Certificate)
35 if err != nil {
@@ -52,7 +53,7 @@ func (fl fileLoader) LoadCertificates() ([]tls.Certificate, error) {
53 return nil, err
54 }
55
55 - certs = append(certs, cert)
56 + certs = append(certs, Certificate{Certificate: cert, Tags: pair.Tags})
57 }
58 return certs, nil
59 }
modules/caddytls/folderloader.go
+5 -3
@@ -29,8 +29,8 @@ type folderLoader []string
29 // listed in fl from all files ending with .pem. This method of loading
30 // certificates expects the certificate and key to be bundled into the
31 // same file.
32 -func (fl folderLoader) LoadCertificates() ([]tls.Certificate, error) {
33 - var certs []tls.Certificate
32 +func (fl folderLoader) LoadCertificates() ([]Certificate, error) {
33 + var certs []Certificate
34 for _, dir := range fl {
35 err := filepath.Walk(dir, func(fpath string, info os.FileInfo, err error) error {
36 if err != nil {
@@ -48,7 +48,7 @@ func (fl folderLoader) LoadCertificates() ([]tls.Certificate, error) {
48 return err
49 }
50
51 - certs = append(certs, cert)
51 + certs = append(certs, Certificate{Certificate: cert})
52
53 return nil
54 })
@@ -120,3 +120,5 @@ func x509CertFromCertAndKeyPEMFile(fpath string) (tls.Certificate, error) {
120
121 return cert, nil
122 }
123 +
124 +var _ CertificateLoader = (folderLoader)(nil)
modules/caddytls/tls.go
+10 -2
@@ -98,7 +98,7 @@ func (t *TLS) Start() error {
98 Storage: t.ctx.Storage(),
99 })
100 for _, cert := range certs {
101 - err := magic.CacheUnmanagedTLSCertificate(cert)
101 + err := magic.CacheUnmanagedTLSCertificate(cert.Certificate, cert.Tags)
102 if err != nil {
103 return fmt.Errorf("caching unmanaged certificate: %v", err)
104 }
@@ -182,8 +182,16 @@ func (t *TLS) getAutomationPolicyForName(name string) AutomationPolicy {
182 }
183
184 // CertificateLoader is a type that can load certificates.
185 +// Certificates can optionally be associated with tags.
186 type CertificateLoader interface {
186 - LoadCertificates() ([]tls.Certificate, error)
187 + LoadCertificates() ([]Certificate, error)
188 +}
189 +
190 +// Certificate is a TLS certificate, optionally
191 +// associated with arbitrary tags.
192 +type Certificate struct {
193 + tls.Certificate
194 + Tags []string
195 }
196
197 // AutomationConfig designates configuration for the