Skip to content

Commit

Permalink
Honor ca-certificate in 1-way TLS
Browse files Browse the repository at this point in the history
This lets you use kt with unauthenticated clusters exposed via a k8s ingress, e.g. as deployed by strimzi
  • Loading branch information
jvansanten authored and fgeller committed Sep 9, 2023
1 parent 486f3b8 commit 9d4c73f
Show file tree
Hide file tree
Showing 2 changed files with 26 additions and 1 deletion.
7 changes: 6 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -283,11 +283,16 @@ Required fields:

- `mode`: This needs to be set to `TLS-1way`

Optional fields:

- `ca-certificate`: Path to your CA certificate


Example:


{
"mode": "TLS-1way",
"mode": "TLS-1way"
}

### Other modes
Expand Down
20 changes: 20 additions & 0 deletions common.go
Original file line number Diff line number Diff line change
Expand Up @@ -238,6 +238,26 @@ func setupSASL(auth authConfig, saramaCfg *sarama.Config) error {
func setupAuthTLS1Way(auth authConfig, saramaCfg *sarama.Config) error {
saramaCfg.Net.TLS.Enable = true
saramaCfg.Net.TLS.Config = &tls.Config{}

if auth.CACert == "" {
return nil
}

caString, err := ioutil.ReadFile(auth.CACert)
if err != nil {
return fmt.Errorf("failed to read ca-certificate err=%v", err)
}

caPool := x509.NewCertPool()
ok := caPool.AppendCertsFromPEM(caString)
if !ok {
failf("unable to add ca-certificate at %s to certificate pool", auth.CACert)
}

tlsCfg := &tls.Config{RootCAs: caPool}
tlsCfg.BuildNameToCertificate()

saramaCfg.Net.TLS.Config = tlsCfg
return nil
}

Expand Down

0 comments on commit 9d4c73f

Please sign in to comment.