qiuyanjun888 commented on code in PR #18397:
URL:
https://github.com/apache/dolphinscheduler/pull/18397#discussion_r3577022165
##########
dolphinscheduler-task-plugin/dolphinscheduler-task-api/src/main/java/org/apache/dolphinscheduler/plugin/task/api/log/SensitiveDataConverter.java:
##########
@@ -37,6 +37,18 @@ public class SensitiveDataConverter extends MessageConverter
{
private static Pattern multilinePattern;
private static final Set<String> maskPatterns = new HashSet<>();
+ private static final String KNOWN_SENSITIVE_CONFIGURATION_KEY_REGEX =
+
"(?:password|access[._-]?key(?:[._-]?(?:id|secret))?|secret[._-]?access[._-]?key|secret[._-]?key)";
+
+ private static final Pattern QUOTED_SENSITIVE_CONFIGURATION_PATTERN =
Pattern.compile(
Review Comment:
1|Fixed in `1e61609d`. I replaced the lazy quoted-value match with
quote-aware delimiter scanning, so escaped quotes are not treated as the end of
the value. Known-sensitive masking now also runs before the legacy configured
patterns, preventing the old password regex from truncating the value first.
2|
3|The exact JSON example now becomes
`{"password":"******","bucket":"ds"}`.
4|
5|Validation: `SensitiveDataConverterTest` passed 7/7,
`DinkyLogSanitizerTest` passed 5/5, and Spotless passed for both task-api and
task-dinky.
6|
##########
dolphinscheduler-task-plugin/dolphinscheduler-task-dinky/src/test/java/org/apache/dolphinscheduler/plugin/task/dinky/DinkyLogSanitizerTest.java:
##########
@@ -0,0 +1,111 @@
+/*
+ * 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.dolphinscheduler.plugin.task.dinky;
+
+import static org.junit.jupiter.api.Assertions.assertFalse;
+import static org.junit.jupiter.api.Assertions.assertNull;
+import static org.junit.jupiter.api.Assertions.assertTrue;
+
+import org.apache.dolphinscheduler.plugin.task.api.TaskExecutionContext;
+import org.apache.dolphinscheduler.plugin.task.api.model.Property;
+
+import java.lang.reflect.Method;
+import java.util.Arrays;
+import java.util.HashMap;
+import java.util.Map;
+
+import org.junit.jupiter.api.Test;
+
+import com.fasterxml.jackson.databind.node.JsonNodeFactory;
+
+class DinkyLogSanitizerTest {
+
+ @Test
+ void testSummarizeVariablesDoesNotExposeValues() {
+ Map<String, String> variables = new HashMap<>();
+ variables.put("accessKeyId", "AKIA_TEST");
+ variables.put("accessKeySecret", "SECRET_TEST");
+ variables.put("businessDate", "2026-07-06");
+
+ String summary = DinkyLogSanitizer.summarizeVariables(variables);
+
+ assertTrue(summary.contains("size=3"));
+ assertTrue(summary.contains("accessKeyId"));
+ assertTrue(summary.contains("accessKeySecret"));
+ assertTrue(summary.contains("businessDate"));
+ assertFalse(summary.contains("AKIA_TEST"));
+ assertFalse(summary.contains("SECRET_TEST"));
+ assertFalse(summary.contains("2026-07-06"));
+ }
+
+ @Test
+ void testSummarizeParametersDoesNotExposeLocalParamValues() {
+ DinkyParameters parameters = new DinkyParameters();
+ parameters.setAddress("http://dinky:8888");
+ parameters.setTaskId("1001");
+ parameters.setOnline(true);
+ parameters.setLocalParams(Arrays.asList(
+ new Property("accessKeyId", null, null, "AKIA_TEST"),
+ new Property("businessDate", null, null, "2026-07-06")));
+
+ String summary = DinkyLogSanitizer.summarizeParameters(parameters);
+
+ assertTrue(summary.contains("address=http://dinky:8888"));
+ assertTrue(summary.contains("taskId=1001"));
+ assertTrue(summary.contains("online=true"));
+ assertTrue(summary.contains("localParamKeys=[accessKeyId,
businessDate]"));
+ assertFalse(summary.contains("AKIA_TEST"));
+ assertFalse(summary.contains("2026-07-06"));
+ }
+
+ @Test
+ void testSanitizeMessageMasksSensitiveValues() {
+ String message =
"{\"accessKeyId\":\"AKIA_TEST\",\"accessKeySecret\":\"SECRET_TEST\"}";
+
+ String sanitized = DinkyLogSanitizer.sanitizeMessage(message);
+
+ assertTrue(sanitized.contains("accessKeyId"));
+ assertTrue(sanitized.contains("accessKeySecret"));
+ assertFalse(sanitized.contains("AKIA_TEST"));
+ assertFalse(sanitized.contains("SECRET_TEST"));
+ }
+
+ @Test
+ void testSanitizeMessageMasksSensitiveValuesInJsonNodeMessage() {
+ String message =
"{\"accessKeyId\":\"AKIA_TEST\",\"accessKeySecret\":\"SECRET_TEST\"}";
+
+ String sanitized =
DinkyLogSanitizer.sanitizeMessage(JsonNodeFactory.instance.textNode(message));
+
+ assertTrue(sanitized.contains("accessKeyId"));
+ assertTrue(sanitized.contains("accessKeySecret"));
+ assertFalse(sanitized.contains("AKIA_TEST"));
+ assertFalse(sanitized.contains("SECRET_TEST"));
+ }
+
+ @Test
+ void testParseMalformedResponseReturnsNullWithoutExposingRawResponse()
throws Exception {
Review Comment:
1|Addressed in `ffe340bc` and revalidated at `1e61609d`. The old
null-return test was replaced with an explicit-failure regression, so it would
fail against the old implementation.
2|
3|`parse` no longer emits a log event with the Jackson throwable or raw
response. It throws a cause-free `DinkyTaskException` containing only the
response length and parser exception type. I also traced the production paths:
submit-side and worker terminal loggers can only receive that safe exception
graph, not the raw response. Therefore an appender assertion at `parse` would
no longer exercise an actual log event.
4|
5|Validation: `DinkyLogSanitizerTest` passed 5/5 in the final targeted
test run.
6|
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: [email protected]
For queries about this service, please contact Infrastructure at:
[email protected]