-
Notifications
You must be signed in to change notification settings - Fork 143
fix: adds a config option to enable TLS/SSL without needing certs loc… #3223
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
base: main
Are you sure you want to change the base?
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -72,6 +72,10 @@ func (o *BrokerOptions) createKafkaConfig(role string) (*sarama.Config, error) { | |
| loggerFunc: logger.Debug, | ||
| } | ||
|
|
||
| if o.KafkaConfig.SecurityProtocol == "SSL" && o.KafkaConfig.TLSInsecure { | ||
| config.Net.TLS.Enable = true | ||
| } | ||
|
Comment on lines
+75
to
+77
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. 🛠️ Refactor suggestion Incorrect gating: TLS for SSL should be enabled regardless of TLSInsecure; also missing InsecureSkipVerify Currently TLS is only enabled for SecurityProtocol == "SSL" when TLSInsecure is true, which breaks valid SSL setups. Additionally, “insecure” mode doesn’t set InsecureSkipVerify, so it won’t achieve the stated goal for self-signed/local certs. Apply this diff to always enable TLS for SSL and conditionally set InsecureSkipVerify: - if o.KafkaConfig.SecurityProtocol == "SSL" && o.KafkaConfig.TLSInsecure {
- config.Net.TLS.Enable = true
- }
+ if o.KafkaConfig.SecurityProtocol == "SSL" {
+ config.Net.TLS.Enable = true
+ if config.Net.TLS.Config == nil {
+ config.Net.TLS.Config = &tls.Config{}
+ }
+ }Add the following block after the SASL_SSL handling (or immediately after SSL/SASL_SSL wiring) to apply “insecure” consistently: // Apply insecure TLS settings if requested
if o.KafkaConfig.TLSInsecure && config.Net.TLS.Enable {
if config.Net.TLS.Config == nil {
config.Net.TLS.Config = &tls.Config{}
}
config.Net.TLS.Config.InsecureSkipVerify = true
}🤖 Prompt for AI Agents |
||
|
|
||
| if o.KafkaConfig.SecurityProtocol == "SASL_SSL" { | ||
| config.Net.SASL.Enable = true | ||
| config.Net.SASL.Handshake = true | ||
|
|
||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
💡 Verification agent
🧩 Analysis chain
TLSInsecure is undocumented and not wired into non-sarama (librdkafka) config; add docs, default, and validation
Apply these diffs and additions:
type KafkaConfiguration struct { Broker string SecurityProtocol string - TLSInsecure bool + // TLSInsecure disables TLS certificate and hostname verification. + // WARNING: Do not use in production. Intended for local dev/testing with self-signed certs. + TLSInsecure bool SaslMechanisms string SaslUsername string SaslPassword stringfunc ConfigureIngest(v *viper.Viper) { v.SetDefault("ingest.kafka.broker", "127.0.0.1:29092") v.SetDefault("ingest.kafka.securityProtocol", "") + v.SetDefault("ingest.kafka.tlsInsecure", false) v.SetDefault("ingest.kafka.saslMechanisms", "") v.SetDefault("ingest.kafka.saslUsername", "") v.SetDefault("ingest.kafka.saslPassword", "")Outside the changed hunk (CreateKafkaConfig), wire TLSInsecure into librdkafka config:
And in validation:
To confirm TLSInsecure is consistently recognized in config files and envs, run:
🏁 Script executed:
Length of output: 294
🏁 Script executed:
Length of output: 8574
Action required: document TLSInsecure, add default & validation, wire it into librdkafka config, and fix Sarama TLS handling
Verified: TLSInsecure is declared in app/config/ingest.go and referenced only in openmeter/watermill/driver/kafka/broker.go. It is not wired into the confluent-librdkafka config (CreateKafkaConfig). The sarama code currently enables TLS only when TLSInsecure is true (bug). Apply the fixes below.
Files to change:
Suggested diffs:
type KafkaConfiguration struct { Broker string SecurityProtocol string - TLSInsecure bool + // TLSInsecure disables TLS certificate and hostname verification. + // WARNING: Do NOT use in production. Intended only for local dev/testing with self-signed certs. + TLSInsecure bool SaslMechanisms string SaslUsername string SaslPassword stringfunc ConfigureIngest(v *viper.Viper) { v.SetDefault("ingest.kafka.broker", "127.0.0.1:29092") v.SetDefault("ingest.kafka.securityProtocol", "") + v.SetDefault("ingest.kafka.tlsInsecure", false) v.SetDefault("ingest.kafka.saslMechanisms", "") v.SetDefault("ingest.kafka.saslUsername", "") v.SetDefault("ingest.kafka.saslPassword", "")func (c KafkaConfiguration) Validate() error { var errs []error ... + if c.TLSInsecure && c.SecurityProtocol != "SSL" && c.SecurityProtocol != "SASL_SSL" { + errs = append(errs, errors.New("tlsInsecure requires securityProtocol to be SSL or SASL_SSL")) + } return errors.Join(errs...) }if c.SecurityProtocol != "" { config["security.protocol"] = c.SecurityProtocol } + // If TLSInsecure is enabled, tell librdkafka to skip cert & hostname verification. + if c.SecurityProtocol == "SSL" || c.SecurityProtocol == "SASL_SSL" { + if c.TLSInsecure { + // librdkafka configs: + // enable.ssl.certificate.verification=false + // ssl.endpoint.identification.algorithm=none + config["enable.ssl.certificate.verification"] = false + config["ssl.endpoint.identification.algorithm"] = "none" + } + }Notes:
📝 Committable suggestion
🤖 Prompt for AI Agents