Skip to content

Commit

Permalink
cmd/contour: force TLS 1.2 for the Contour xDS session (projectcontou…
Browse files Browse the repository at this point in the history
…r#2947)

Set the minimum TLS version to TLSv1.2 for gRPC XDS interface, removing
support for TLSv1.0 and TLSv1.1, which are now deprecated.

Signed-off-by: Tero Saarni <tero.saarni@est.tech>
  • Loading branch information
tsaarni authored Sep 28, 2020
1 parent 2cf8324 commit 54c0fa5
Show file tree
Hide file tree
Showing 2 changed files with 30 additions and 0 deletions.
1 change: 1 addition & 0 deletions cmd/contour/servecontext.go
Original file line number Diff line number Diff line change
Expand Up @@ -385,6 +385,7 @@ func (ctx *serveContext) tlsconfig(log logrus.FieldLogger) *tls.Config {
ClientAuth: tls.RequireAndVerifyClientCert,
ClientCAs: certPool,
Rand: rand.Reader,
MinVersion: tls.VersionTLS12,
}, nil
}

Expand Down
29 changes: 29 additions & 0 deletions cmd/contour/servecontext_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -381,6 +381,35 @@ func TestServeContextCertificateHandling(t *testing.T) {
}
}

func TestTlsVersionDeprecation(t *testing.T) {
// To get tls.Config for the gRPC XDS server, we need to arrange valid TLS certificates and keys.
// Create temporary directory to store them for the server.
configDir, err := ioutil.TempDir("", "contour-testdata-")
checkFatalErr(t, err)
defer os.RemoveAll(configDir)

ctx := serveContext{
ServerConfig: ServerConfig{
caFile: filepath.Join(configDir, "CAcert.pem"),
contourCert: filepath.Join(configDir, "contourcert.pem"),
contourKey: filepath.Join(configDir, "contourkey.pem"),
},
}

err = linkFiles("testdata/1", configDir)
checkFatalErr(t, err)

// Get preliminary TLS config from the serveContext.
log := fixture.NewTestLogger(t)
preliminaryTLSConfig := ctx.tlsconfig(log)

// Get actual TLS config that will be used during TLS handshake.
tlsConfig, err := preliminaryTLSConfig.GetConfigForClient(nil)
checkFatalErr(t, err)

assert.Equal(t, tlsConfig.MinVersion, uint16(tls.VersionTLS12))
}

func checkFatalErr(t *testing.T, err error) {
t.Helper()
if err != nil {
Expand Down

0 comments on commit 54c0fa5

Please sign in to comment.