Skip to content

NIFI-13015: Support sensitive dynamic properties in ExecuteGroovyScript #9879

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

Open
wants to merge 1 commit into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -85,10 +85,12 @@
expressionLanguageScope = ExpressionLanguageScope.FLOWFILE_ATTRIBUTES,
description = "Updates a script engine property specified by the Dynamic Property's key with the value specified by the Dynamic Property's value. "
+ "Use `CTL.` to access any controller services, `SQL.` to access any DBCPServices, `RecordReader.` to access RecordReaderFactory instances, or "
+ "`RecordWriter.` to access any RecordSetWriterFactory instances.")
+ "`RecordWriter.` to access any RecordSetWriterFactory instances. Use `SENSITIVE.` to mark the property as sensitive.")
public class ExecuteGroovyScript extends AbstractProcessor {
public static final String GROOVY_CLASSPATH = "${groovy.classes.path}";

protected static final String SENSITIVE_PROPERTY_PREFIX = "SENSITIVE.";

private static final String PRELOADS = "import org.apache.nifi.components.*;" + "import org.apache.nifi.flowfile.FlowFile;" + "import org.apache.nifi.processor.*;"
+ "import org.apache.nifi.processor.FlowFileFilter.FlowFileFilterResult;" + "import org.apache.nifi.processor.exception.*;" + "import org.apache.nifi.processor.io.*;"
+ "import org.apache.nifi.processor.util.*;" + "import org.apache.nifi.processors.script.*;" + "import org.apache.nifi.logging.ComponentLog;";
Expand Down Expand Up @@ -542,13 +544,19 @@ protected PropertyDescriptor getSupportedDynamicPropertyDescriptor(final String
.identifiesControllerService(RecordSetWriterFactory.class)
.build();
}
return new PropertyDescriptor.Builder()

final PropertyDescriptor.Builder builder = new PropertyDescriptor.Builder()
.name(propertyDescriptorName)
.required(false)
.addValidator(StandardValidators.NON_EMPTY_VALIDATOR)
.expressionLanguageSupported(ExpressionLanguageScope.ENVIRONMENT)
.dynamic(true)
.build();
.dynamic(true);

if (propertyDescriptorName.startsWith(SENSITIVE_PROPERTY_PREFIX)) {
builder.sensitive(true);
}

return builder.build();
}

/** simple HashMap with exception on access of non-existent key */
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,6 @@
import org.junit.jupiter.api.condition.DisabledOnOs;
import org.junit.jupiter.api.condition.OS;
import org.junit.jupiter.api.io.TempDir;

import java.io.ByteArrayOutputStream;
import java.io.File;
import java.io.FileInputStream;
Expand Down Expand Up @@ -555,6 +554,15 @@ public void test_attribute_passed_to_SQL() {
assertEquals("testDB", ((DBCPServiceSimpleImpl) dbcp).getDatabaseName());
}

@Test
public void test_sensitive_dynamic_property() throws Exception {
runner.setProperty("SENSITIVE.password", "MyP@ssW0rd!");
runner.setProperty(ExecuteGroovyScript.SCRIPT_BODY,
"assert context.getProperties().find {k,v -> k.name == 'SENSITIVE.password'}.key.sensitive");
runner.assertValid();
runner.run();
}


private HashMap<String, String> map(String key, String value) {
HashMap<String, String> attrs = new HashMap<>();
Expand Down