[GitHub] [nifi] turcsanyip commented on a change in pull request #4369: NIFI-7581 Add CS-based credential settings support for ADLS processors
turcsanyip commented on a change in pull request #4369: URL: https://github.com/apache/nifi/pull/4369#discussion_r452307527 ## File path: nifi-nar-bundles/nifi-azure-bundle/nifi-azure-processors/src/main/java/org/apache/nifi/services/azure/storage/ADLSCredentialsControllerService.java ## @@ -0,0 +1,153 @@ +/* + * 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.services.azure.storage; + +import com.google.common.base.Function; Review comment: Is Guava's `Function` used intentionally? ## File path: nifi-nar-bundles/nifi-azure-bundle/nifi-azure-processors/src/main/java/org/apache/nifi/processors/azure/AbstractAzureDataLakeStorageProcessor.java ## @@ -33,66 +33,26 @@ import org.apache.commons.lang3.StringUtils; import org.apache.nifi.components.PropertyDescriptor; -import org.apache.nifi.components.ValidationContext; -import org.apache.nifi.components.ValidationResult; import org.apache.nifi.components.Validator; import org.apache.nifi.context.PropertyContext; import org.apache.nifi.expression.ExpressionLanguageScope; import org.apache.nifi.flowfile.FlowFile; import org.apache.nifi.processor.AbstractProcessor; import org.apache.nifi.processor.Relationship; import org.apache.nifi.processor.util.StandardValidators; +import org.apache.nifi.services.azure.storage.ADLSCredentialsDetails; +import org.apache.nifi.services.azure.storage.ADLSCredentialsService; +import reactor.core.publisher.Mono; public abstract class AbstractAzureDataLakeStorageProcessor extends AbstractProcessor { -public static final PropertyDescriptor ACCOUNT_NAME = new PropertyDescriptor.Builder() -.name("storage-account-name").displayName("Storage Account Name") -.description("The storage account name. There are certain risks in allowing the account name to be stored as a flowfile " + -"attribute. While it does provide for a more flexible flow by allowing the account name to " + -"be fetched dynamically from a flowfile attribute, care must be taken to restrict access to " + -"the event provenance data (e.g. by strictly controlling the policies governing provenance for this Processor). " + -"In addition, the provenance repositories may be put on encrypted disk partitions." + -" Instead of defining the Storage Account Name, Storage Account Key and SAS Token properties directly on the processor, " + -"the preferred way is to configure them through a controller service") -.addValidator(StandardValidators.NON_EMPTY_VALIDATOR) - .expressionLanguageSupported(ExpressionLanguageScope.FLOWFILE_ATTRIBUTES) -.required(true) -.sensitive(true).build(); - -public static final PropertyDescriptor ACCOUNT_KEY = new PropertyDescriptor.Builder() -.name("storage-account-key").displayName("Storage Account Key") -.description("The storage account key. This is an admin-like password providing access to every container in this account. It is recommended " + -"one uses Shared Access Signature (SAS) token instead for fine-grained control with policies. " + -"There are certain risks in allowing the account key to be stored as a flowfile " + -"attribute. While it does provide for a more flexible flow by allowing the account key to " + -"be fetched dynamically from a flow file attribute, care must be taken to restrict access to " + -"the event provenance data (e.g. by strictly controlling the policies governing provenance for this Processor). " + -"In addition, the provenance repositories may be put on encrypted disk partitions.") -.addValidator(StandardValidators.NON_EMPTY_VALIDATOR) - .expressionLanguageSupported(ExpressionLanguageScope.FLOWFILE_ATTRIBUTES) -.required(false) -.sensitive(true).build(); - -public static final PropertyDescriptor SAS_TOKEN = new PropertyDescriptor.Builder() -.name("storage-sas-token").disp
[GitHub] [nifi] turcsanyip commented on a change in pull request #4369: NIFI-7581 Add CS-based credential settings support for ADLS processors
turcsanyip commented on a change in pull request #4369: URL: https://github.com/apache/nifi/pull/4369#discussion_r452068857 ## File path: nifi-nar-bundles/nifi-azure-bundle/nifi-azure-processors/src/main/java/org/apache/nifi/services/azure/storage/ADLSCredentialsControllerService.java ## @@ -0,0 +1,152 @@ +/* + * 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.services.azure.storage; + +import com.google.common.base.Function; +import org.apache.commons.lang3.StringUtils; +import org.apache.nifi.annotation.documentation.CapabilityDescription; +import org.apache.nifi.annotation.documentation.Tags; +import org.apache.nifi.annotation.lifecycle.OnEnabled; +import org.apache.nifi.components.PropertyDescriptor; +import org.apache.nifi.components.PropertyValue; +import org.apache.nifi.components.ValidationContext; +import org.apache.nifi.components.ValidationResult; +import org.apache.nifi.controller.AbstractControllerService; +import org.apache.nifi.controller.ConfigurationContext; +import org.apache.nifi.processor.util.StandardValidators; +import org.apache.nifi.processors.azure.storage.utils.AzureStorageUtils; + +import java.util.ArrayList; +import java.util.Arrays; +import java.util.Collection; +import java.util.Collections; +import java.util.List; +import java.util.Map; +import java.util.StringJoiner; +import java.util.function.BiConsumer; + +/** + * Provides credentials details for ADLS + * + * @see AbstractControllerService + */ +@Tags({"azure", "microsoft", "cloud", "storage", "adls", "credentials"}) +@CapabilityDescription("Defines credentials for ADLS processors.") +public class ADLSCredentialsControllerService extends AbstractControllerService implements ADLSCredentialsService { + +public static final PropertyDescriptor ACCOUNT_NAME = new PropertyDescriptor.Builder() +.fromPropertyDescriptor(AzureStorageUtils.ACCOUNT_NAME) +.description(AzureStorageUtils.ACCOUNT_NAME_BASE_DESCRIPTION) +.required(true) +.build(); + +public static final PropertyDescriptor ENDPOINT_SUFFIX = new PropertyDescriptor.Builder() +.fromPropertyDescriptor(AzureStorageUtils.ENDPOINT_SUFFIX) +.description( +"Storage accounts in public Azure always use a common FQDN suffix. " + +"Override this endpoint suffix with a different suffix in certain circumsances (like Azure Stack or non-public Azure regions).") +.required(true) +.defaultValue("dfs.core.windows.net") +.build(); + +public static final PropertyDescriptor USE_MANAGED_IDENTITY = new PropertyDescriptor.Builder() +.name("storage-use-managed-identity") +.displayName("Use Azure Managed Identity") +.description("Choose whether or not to use the managed identity of Azure VM/VMSS ") +.required(false) +.defaultValue("false") +.allowableValues("true", "false") +.addValidator(StandardValidators.BOOLEAN_VALIDATOR) +.build(); + +private static final List PROPERTIES = Collections.unmodifiableList(Arrays.asList( +ACCOUNT_NAME, +AzureStorageUtils.ACCOUNT_KEY, +AzureStorageUtils.PROP_SAS_TOKEN, +ENDPOINT_SUFFIX, Review comment: I would move it up after the Account Name. It is not really a credential attribute, but rather belongs to the storage "location" and Account Name is also related to the location / storage url. ## File path: nifi-nar-bundles/nifi-azure-bundle/nifi-azure-processors/src/main/java/org/apache/nifi/processors/azure/AbstractAzureDataLakeStorageProcessor.java ## @@ -136,11 +88,7 @@ .build(); private static final List PROPERTIES = Collections.unmodifiableList( -Arrays.asList(AbstractAzureDataLakeStorageProcessor.ACCOUNT_NAME, -AbstractAzureDataLakeStorageProcessor.ACCOUNT_KEY, -AbstractAzureDataLakeStorageProcessor.SAS_TOKEN, -AbstractAzureDataLakeStorageProcessor.USE_MANAGED_IDENTITY, -AbstractAzureDataLakeStorageProcessor.ENDPOINT_SUFFIX, +Arrays.asList(AzureStorageUtils.STORAGE_CREDENTIALS_SERVICE, Review comment:
[GitHub] [nifi] turcsanyip commented on a change in pull request #4369: NIFI-7581 Add CS-based credential settings support for ADLS processors
turcsanyip commented on a change in pull request #4369: URL: https://github.com/apache/nifi/pull/4369#discussion_r450057671 ## File path: nifi-nar-bundles/nifi-azure-bundle/nifi-azure-processors/src/main/java/org/apache/nifi/processors/azure/AbstractAzureDataLakeStorageProcessor.java ## @@ -158,41 +173,51 @@ public static Collection validateCredentialProperties(final ValidationContext validationContext) { final List results = new ArrayList<>(); -final boolean useManagedIdentity = validationContext.getProperty(USE_MANAGED_IDENTITY).asBoolean(); -final boolean accountKeyIsSet = validationContext.getProperty(ACCOUNT_KEY).isSet(); -final boolean sasTokenIsSet = validationContext.getProperty(SAS_TOKEN).isSet(); - -int credential_config_found = 0; -if(useManagedIdentity) credential_config_found++; -if(accountKeyIsSet) credential_config_found++; -if(sasTokenIsSet) credential_config_found++; - -if(credential_config_found == 0){ -final String msg = String.format( -"At least one of ['%s', '%s', '%s'] should be set", -ACCOUNT_KEY.getDisplayName(), -SAS_TOKEN.getDisplayName(), -USE_MANAGED_IDENTITY.getDisplayName() -); -results.add(new ValidationResult.Builder().subject("Credentials config").valid(false).explanation(msg).build()); -} else if(credential_config_found > 1) { -final String msg = String.format( -"Only one of ['%s', '%s', '%s'] should be set", -ACCOUNT_KEY.getDisplayName(), -SAS_TOKEN.getDisplayName(), -USE_MANAGED_IDENTITY.getDisplayName() -); -results.add(new ValidationResult.Builder().subject("Credentials config").valid(false).explanation(msg).build()); +if (!validationContext.getProperty(AzureStorageUtils.STORAGE_CREDENTIALS_SERVICE).isSet()) { Review comment: When the CS defined, the processor level credential properties should not be defined. It should be validated. Another option would be to get rid of the processor level credential properties. That would make the validation easier and the whole code simpler. ## File path: nifi-nar-bundles/nifi-azure-bundle/nifi-azure-processors/src/main/java/org/apache/nifi/processors/azure/AbstractAzureDataLakeStorageProcessor.java ## @@ -158,41 +173,51 @@ public static Collection validateCredentialProperties(final ValidationContext validationContext) { final List results = new ArrayList<>(); -final boolean useManagedIdentity = validationContext.getProperty(USE_MANAGED_IDENTITY).asBoolean(); -final boolean accountKeyIsSet = validationContext.getProperty(ACCOUNT_KEY).isSet(); -final boolean sasTokenIsSet = validationContext.getProperty(SAS_TOKEN).isSet(); - -int credential_config_found = 0; -if(useManagedIdentity) credential_config_found++; -if(accountKeyIsSet) credential_config_found++; -if(sasTokenIsSet) credential_config_found++; - -if(credential_config_found == 0){ -final String msg = String.format( -"At least one of ['%s', '%s', '%s'] should be set", -ACCOUNT_KEY.getDisplayName(), -SAS_TOKEN.getDisplayName(), -USE_MANAGED_IDENTITY.getDisplayName() -); -results.add(new ValidationResult.Builder().subject("Credentials config").valid(false).explanation(msg).build()); -} else if(credential_config_found > 1) { -final String msg = String.format( -"Only one of ['%s', '%s', '%s'] should be set", -ACCOUNT_KEY.getDisplayName(), -SAS_TOKEN.getDisplayName(), -USE_MANAGED_IDENTITY.getDisplayName() -); -results.add(new ValidationResult.Builder().subject("Credentials config").valid(false).explanation(msg).build()); +if (!validationContext.getProperty(AzureStorageUtils.STORAGE_CREDENTIALS_SERVICE).isSet()) { +final boolean useManagedIdentity = validationContext.getProperty(USE_MANAGED_IDENTITY).asBoolean(); +final boolean accountKeyIsSet = validationContext.getProperty(ACCOUNT_KEY).isSet(); +final boolean sasTokenIsSet = validationContext.getProperty(SAS_TOKEN).isSet(); + +int credential_config_found = 0; +if (useManagedIdentity) credential_config_found++; +if (accountKeyIsSet) credential_config_found++; +if (sasTokenIsSet) credential_config_found++; + +if (credential_config_found == 0) { +final String msg = String.format( +"At least one of ['%s', '%s', '%s'] should be set", +ACCOUNT_KEY.getDisplayName(), +SAS_TOKEN.getDisplayName(), +