Skip to content
This repository has been archived by the owner on May 5, 2024. It is now read-only.

Commit

Permalink
fix: Do not print password when running in verbose mode (#49)
Browse files Browse the repository at this point in the history
Sanitize the `sasl.jaas.config` configuration setting before printing it and replace the configured password with a placeholder.

Fixes devshawn#96
  • Loading branch information
joschi authored Oct 19, 2022
1 parent a3a0549 commit 8fd14ee
Showing 1 changed file with 12 additions and 1 deletion.
Original file line number Diff line number Diff line change
Expand Up @@ -62,12 +62,23 @@ private static void setConfigFromEnvironment(KafkaGitopsConfig.Builder builder)

handleAuthentication(username, password, config);

log.info("Kafka Config: {}", config);
log.info("Kafka Config: {}", sanitizeConfiguration(config));

builder.putAllConfig(config);
handleDefaultConfig(builder);
}

private static Map<String, Object> sanitizeConfiguration(Map<String, Object> config) {
Map<String, Object> sanitizedConfig = new HashMap<>(config);

String saslConfig = (String) config.get(SaslConfigs.SASL_JAAS_CONFIG);
if (saslConfig != null) {
sanitizedConfig.replace(SaslConfigs.SASL_JAAS_CONFIG, saslConfig.replaceFirst("password=\".*\";", "password=[redacted];"));
}

return sanitizedConfig;
}

private static void handleDefaultConfig(KafkaGitopsConfig.Builder builder) {
if (!builder.getConfig().containsKey(CommonClientConfigs.BOOTSTRAP_SERVERS_CONFIG)) {
builder.putConfig(CommonClientConfigs.BOOTSTRAP_SERVERS_CONFIG, "localhost:9092");
Expand Down

0 comments on commit 8fd14ee

Please sign in to comment.