Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

kafkabase: Add support for custom CA certificate in Kafka SSL configuration #23

Merged
merged 1 commit into from
Jan 27, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 8 additions & 0 deletions .docs/server-config.md
Original file line number Diff line number Diff line change
Expand Up @@ -83,6 +83,14 @@ List of Kafka brokers separated by comma. Each broker should be in format `host:

If SSL should be enabled

### `BULKER_KAFKA_SSL_CA`

CA certificate string (PEM format) for verifying the broker's key.

### `BULKER_KAFKA_SSL_CA_FILE`

File path to CA certificate for verifying the broker's key.

### `BULKER_KAFKA_SSL_SKIP_VERIFY`

Skip SSL verification of kafka server certificate.
Expand Down
11 changes: 10 additions & 1 deletion kafkabase/kafka_config.go
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,10 @@ type KafkaConfig struct {
KafkaBootstrapServers string `mapstructure:"KAFKA_BOOTSTRAP_SERVERS"`
KafkaSSL bool `mapstructure:"KAFKA_SSL" default:"false"`
KafkaSSLSkipVerify bool `mapstructure:"KAFKA_SSL_SKIP_VERIFY" default:"false"`
//Kafka authorization as JSON object {"mechanism": "SCRAM-SHA-256|PLAIN", "username": "user", "password": "password"}
KafkaSSLCA string `mapstructure:"KAFKA_SSL_CA"`
KafkaSSLCAFile string `mapstructure:"KAFKA_SSL_CA_FILE"`

// Kafka authorization as JSON object {"mechanism": "SCRAM-SHA-256|PLAIN", "username": "user", "password": "password"}
KafkaSASL string `mapstructure:"KAFKA_SASL"`

KafkaSessionTimeoutMs int `mapstructure:"KAFKA_SESSION_TIMEOUT_MS" default:"45000"`
Expand Down Expand Up @@ -63,6 +66,12 @@ func (ac *KafkaConfig) GetKafkaConfig() *kafka.ConfigMap {
if ac.KafkaSSLSkipVerify {
_ = kafkaConfig.SetKey("enable.ssl.certificate.verification", false)
}
if ac.KafkaSSLCA != "" {
_ = kafkaConfig.SetKey("ssl.ca.pem", ac.KafkaSSLCA)
}
if ac.KafkaSSLCAFile != "" {
_ = kafkaConfig.SetKey("ssl.ca.location", ac.KafkaSSLCAFile)
}
}
if ac.KafkaSASL != "" {
sasl := map[string]interface{}{}
Expand Down