You are viewing a plain text version of this content. The canonical link for it is here.
Posted to issues@nifi.apache.org by "pvillard31 (via GitHub)" <gi...@apache.org> on 2026/06/10 16:40:24 UTC
[PR] NIFI-16010 - Enforce service-account credential type in GCP credential strategies [nifi]
pvillard31 opened a new pull request, #11323:
URL: https://github.com/apache/nifi/pull/11323
# Summary
NIFI-16010 - Enforce service-account credential type in GCP credential strategies
# 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 contains [commits signed](https://docs.github.com/en/authentication/managing-commit-signature-verification/signing-commits) with a registered key indicating `Verified` status
### 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.
### Build
- [ ] Build completed using `./mvnw clean install -P contrib-check`
- [ ] JDK 21
- [ ] JDK 25
### 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-16010 - Enforce service-account credential type in GCP credential strategies [nifi]
Posted by "turcsanyip (via GitHub)" <gi...@apache.org>.
turcsanyip merged PR #11323:
URL: https://github.com/apache/nifi/pull/11323
--
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-16010 - Enforce service-account credential type in GCP credential strategies [nifi]
Posted by "turcsanyip (via GitHub)" <gi...@apache.org>.
turcsanyip commented on code in PR #11323:
URL: https://github.com/apache/nifi/pull/11323#discussion_r3391205389
##########
nifi-extension-bundles/nifi-gcp-bundle/nifi-gcp-processors/src/main/java/org/apache/nifi/processors/gcp/credentials/factory/ServiceAccountJsonValidator.java:
##########
@@ -0,0 +1,73 @@
+/*
+ * 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.processors.gcp.credentials.factory;
+
+import com.fasterxml.jackson.databind.JsonNode;
+import com.fasterxml.jackson.databind.ObjectMapper;
+import org.apache.nifi.components.ValidationContext;
+import org.apache.nifi.components.ValidationResult;
+import org.apache.nifi.components.Validator;
+import org.apache.nifi.processor.util.JsonValidator;
+
+/**
+ * Validates that a property value is a JSON object describing a Google Service Account key, that is a JSON object
+ * whose {@code type} field is {@code service_account}. Other Google credential types, such as {@code external_account},
+ * are rejected so that external identity credentials are configured through the Workload Identity Federation strategy.
+ */
+public class ServiceAccountJsonValidator implements Validator {
+ public static final ServiceAccountJsonValidator INSTANCE = new ServiceAccountJsonValidator();
+
+ private static final ObjectMapper OBJECT_MAPPER = new ObjectMapper();
+
+ private static final String TYPE_FIELD = "type";
+ private static final String SERVICE_ACCOUNT_TYPE = "service_account";
+
+ @Override
+ public ValidationResult validate(final String subject, final String input, final ValidationContext context) {
+ final ValidationResult jsonResult = JsonValidator.INSTANCE.validate(subject, input, context);
+ if (!jsonResult.isValid()) {
+ return jsonResult;
+ }
+
+ if (context.isExpressionLanguageSupported(subject) && context.isExpressionLanguagePresent(input)) {
+ return jsonResult;
+ }
+
+ final ValidationResult.Builder builder = new ValidationResult.Builder()
+ .subject(subject)
+ .input(input);
+
+ try {
+ final JsonNode rootNode = OBJECT_MAPPER.readTree(input);
+ final JsonNode typeNode = rootNode.get(TYPE_FIELD);
+ if (typeNode != null && SERVICE_ACCOUNT_TYPE.equals(typeNode.asText())) {
+ builder.valid(true);
+ builder.explanation("Service Account JSON found");
+ } else {
+ final String foundType = typeNode == null ? "none" : typeNode.asText();
+ builder.valid(false);
+ builder.explanation(("Expected a Service Account key with \"type\": \"service_account\" but found type: %s. "
Review Comment:
```suggestion
builder.explanation(("Expected a Service Account key with \"type\": \"service_account\" but found \"type\": \"%s\". "
```
##########
nifi-extension-bundles/nifi-gcp-bundle/nifi-gcp-processors/src/main/java/org/apache/nifi/processors/gcp/credentials/factory/strategies/AbstractServiceAccountCredentialsStrategy.java:
##########
@@ -38,14 +39,24 @@ public AbstractServiceAccountCredentialsStrategy(String name) {
protected abstract InputStream getServiceAccountJson(Map<PropertyDescriptor, String> properties) throws IOException;
@Override
- public GoogleCredentials getGoogleCredentials(Map<PropertyDescriptor, String> properties, HttpTransportFactory transportFactory) throws IOException {
+ public GoogleCredentials getGoogleCredentials(final Map<PropertyDescriptor, String> properties, final HttpTransportFactory transportFactory) throws IOException {
+ final GoogleCredentials credentials;
+ try (final InputStream serviceAccountJson = getServiceAccountJson(properties)) {
+ credentials = GoogleCredentials.fromStream(serviceAccountJson, transportFactory);
+ }
+
+ if (!(credentials instanceof ServiceAccountCredentials)) {
+ throw new IOException(("Configured credentials must be a Google Service Account key (\"type\": \"service_account\") but resolved to %s. "
+ + "Use the Workload Identity Federation strategy for external account credentials.").formatted(credentials.getClass().getSimpleName()));
Review Comment:
Same as in `ServiceAccountJsonValidator`: the actual type should be checked for `ExternalAccountCredentials`.
##########
nifi-extension-bundles/nifi-gcp-bundle/nifi-gcp-processors/src/main/java/org/apache/nifi/processors/gcp/credentials/factory/ServiceAccountJsonValidator.java:
##########
@@ -0,0 +1,73 @@
+/*
+ * 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.processors.gcp.credentials.factory;
+
+import com.fasterxml.jackson.databind.JsonNode;
+import com.fasterxml.jackson.databind.ObjectMapper;
+import org.apache.nifi.components.ValidationContext;
+import org.apache.nifi.components.ValidationResult;
+import org.apache.nifi.components.Validator;
+import org.apache.nifi.processor.util.JsonValidator;
+
+/**
+ * Validates that a property value is a JSON object describing a Google Service Account key, that is a JSON object
+ * whose {@code type} field is {@code service_account}. Other Google credential types, such as {@code external_account},
+ * are rejected so that external identity credentials are configured through the Workload Identity Federation strategy.
+ */
+public class ServiceAccountJsonValidator implements Validator {
+ public static final ServiceAccountJsonValidator INSTANCE = new ServiceAccountJsonValidator();
+
+ private static final ObjectMapper OBJECT_MAPPER = new ObjectMapper();
+
+ private static final String TYPE_FIELD = "type";
+ private static final String SERVICE_ACCOUNT_TYPE = "service_account";
+
+ @Override
+ public ValidationResult validate(final String subject, final String input, final ValidationContext context) {
+ final ValidationResult jsonResult = JsonValidator.INSTANCE.validate(subject, input, context);
+ if (!jsonResult.isValid()) {
+ return jsonResult;
+ }
+
+ if (context.isExpressionLanguageSupported(subject) && context.isExpressionLanguagePresent(input)) {
+ return jsonResult;
+ }
+
+ final ValidationResult.Builder builder = new ValidationResult.Builder()
+ .subject(subject)
+ .input(input);
+
+ try {
+ final JsonNode rootNode = OBJECT_MAPPER.readTree(input);
+ final JsonNode typeNode = rootNode.get(TYPE_FIELD);
+ if (typeNode != null && SERVICE_ACCOUNT_TYPE.equals(typeNode.asText())) {
+ builder.valid(true);
+ builder.explanation("Service Account JSON found");
+ } else {
+ final String foundType = typeNode == null ? "none" : typeNode.asText();
+ builder.valid(false);
+ builder.explanation(("Expected a Service Account key with \"type\": \"service_account\" but found type: %s. "
+ + "Use the Workload Identity Federation strategy for external account credentials.").formatted(foundType));
Review Comment:
I think we should add this note only when the type is really `external_account`.
--
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-16010 - Enforce service-account credential type in GCP credential strategies [nifi]
Posted by "turcsanyip (via GitHub)" <gi...@apache.org>.
turcsanyip commented on code in PR #11323:
URL: https://github.com/apache/nifi/pull/11323#discussion_r3391272380
##########
nifi-extension-bundles/nifi-gcp-bundle/nifi-gcp-processors/src/main/java/org/apache/nifi/processors/gcp/credentials/factory/ServiceAccountJsonValidator.java:
##########
@@ -0,0 +1,73 @@
+/*
+ * 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.processors.gcp.credentials.factory;
+
+import com.fasterxml.jackson.databind.JsonNode;
+import com.fasterxml.jackson.databind.ObjectMapper;
+import org.apache.nifi.components.ValidationContext;
+import org.apache.nifi.components.ValidationResult;
+import org.apache.nifi.components.Validator;
+import org.apache.nifi.processor.util.JsonValidator;
+
+/**
+ * Validates that a property value is a JSON object describing a Google Service Account key, that is a JSON object
+ * whose {@code type} field is {@code service_account}. Other Google credential types, such as {@code external_account},
+ * are rejected so that external identity credentials are configured through the Workload Identity Federation strategy.
+ */
+public class ServiceAccountJsonValidator implements Validator {
+ public static final ServiceAccountJsonValidator INSTANCE = new ServiceAccountJsonValidator();
+
+ private static final ObjectMapper OBJECT_MAPPER = new ObjectMapper();
+
+ private static final String TYPE_FIELD = "type";
+ private static final String SERVICE_ACCOUNT_TYPE = "service_account";
+
+ @Override
+ public ValidationResult validate(final String subject, final String input, final ValidationContext context) {
+ final ValidationResult jsonResult = JsonValidator.INSTANCE.validate(subject, input, context);
+ if (!jsonResult.isValid()) {
+ return jsonResult;
+ }
+
+ if (context.isExpressionLanguageSupported(subject) && context.isExpressionLanguagePresent(input)) {
+ return jsonResult;
+ }
+
+ final ValidationResult.Builder builder = new ValidationResult.Builder()
+ .subject(subject)
+ .input(input);
+
+ try {
+ final JsonNode rootNode = OBJECT_MAPPER.readTree(input);
+ final JsonNode typeNode = rootNode.get(TYPE_FIELD);
+ if (typeNode != null && SERVICE_ACCOUNT_TYPE.equals(typeNode.asText())) {
+ builder.valid(true);
+ builder.explanation("Service Account JSON found");
+ } else {
+ final String foundType = typeNode == null ? "none" : typeNode.asText();
+ builder.valid(false);
+ builder.explanation(("Expected a Service Account key with \"type\": \"service_account\" but found type: %s. "
+ + "Use the Workload Identity Federation strategy for external account credentials.").formatted(foundType));
Review Comment:
I meant only line 64 ("Use the Workload Identity Federation strategy..."). The code selection looks weird for some reason.
--
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-16010 - Enforce service-account credential type in GCP credential strategies [nifi]
Posted by "turcsanyip (via GitHub)" <gi...@apache.org>.
turcsanyip commented on code in PR #11323:
URL: https://github.com/apache/nifi/pull/11323#discussion_r3391272380
##########
nifi-extension-bundles/nifi-gcp-bundle/nifi-gcp-processors/src/main/java/org/apache/nifi/processors/gcp/credentials/factory/ServiceAccountJsonValidator.java:
##########
@@ -0,0 +1,73 @@
+/*
+ * 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.processors.gcp.credentials.factory;
+
+import com.fasterxml.jackson.databind.JsonNode;
+import com.fasterxml.jackson.databind.ObjectMapper;
+import org.apache.nifi.components.ValidationContext;
+import org.apache.nifi.components.ValidationResult;
+import org.apache.nifi.components.Validator;
+import org.apache.nifi.processor.util.JsonValidator;
+
+/**
+ * Validates that a property value is a JSON object describing a Google Service Account key, that is a JSON object
+ * whose {@code type} field is {@code service_account}. Other Google credential types, such as {@code external_account},
+ * are rejected so that external identity credentials are configured through the Workload Identity Federation strategy.
+ */
+public class ServiceAccountJsonValidator implements Validator {
+ public static final ServiceAccountJsonValidator INSTANCE = new ServiceAccountJsonValidator();
+
+ private static final ObjectMapper OBJECT_MAPPER = new ObjectMapper();
+
+ private static final String TYPE_FIELD = "type";
+ private static final String SERVICE_ACCOUNT_TYPE = "service_account";
+
+ @Override
+ public ValidationResult validate(final String subject, final String input, final ValidationContext context) {
+ final ValidationResult jsonResult = JsonValidator.INSTANCE.validate(subject, input, context);
+ if (!jsonResult.isValid()) {
+ return jsonResult;
+ }
+
+ if (context.isExpressionLanguageSupported(subject) && context.isExpressionLanguagePresent(input)) {
+ return jsonResult;
+ }
+
+ final ValidationResult.Builder builder = new ValidationResult.Builder()
+ .subject(subject)
+ .input(input);
+
+ try {
+ final JsonNode rootNode = OBJECT_MAPPER.readTree(input);
+ final JsonNode typeNode = rootNode.get(TYPE_FIELD);
+ if (typeNode != null && SERVICE_ACCOUNT_TYPE.equals(typeNode.asText())) {
+ builder.valid(true);
+ builder.explanation("Service Account JSON found");
+ } else {
+ final String foundType = typeNode == null ? "none" : typeNode.asText();
+ builder.valid(false);
+ builder.explanation(("Expected a Service Account key with \"type\": \"service_account\" but found type: %s. "
+ + "Use the Workload Identity Federation strategy for external account credentials.").formatted(foundType));
Review Comment:
I meant only line 64 (""Use the Workload Identity Federation strategy..."). The code selection looks weird for some reason.
--
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-16010 - Enforce service-account credential type in GCP credential strategies [nifi]
Posted by "pvillard31 (via GitHub)" <gi...@apache.org>.
pvillard31 commented on PR #11323:
URL: https://github.com/apache/nifi/pull/11323#issuecomment-4677131874
Thanks for the review @turcsanyip - I pushed a commit to address your comments
--
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-16010 - Enforce service-account credential type in GCP credential strategies [nifi]
Posted by "turcsanyip (via GitHub)" <gi...@apache.org>.
turcsanyip commented on code in PR #11323:
URL: https://github.com/apache/nifi/pull/11323#discussion_r3391272380
##########
nifi-extension-bundles/nifi-gcp-bundle/nifi-gcp-processors/src/main/java/org/apache/nifi/processors/gcp/credentials/factory/ServiceAccountJsonValidator.java:
##########
@@ -0,0 +1,73 @@
+/*
+ * 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.processors.gcp.credentials.factory;
+
+import com.fasterxml.jackson.databind.JsonNode;
+import com.fasterxml.jackson.databind.ObjectMapper;
+import org.apache.nifi.components.ValidationContext;
+import org.apache.nifi.components.ValidationResult;
+import org.apache.nifi.components.Validator;
+import org.apache.nifi.processor.util.JsonValidator;
+
+/**
+ * Validates that a property value is a JSON object describing a Google Service Account key, that is a JSON object
+ * whose {@code type} field is {@code service_account}. Other Google credential types, such as {@code external_account},
+ * are rejected so that external identity credentials are configured through the Workload Identity Federation strategy.
+ */
+public class ServiceAccountJsonValidator implements Validator {
+ public static final ServiceAccountJsonValidator INSTANCE = new ServiceAccountJsonValidator();
+
+ private static final ObjectMapper OBJECT_MAPPER = new ObjectMapper();
+
+ private static final String TYPE_FIELD = "type";
+ private static final String SERVICE_ACCOUNT_TYPE = "service_account";
+
+ @Override
+ public ValidationResult validate(final String subject, final String input, final ValidationContext context) {
+ final ValidationResult jsonResult = JsonValidator.INSTANCE.validate(subject, input, context);
+ if (!jsonResult.isValid()) {
+ return jsonResult;
+ }
+
+ if (context.isExpressionLanguageSupported(subject) && context.isExpressionLanguagePresent(input)) {
+ return jsonResult;
+ }
+
+ final ValidationResult.Builder builder = new ValidationResult.Builder()
+ .subject(subject)
+ .input(input);
+
+ try {
+ final JsonNode rootNode = OBJECT_MAPPER.readTree(input);
+ final JsonNode typeNode = rootNode.get(TYPE_FIELD);
+ if (typeNode != null && SERVICE_ACCOUNT_TYPE.equals(typeNode.asText())) {
+ builder.valid(true);
+ builder.explanation("Service Account JSON found");
+ } else {
+ final String foundType = typeNode == null ? "none" : typeNode.asText();
+ builder.valid(false);
+ builder.explanation(("Expected a Service Account key with \"type\": \"service_account\" but found type: %s. "
+ + "Use the Workload Identity Federation strategy for external account credentials.").formatted(foundType));
Review Comment:
I meant only line 64 (""Use the Workload Identity Federation strategy..."). The code selection looks weird for som reason.
--
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