Skip to content

Commit

Permalink
fix(core): always add the secret consumer
Browse files Browse the repository at this point in the history
This causes a WARNING in the log for some cases, with the risk to have a secret leaked into the logs.

Fixes kestra-io/kestra-ee#1741
  • Loading branch information
loicmathieu committed Sep 19, 2024
1 parent 6f638df commit d9d9bdd
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 4 deletions.
7 changes: 4 additions & 3 deletions core/src/main/java/io/kestra/core/runners/RunVariables.java
Original file line number Diff line number Diff line change
Expand Up @@ -274,9 +274,10 @@ public Map<String, Object> build(final RunContextLogger logger) {
// adds any additional variables
if (variables != null) {
builder.putAll(variables);
if (logger != null && !variables.containsKey(RunVariables.SECRET_CONSUMER_VARIABLE_NAME)) {
builder.put(RunVariables.SECRET_CONSUMER_VARIABLE_NAME, (Consumer<String>) logger::usedSecret);
}
}

if (logger != null && (variables == null || !variables.containsKey(RunVariables.SECRET_CONSUMER_VARIABLE_NAME))) {
builder.put(RunVariables.SECRET_CONSUMER_VARIABLE_NAME, (Consumer<String>) logger::usedSecret);
}

return builder.build();
Expand Down
10 changes: 9 additions & 1 deletion core/src/test/java/io/kestra/core/runners/RunVariablesTest.java
Original file line number Diff line number Diff line change
Expand Up @@ -8,12 +8,20 @@

import java.util.Map;

import static org.hamcrest.MatcherAssert.assertThat;
import static org.hamcrest.Matchers.is;
import static org.hamcrest.Matchers.notNullValue;

class RunVariablesTest {

@Test
@SuppressWarnings("unchecked")
void shouldGetEmptyVariables() {
Map<String, Object> variables = new RunVariables.DefaultBuilder().build(new RunContextLogger());
Assertions.assertEquals(Map.of("envs", Map.of(), "globals", Map.of()), variables);
assertThat(variables.size(), is(3));
assertThat((Map<String, Object>) variables.get("envs"), is(Map.of()));
assertThat((Map<String, Object>) variables.get("globals"), is(Map.of()));
assertThat(variables.get("addSecretConsumer"), notNullValue());
}

@Test
Expand Down

0 comments on commit d9d9bdd

Please sign in to comment.