-
Notifications
You must be signed in to change notification settings - Fork 24
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
* Kafka TLS - Add API / config - Read certificates / prepare TLS config for HTTP transport * Allow insecure + ca cert * Add TLS to kafka transformer (ingester) * Remove currently unused server tls config * Add TLS config tests * Use explicit defaults from DefaultDialer
- Loading branch information
Showing
10 changed files
with
364 additions
and
29 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,66 @@ | ||
/* | ||
* Copyright (C) 2022 IBM, Inc. | ||
* | ||
* Licensed under the Apache License, Version 2.0 (the "License"); | ||
* you may not use this file except in compliance with the License. | ||
* You may obtain a copy of the License at | ||
* | ||
* http://www.apache.org/licenses/LICENSE-2.0 | ||
* | ||
* Unless required by applicable law or agreed to in writing, software | ||
* distributed under the License is distributed on an "AS IS" BASIS, | ||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
* See the License for the specific language governing permissions and | ||
* limitations under the License. | ||
* | ||
*/ | ||
|
||
package api | ||
|
||
import ( | ||
"crypto/tls" | ||
"crypto/x509" | ||
"errors" | ||
"io/ioutil" | ||
) | ||
|
||
type ClientTLS struct { | ||
InsecureSkipVerify bool `yaml:"insecureSkipVerify,omitempty" json:"insecureSkipVerify,omitempty" doc:"skip client verifying the server's certificate chain and host name"` | ||
CACertPath string `yaml:"caCertPath,omitempty" json:"caCertPath,omitempty" doc:"path to the CA certificate"` | ||
UserCertPath string `yaml:"userCertPath,omitempty" json:"userCertPath,omitempty" doc:"path to the user certificate"` | ||
UserKeyPath string `yaml:"userKeyPath,omitempty" json:"userKeyPath,omitempty" doc:"path to the user private key"` | ||
} | ||
|
||
func (c *ClientTLS) Build() (*tls.Config, error) { | ||
tlsConfig := &tls.Config{ | ||
InsecureSkipVerify: c.InsecureSkipVerify, | ||
} | ||
if c.CACertPath != "" { | ||
caCert, err := ioutil.ReadFile(c.CACertPath) | ||
if err != nil { | ||
return nil, err | ||
} | ||
tlsConfig.RootCAs = x509.NewCertPool() | ||
tlsConfig.RootCAs.AppendCertsFromPEM(caCert) | ||
|
||
if c.UserCertPath != "" && c.UserKeyPath != "" { | ||
userCert, err := ioutil.ReadFile(c.UserCertPath) | ||
if err != nil { | ||
return nil, err | ||
} | ||
userKey, err := ioutil.ReadFile(c.UserKeyPath) | ||
if err != nil { | ||
return nil, err | ||
} | ||
pair, err := tls.X509KeyPair([]byte(userCert), []byte(userKey)) | ||
if err != nil { | ||
return nil, err | ||
} | ||
tlsConfig.Certificates = []tls.Certificate{pair} | ||
} else if c.UserCertPath != "" || c.UserKeyPath != "" { | ||
return nil, errors.New("userCertPath and userKeyPath must be both present or both absent.") | ||
} | ||
return tlsConfig, nil | ||
} | ||
return nil, nil | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.