Skip to content

Commit 84053ea

Browse files
authored
Enforce minimum TLS version of 1.2 (#831)
* Enforce minimum TLS version of 1.2
1 parent 1852086 commit 84053ea

File tree

6 files changed

+71
-23
lines changed

6 files changed

+71
-23
lines changed

common/auth/tlsConfigHelper.go

Lines changed: 57 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,57 @@
1+
// The MIT License
2+
//
3+
// Copyright (c) 2020 Temporal Technologies Inc. All rights reserved.
4+
//
5+
// Permission is hereby granted, free of charge, to any person obtaining a copy
6+
// of this software and associated documentation files (the "Software"), to deal
7+
// in the Software without restriction, including without limitation the rights
8+
// to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9+
// copies of the Software, and to permit persons to whom the Software is
10+
// furnished to do so, subject to the following conditions:
11+
//
12+
// The above copyright notice and this permission notice shall be included in
13+
// all copies or substantial portions of the Software.
14+
//
15+
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16+
// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17+
// FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18+
// AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19+
// LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20+
// OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
21+
// THE SOFTWARE.
22+
23+
package auth
24+
25+
import (
26+
"crypto/tls"
27+
"crypto/x509"
28+
)
29+
30+
// Helper methods for creating tls.Config structs to ensure MinVersion is 1.3
31+
32+
func NewEmptyTLSConfig() *tls.Config {
33+
return &tls.Config{
34+
MinVersion: tls.VersionTLS12,
35+
}
36+
}
37+
38+
func NewTLSConfigForServer(serverName string) *tls.Config {
39+
c := NewEmptyTLSConfig()
40+
c.ServerName = serverName
41+
return c
42+
}
43+
44+
func NewTLSConfigWithCertsAndCAs(certificates []tls.Certificate, rootCAs *x509.CertPool, serverName string) *tls.Config {
45+
c := NewTLSConfigForServer(serverName)
46+
c.Certificates = certificates
47+
c.RootCAs = rootCAs
48+
return c
49+
}
50+
51+
func NewTLSConfigWithClientAuthAndCAs(clientAuth tls.ClientAuthType, certificates []tls.Certificate, clientCAs *x509.CertPool) *tls.Config {
52+
c := NewEmptyTLSConfig()
53+
c.ClientAuth = clientAuth
54+
c.Certificates = certificates
55+
c.ClientCAs = clientCAs
56+
return c
57+
}

common/cassandra/cassandraCluster.go

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -35,6 +35,7 @@ import (
3535

3636
"github.com/gocql/gocql"
3737

38+
"go.temporal.io/server/common/auth"
3839
"go.temporal.io/server/common/service/config"
3940
)
4041

@@ -65,9 +66,7 @@ func NewCassandraCluster(cfg config.Cassandra) (*gocql.ClusterConfig, error) {
6566
CaPath: cfg.TLS.CaFile,
6667
EnableHostVerification: cfg.TLS.EnableHostVerification,
6768

68-
Config: &tls.Config{
69-
ServerName: cfg.TLS.ServerName,
70-
},
69+
Config: auth.NewTLSConfigForServer(cfg.TLS.ServerName),
7170
}
7271

7372
if cfg.TLS.CertData != "" {

common/messaging/kafkaClient.go

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -195,8 +195,5 @@ func CreateTLSConfig(tlsConfig auth.TLS) (*tls.Config, error) {
195195
}
196196
caCertPool.AppendCertsFromPEM(pemData)
197197

198-
return &tls.Config{
199-
Certificates: []tls.Certificate{cert},
200-
RootCAs: caCertPool,
201-
}, nil
198+
return auth.NewTLSConfigWithCertsAndCAs([]tls.Certificate{cert}, caCertPool, ""), nil
202199
}

common/persistence/sql/sqlplugin/mysql/plugin.go

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -38,6 +38,7 @@ import (
3838
"github.com/iancoleman/strcase"
3939
"github.com/jmoiron/sqlx"
4040

41+
"go.temporal.io/server/common/auth"
4142
"go.temporal.io/server/common/persistence/sql"
4243
"go.temporal.io/server/common/persistence/sql/sqlplugin"
4344
"go.temporal.io/server/common/service/config"
@@ -128,9 +129,7 @@ func registerTLSConfig(cfg *config.SQL) error {
128129
}
129130

130131
// TODO: create a way to set MinVersion and CipherSuites via cfg.
131-
tlsConfig := &tls.Config{
132-
ServerName: host,
133-
}
132+
tlsConfig := auth.NewTLSConfigForServer(host)
134133

135134
if cfg.TLS.CaFile != "" {
136135
rootCertPool := x509.NewCertPool()

common/rpc/encryption/localStoreTlsFactory.go

Lines changed: 7 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -30,6 +30,7 @@ import (
3030
"fmt"
3131
"sync"
3232

33+
"go.temporal.io/server/common/auth"
3334
"go.temporal.io/server/common/service/config"
3435
)
3536

@@ -137,11 +138,7 @@ func newServerTLSConfig(certProvider CertProvider, settingsProvider CertProvider
137138
clientCaPool = ca
138139
}
139140

140-
return &tls.Config{
141-
ClientAuth: clientAuthType,
142-
Certificates: []tls.Certificate{*serverCert},
143-
ClientCAs: clientCaPool,
144-
}, nil
141+
return auth.NewTLSConfigWithClientAuthAndCAs(clientAuthType, []tls.Certificate{*serverCert}, clientCaPool), nil
145142
}
146143

147144
func newClientTLSConfig(localProvider CertProvider, remoteProvider CertProvider) (*tls.Config, error) {
@@ -165,9 +162,9 @@ func newClientTLSConfig(localProvider CertProvider, remoteProvider CertProvider)
165162
clientCerts = []tls.Certificate{*cert}
166163
}
167164

168-
return &tls.Config{
169-
Certificates: clientCerts,
170-
RootCAs: serverCa,
171-
ServerName: remoteProvider.GetSettings().Client.ServerName,
172-
}, nil
165+
return auth.NewTLSConfigWithCertsAndCAs(
166+
clientCerts,
167+
serverCa,
168+
remoteProvider.GetSettings().Client.ServerName,
169+
), nil
173170
}

tools/cli/factory.go

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -39,6 +39,7 @@ import (
3939
"google.golang.org/grpc/credentials"
4040

4141
"go.temporal.io/server/api/adminservice/v1"
42+
"go.temporal.io/server/common/auth"
4243
"go.temporal.io/server/common/log"
4344
)
4445

@@ -135,9 +136,7 @@ func (b *clientFactory) createGRPCConnection(c *cli.Context) (*grpc.ClientConn,
135136
}
136137
// If we are given arguments to verify either server or client, configure TLS
137138
if caPool != nil || cert != nil {
138-
tlsConfig := &tls.Config{
139-
ServerName: host,
140-
}
139+
tlsConfig := auth.NewTLSConfigForServer(host)
141140
if caPool != nil {
142141
tlsConfig.RootCAs = caPool
143142
}

0 commit comments

Comments
 (0)