Skip to content

Commit 3bfd269

Browse files
authored
feat(cdc): Add superflag to enable TLS without CA or certs. (#7946) (#8097)
This will attempt to connect to Kafka over TLS using the system certs. * Add helper function x.TLSBaseConfig. Sets the min TLS version to v1.2 along with the minimum cipher suites.
1 parent da9655b commit 3bfd269

File tree

3 files changed

+37
-21
lines changed

3 files changed

+37
-21
lines changed

worker/server_state.go

+1-1
Original file line numberDiff line numberDiff line change
@@ -42,7 +42,7 @@ const (
4242
BadgerDefaults = `compression=snappy; numgoroutines=8;`
4343
CacheDefaults = `size-mb=1024; percentage=50,30,20;`
4444
CDCDefaults = `file=; kafka=; sasl_user=; sasl_password=; ca_cert=; client_cert=; ` +
45-
`client_key=; sasl-mechanism=PLAIN;`
45+
`client_key=; sasl-mechanism=PLAIN; tls=false;`
4646
GraphQLDefaults = `introspection=true; debug=false; extensions=true; poll-interval=1s; `
4747
LambdaDefaults = `url=; num=1; port=20000; restart-after=30s; `
4848
LimitDefaults = `mutations=allow; query-edge=1000000; normalize-node=10000; ` +

worker/sink_handler.go

+12-2
Original file line numberDiff line numberDiff line change
@@ -86,8 +86,18 @@ func newKafkaSink(config *z.SuperFlag) (Sink, error) {
8686
saramaConf.Producer.Return.Successes = true
8787
saramaConf.Producer.Return.Errors = true
8888

89-
if config.GetPath("ca-cert") != "" {
90-
tlsCfg := &tls.Config{}
89+
if config.GetBool("tls") && config.GetPath("ca-cert") == "" {
90+
tlsCfg := x.TLSBaseConfig()
91+
var pool *x509.CertPool
92+
var err error
93+
if pool, err = x509.SystemCertPool(); err != nil {
94+
return nil, err
95+
}
96+
tlsCfg.RootCAs = pool
97+
saramaConf.Net.TLS.Enable = true
98+
saramaConf.Net.TLS.Config = tlsCfg
99+
} else if config.GetPath("ca-cert") != "" {
100+
tlsCfg := x.TLSBaseConfig()
91101
var pool *x509.CertPool
92102
var err error
93103
if pool, err = x509.SystemCertPool(); err != nil {

x/tls_helper.go

+24-18
Original file line numberDiff line numberDiff line change
@@ -263,11 +263,34 @@ func setupClientAuth(authType string) (tls.ClientAuthType, error) {
263263
return tls.NoClientCert, nil
264264
}
265265

266+
// TLSBaseConfig returns a *tls.Config with the base set of security
267+
// requirements (minimum TLS v1.2 and set of cipher suites)
268+
func TLSBaseConfig() *tls.Config {
269+
tlsCfg := new(tls.Config)
270+
tlsCfg.MinVersion = tls.VersionTLS12
271+
tlsCfg.CipherSuites = []uint16{
272+
tls.TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256,
273+
tls.TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384,
274+
tls.TLS_ECDHE_ECDSA_WITH_AES_128_GCM_SHA256,
275+
tls.TLS_ECDHE_ECDSA_WITH_AES_256_GCM_SHA384,
276+
tls.TLS_ECDHE_RSA_WITH_CHACHA20_POLY1305,
277+
tls.TLS_ECDHE_ECDSA_WITH_CHACHA20_POLY1305,
278+
tls.TLS_ECDHE_RSA_WITH_AES_128_CBC_SHA,
279+
tls.TLS_ECDHE_ECDSA_WITH_AES_128_CBC_SHA,
280+
tls.TLS_ECDHE_RSA_WITH_AES_256_CBC_SHA,
281+
tls.TLS_ECDHE_ECDSA_WITH_AES_256_CBC_SHA,
282+
tls.TLS_RSA_WITH_AES_128_GCM_SHA256,
283+
tls.TLS_RSA_WITH_AES_256_GCM_SHA384,
284+
tls.TLS_RSA_WITH_AES_256_CBC_SHA,
285+
}
286+
return tlsCfg
287+
}
288+
266289
// GenerateServerTLSConfig creates and returns a new *tls.Config with the
267290
// configuration provided.
268291
func GenerateServerTLSConfig(config *TLSHelperConfig) (tlsCfg *tls.Config, err error) {
269292
if config.CertRequired {
270-
tlsCfg = new(tls.Config)
293+
tlsCfg = TLSBaseConfig()
271294
cert, err := tls.LoadX509KeyPair(config.Cert, config.Key)
272295
if err != nil {
273296
return nil, err
@@ -286,23 +309,6 @@ func GenerateServerTLSConfig(config *TLSHelperConfig) (tlsCfg *tls.Config, err e
286309
}
287310
tlsCfg.ClientAuth = auth
288311

289-
tlsCfg.MinVersion = tls.VersionTLS12
290-
tlsCfg.CipherSuites = []uint16{
291-
tls.TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256,
292-
tls.TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384,
293-
tls.TLS_ECDHE_ECDSA_WITH_AES_128_GCM_SHA256,
294-
tls.TLS_ECDHE_ECDSA_WITH_AES_256_GCM_SHA384,
295-
tls.TLS_ECDHE_RSA_WITH_CHACHA20_POLY1305,
296-
tls.TLS_ECDHE_ECDSA_WITH_CHACHA20_POLY1305,
297-
tls.TLS_ECDHE_RSA_WITH_AES_128_CBC_SHA,
298-
tls.TLS_ECDHE_ECDSA_WITH_AES_128_CBC_SHA,
299-
tls.TLS_ECDHE_RSA_WITH_AES_256_CBC_SHA,
300-
tls.TLS_ECDHE_ECDSA_WITH_AES_256_CBC_SHA,
301-
tls.TLS_RSA_WITH_AES_128_GCM_SHA256,
302-
tls.TLS_RSA_WITH_AES_256_GCM_SHA384,
303-
tls.TLS_RSA_WITH_AES_256_CBC_SHA,
304-
}
305-
306312
return tlsCfg, nil
307313
}
308314
return nil, nil

0 commit comments

Comments
 (0)