You are viewing a plain text version of this content. The canonical link for it is here.
Posted to issues@nifi.apache.org by "bobpaulin (via GitHub)" <gi...@apache.org> on 2025/01/15 19:00:58 UTC
[PR] NIFI-14163: Enhance GCP Credential to use delegate user [nifi]
bobpaulin opened a new pull request, #9635:
URL: https://github.com/apache/nifi/pull/9635
<!-- 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. -->
# Summary
[NIFI-14163](https://issues.apache.org/jira/browse/NIFI-14163)
# Tracking
Please complete the following tracking steps prior to pull request creation.
### Issue Tracking
- [ ] [Apache NiFi Jira](https://issues.apache.org/jira/browse/NIFI) issue created
### Pull Request Tracking
- [ ] Pull Request title starts with Apache NiFi Jira issue number, such as `NIFI-00000`
- [ ] Pull Request commit message starts with Apache NiFi Jira issue number, as such `NIFI-00000`
### Pull Request Formatting
- [ ] Pull Request based on current revision of the `main` branch
- [ ] Pull Request refers to a feature branch with one commit containing changes
# Verification
Please indicate the verification steps performed prior to pull request creation.
To verify this change you must use a service account credential that has been configured to use domain-wide delegation with the scopes that your processors are expecting to use (per https://developers.google.com/identity/protocols/oauth2/service-account#delegatingauthority). Ex ListGoogleDrive specifically requires the https://www.googleapis.com/auth/drive.metadata.readonly scope.
To verify positve and negative cases:
Use a Google Drive that has the service account user added and configure the GCPCredentialControllerService to use a Service Account JSON.
Expected Result: Drive Files should appear
Remove the same Service Account email from the drive permissions.
Expected Result: Drive Files will not appear. (Service Account can't access them)
Configure GCPCredentialControllerService to use the delegation user of an email that currently has access to the drive.
Expected Result: Drive Files will appear.,
### Build
- [ ] Build completed using `mvn clean install -P contrib-check`
- [ ] JDK 21
### Licensing
- [ ] New dependencies are compatible with the [Apache License 2.0](https://apache.org/licenses/LICENSE-2.0) according to the [License Policy](https://www.apache.org/legal/resolved.html)
- [ ] New dependencies are documented in applicable `LICENSE` and `NOTICE` files
### Documentation
- [ ] Documentation formatting appears as expected in rendered files
--
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: issues-unsubscribe@nifi.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
Re: [PR] NIFI-14163: Enhance GCP Credential to use delegate user [nifi]
Posted by "bobpaulin (via GitHub)" <gi...@apache.org>.
bobpaulin commented on PR #9635:
URL: https://github.com/apache/nifi/pull/9635#issuecomment-2593878714
Thank you for the review @pvillard31 ! Updates made.
--
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: issues-unsubscribe@nifi.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
Re: [PR] NIFI-14163: Enhance GCP Credential to use delegate user [nifi]
Posted by "pvillard31 (via GitHub)" <gi...@apache.org>.
pvillard31 closed pull request #9635: NIFI-14163: Enhance GCP Credential to use delegate user
URL: https://github.com/apache/nifi/pull/9635
--
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: issues-unsubscribe@nifi.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
Re: [PR] NIFI-14163: Enhance GCP Credential to use delegate user [nifi]
Posted by "bobpaulin (via GitHub)" <gi...@apache.org>.
bobpaulin commented on code in PR #9635:
URL: https://github.com/apache/nifi/pull/9635#discussion_r1917253902
##########
nifi-extension-bundles/nifi-gcp-bundle/nifi-gcp-processors/src/main/java/org/apache/nifi/processors/gcp/credentials/factory/CredentialPropertyDescriptors.java:
##########
@@ -91,4 +91,24 @@ private CredentialPropertyDescriptors() { }
.sensitive(true)
.build();
+ public static final PropertyDescriptor DELEGATION_STRATEGY = new PropertyDescriptor.Builder()
+ .name("delegation-strategy")
+ .displayName("Delegation Strategy")
Review Comment:
Are we ok if the name doesn't match the convention of the other names in the class? Or are you asking me to update all the names and create a migrate properties to ensure older version convert? I understand the desire to get away from display name just want to ensure we're ok with some of the code looking patchy or requiring upgrade methods.
--
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: issues-unsubscribe@nifi.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
Re: [PR] NIFI-14163: Enhance GCP Credential to use delegate user [nifi]
Posted by "bobpaulin (via GitHub)" <gi...@apache.org>.
bobpaulin commented on code in PR #9635:
URL: https://github.com/apache/nifi/pull/9635#discussion_r1917248042
##########
nifi-extension-bundles/nifi-gcp-bundle/nifi-gcp-processors/src/main/java/org/apache/nifi/processors/gcp/credentials/factory/strategies/AbstractServiceAccountCredentialsStrategy.java:
##########
@@ -37,7 +39,13 @@ public AbstractServiceAccountCredentialsStrategy(String name, PropertyDescriptor
@Override
public GoogleCredentials getGoogleCredentials(Map<PropertyDescriptor, String> properties, HttpTransportFactory transportFactory) throws IOException {
+ final String delegationStrategy = properties.get(CredentialPropertyDescriptors.DELEGATION_STRATEGY);
+ if (delegationStrategy != null && delegationStrategy.equals(DelegationStrategy.DELEGATED_ACCOUNT.getValue())) {
+ final String delegationUser = properties.get(CredentialPropertyDescriptors.DELEGATION_USER);
+ return GoogleCredentials.fromStream(getServiceAccountJson(properties), transportFactory).createDelegated(delegationUser);
+ } else {
return GoogleCredentials.fromStream(getServiceAccountJson(properties), transportFactory);
+ }
Review Comment:
So that would be possible but the switch statement would be based on the string value since properties map doesn't return the enum directly. So I'd still have a default case to handle that would essentially be the null check.
```
switch (delegationStrategy) {
case DelegationStrategy.DELEGATED_ACCOUNT.getValue():
....
case DelegationStrategy.SERVICE_ACCOUNT.getValue()
...
default:
throw IllegalArgumentException("Delegation Strategy not defined");
}
```
--
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: issues-unsubscribe@nifi.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
Re: [PR] NIFI-14163: Enhance GCP Credential to use delegate user [nifi]
Posted by "pvillard31 (via GitHub)" <gi...@apache.org>.
pvillard31 commented on code in PR #9635:
URL: https://github.com/apache/nifi/pull/9635#discussion_r1917265662
##########
nifi-extension-bundles/nifi-gcp-bundle/nifi-gcp-processors/src/main/java/org/apache/nifi/processors/gcp/credentials/factory/strategies/AbstractServiceAccountCredentialsStrategy.java:
##########
@@ -37,7 +39,13 @@ public AbstractServiceAccountCredentialsStrategy(String name, PropertyDescriptor
@Override
public GoogleCredentials getGoogleCredentials(Map<PropertyDescriptor, String> properties, HttpTransportFactory transportFactory) throws IOException {
+ final String delegationStrategy = properties.get(CredentialPropertyDescriptors.DELEGATION_STRATEGY);
+ if (delegationStrategy != null && delegationStrategy.equals(DelegationStrategy.DELEGATED_ACCOUNT.getValue())) {
+ final String delegationUser = properties.get(CredentialPropertyDescriptors.DELEGATION_USER);
+ return GoogleCredentials.fromStream(getServiceAccountJson(properties), transportFactory).createDelegated(delegationUser);
+ } else {
return GoogleCredentials.fromStream(getServiceAccountJson(properties), transportFactory);
+ }
Review Comment:
Yeah I thought that we would convert the string to the enum so that we anticipate the case where a value may be added to the enum to support another strategy and in that case the switch case would error as not all values would be covered. But I don't really mind to be honest, I'm ok with all options.
--
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: issues-unsubscribe@nifi.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
Re: [PR] NIFI-14163: Enhance GCP Credential to use delegate user [nifi]
Posted by "pvillard31 (via GitHub)" <gi...@apache.org>.
pvillard31 commented on code in PR #9635:
URL: https://github.com/apache/nifi/pull/9635#discussion_r1917214840
##########
nifi-extension-bundles/nifi-gcp-bundle/nifi-gcp-processors/src/main/java/org/apache/nifi/processors/gcp/credentials/factory/CredentialPropertyDescriptors.java:
##########
@@ -91,4 +91,24 @@ private CredentialPropertyDescriptors() { }
.sensitive(true)
.build();
+ public static final PropertyDescriptor DELEGATION_STRATEGY = new PropertyDescriptor.Builder()
+ .name("delegation-strategy")
+ .displayName("Delegation Strategy")
Review Comment:
We're trying to get away from `.displayName`, we should only use `.name` for new properties. I think it'd be worth for us to mark `displayName` as deprecated on the API side to make this more obvious.
##########
nifi-extension-bundles/nifi-gcp-bundle/nifi-gcp-processors/src/main/java/org/apache/nifi/processors/gcp/credentials/factory/CredentialPropertyDescriptors.java:
##########
@@ -91,4 +91,24 @@ private CredentialPropertyDescriptors() { }
.sensitive(true)
.build();
+ public static final PropertyDescriptor DELEGATION_STRATEGY = new PropertyDescriptor.Builder()
+ .name("delegation-strategy")
+ .displayName("Delegation Strategy")
+ .required(false)
Review Comment:
Since it's a property with allowable values, I believe the convention is to have it as required = true.
##########
nifi-extension-bundles/nifi-gcp-bundle/nifi-gcp-processors/src/main/java/org/apache/nifi/processors/gcp/credentials/factory/strategies/AbstractServiceAccountCredentialsStrategy.java:
##########
@@ -37,7 +39,13 @@ public AbstractServiceAccountCredentialsStrategy(String name, PropertyDescriptor
@Override
public GoogleCredentials getGoogleCredentials(Map<PropertyDescriptor, String> properties, HttpTransportFactory transportFactory) throws IOException {
+ final String delegationStrategy = properties.get(CredentialPropertyDescriptors.DELEGATION_STRATEGY);
+ if (delegationStrategy != null && delegationStrategy.equals(DelegationStrategy.DELEGATED_ACCOUNT.getValue())) {
+ final String delegationUser = properties.get(CredentialPropertyDescriptors.DELEGATION_USER);
+ return GoogleCredentials.fromStream(getServiceAccountJson(properties), transportFactory).createDelegated(delegationUser);
+ } else {
return GoogleCredentials.fromStream(getServiceAccountJson(properties), transportFactory);
+ }
Review Comment:
Given this is an enum and it'll never be null, can't we use the switch case return style here?
##########
nifi-extension-bundles/nifi-gcp-bundle/nifi-gcp-processors/src/main/java/org/apache/nifi/processors/gcp/credentials/factory/CredentialPropertyDescriptors.java:
##########
@@ -91,4 +91,24 @@ private CredentialPropertyDescriptors() { }
.sensitive(true)
.build();
+ public static final PropertyDescriptor DELEGATION_STRATEGY = new PropertyDescriptor.Builder()
+ .name("delegation-strategy")
+ .displayName("Delegation Strategy")
+ .required(false)
+ .defaultValue(DelegationStrategy.SERVICE_ACCOUNT)
+ .allowableValues(DelegationStrategy.class)
+ .description("The Delegation Strategy determines which account is used when calls are made with the GCP Credential.")
+ .build();
+
+ public static final PropertyDescriptor DELEGATION_USER = new PropertyDescriptor.Builder()
+ .name("delegation-user")
+ .displayName("Delegation User")
Review Comment:
Remove use of `displayName`
--
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: issues-unsubscribe@nifi.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
Re: [PR] NIFI-14163: Enhance GCP Credential to use delegate user [nifi]
Posted by "pvillard31 (via GitHub)" <gi...@apache.org>.
pvillard31 commented on code in PR #9635:
URL: https://github.com/apache/nifi/pull/9635#discussion_r1917264145
##########
nifi-extension-bundles/nifi-gcp-bundle/nifi-gcp-processors/src/main/java/org/apache/nifi/processors/gcp/credentials/factory/CredentialPropertyDescriptors.java:
##########
@@ -91,4 +91,24 @@ private CredentialPropertyDescriptors() { }
.sensitive(true)
.build();
+ public static final PropertyDescriptor DELEGATION_STRATEGY = new PropertyDescriptor.Builder()
+ .name("delegation-strategy")
+ .displayName("Delegation Strategy")
Review Comment:
I'd say just remove on the newly added properties and leave the existing ones as-is even if it's not consistent. We did the same in another PR we merged earlier today.
--
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: issues-unsubscribe@nifi.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org