-
Notifications
You must be signed in to change notification settings - Fork 5.1k
[Feature-17398][Task] Avoid leaking sensitive Dinky task logs #18397
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: dev
Are you sure you want to change the base?
Changes from 2 commits
e602c68
2ef76bd
ffe340b
1e61609
d001ec7
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,71 @@ | ||
| /* | ||
| * 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 org.apache.dolphinscheduler.plugin.task.api.log.SensitiveDataConverter; | ||
| import org.apache.dolphinscheduler.plugin.task.api.model.Property; | ||
|
|
||
| import java.util.List; | ||
| import java.util.Map; | ||
| import java.util.Set; | ||
| import java.util.TreeSet; | ||
|
|
||
| final class DinkyLogSanitizer { | ||
|
|
||
| private DinkyLogSanitizer() { | ||
| throw new UnsupportedOperationException("Utility class"); | ||
| } | ||
|
|
||
| static String summarizeParameters(final DinkyParameters parameters) { | ||
| if (parameters == null) { | ||
| return "null"; | ||
| } | ||
| return "address=" + sanitizeMessage(parameters.getAddress()) | ||
| + ", taskId=" + sanitizeMessage(parameters.getTaskId()) | ||
| + ", online=" + parameters.isOnline() | ||
| + ", localParamKeys=" + summarizeLocalParamKeys(parameters.getLocalParams()); | ||
| } | ||
|
|
||
| static String summarizeVariables(final Map<String, String> variables) { | ||
| if (variables == null || variables.isEmpty()) { | ||
| return "size=0, keys=[]"; | ||
| } | ||
| Set<String> keys = new TreeSet<>(variables.keySet()); | ||
| return "size=" + variables.size() + ", keys=" + keys; | ||
| } | ||
|
|
||
| static String sanitizeMessage(final Object message) { | ||
| if (message == null) { | ||
| return null; | ||
| } | ||
| return SensitiveDataConverter.maskSensitiveData(String.valueOf(message)); | ||
| } | ||
|
|
||
| private static Set<String> summarizeLocalParamKeys(final List<Property> localParams) { | ||
| Set<String> keys = new TreeSet<>(); | ||
| if (localParams == null) { | ||
| return keys; | ||
| } | ||
| for (Property property : localParams) { | ||
| if (property != null && property.getProp() != null) { | ||
| keys.add(property.getProp()); | ||
| } | ||
| } | ||
| return keys; | ||
| } | ||
| } |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -80,7 +80,7 @@ public List<String> getApplicationIds() throws TaskException { | |
| public void init() { | ||
| final String taskParams = taskExecutionContext.getTaskParams(); | ||
| this.dinkyParameters = JSONUtils.parseObject(taskParams, DinkyParameters.class); | ||
| log.info("Initialize dinky task params: {}", JSONUtils.toPrettyJsonString(dinkyParameters)); | ||
| log.info("Initialize dinky task: {}", DinkyLogSanitizer.summarizeParameters(dinkyParameters)); | ||
| if (this.dinkyParameters == null || !this.dinkyParameters.checkParameters()) { | ||
| throw new DinkyTaskException("dinky task params is not valid"); | ||
| } | ||
|
|
@@ -160,10 +160,10 @@ private void submitApplicationV1() { | |
| result.get(apiResultDataKey).get(DinkyTaskConstants.API_RESULT_JOB_INSTANCE_ID).asText(); | ||
| } | ||
| } else { | ||
| log.error(DinkyTaskConstants.SUBMIT_FAILED_MSG + "{}", result.get(DinkyTaskConstants.API_RESULT_MSG)); | ||
| String errorMessage = DinkyLogSanitizer.sanitizeMessage(result.get(DinkyTaskConstants.API_RESULT_MSG)); | ||
| log.error(DinkyTaskConstants.SUBMIT_FAILED_MSG + "{}", errorMessage); | ||
| setExitStatusCode(EXIT_CODE_FAILURE); | ||
| throw new TaskException( | ||
| DinkyTaskConstants.SUBMIT_FAILED_MSG + result.get(DinkyTaskConstants.API_RESULT_MSG)); | ||
| throw new TaskException(DinkyTaskConstants.SUBMIT_FAILED_MSG + errorMessage); | ||
| } | ||
| } catch (Exception ex) { | ||
| Thread.currentThread().interrupt(); | ||
|
|
@@ -199,8 +199,7 @@ public void trackApplicationStatusV0() throws TaskException { | |
| // Use address-taskId as app id | ||
| setAppIds(String.format(DinkyTaskConstants.APPIDS_FORMAT, address, taskId)); | ||
| setExitStatusCode(exitStatusCode); | ||
| log.info("dinky task finished with results: {}", | ||
| jobInstanceInfoResult.get(apiResultDatasKey)); | ||
| log.info("dinky task finished, status: {}", jobInstanceStatus); | ||
| finishFlag = true; | ||
| break; | ||
| case DinkyTaskConstants.STATUS_FAILED: | ||
|
|
@@ -250,8 +249,7 @@ public void trackApplicationStatusV1() throws TaskException { | |
| // Use address-taskId as app id | ||
| setAppIds(String.format(DinkyTaskConstants.APPIDS_FORMAT, address, taskId)); | ||
| setExitStatusCode(exitStatusCode); | ||
| log.info("dinky task finished with results: {}", | ||
| jobInstanceInfoResult.get(apiResultDataKey)); | ||
| log.info("dinky task finished, status: {}", jobInstanceStatus); | ||
| finishFlag = true; | ||
| break; | ||
| case DinkyTaskConstants.STATUS_FAILED: | ||
|
|
@@ -312,7 +310,7 @@ private boolean checkResultV1(JsonNode result) { | |
|
|
||
| private void errorHandle(Object msg) { | ||
| setExitStatusCode(TaskConstants.EXIT_CODE_FAILURE); | ||
| log.error("dinky task submit failed with error: {}", msg); | ||
| log.error("dinky task submit failed with error: {}", DinkyLogSanitizer.sanitizeMessage(msg)); | ||
| } | ||
|
|
||
| @Override | ||
|
|
@@ -352,7 +350,7 @@ private Map<String, String> generateVariables() { | |
| } | ||
| } | ||
| } | ||
| log.info("sending variables to dinky: {}", variables); | ||
| log.info("sending variables to dinky: {}", DinkyLogSanitizer.summarizeVariables(variables)); | ||
| return variables; | ||
| } | ||
|
|
||
|
|
@@ -404,7 +402,8 @@ private JsonNode parse(String res) { | |
| try { | ||
| result = mapper.readTree(res); | ||
| } catch (JsonProcessingException e) { | ||
| log.error("dinky task submit failed with error", e); | ||
| log.error("dinky task response parse failed, responseLength: {}, errorType: {}", | ||
|
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. The parse error should fail explicitly.
Contributor
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Fixed by throwing Verification: |
||
| StringUtils.length(res), e.getClass().getSimpleName()); | ||
| } | ||
| return result; | ||
| } | ||
|
|
@@ -426,7 +425,8 @@ private String doGet(String url, Map<String, String> params) { | |
| HttpResponse response = httpClient.execute(httpGet); | ||
| if (response.getStatusLine().getStatusCode() == HttpStatus.SC_OK) { | ||
| result = EntityUtils.toString(response.getEntity()); | ||
| log.info("dinky task succeed with results: {}", result); | ||
| log.info("dinky task request succeeded, statusCode: {}, responseLength: {}", | ||
| response.getStatusLine().getStatusCode(), result.length()); | ||
| } else { | ||
| log.error("dinky task terminated,response: {}", response); | ||
| } | ||
|
|
@@ -455,7 +455,8 @@ private String sendJsonStr(String url, String params) { | |
| HttpResponse response = httpClient.execute(httpPost); | ||
| if (response.getStatusLine().getStatusCode() == HttpStatus.SC_OK) { | ||
| result = EntityUtils.toString(response.getEntity()); | ||
| log.info("dinky task succeed with results: {}", result); | ||
| log.info("dinky task request succeeded, statusCode: {}, responseLength: {}", | ||
| response.getStatusLine().getStatusCode(), result.length()); | ||
| } else { | ||
| log.error("dinky task terminated,response: {}", response); | ||
| } | ||
|
|
||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -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 { | ||
|
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. This only asserts that the return value is null; it does not capture or inspect any log event. The test would also pass with the old implementation even if the raw response were written through the exception log.
Contributor
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Addressed in
Validation: |
||
| DinkyTask task = new DinkyTask(new TaskExecutionContext()); | ||
| Method parseMethod = DinkyTask.class.getDeclaredMethod("parse", String.class); | ||
| parseMethod.setAccessible(true); | ||
|
|
||
| Object result = parseMethod.invoke(task, | ||
| "malformed response accessKeyId=AKIA_TEST accessKeySecret=SECRET_TEST"); | ||
|
|
||
| assertNull(result); | ||
| } | ||
| } | ||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
.*?does not distinguish an escaped quote from the actual string terminator.eg, given valid JSON:
result output:
Uh oh!
There was an error while loading. Please reload this page.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
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.The exact JSON example now becomes
{"password":"******","bucket":"ds"}.Validation:
SensitiveDataConverterTestpassed 7/7,DinkyLogSanitizerTestpassed 5/5, and Spotless passed for both task-api and task-dinky.