This is an automated email from the ASF dual-hosted git repository.
swaminathanmanish pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/pinot.git
The following commit(s) were added to refs/heads/master by this push:
new a7075cc54c1 Mask stream credentials in StreamConfig#toString() and
table add/update logs (#19775)
a7075cc54c1 is described below
commit a7075cc54c17b964a26cd0b9b90d9e176ae72b13
Author: Deshmukh P <[email protected]>
AuthorDate: Tue Nov 17 18:16:25 2026 +0530
Mask stream credentials in StreamConfig#toString() and table add/update
logs (#19775)
* Redact credentials from StreamConfig#toString() before logging
StreamConfig#toString() dumped _streamConfigMap/_decoderProperties
verbatim, leaking plaintext
secrets (e.g. Kafka sasl.jaas.config username/password) into server logs
whenever a stream config
error is logged, such as a failed StreamMessageDecoder initialization.
Mask values for sensitive-looking keys via the existing Obfuscator, and
additionally redact
username=/password= pairs embedded inside a single value (as in a JAAS
login-module string),
which key-based masking alone cannot reach.
Fixes #19774
* Mask sasl.jaas.config by key and redact table config logs
Address review feedback on the credential redaction:
- Add sasl.jaas.config (including prefixed forms) to the default Obfuscator
key patterns so the whole JAAS value is masked. This replaces the
double-quote-only regex, which missed single-quoted and unquoted values
and
leaked the tail of a value containing an escaped quote.
- StreamConfig#toString() now delegates to Obfuscator for both the stream
config map and the decoder properties, without touching the real maps.
- Log the table config through Obfuscator when a table is added or updated
in
PinotTableRestletResource, which previously printed the raw stream
configs.
- Add StreamConfigTest and extend ObfuscatorTest, covering all JAAS quoting
forms, prefixed and case-insensitive keys, the custom-pattern contract,
and a
real TableConfig that keeps its real values.
Co-Authored-By: Claude Sonnet 5.5 <[email protected]>
---------
Co-authored-by: Claude Sonnet 5.5 <[email protected]>
---
.../api/resources/PinotTableRestletResource.java | 7 +-
.../org/apache/pinot/spi/stream/StreamConfig.java | 17 ++-
.../apache/pinot/spi/stream/StreamConfigTest.java | 131 +++++++++++++++++++++
.../org/apache/pinot/spi/utils/ObfuscatorTest.java | 82 +++++++++++++
4 files changed, 233 insertions(+), 4 deletions(-)
diff --git
a/pinot-controller/src/main/java/org/apache/pinot/controller/api/resources/PinotTableRestletResource.java
b/pinot-controller/src/main/java/org/apache/pinot/controller/api/resources/PinotTableRestletResource.java
index 34b24cdff06..637e14bfa5e 100644
---
a/pinot-controller/src/main/java/org/apache/pinot/controller/api/resources/PinotTableRestletResource.java
+++
b/pinot-controller/src/main/java/org/apache/pinot/controller/api/resources/PinotTableRestletResource.java
@@ -138,6 +138,7 @@ import org.apache.pinot.spi.utils.CommonConstants;
import org.apache.pinot.spi.utils.Enablement;
import org.apache.pinot.spi.utils.IngestionConfigUtils;
import org.apache.pinot.spi.utils.JsonUtils;
+import org.apache.pinot.spi.utils.Obfuscator;
import org.apache.pinot.spi.utils.builder.ControllerRequestURLBuilder;
import org.apache.pinot.spi.utils.builder.TableNameBuilder;
import org.apache.pinot.spi.utils.retry.RetryPolicies;
@@ -267,7 +268,8 @@ public class PinotTableRestletResource {
// TODO: validate that table was created successfully
// (in realtime case, metadata might not have been created but would be
created successfully in the next run of
// the validation manager)
- LOGGER.info("Successfully added table: {} with config: {}",
tableNameWithType, tableConfig);
+ LOGGER.info("Successfully added table: {} with config: {}",
tableNameWithType,
+ Obfuscator.DEFAULT.toJsonString(tableConfig));
return new ConfigSuccessResponse("Table " + tableNameWithType + "
successfully added",
tableConfigAndUnrecognizedProperties.getRight());
} catch (Exception e) {
@@ -816,7 +818,8 @@ public class PinotTableRestletResource {
_controllerMetrics.addMeteredGlobalValue(ControllerMeter.CONTROLLER_TABLE_UPDATE_ERROR,
1L);
throw e;
}
- LOGGER.info("Successfully updated table: {} with new config: {}",
tableNameWithType, tableConfig);
+ LOGGER.info("Successfully updated table: {} with new config: {}",
tableNameWithType,
+ Obfuscator.DEFAULT.toJsonString(tableConfig));
return new ConfigSuccessResponse("Table config updated for " + tableName,
tableConfigAndUnrecognizedProperties.getRight());
}
diff --git
a/pinot-spi/src/main/java/org/apache/pinot/spi/stream/StreamConfig.java
b/pinot-spi/src/main/java/org/apache/pinot/spi/stream/StreamConfig.java
index 94999d5ee3f..49cdc2a1e1c 100644
--- a/pinot-spi/src/main/java/org/apache/pinot/spi/stream/StreamConfig.java
+++ b/pinot-spi/src/main/java/org/apache/pinot/spi/stream/StreamConfig.java
@@ -18,6 +18,7 @@
*/
package org.apache.pinot.spi.stream;
+import com.fasterxml.jackson.databind.JsonNode;
import com.google.common.base.Preconditions;
import java.util.HashMap;
import java.util.Map;
@@ -25,6 +26,7 @@ import java.util.Objects;
import java.util.concurrent.TimeUnit;
import javax.annotation.Nullable;
import org.apache.pinot.spi.utils.DataSizeUtils;
+import org.apache.pinot.spi.utils.Obfuscator;
import org.apache.pinot.spi.utils.TimeUtils;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
@@ -501,6 +503,17 @@ public class StreamConfig {
return _streamConfigMap;
}
+ /// Returns a copy of the given config map with the values of sensitive keys
masked (see [Obfuscator]), suitable
+ /// for logging. The original map is left untouched because its values are
handed to the stream consumers.
+ private static Map<String, String> redactSensitiveValues(Map<String, String>
configMap) {
+ JsonNode masked = Obfuscator.DEFAULT.toJson(configMap);
+ Map<String, String> redacted = new HashMap<>();
+ for (String key : configMap.keySet()) {
+ redacted.put(key, masked.get(key).asText());
+ }
+ return redacted;
+ }
+
@Override
public String toString() {
return "StreamConfig{"
@@ -509,7 +522,7 @@ public class StreamConfig {
+ ", _tableNameWithType='" + _tableNameWithType + '\''
+ ", _consumerFactoryClassName='" + _consumerFactoryClassName + '\''
+ ", _decoderClass='" + _decoderClass + '\''
- + ", _decoderProperties=" + _decoderProperties
+ + ", _decoderProperties=" + redactSensitiveValues(_decoderProperties)
+ ", _connectionTimeoutMillis=" + _connectionTimeoutMillis
+ ", _fetchTimeoutMillis=" + _fetchTimeoutMillis
+ ", _idleTimeoutMillis=" + _idleTimeoutMillis
@@ -527,7 +540,7 @@ public class StreamConfig {
+ ", _offsetAutoResetOffsetThreshold=" +
_offsetAutoResetOffsetThreshold
+ ", _offsetAutoResetTimeSecThreshold=" +
_offsetAutoResetTimeSecThreshold
+ ", _backfillTopic=" + _backfillTopic
- + ", _streamConfigMap=" + _streamConfigMap
+ + ", _streamConfigMap=" + redactSensitiveValues(_streamConfigMap)
+ ", _offsetCriteria=" + _offsetCriteria
+ ", _serverUploadToDeepStore=" + _serverUploadToDeepStore
+ '}';
diff --git
a/pinot-spi/src/test/java/org/apache/pinot/spi/stream/StreamConfigTest.java
b/pinot-spi/src/test/java/org/apache/pinot/spi/stream/StreamConfigTest.java
new file mode 100644
index 00000000000..8bc83977afe
--- /dev/null
+++ b/pinot-spi/src/test/java/org/apache/pinot/spi/stream/StreamConfigTest.java
@@ -0,0 +1,131 @@
+/**
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied. See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+package org.apache.pinot.spi.stream;
+
+import java.util.HashMap;
+import java.util.Map;
+import org.testng.annotations.Test;
+
+import static org.testng.Assert.assertEquals;
+import static org.testng.Assert.assertFalse;
+import static org.testng.Assert.assertTrue;
+
+
+public class StreamConfigTest {
+ private static final String JAAS_KEY = "sasl.jaas.config";
+ private static final String JAAS_VALUE =
"org.apache.kafka.common.security.plain.PlainLoginModule required "
+ + "username=\"exampleUser\" password=\"examplePass\";";
+
+ private static Map<String, String> baseConfigMap() {
+ Map<String, String> map = new HashMap<>();
+ map.put("streamType", "kafka");
+ map.put("stream.kafka.topic.name", "myTopic");
+ map.put("stream.kafka.decoder.class.name",
"org.apache.pinot.plugin.inputformat.json.JSONMessageDecoder");
+ return map;
+ }
+
+ @Test
+ public void testToStringMasksSaslJaasConfig() {
+ Map<String, String> map = baseConfigMap();
+ map.put(JAAS_KEY, JAAS_VALUE);
+
+ String str = new StreamConfig("myTable_REALTIME", map).toString();
+
+ assertFalse(str.contains("exampleUser"), str);
+ assertFalse(str.contains("examplePass"), str);
+ assertFalse(str.contains("PlainLoginModule"), str);
+ assertTrue(str.contains("sasl.jaas.config=*****"), str);
+ }
+
+ @Test
+ public void testToStringMasksSaslJaasConfigInAllQuotingForms() {
+ String[] jaasConfigs = {
+ "required username='exampleUser' password='examplePass';",
+ "required username=exampleUser password=examplePass;",
+ "required username=\"exampleUser\"
password=\"prefix\\\"examplePass-tail\";"
+ };
+ for (String jaasConfig : jaasConfigs) {
+ Map<String, String> map = baseConfigMap();
+ map.put(JAAS_KEY, jaasConfig);
+
+ String str = new StreamConfig("myTable_REALTIME", map).toString();
+
+ assertFalse(str.contains("exampleUser"), str);
+ assertFalse(str.contains("examplePass"), str);
+ assertTrue(str.contains("sasl.jaas.config=*****"), str);
+ }
+ }
+
+ @Test
+ public void testToStringMasksSensitiveKeys() {
+ Map<String, String> map = baseConfigMap();
+ map.put("ssl.keystore.password", "keystoreSecret");
+ map.put("ssl.truststore.password", "truststoreSecret");
+ map.put("some.api.token", "tokenSecret");
+
+ String str = new StreamConfig("myTable_REALTIME", map).toString();
+
+ assertFalse(str.contains("keystoreSecret"), str);
+ assertFalse(str.contains("truststoreSecret"), str);
+ assertFalse(str.contains("tokenSecret"), str);
+ assertTrue(str.contains("ssl.keystore.password=*****"), str);
+ }
+
+ @Test
+ public void testToStringRedactsDecoderProperties() {
+ Map<String, String> map = baseConfigMap();
+ map.put("stream.kafka.decoder.prop.sasl.jaas.config", JAAS_VALUE);
+ map.put("stream.kafka.decoder.prop.schema.registry.password",
"registrySecret");
+
+ String str = new StreamConfig("myTable_REALTIME", map).toString();
+
+ assertFalse(str.contains("exampleUser"), str);
+ assertFalse(str.contains("examplePass"), str);
+ assertFalse(str.contains("registrySecret"), str);
+ assertTrue(str.contains("sasl.jaas.config=*****"), str);
+ assertTrue(str.contains("schema.registry.password=*****"), str);
+ }
+
+ @Test
+ public void testToStringKeepsNonSensitiveValues() {
+ Map<String, String> map = baseConfigMap();
+ map.put("bootstrap.servers", "localhost:9092");
+
+ String str = new StreamConfig("myTable_REALTIME", map).toString();
+
+ assertTrue(str.contains("_topicName='myTopic'"), str);
+ assertTrue(str.contains("bootstrap.servers=localhost:9092"), str);
+ }
+
+ @Test
+ public void testRedactionDoesNotMutateUnderlyingConfig() {
+ Map<String, String> map = baseConfigMap();
+ map.put(JAAS_KEY, JAAS_VALUE);
+ map.put("ssl.keystore.password", "keystoreSecret");
+ map.put("stream.kafka.decoder.prop.sasl.jaas.config", JAAS_VALUE);
+ StreamConfig streamConfig = new StreamConfig("myTable_REALTIME", map);
+
+ streamConfig.toString();
+
+ // The real values must stay intact, because they are handed to the stream
consumer clients
+ assertEquals(streamConfig.getStreamConfigsMap().get(JAAS_KEY), JAAS_VALUE);
+
assertEquals(streamConfig.getStreamConfigsMap().get("ssl.keystore.password"),
"keystoreSecret");
+ assertEquals(streamConfig.getDecoderProperties().get(JAAS_KEY),
JAAS_VALUE);
+ }
+}
diff --git
a/pinot-spi/src/test/java/org/apache/pinot/spi/utils/ObfuscatorTest.java
b/pinot-spi/src/test/java/org/apache/pinot/spi/utils/ObfuscatorTest.java
index d7e0318f892..891f236e783 100644
--- a/pinot-spi/src/test/java/org/apache/pinot/spi/utils/ObfuscatorTest.java
+++ b/pinot-spi/src/test/java/org/apache/pinot/spi/utils/ObfuscatorTest.java
@@ -26,6 +26,11 @@ import java.util.List;
import java.util.Map;
import java.util.regex.Pattern;
import org.apache.commons.lang3.tuple.Pair;
+import org.apache.pinot.spi.config.table.TableConfig;
+import org.apache.pinot.spi.config.table.TableType;
+import org.apache.pinot.spi.config.table.ingestion.IngestionConfig;
+import org.apache.pinot.spi.config.table.ingestion.StreamIngestionConfig;
+import org.apache.pinot.spi.utils.builder.TableConfigBuilder;
import org.testng.Assert;
import org.testng.annotations.BeforeMethod;
import org.testng.annotations.Test;
@@ -116,6 +121,83 @@ public class ObfuscatorTest {
Assert.assertTrue(output.contains(SECRET));
}
+ @Test
+ public void testSaslJaasConfig() {
+ // Kafka accepts double-quoted, single-quoted and unquoted values, and
escaped quotes inside a quoted value. The
+ // whole value must be masked regardless of the quoting form.
+ String[] jaasConfigs = {
+ "org.apache.kafka.common.security.plain.PlainLoginModule required
username=\"user1\" password=\"pass1\";",
+ "org.apache.kafka.common.security.plain.PlainLoginModule required
username='user1' password='pass1';",
+ "org.apache.kafka.common.security.plain.PlainLoginModule required
username=user1 password=pass1;",
+ "org.apache.kafka.common.security.plain.PlainLoginModule required
username=\"user1\" "
+ + "password=\"prefix\\\"secret-tail\";"
+ };
+ for (String jaasConfig : jaasConfigs) {
+ Map<String, String> map = new HashMap<>();
+ map.put("sasl.jaas.config", jaasConfig);
+ map.put("sasl.mechanism", "PLAIN");
+
+ String output = _obfuscator.toJsonString(map);
+
+ Assert.assertFalse(output.contains("user1"), output);
+ Assert.assertFalse(output.contains("pass1"), output);
+ Assert.assertFalse(output.contains("secret-tail"), output);
+ Assert.assertFalse(output.contains("PlainLoginModule"), output);
+ Assert.assertTrue(output.contains("\"sasl.jaas.config\":\"*****\""),
output);
+ Assert.assertTrue(output.contains("\"sasl.mechanism\":\"PLAIN\""),
output);
+ }
+ }
+
+ @Test
+ public void testSaslJaasConfigPrefixedAndCaseInsensitiveKeys() {
+ Map<String, String> map = new HashMap<>();
+ map.put("stream.kafka.consumer.prop.sasl.jaas.config", "username=\"user1\"
password=\"pass1\"");
+ map.put("listener.name.sasl_ssl.plain.sasl.jaas.config",
"username=\"user2\" password=\"pass2\"");
+ map.put("SASL.JAAS.CONFIG", "username=\"user3\" password=\"pass3\"");
+ map.put("sasl.jaas.config.other", "not-a-secret");
+
+ String output = _obfuscator.toJsonString(map);
+
+ Assert.assertFalse(output.contains("user1") || output.contains("user2") ||
output.contains("user3"), output);
+ Assert.assertFalse(output.contains("pass1") || output.contains("pass2") ||
output.contains("pass3"), output);
+ Assert.assertTrue(output.contains("not-a-secret"), output);
+ }
+
+ @Test
+ public void testCustomPatternDoesNotApplyDefaultSaslJaasConfig() {
+ // The custom-pattern constructor keeps its contract that the defaults do
not apply
+ Obfuscator obfuscator = new Obfuscator("masked",
List.of(Pattern.compile("^value$")));
+ String output = obfuscator.toJsonString(Map.of("sasl.jaas.config",
"username=\"user1\""));
+ Assert.assertTrue(output.contains("user1"), output);
+ }
+
+ @Test
+ public void testTableConfigWithStreamCredentials() {
+ String jaas = "org.apache.kafka.common.security.plain.PlainLoginModule
required username=\"user1\" "
+ + "password=\"pass1\";";
+ Map<String, String> streamConfigMap = new HashMap<>();
+ streamConfigMap.put("streamType", "kafka");
+ streamConfigMap.put("stream.kafka.topic.name", "myTopic");
+ streamConfigMap.put("sasl.jaas.config", jaas);
+ streamConfigMap.put("ssl.keystore.password", SECRET);
+ IngestionConfig ingestionConfig = new IngestionConfig();
+ ingestionConfig.setStreamIngestionConfig(new
StreamIngestionConfig(List.of(streamConfigMap)));
+ TableConfig tableConfig =
+ new
TableConfigBuilder(TableType.REALTIME).setTableName("myTable").setIngestionConfig(ingestionConfig).build();
+
+ String output = _obfuscator.toJsonString(tableConfig);
+
+ Assert.assertTrue(output.contains("myTopic"), output);
+ Assert.assertFalse(output.contains("user1"), output);
+ Assert.assertFalse(output.contains("pass1"), output);
+ Assert.assertFalse(output.contains(SECRET), output);
+ // The table config itself must keep the real values
+ Map<String, String> actual =
+
tableConfig.getIngestionConfig().getStreamIngestionConfig().getStreamConfigMaps().get(0);
+ Assert.assertEquals(actual.get("sasl.jaas.config"), jaas);
+ Assert.assertEquals(actual.get("ssl.keystore.password"), SECRET);
+ }
+
@Test
public void testJsonNode()
throws IOException {
---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]