From ffd1f122de1cce0c01a1f9be00982bfcaff499ac Mon Sep 17 00:00:00 2001 From: Daniel Tomcej Date: Thu, 12 Sep 2019 07:48:05 -0500 Subject: [PATCH] Add TLS minversion constraint --- configuration/configuration.go | 6 +++ configuration/configuration_test.go | 67 +++++++++++++++++++++++++++++ 2 files changed, 73 insertions(+) diff --git a/configuration/configuration.go b/configuration/configuration.go index 9040e0c7a..ede7d8f86 100644 --- a/configuration/configuration.go +++ b/configuration/configuration.go @@ -212,6 +212,12 @@ func (gc *GlobalConfiguration) SetEffectiveConfiguration(configFile string) { } } + // Thanks to SSLv3 being enabled by mistake in golang 1.12, + // If no minVersion is set, apply TLS1.0 as the minimum. + if entryPoint.TLS != nil && len(entryPoint.TLS.MinVersion) == 0 { + entryPoint.TLS.MinVersion = "VersionTLS10" + } + if entryPoint.TLS != nil && entryPoint.TLS.DefaultCertificate == nil && len(entryPoint.TLS.Certificates) > 0 { log.Infof("No tls.defaultCertificate given for %s: using the first item in tls.certificates as a fallback.", entryPointName) entryPoint.TLS.DefaultCertificate = &entryPoint.TLS.Certificates[0] diff --git a/configuration/configuration_test.go b/configuration/configuration_test.go index b3be08aa0..152734003 100644 --- a/configuration/configuration_test.go +++ b/configuration/configuration_test.go @@ -12,6 +12,7 @@ import ( "github.com/containous/traefik/provider" acmeprovider "github.com/containous/traefik/provider/acme" "github.com/containous/traefik/provider/file" + "github.com/containous/traefik/tls" "github.com/stretchr/testify/assert" ) @@ -269,3 +270,69 @@ func TestInitACMEProvider(t *testing.T) { }) } } + +func TestSetEffectiveConfigurationTLSMinVersion(t *testing.T) { + testCases := []struct { + desc string + provided EntryPoint + expected EntryPoint + }{ + { + desc: "Entrypoint with no TLS", + provided: EntryPoint{ + Address: ":80", + }, + expected: EntryPoint{ + Address: ":80", + ForwardedHeaders: &ForwardedHeaders{Insecure: true}, + }, + }, + { + desc: "Entrypoint with TLS Specifying MinVersion", + provided: EntryPoint{ + Address: ":443", + TLS: &tls.TLS{ + MinVersion: "VersionTLS12", + }, + }, + expected: EntryPoint{ + Address: ":443", + ForwardedHeaders: &ForwardedHeaders{Insecure: true}, + TLS: &tls.TLS{ + MinVersion: "VersionTLS12", + }, + }, + }, + { + desc: "Entrypoint with TLS without Specifying MinVersion", + provided: EntryPoint{ + Address: ":443", + TLS: &tls.TLS{}, + }, + expected: EntryPoint{ + Address: ":443", + ForwardedHeaders: &ForwardedHeaders{Insecure: true}, + TLS: &tls.TLS{ + MinVersion: "VersionTLS10", + }, + }, + }, + } + + for _, test := range testCases { + test := test + t.Run(test.desc, func(t *testing.T) { + t.Parallel() + + gc := &GlobalConfiguration{ + EntryPoints: map[string]*EntryPoint{ + "foo": &test.provided, + }, + } + + gc.SetEffectiveConfiguration(defaultConfigFile) + + assert.Equal(t, &test.expected, gc.EntryPoints["foo"]) + }) + } +}