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

fix: TLS configuration from directory. #5118

Merged
merged 1 commit into from
Jul 18, 2019
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
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