Skip to content

Commit

Permalink
runtime-v2: allow mark sensitive data for task.execute result
Browse files Browse the repository at this point in the history
  • Loading branch information
brig committed Nov 19, 2024
1 parent 3cc024b commit c57669f
Show file tree
Hide file tree
Showing 6 changed files with 36 additions and 11 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -1358,7 +1358,7 @@ public void testSensitiveData() throws Exception {
byte[] log = run();
assertLog(log, ".*" + Pattern.quote("sensitive: ******") + ".*");
assertLog(log, ".*" + Pattern.quote("log value: ******") + ".*");
assertLog(log, ".*" + Pattern.quote("hack: B O O M") + ".*");
assertLog(log, ".*" + Pattern.quote("hack: M A S K _ M E ") + ".*");

assertLog(log, ".*" + Pattern.quote("map: {nonSecretButMasked=******, secret=******}") + ".*");
assertLog(log, ".*" + Pattern.quote("map: {nonSecret=non secret value, secret=******}") + ".*");
Expand All @@ -1367,6 +1367,8 @@ public void testSensitiveData() throws Exception {

assertLog(log, ".*" + Pattern.quote("secret from map: ******") + ".*");

assertLog(log, ".*secret from task execute: .*" + Pattern.quote("keyWithSecretValue=******") + ".*");

log = resume("ev1", ProcessConfiguration.builder().build());
assertLog(log, ".*" + Pattern.quote("mySecret after suspend: ******") + ".*");
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,9 +9,9 @@
* Licensed 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.
Expand Down Expand Up @@ -305,6 +305,13 @@ public String get(Object key) {
public Set<Entry<String, String>> entrySet() {
return null;
}

@SensitiveData(keys = "keyWithSecretValue")
@Override
public TaskResult execute(Variables input) {
return TaskResult.success()
.value("keyWithSecretValue", "topSecret!!!!");
}
}

@Named("injectorTestBean")
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ flows:
default:
- log: "sensitive: ${sensitiveTask.getSensitive('BOOM')}"

- expr: "${sensitiveTask.getSensitive('BOOM')}"
- expr: "${sensitiveTask.getSensitive('MASK_ME')}"
out: mySecret

- log: "log value: ${mySecret}"
Expand All @@ -16,6 +16,10 @@ flows:

- log: "secret from map: ${sensitiveTask.mySecretKey}"

- task: sensitiveTask
out: taskResult
- log: "secret from task execute: ${taskResult}"

- suspend: ev1

- log: "mySecret after suspend: ${mySecret}"
Original file line number Diff line number Diff line change
Expand Up @@ -114,8 +114,7 @@ <T> T evalValue(LazyEvalContext ctx, Object value, Class<T> expectedType) {
}

return expectedType.cast(src);
} else if (value instanceof String) {
String s = (String) value;
} else if (value instanceof String s) {
if (hasExpression(s)) {
return evalExpr(ctx, s, expectedType);
}
Expand Down Expand Up @@ -193,7 +192,7 @@ private ELResolver createResolver(LazyEvalContext evalContext,
r.add(new ListELResolver());
r.add(new ArrayELResolver());
if (evalContext.context() != null) {
r.add(new TaskMethodResolver(taskMethodResolvers, evalContext.context()));
r.add(new TaskMethodResolver(taskMethodResolvers, customBeanELResolvers, evalContext.context()));
}
r.add(new BeanELResolver(customBeanELResolvers));
return r;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@
import com.walmartlabs.concord.runtime.v2.runner.tasks.TaskCallInterceptor;
import com.walmartlabs.concord.runtime.v2.runner.tasks.TaskException;
import com.walmartlabs.concord.runtime.v2.sdk.Context;
import com.walmartlabs.concord.runtime.v2.sdk.CustomBeanELResolver;
import com.walmartlabs.concord.runtime.v2.sdk.CustomTaskMethodResolver;
import com.walmartlabs.concord.runtime.v2.sdk.Task;

Expand All @@ -42,10 +43,14 @@
public class TaskMethodResolver extends ELResolver {

private final List<CustomTaskMethodResolver> customResolvers;
private final List<CustomBeanELResolver> customBeanELResolvers;
private final Context context;

public TaskMethodResolver(List<CustomTaskMethodResolver> customResolvers, Context context) {
public TaskMethodResolver(List<CustomTaskMethodResolver> customResolvers,
List<CustomBeanELResolver> customBeanELResolvers,
Context context) {
this.customResolvers = customResolvers;
this.customBeanELResolvers = customBeanELResolvers;
this.context = context;
}

Expand Down Expand Up @@ -79,7 +84,7 @@ public Object invoke(ELContext elContext, Object base, Object method, Class<?>[]
try {
return interceptor.invoke(callContext, Method.of(invocation.taskClass(), method.toString(), Arrays.asList(params)),
() -> {
var result = invocation.invoke(new DefaultInvocationContext(elContext));
var result = invocation.invoke(new DefaultInvocationContext(customBeanELResolvers, elContext));
elContext.setPropertyResolved(true);
return result;
});
Expand Down Expand Up @@ -155,9 +160,10 @@ private static class DefaultInvocationContext implements CustomTaskMethodResolve
private final ELContext elContext;
private final javax.el.BeanELResolver beanELResolver;

private DefaultInvocationContext(ELContext elContext) {
private DefaultInvocationContext(List<CustomBeanELResolver> customBeanELResolvers,
ELContext elContext) {
this.elContext = elContext;
this.beanELResolver = new javax.el.BeanELResolver();
this.beanELResolver = new BeanELResolver(customBeanELResolvers);
}

@Override
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,8 +20,10 @@
* =====
*/

import com.sun.el.util.ReflectionUtil;
import com.walmartlabs.concord.runtime.v2.model.TaskCall;
import com.walmartlabs.concord.runtime.v2.model.TaskCallOptions;
import com.walmartlabs.concord.runtime.v2.runner.el.resolvers.SensitiveDataProcessor;
import com.walmartlabs.concord.runtime.v2.runner.tasks.TaskCallInterceptor;
import com.walmartlabs.concord.runtime.v2.runner.tasks.TaskException;
import com.walmartlabs.concord.runtime.v2.runner.tasks.TaskProviders;
Expand Down Expand Up @@ -83,6 +85,11 @@ protected void execute(Runtime runtime, State state, ThreadId threadId) {
try {
result = interceptor.invoke(callContext, Method.of(t.getClass(), "execute", Collections.singletonList(input)),
() -> t.execute(input));

if (result instanceof TaskResult.SimpleResult simpleResult) {
var m = ReflectionUtil.findMethod(t.getClass(), "execute", new Class[]{Variables.class}, new Variables[]{input});
SensitiveDataProcessor.process(simpleResult.values(), m);
}
} catch (TaskException e) {
result = TaskResult.fail(e.getCause());
} catch (RuntimeException e) {
Expand Down

0 comments on commit c57669f

Please sign in to comment.