Skip to content
Closed
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
Original file line number Diff line number Diff line change
Expand Up @@ -381,7 +381,7 @@ public void replay(ConfigRecord record) {
if (configs.isEmpty()) {
configData.remove(configResource);
}
log.info("{}: set configuration {} to {}", configResource, record.name(), record.value());
log.info("{}: set configuration {} to {}", configResource, record.name(), configSchema.getLoggableValue(record));
}

// VisibleForTesting
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,7 @@
import java.util.List;
import java.util.Map;
import java.util.function.Function;
import java.util.Locale;

import static java.util.Collections.emptyList;
import static java.util.Collections.emptyMap;
Expand Down Expand Up @@ -141,9 +142,21 @@ public boolean isSensitive(ConfigResource.Type type, String key) {
if (configDef == null) return true;
ConfigDef.ConfigKey configKey = configDef.configKeys().get(key);
if (configKey == null) return true;
if (key.toUpperCase(Locale.ROOT).contains(ConfigDef.Type.PASSWORD.toString())) return true;
return configKey.type.isSensitive();
}

/**
* Sensitive configs such as Password must be hidden from logging.
* */
public String getLoggableValue(ConfigRecord record) {
if (record == null) return null;
if (isSensitive(record)) {
return Password.HIDDEN;
}
return record.value();
}

/**
* Get the default value of the configuration key, or null if no default is specified.
*/
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,8 @@
import org.apache.kafka.clients.admin.ConfigEntry;
import org.apache.kafka.common.config.ConfigDef;
import org.apache.kafka.common.config.ConfigResource;
import org.apache.kafka.common.config.types.Password;
import org.apache.kafka.common.metadata.ConfigRecord;
import org.apache.kafka.common.requests.DescribeConfigsResponse;
import org.junit.jupiter.api.Test;
import org.junit.jupiter.api.Timeout;
Expand All @@ -36,6 +38,7 @@
import static org.junit.jupiter.api.Assertions.assertEquals;
import static org.junit.jupiter.api.Assertions.assertFalse;
import static org.junit.jupiter.api.Assertions.assertTrue;
import static org.junit.jupiter.api.Assertions.assertNull;


@Timeout(value = 40)
Expand All @@ -48,7 +51,8 @@ public class KafkaConfigSchemaTest {
define("baz", ConfigDef.Type.STRING, ConfigDef.Importance.HIGH, "baz doc").
define("quux", ConfigDef.Type.INT, ConfigDef.Importance.HIGH, "quux doc").
define("quuux", ConfigDef.Type.PASSWORD, ConfigDef.Importance.HIGH, "quuux doc").
define("quuux2", ConfigDef.Type.PASSWORD, ConfigDef.Importance.HIGH, "quuux2 doc"));
define("quuux2", ConfigDef.Type.PASSWORD, ConfigDef.Importance.HIGH, "quuux2 doc").
define("ssl.password", ConfigDef.Type.PASSWORD, ConfigDef.Importance.HIGH, "password doc"));
CONFIGS.put(TOPIC, new ConfigDef().
define("abc", ConfigDef.Type.LIST, ConfigDef.Importance.HIGH, "abc doc").
define("def", ConfigDef.Type.LONG, ConfigDef.Importance.HIGH, "def doc").
Expand Down Expand Up @@ -162,4 +166,18 @@ ConfigEntry.ConfigSource.DEFAULT_CONFIG, true, false, emptyList(),
dynamicNodeConfigs,
dynamicTopicConfigs));
}

@Test
public void testGetLoggableValue() {
ConfigRecord record1 = new ConfigRecord().
setResourceType(BROKER.id()).setResourceName("0").
setName("foo.bar").setValue("bar");
assertEquals(SCHEMA.getLoggableValue(record1), record1.value());
ConfigRecord record2 = null;
assertNull(SCHEMA.getLoggableValue(record2));
ConfigRecord record3 = new ConfigRecord().
setResourceType(BROKER.id()).setResourceName("0").
setName("ssl.password").setValue("bar");
assertEquals(SCHEMA.getLoggableValue(record3), Password.HIDDEN);
}
}