Skip to content

Commit

Permalink
fix: TLS configuration from directory.
Browse files Browse the repository at this point in the history
  • Loading branch information
ldez authored and traefiker committed Jul 18, 2019
1 parent 68c349b commit 4dc4480
Show file tree
Hide file tree
Showing 4 changed files with 47 additions and 13 deletions.
24 changes: 23 additions & 1 deletion pkg/provider/file/file.go
Original file line number Diff line number Diff line change
Expand Up @@ -295,9 +295,31 @@ func (p *Provider) loadFileConfigFromDirectory(ctx context.Context, directory st
configTLSMaps[conf] = struct{}{}
}
}

for name, conf := range c.TLS.Options {
if _, exists := configuration.TLS.Options[name]; exists {
logger.Warnf("TLS options %v already configured, skipping", name)
} else {
if configuration.TLS.Options == nil {
configuration.TLS.Options = map[string]tls.Options{}
}
configuration.TLS.Options[name] = conf
}
}

for name, conf := range c.TLS.Stores {
if _, exists := configuration.TLS.Stores[name]; exists {
logger.Warnf("TLS store %v already configured, skipping", name)
} else {
if configuration.TLS.Stores == nil {
configuration.TLS.Stores = map[string]tls.Store{}
}
configuration.TLS.Stores[name] = conf
}
}
}

if len(configTLSMaps) > 0 {
if len(configTLSMaps) > 0 && configuration.TLS == nil {
configuration.TLS = &dynamic.TLSConfiguration{}
}

Expand Down
28 changes: 16 additions & 12 deletions pkg/provider/file/file_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -17,12 +17,13 @@ import (
)

type ProvideTestCase struct {
desc string
directoryPaths []string
filePath string
expectedNumRouter int
expectedNumService int
expectedNumTLSConf int
desc string
directoryPaths []string
filePath string
expectedNumRouter int
expectedNumService int
expectedNumTLSConf int
expectedNumTLSOptions int
}

func TestTLSContent(t *testing.T) {
Expand Down Expand Up @@ -94,6 +95,7 @@ func TestProvideWithoutWatch(t *testing.T) {
assert.Len(t, conf.Configuration.HTTP.Routers, test.expectedNumRouter)
require.NotNil(t, conf.Configuration.TLS)
assert.Len(t, conf.Configuration.TLS.Certificates, test.expectedNumTLSConf)
assert.Len(t, conf.Configuration.TLS.Options, test.expectedNumTLSOptions)
case <-timeout:
t.Errorf("timeout while waiting for config")
}
Expand Down Expand Up @@ -192,9 +194,10 @@ func getTestCases() []ProvideTestCase {
"./fixtures/toml/dir01_file02.toml",
"./fixtures/toml/dir01_file03.toml",
},
expectedNumRouter: 2,
expectedNumService: 3,
expectedNumTLSConf: 4,
expectedNumRouter: 2,
expectedNumService: 3,
expectedNumTLSConf: 4,
expectedNumTLSOptions: 1,
},
{
desc: "simple directory yaml",
Expand All @@ -203,9 +206,10 @@ func getTestCases() []ProvideTestCase {
"./fixtures/yaml/dir01_file02.yml",
"./fixtures/yaml/dir01_file03.yml",
},
expectedNumRouter: 2,
expectedNumService: 3,
expectedNumTLSConf: 4,
expectedNumRouter: 2,
expectedNumService: 3,
expectedNumTLSConf: 4,
expectedNumTLSOptions: 1,
},
{
desc: "template in directory",
Expand Down
4 changes: 4 additions & 0 deletions pkg/provider/file/fixtures/toml/dir01_file03.toml
Original file line number Diff line number Diff line change
Expand Up @@ -15,3 +15,7 @@
[[tls.certificates]]
certFile = "integration/fixtures/https/snitest4.com.cert"
keyFile = "integration/fixtures/https/snitest4.com.key"

[tls.options]
[tls.options.mintls13]
minVersion = "VersionTLS13"
4 changes: 4 additions & 0 deletions pkg/provider/file/fixtures/yaml/dir01_file03.yml
Original file line number Diff line number Diff line change
Expand Up @@ -8,3 +8,7 @@ tls:
keyFile: integration/fixtures/https/snitest3.com.key
- certFile: integration/fixtures/https/snitest4.com.cert
keyFile: integration/fixtures/https/snitest4.com.key

options:
mintls13:
minVersion: VersionTLS13

0 comments on commit 4dc4480

Please sign in to comment.