Skip to content

Commit

Permalink
Add CaFile for KafkaRecorder when simpleSSL enabled
Browse files Browse the repository at this point in the history
  • Loading branch information
paragor committed Jun 19, 2023
1 parent 347a36d commit 11e22d3
Showing 1 changed file with 12 additions and 10 deletions.
22 changes: 12 additions & 10 deletions pkg/handler/data_recorder_kafka.go
Original file line number Diff line number Diff line change
Expand Up @@ -91,23 +91,14 @@ var NewKafkaRecorder = func() DataRecorder {
}

func createTLSConfiguration(certFile string, keyFile string, caFile string, verifySSL bool, simpleSSL bool) (t *tls.Config) {
if certFile != "" && keyFile != "" && caFile != "" {
if certFile != "" && keyFile != "" {
cert, err := tls.LoadX509KeyPair(certFile, keyFile)
if err != nil {
logrus.WithField("TLSConfigurationError", err).Panic(err)
}

caCert, err := os.ReadFile(caFile)
if err != nil {
logrus.WithField("TLSConfigurationError", err).Panic(err)
}

caCertPool := x509.NewCertPool()
caCertPool.AppendCertsFromPEM(caCert)

t = &tls.Config{
Certificates: []tls.Certificate{cert},
RootCAs: caCertPool,
InsecureSkipVerify: !verifySSL,
}
}
Expand All @@ -117,6 +108,17 @@ func createTLSConfiguration(certFile string, keyFile string, caFile string, veri
InsecureSkipVerify: !verifySSL,
}
}

if caFile != "" && t != nil {
caCert, err := os.ReadFile(caFile)
if err != nil {
logrus.WithField("TLSConfigurationError", err).Panic(err)
}

caCertPool := x509.NewCertPool()
caCertPool.AppendCertsFromPEM(caCert)
t.RootCAs = caCertPool
}
// will be nil by default if nothing is provided
return t
}
Expand Down

0 comments on commit 11e22d3

Please sign in to comment.