fix: Masked kafka credentials getting printed in logs (#33730)

issue: https://github.com/milvus-io/milvus/issues/33727

Signed-off-by: Aldrin <imagesai32@gmail.com>
pull/33633/head^2
Aldrin 2024-06-09 21:35:54 +05:30 committed by GitHub
parent f53ab54c5d
commit 8a4ef1b836
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
1 changed files with 20 additions and 3 deletions

View File

@ -43,15 +43,32 @@ func getBasicConfig(address string) kafka.ConfigMap {
}
}
func ConfigtoString(config kafka.ConfigMap) string {
configString := "["
for key := range config {
if key == "sasl.password" || key == "sasl.username" {
configString += key + ":" + "*** "
} else {
value, _ := config.Get(key, nil)
configString += key + ":" + fmt.Sprintf("%v ", value)
}
}
if len(configString) > 1 {
configString = configString[:len(configString)-1]
}
configString += "]"
return configString
}
func NewKafkaClientInstance(address string) *kafkaClient {
config := getBasicConfig(address)
return NewKafkaClientInstanceWithConfigMap(config, kafka.ConfigMap{}, kafka.ConfigMap{})
}
func NewKafkaClientInstanceWithConfigMap(config kafka.ConfigMap, extraConsumerConfig kafka.ConfigMap, extraProducerConfig kafka.ConfigMap) *kafkaClient {
log.Info("init kafka Config ", zap.String("commonConfig", fmt.Sprintf("+%v", config)),
zap.String("extraConsumerConfig", fmt.Sprintf("+%v", extraConsumerConfig)),
zap.String("extraProducerConfig", fmt.Sprintf("+%v", extraProducerConfig)),
log.Info("init kafka Config ", zap.String("commonConfig", ConfigtoString(config)),
zap.String("extraConsumerConfig", ConfigtoString(extraConsumerConfig)),
zap.String("extraProducerConfig", ConfigtoString(extraProducerConfig)),
)
return &kafkaClient{basicConfig: config, consumerConfig: extraConsumerConfig, producerConfig: extraProducerConfig}
}