Skip to content

Commit

Permalink
Add CaFile for KafkaRecorder when simpleSSL enabled (#534)
Browse files Browse the repository at this point in the history
  • Loading branch information
paragor authored Jun 30, 2023
1 parent 8bfa0cc commit 65a3601
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 @@ -92,23 +92,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 @@ -118,6 +109,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 65a3601

Please sign in to comment.