ferencerdei commented on code in PR #8151:
URL: https://github.com/apache/nifi/pull/8151#discussion_r1424971904
##########
minifi/minifi-bootstrap/src/main/java/org/apache/nifi/minifi/bootstrap/service/MiNiFiExecCommandProvider.java:
##########
@@ -159,15 +183,58 @@ private String buildClassPath(File confDir, File libDir) {
.collect(joining(File.pathSeparator));
}
- private List<String> getJavaAdditionalArgs(Properties props) {
- return props.entrySet()
+ private List<String> getJavaAdditionalArgs(BootstrapProperties props) {
+ return props.getPropertyKeys()
.stream()
- .filter(entry -> ((String)
entry.getKey()).startsWith(JAVA_ARG_KEY_PREFIX))
- .map(entry -> (String) entry.getValue())
+ .filter(entry -> entry.startsWith(JAVA_ARG_KEY_PREFIX))
+ .map(props::getProperty)
.toList();
}
private String systemProperty(String key, Object value) {
return String.format(SYSTEM_PROPERTY_TEMPLATE, key, value);
}
+
+ private boolean isSensitiveKeyPresent(BootstrapProperties
bootstrapProperties) {
+ return bootstrapProperties.containsKey(MINIFI_BOOTSTRAP_SENSITIVE_KEY)
&&
!StringUtils.isBlank(bootstrapProperties.getProperty(MINIFI_BOOTSTRAP_SENSITIVE_KEY));
+ }
+
+ private Path createSensitiveKeyFile(File confDir) {
Review Comment:
I wanted to keep to logic as consistent as possible with the NiFi, so we can
easily switch when we change the bootstrap / application properties file
structure to the same as in NiFi. But yea, It can be read from bootstrap
directly (it could be even in NiFi.)
##########
minifi/minifi-commons/minifi-commons-utils/src/main/java/org/apache/nifi/minifi/commons/utils/PropertyUtil.java:
##########
@@ -48,4 +62,96 @@ private static Optional<String> getPropertyValue(String
name, Map<?, ?> properti
private static Stream<String> keyPermutations(String name) {
return Stream.of(name, name.replace(DOT, UNDERSCORE),
name.replace(HYPHEN, UNDERSCORE), name.replace(DOT, UNDERSCORE).replace(HYPHEN,
UNDERSCORE)).distinct();
}
+
+ public static String getFormattedKey(String[] args) {
Review Comment:
Moved to SensitivePropertyUtils
##########
minifi/minifi-nar-bundles/minifi-framework-bundle/minifi-framework/minifi-properties-loader/src/main/java/org/apache/nifi/minifi/properties/MiNiFiPropertiesLoader.java:
##########
@@ -0,0 +1,168 @@
+/*
+ * 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.nifi.minifi.properties;
+
+import java.io.BufferedInputStream;
+import java.io.File;
+import java.io.FileInputStream;
+import java.io.InputStream;
+import java.util.Properties;
+import org.apache.nifi.properties.AesGcmSensitivePropertyProvider;
+import org.apache.nifi.properties.SensitivePropertyProvider;
+import org.apache.nifi.util.NiFiBootstrapUtils;
+import org.apache.nifi.util.NiFiProperties;
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
+
+public class MiNiFiPropertiesLoader {
+
+ private static final Logger logger =
LoggerFactory.getLogger(MiNiFiPropertiesLoader.class);
+ private static final String DEFAULT_APPLICATION_PROPERTIES_FILE_PATH =
NiFiBootstrapUtils.getDefaultApplicationPropertiesFilePath();
+
+ private NiFiProperties instance;
+ private String keyHex;
+
+ private MiNiFiPropertiesLoader() {
+ }
+
+ /**
+ * Returns an instance of the loader configured with the key.
+ * <p>
+ * <p>
+ * NOTE: This method is used reflectively by the process which starts
MiNiFi
+ * so changes to it must be made in conjunction with that mechanism.</p>
+ *
+ * @param keyHex the key used to encrypt any sensitive properties
+ * @return the configured loader
+ */
+ public static MiNiFiPropertiesLoader withKey(String keyHex) {
+ MiNiFiPropertiesLoader loader = new MiNiFiPropertiesLoader();
+ loader.setKeyHex(keyHex);
+ return loader;
+ }
Review Comment:
done
##########
minifi/minifi-nar-bundles/minifi-framework-bundle/minifi-framework/minifi-runtime/pom.xml:
##########
@@ -76,5 +77,11 @@ limitations under the License.
<groupId>com.fasterxml.jackson.core</groupId>
<artifactId>jackson-databind</artifactId>
</dependency>
+
+ <dependency>
+ <groupId>ch.qos.logback</groupId>
+ <artifactId>logback-classic</artifactId>
+ <scope>test</scope>
+ </dependency>
Review Comment:
thanks, removed
##########
minifi/minifi-toolkit/minifi-toolkit-assembly/README.md:
##########
@@ -60,6 +61,87 @@ After downloading the binary and extracting it, to run the
MiNiFi Toolkit Conver
## Note
It's not guaranteed in all circumstances that the migration will result in a
correct flow. For example if a processor's configuration has changed between
version, the conversion tool won't be aware of this, and will use the
deprecated property names. You will need to fix such issues manually.
+# <a id="encrypt-sensitive-properties-in-bootstrapconf"
href="#encrypt-sensitive-properties-in-bootstrapconf">Encrypting Sensitive
Properties in bootstrap.conf</a>
+
+## MiNiFi Encrypt-Config Tool
+The encrypt-config command line tool (invoked in minifi-toolkit as
./bin/encrypt-config.sh or bin\encrypt-config.bat) reads from a bootstrap.conf
file with plaintext sensitive configuration values, prompts for a root password
or raw hexadecimal key, and encrypts each value. It replaces the plain values
with the protected value in the same file, or writes to a new bootstrap.conf
file if specified.
Review Comment:
yepp, I forgot to update this part. Thanks for noticing it.
##########
minifi/minifi-toolkit/minifi-toolkit-assembly/README.md:
##########
@@ -60,6 +61,87 @@ After downloading the binary and extracting it, to run the
MiNiFi Toolkit Conver
## Note
It's not guaranteed in all circumstances that the migration will result in a
correct flow. For example if a processor's configuration has changed between
version, the conversion tool won't be aware of this, and will use the
deprecated property names. You will need to fix such issues manually.
+# <a id="encrypt-sensitive-properties-in-bootstrapconf"
href="#encrypt-sensitive-properties-in-bootstrapconf">Encrypting Sensitive
Properties in bootstrap.conf</a>
+
+## MiNiFi Encrypt-Config Tool
+The encrypt-config command line tool (invoked in minifi-toolkit as
./bin/encrypt-config.sh or bin\encrypt-config.bat) reads from a bootstrap.conf
file with plaintext sensitive configuration values, prompts for a root password
or raw hexadecimal key, and encrypts each value. It replaces the plain values
with the protected value in the same file, or writes to a new bootstrap.conf
file if specified.
+
+The supported encryption algorithm utilized is AES/GCM 128/256-bit. 128-bit is
used if the JCE Unlimited Strength Cryptographic Jurisdiction Policy files are
not installed, and 256-bit is used if they are installed.
+
Review Comment:
ok
##########
minifi/minifi-toolkit/minifi-toolkit-encrypt-config/src/main/java/org/apache/nifi/minifi/toolkit/config/command/MiNiFiEncryptConfig.java:
##########
@@ -0,0 +1,146 @@
+/*
+ * 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.nifi.minifi.toolkit.config.command;
+
+import java.io.IOException;
+import java.io.UncheckedIOException;
+import java.nio.file.Files;
+import java.nio.file.Path;
+import java.nio.file.StandardCopyOption;
+import java.security.SecureRandom;
+import java.util.HashSet;
+import java.util.Optional;
+import java.util.Set;
+import org.apache.commons.codec.binary.Hex;
+import org.apache.nifi.minifi.properties.BootstrapProperties;
+import org.apache.nifi.minifi.properties.BootstrapPropertiesLoader;
+import org.apache.nifi.minifi.properties.ProtectedBootstrapProperties;
+import
org.apache.nifi.minifi.toolkit.config.transformer.ApplicationPropertiesFileTransformer;
+import
org.apache.nifi.minifi.toolkit.config.transformer.BootstrapConfigurationFileTransformer;
+import org.apache.nifi.minifi.toolkit.config.transformer.FileTransformer;
+import org.apache.nifi.properties.AesGcmSensitivePropertyProvider;
+import org.apache.nifi.properties.SensitivePropertyProvider;
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
+import picocli.CommandLine.Command;
+import picocli.CommandLine.Option;
+
+/**
+ * Shared Encrypt Configuration for NiFi and NiFi Registry
+ */
+@Command(
+ name = "encrypt-config",
+ sortOptions = false,
+ mixinStandardHelpOptions = true,
+ usageHelpWidth = 160,
+ separator = " ",
+ version = {
+ "Java ${java.version} (${java.vendor} ${java.vm.name}
${java.vm.version})"
+ },
+ descriptionHeading = "Description: ",
+ description = {
+ "encrypt-config supports protection of sensitive values in
Apache MiNiFi"
+ }
+)
+public class MiNiFiEncryptConfig implements Runnable{
+
+ static final String BOOTSTRAP_ROOT_KEY_PROPERTY =
"minifi.bootstrap.sensitive.key";
+
+ private static final String WORKING_FILE_NAME_FORMAT = "%s.%d.working";
+ private static final int KEY_LENGTH = 32;
+
+ @Option(
+ names = {"-b", "--bootstrapConf"},
+ description = "Path to file containing Bootstrap Configuration
[bootstrap.conf] for optional root key and property protection scheme settings"
+ )
+ Path bootstrapConfPath;
+
+ @Option(
+ names = {"-B", "--outputBootstrapConf"},
+ description = "Path to output file for Bootstrap Configuration
[bootstrap.conf] with root key configured"
+ )
+ Path outputBootstrapConf;
+
+ protected final Logger logger = LoggerFactory.getLogger(getClass());
+
+ @Override
+ public void run() {
+ processBootstrapConf();
+ }
+
+ /**
+ * Process bootstrap.conf writing new Root Key to specified Root Key
Property when bootstrap.conf is specified
+ *
+ */
+ protected void processBootstrapConf() {
+ BootstrapProperties unprotectedProperties =
BootstrapPropertiesLoader.load(bootstrapConfPath.toFile());
Review Comment:
This does exactly what you've described. The BootstrapPropertiesLoader.load
loads the unencrypted values, and if you run the encryption tool multiple times
it always encrypt the original values.
##########
minifi/minifi-bootstrap/src/main/java/org/apache/nifi/minifi/bootstrap/service/MiNiFiExecCommandProvider.java:
##########
@@ -116,8 +134,14 @@ public List<String> getMiNiFiExecCommand(int listenPort,
File workingDir) throws
systemProperty(BOOTSTRAP_LOG_FILE_EXTENSION,
minifiBootstrapLogFileExtension)
);
- return List.of(javaCommand, javaAdditionalArgs, systemProperties,
List.of(MINIFI_FULLY_QUALIFIED_CLASS_NAME))
- .stream()
+ String sensitiveParameter = null;
+ if (isSensitiveKeyPresent(bootstrapProperties)) {
+ Path sensitiveKeyFile = createSensitiveKeyFile(confDir);
+ writeSensitiveKeyFile(bootstrapProperties, sensitiveKeyFile);
+ sensitiveParameter = "-K " +
sensitiveKeyFile.toFile().getAbsolutePath();
Review Comment:
ok, I'll apply that change
##########
minifi/minifi-nar-bundles/minifi-framework-bundle/minifi-framework/minifi-properties-loader/pom.xml:
##########
@@ -0,0 +1,61 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<!--
+ ~ 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.
+ -->
+
+<project xmlns="http://maven.apache.org/POM/4.0.0"
+ xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
+ xsi:schemaLocation="http://maven.apache.org/POM/4.0.0
http://maven.apache.org/xsd/maven-4.0.0.xsd">
+ <modelVersion>4.0.0</modelVersion>
+ <parent>
+ <groupId>org.apache.nifi.minifi</groupId>
+ <artifactId>minifi-framework</artifactId>
+ <version>2.0.0-SNAPSHOT</version>
+ </parent>
+
+ <artifactId>minifi-properties-loader</artifactId>
+
+ <dependencies>
+ <dependency>
+ <groupId>org.apache.nifi</groupId>
+ <artifactId>nifi-property-protection-loader</artifactId>
+ </dependency>
+ <dependency>
+ <groupId>org.apache.nifi</groupId>
+ <artifactId>nifi-property-protection-factory</artifactId>
Review Comment:
Thanks, actually this is a leftover of my initial change and not even used.
I'm removing it.
##########
minifi/minifi-commons/minifi-commons-utils/src/main/java/org/apache/nifi/minifi/commons/utils/PropertyUtil.java:
##########
@@ -48,4 +62,96 @@ private static Optional<String> getPropertyValue(String
name, Map<?, ?> properti
private static Stream<String> keyPermutations(String name) {
return Stream.of(name, name.replace(DOT, UNDERSCORE),
name.replace(HYPHEN, UNDERSCORE), name.replace(DOT, UNDERSCORE).replace(HYPHEN,
UNDERSCORE)).distinct();
}
+
+ public static String getFormattedKey(String[] args) {
+ String key = null;
+ Optional<String> keyFileLocation = getKeyFileArg(args);
+ if (keyFileLocation.isPresent()) {
+ LOGGER.debug("The bootstrap process provided the {} flag",
KEY_FILE_FLAG);
+ key = getKeyFromKeyFileAndPrune(keyFileLocation.get());
+ }
+
+ // Format the key (check hex validity and remove spaces)
+ return getFormattedKey(key);
+ }
+
+ public static String getFormattedKey(String unformattedKey) {
+ String key = formatHexKey(unformattedKey);
+
+ if (isNotEmpty(key) && !isHexKeyValid(key)) {
+ throw new IllegalArgumentException("The key was not provided in
valid hex format and of the correct length");
+ } else {
+ return key;
+ }
+ }
+
+ private static String formatHexKey(String input) {
+ return Optional.ofNullable(input)
+ .map(String::trim)
+ .filter(PropertyUtil::isNotEmpty)
+ .map(str -> str.replaceAll("[^0-9a-fA-F]", EMPTY).toLowerCase())
+ .orElse(EMPTY);
+ }
+
+ private static boolean isHexKeyValid(String key) {
+ return Optional.ofNullable(key)
+ .map(String::trim)
+ .filter(PropertyUtil::isNotEmpty)
+ .map(__ -> Arrays.asList(128, 196, 256).contains(key.length() * 4)
&& key.matches("^[0-9a-fA-F]*$"))
Review Comment:
ok
##########
minifi/minifi-nar-bundles/minifi-framework-bundle/minifi-framework/minifi-properties-loader/src/main/java/org/apache/nifi/minifi/properties/ProtectedBootstrapProperties.java:
##########
@@ -0,0 +1,135 @@
+/*
+ * 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.nifi.minifi.properties;
+
+import static
org.apache.nifi.minifi.properties.ProtectedMiNiFiProperties.DEFAULT_SENSITIVE_PROPERTIES;
+
+import java.util.Arrays;
+import java.util.List;
+import java.util.Map;
+import java.util.Properties;
+import java.util.Set;
+import java.util.stream.Collectors;
+import java.util.stream.Stream;
+import org.apache.nifi.minifi.commons.api.MiNiFiProperties;
+import org.apache.nifi.properties.ApplicationPropertiesProtector;
+import org.apache.nifi.properties.ProtectedProperties;
+import org.apache.nifi.properties.SensitivePropertyProtectionException;
+import org.apache.nifi.properties.SensitivePropertyProtector;
+import org.apache.nifi.properties.SensitivePropertyProvider;
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
+
+public class ProtectedBootstrapProperties extends BootstrapProperties
implements ProtectedProperties<BootstrapProperties>,
+ SensitivePropertyProtector<ProtectedBootstrapProperties,
BootstrapProperties> {
+
+ private static final Logger logger =
LoggerFactory.getLogger(ProtectedBootstrapProperties.class);
+
+ private BootstrapProperties bootstrapProperties;
+
+ private final SensitivePropertyProtector<ProtectedBootstrapProperties,
BootstrapProperties> propertyProtectionDelegate;
+
+ public static final String ADDITIONAL_SENSITIVE_PROPERTIES_KEY =
"nifi.sensitive.props.additional.keys";
Review Comment:
changed the property name to minifi.xxxx and moved it to a common class
##########
minifi/minifi-nar-bundles/minifi-framework-bundle/minifi-framework/minifi-properties-loader/src/main/java/org/apache/nifi/minifi/properties/ProtectedMiNiFiProperties.java:
##########
@@ -0,0 +1,241 @@
+/*
+ * 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.nifi.minifi.properties;
+
+import static java.util.Arrays.asList;
+
+import java.util.ArrayList;
+import java.util.Arrays;
+import java.util.List;
+import java.util.Map;
+import java.util.Properties;
+import java.util.Set;
+import java.util.function.Function;
+import java.util.stream.Collectors;
+import java.util.stream.Stream;
+import org.apache.nifi.minifi.commons.api.MiNiFiProperties;
+import org.apache.nifi.properties.ApplicationPropertiesProtector;
+import org.apache.nifi.properties.ProtectedProperties;
+import org.apache.nifi.properties.SensitivePropertyProtectionException;
+import org.apache.nifi.properties.SensitivePropertyProtector;
+import org.apache.nifi.properties.SensitivePropertyProvider;
+import org.apache.nifi.util.NiFiProperties;
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
+
+/**
+ * Decorator class for intermediate phase when {@link MiNiFiPropertiesLoader}
loads the
+ * raw properties file and performs unprotection activities before returning a
clean
+ * implementation of {@link NiFiProperties}.
+ * This encapsulates the sensitive property access logic from external
consumers
+ * of {@code NiFiProperties}.
+ */
+public class ProtectedMiNiFiProperties extends NiFiProperties implements
ProtectedProperties<NiFiProperties>,
+ SensitivePropertyProtector<ProtectedMiNiFiProperties, NiFiProperties> {
+ private static final Logger logger =
LoggerFactory.getLogger(ProtectedMiNiFiProperties.class);
+ public static final String ADDITIONAL_SENSITIVE_PROPERTIES_KEY =
"nifi.sensitive.props.additional.keys";
Review Comment:
done.
##########
minifi/minifi-nar-bundles/minifi-framework-bundle/minifi-framework/minifi-runtime/src/main/java/org/apache/nifi/minifi/MiNiFi.java:
##########
@@ -45,7 +49,8 @@
public class MiNiFi {
- private static final Logger logger = LoggerFactory.getLogger(MiNiFi.class);
+ private static final Logger LOGGER = LoggerFactory.getLogger(MiNiFi.class);
Review Comment:
ok
##########
minifi/minifi-nar-bundles/minifi-framework-bundle/minifi-framework/minifi-properties-loader/src/main/java/org/apache/nifi/minifi/properties/ProtectedMiNiFiProperties.java:
##########
@@ -0,0 +1,241 @@
+/*
+ * 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.nifi.minifi.properties;
+
+import static java.util.Arrays.asList;
+
+import java.util.ArrayList;
+import java.util.Arrays;
+import java.util.List;
+import java.util.Map;
+import java.util.Properties;
+import java.util.Set;
+import java.util.function.Function;
+import java.util.stream.Collectors;
+import java.util.stream.Stream;
+import org.apache.nifi.minifi.commons.api.MiNiFiProperties;
+import org.apache.nifi.properties.ApplicationPropertiesProtector;
+import org.apache.nifi.properties.ProtectedProperties;
+import org.apache.nifi.properties.SensitivePropertyProtectionException;
+import org.apache.nifi.properties.SensitivePropertyProtector;
+import org.apache.nifi.properties.SensitivePropertyProvider;
+import org.apache.nifi.util.NiFiProperties;
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
+
+/**
+ * Decorator class for intermediate phase when {@link MiNiFiPropertiesLoader}
loads the
+ * raw properties file and performs unprotection activities before returning a
clean
+ * implementation of {@link NiFiProperties}.
+ * This encapsulates the sensitive property access logic from external
consumers
+ * of {@code NiFiProperties}.
+ */
+public class ProtectedMiNiFiProperties extends NiFiProperties implements
ProtectedProperties<NiFiProperties>,
+ SensitivePropertyProtector<ProtectedMiNiFiProperties, NiFiProperties> {
+ private static final Logger logger =
LoggerFactory.getLogger(ProtectedMiNiFiProperties.class);
+ public static final String ADDITIONAL_SENSITIVE_PROPERTIES_KEY =
"nifi.sensitive.props.additional.keys";
+ public static final List<String> DEFAULT_SENSITIVE_PROPERTIES = new
ArrayList<>(asList(
+ SECURITY_KEY_PASSWD,
+ SECURITY_KEYSTORE_PASSWD,
+ SECURITY_TRUSTSTORE_PASSWD,
+ SENSITIVE_PROPS_KEY,
+ REPOSITORY_ENCRYPTION_KEY_PROVIDER_KEYSTORE_PASSWORD,
+ SECURITY_USER_OIDC_CLIENT_SECRET
Review Comment:
The MiNiFi core is the same as the NiFi core therefore we have the same
properties in the MiNiFi properties + some additional C2 properties that are
used only in MiNiFi.
##########
minifi/minifi-toolkit/minifi-toolkit-encrypt-config/src/main/java/org/apache/nifi/minifi/toolkit/config/command/MiNiFiEncryptConfig.java:
##########
@@ -0,0 +1,146 @@
+/*
+ * 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.nifi.minifi.toolkit.config.command;
+
+import java.io.IOException;
+import java.io.UncheckedIOException;
+import java.nio.file.Files;
+import java.nio.file.Path;
+import java.nio.file.StandardCopyOption;
+import java.security.SecureRandom;
+import java.util.HashSet;
+import java.util.Optional;
+import java.util.Set;
+import org.apache.commons.codec.binary.Hex;
Review Comment:
Awesome
##########
minifi/minifi-nar-bundles/minifi-framework-bundle/pom.xml:
##########
@@ -80,6 +80,21 @@ limitations under the License.
<version>2.0.0-SNAPSHOT</version>
<scope>test</scope>
</dependency>
+ <dependency>
+ <groupId>org.apache.nifi</groupId>
+ <artifactId>nifi-property-protection-factory</artifactId>
Review Comment:
removed it
##########
minifi/minifi-nar-bundles/minifi-framework-bundle/minifi-framework/minifi-runtime/src/main/java/org/apache/nifi/minifi/MiNiFi.java:
##########
@@ -216,12 +221,43 @@ public void run() {
* @param args things which are ignored
*/
public static void main(String[] args) {
- logger.info("Launching MiNiFi...");
+ LOGGER.info("Launching MiNiFi...");
try {
- NiFiProperties niFiProperties =
MultiSourceMinifiProperties.getInstance();
- new MiNiFi(niFiProperties);
+ NiFiProperties properties = getValidatedMiNifiProperties(args);
+ new MiNiFi(properties);
} catch (final Throwable t) {
- logger.error("Failure to launch MiNiFi due to " + t, t);
+ LOGGER.error("Failure to launch MiNiFi due to " + t, t);
+ }
+ }
+
+ protected static NiFiProperties getValidatedMiNifiProperties(String[]
args) {
+ NiFiProperties properties = initializeProperties(args,
createBootstrapClassLoader());
+ properties.validate();
+ return properties;
+ }
+
+ private static NiFiProperties initializeProperties(final String[] args,
final ClassLoader boostrapLoader) {
+ ClassLoader contextClassLoader =
Thread.currentThread().getContextClassLoader();
+ String key = getFormattedKey(args);
+
+ Thread.currentThread().setContextClassLoader(boostrapLoader);
+
+ try {
+ Class<?> propsLoaderClass =
Class.forName("org.apache.nifi.minifi.properties.MiNiFiPropertiesLoader", true,
boostrapLoader);
+ Method withKeyMethod = propsLoaderClass.getMethod("withKey",
String.class);
+ Object loaderInstance = withKeyMethod.invoke(null, key);
Review Comment:
I tried to remove it and simply using a constructor method of the
MiNiFiPropertiesLoader, but I got class not found errors coming from
commons-lang3, seems it somehow pollutes other classloaders. so I think we need
to keep this approach.
--
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]