Skip to main content
Bronze ⭐️⭐️⭐️
Nov 13, 2026 11:17 AM UTC
Question

NiFi 2.9 Kafka3ConnectionService with Google Cloud Managed Kafka using SASL_SSL/OAUTHBEARER

Hi,

I am using Apache NiFi 2.9 running in Kubernetes and need to connect a ConsumeKafka processor to Google Cloud Managed Service for Apache Kafka using Kafka3ConnectionService.

Due to a security constraint, SASL/PLAIN cannot be used. I need to use:

Security Protocol: SASL_SSL

SASL Mechanism: OAUTHBEARER

For Google Cloud Managed Kafka authentication, I am trying to use Google's Kafka authentication callback handler with Application Default Credentials (ADC).

The authentication setup requires the Google/Kafka authentication dependencies, including:

 

google-auth-library-oauth2-http-1.47.0.jar

kafka-oauth-client-0.17.1.jar

managed-kafka-auth-login-handler-1.0.5.jar

I have made these dependencies available to the NiFi environment.

I have also configured NiFi to use a JAAS configuration file through bootstrap.conf:

.properties

 

 

java.arg.18=-Djava.security.auth.login.config=/opt/nifi/nifi-current/conf/kafka_client_jaas.conf

The JAAS configuration uses:

 

org.apache.kafka.common.security.oauthbearer.OAuthBearerLoginModule required;

 

For the Google Managed Kafka authentication mechanism, I also need the Kafka client to use:

.properties

 

 

sasl.login.callback.handler.class=com.google.cloud.hosted.kafka.auth.GcpLoginCallbackHandler

Issue

When I configure Kafka3ConnectionService with:

 

Security Protocol = SASL_SSL

SASL Mechanism = OAUTHBEARER

NiFi requires me to configure an OAuth2 Access Token Provider Service.

My understanding is that the Google authentication library can handle token acquisition through GcpLoginCallbackHandler using Google credentials/ADC.

Therefore, I am trying to understand how this authentication model should be integrated with Kafka3ConnectionService.

I also don't see a way to add the following Kafka client property as a dynamic property in Kafka3ConnectionService:

.properties

 

 

sasl.login.callback.handler.class=com.google.cloud.hosted.kafka.auth.GcpLoginCallbackHandler

Questions

  1. Does Kafka3ConnectionService in NiFi 2.9 support using a custom Kafka sasl.login.callback.handler.class with the OAUTHBEARER mechanism?

  2. Is there a supported way to use Google's:

 

com.google.cloud.hosted.kafka.auth.GcpLoginCallbackHandler

with Kafka3ConnectionService without configuring NiFi's OAuth2 Access Token Provider Service?

  1. If Kafka3ConnectionService requires an OAuth2AccessTokenProvider for OAUTHBEARER, would implementing a custom NiFi OAuth2AccessTokenProvider Controller Service as a separate NAR be the recommended extension point for Google Cloud Managed Kafka?

  2. Is there another recommended approach for passing the required Google Kafka authentication configuration to the underlying Kafka client?

Upgradeability requirement

I would prefer a solution that does not modify or rebuild NiFi's standard Kafka NARs.

Since NiFi is deployed as a Kubernetes pod and will be upgraded to newer NiFi versions over time, ideally the Google authentication integration would be packaged/configured separately so that NiFi upgrades do not require rebuilding the standard NiFi Kafka components.

Has anyone successfully configured NiFi 2.9 + Kafka3ConnectionService + Google Cloud Managed Kafka using SASL_SSL/OAUTHBEARER?

Any guidance on the supported extension/configuration approach would be greatly appreciated.

Thanks.

2 replies

vafs
Gold ⭐️⭐️⭐️
Gold ⭐️⭐️⭐️
Nov 13, 2026 9:58 PM UTC

Hello ​@sasirekha87, 

Thanks for being part of our community. 

 

The Kafka3ConnectionService does not support a custom Kafka sasl.login.callback.handler.class because it needs a org.apache.nifi.oauth2.OAuth2AccessTokenProvider associated. 
Also, there is no direct method to update the dynamic properties because they are already set, so they cannot be updated: 

In the event a dynamic property represents a property that was already set, its value will be ignored and WARN message logged.

https://nifi.apache.org/components/org.apache.nifi.kafka.service.Kafka3ConnectionService/

 

Your approach to use a custom NAR for OAuth2AccessTokenProvider would be the best option here. 
You can create a project with nifi-api, nifi-oauth2-provider-api, managed-kafka-auth-login-handler and google-auth-library-oauth2-http. 
Then, load the NAR and use this service. 
You do not need to modify the base NiFi and can be reused on upgrades. 

 

Regards, 
Andrés Fallas 
-- Was your question answered? 
Please take some time to click on "Accept as Solution" below this post. 
If you find a reply useful, say thanks by clicking on the thumbs-up button.

Translate
Shelton
Gold ⭐️⭐️⭐️
Nov 15, 2026 9:10 PM UTC

​@sasirekha87 
There are 2 options or answers to you issue with 2 different tradeoffs personally I would go for the sidecar option 2

 

Answer 1:
Custom OAuth2 Access Token Provider NAR (in-process)


Summary: Kafka3ConnectionService in NiFi 2.9 can’t use Google’s GcpLoginCallbackHandler directly. It does accept a custom OAuth2AccessTokenProvider controller service, packaged as a separate NAR, that returns Google Managed Kafka’s token format. The stock Kafka NARs aren’t modified. The project is in nifi-gcp-managed-kafka-oauth2.zip. Build and test it on your side.

Why the direct approach doesn’t work

  • When the mechanism is OAUTHBEARER, Kafka3ConnectionService hard-codes sasl.login.callback.handler.class to NiFi’s own OAuthBearerLoginCallbackHandler. Your dynamic property is dropped: “In the event a dynamic property represents a property that was already set, its value will be ignored and WARN message” “logged.”
  • The OAuth2 Access Token Provider Service is required and only applies when SASL Mechanism is OAUTHBEARER.
  • NiFi’s handler calls refreshAccessDetails() and then getAccessDetails().getAccessToken(). It parses the result with Kafka’s ClientJwtValidator, which reads the claims without checking a signature. That fits Google’s token: a JWT-shaped string base64url(header).base64url(payload).base64url(access_token), where the header is {“typ”:”JWT”,”alg”:”GOOG_OAUTH2_TOKEN”}, the payload holds exp/iat/iss/sub, and the last segment is a Google OAuth2 access token. 

Steps

  1. Clean up. Delete java.arg.18 from bootstrap.conf, because NiFi builds its own sasl.jaas.config for each client. Take the three JARs out of NiFi’s lib/, since jars there are visible to every NAR and can cause conflicts.
  2. Set up the Google identity for the pod.
    • The principal needs roles/managedkafka.client in the Google Cloud project that contains your managed Kafka cluster. 
    • On GKE, authentication is not supported for clients using Workload Identity Federation for GKE. As an alternative, link Kubernetes service accounts to IAM service accounts. So annotate the Kubernetes service account with iam.gke.io/gcp-service-account=<gsa>@<project>.iam.gserviceaccount.com, and grant roles/iam.workloadIdentityUser. 
    • Outside GKE, mount a service account key and set GOOGLE_APPLICATION_CREDENTIALS.
  3. Build the NAR. Run mvn clean package. The project targets NiFi 2.9.0, nifi-api 2.8.0, NAR plugin 2.3.0 and Java 21. Its parent NAR is nifi-standard-shared-nar, the same parent the stock OAuth2 provider uses. The Google auth library is packaged inside the NAR.
  4. Deploy it. Put the .nar in /opt/nifi/nifi-current/extensions/, which NiFi autoloads. Either use a thin image (FROM apache/nifi:2.9.0 plus COPY), or have an init container copy it into a mounted volume.
  5. Configure it in NiFi.
    • Add GcpManagedKafkaAccessTokenProvider. Leave “Principal Override” empty unless the service account email can’t be detected.
    • In Kafka3ConnectionService, set:
      • Bootstrap Servers to the value from the cluster’s page in the console (port 9092)
      • Security Protocol to SASL_SSL
      • SASL Mechanism to OAUTHBEARER
      • OAuth2 Access Token Provider Service to the new service
    • Try it first with no SSL Context Service. I believe the default JVM truststore is enough, but I haven’t verified that.
  6. Check that it works. Look in nifi-app.log for messages from NiFi’s OAuthBearerLoginCallbackHandler:
    • “Could not retrieve access token” points to an ADC or identity problem.
    • “Could not validate and parse access token” points to a token format problem.
    • An authentication error from the broker usually means a wrong sub or a missing IAM role.
  7. Upgrades. The stock NARs stay untouched. Change nifi.version in the pom and rebuild. I’m not certain NiFi will load a NAR whose declared parent version doesn’t match the running version, so make the rebuild part of your upgrade pipeline.

Trade-off: there’s no extra container and no local token endpoint, but you rebuild one small NAR at each NiFi upgrade.
 

Answer 2:
Token sidecar with the stock StandardOauth2AccessTokenProvid er (no custom code)


Summary: Google publishes a local token server that already returns tokens in the format Managed Kafka expects. Run it as a sidecar in the NiFi pod and point NiFi’s built-in StandardOauth2AccessTokenProvider at it. You write no Java, and nothing in NiFi needs rebuilding at upgrades.

Why this works

  • Kafka3ConnectionService requires an OAuth2 Access Token Provider for OAUTHBEARER: Required: true; Dependency: only applies when SASL Mechanism is OAUTHBEARER. Any custom sasl.login.callback.handler.class you add as a dynamic property is ignored. 
  • Google’s kafka_gcp_credentials_server.py listens on localhost:14293 and answers GET and POST requests. It returns access_token, already in the Google format, plus token_type and expires_in, so NiFi’s stock provider can call it like any OAuth server.

Steps

  1. Clean up. Delete java.arg.18 from bootstrap.conf and take the three JARs out of NiFi’s lib/. Neither is needed with this approach.
  2. Set up the Google identity for the pod.
    • The principal needs roles/managedkafka.client in the Google Cloud project that contains your managed Kafka cluster. 
    • On GKE, link the Kubernetes service account to a Google service account with the iam.gke.io/gcp-service-account annotation and roles/iam.workloadIdentityUser. A fork of Google’s client library notes that authentication is not supported for clients using Workload Identity Federation for GKE. 
    • Outside GKE, mount a key and set GOOGLE_APPLICATION_CREDENTIALS in the sidecar.
  3. Build the sidecar image. Use a Python base image, pip install google-auth urllib3, and add kafka-auth-local-server/kafka_gcp_credentials_server.py from googleapis/managedkafka. Run it as a second container in the NiFi pod. It has to be in the same pod because it binds to localhost only.
  4. Configure StandardOauth2AccessTokenProvider in NiFi:
    • Authorization Server URL: http://localhost:14293
    • Grant Type: Client Credentials
    • Client ID: empty (it’s optional in the 2.9.0 source)
  5. Configure Kafka3ConnectionService:
    • Bootstrap Servers: the value from the cluster’s page in the console (port 9092)
    • Security Protocol: SASL_SSL
    • SASL Mechanism: OAUTHBEARER
    • OAuth2 Access Token Provider Service: the provider from step 4
    • Try it first with no SSL Context Service. I haven’t verified that the default truststore is enough.
  6. Check that it works.
    • Run curl http://localhost:14293 from inside the NiFi container to confirm the sidecar returns a token.
    • The server returns expires_in as a decimal number, while NiFi stores a whole number. I expect it to be rounded down, but check the log on the first fetch.
    • Then look for errors from OAuthBearerLoginCallbackHandler in nifi-app.log, as in Answer 1.
  7. Upgrades. Nothing to do on the NiFi side. Only update the sidecar image if Google changes the script.

Trade-off: this is the most upgrade-proof option, but it adds a container. It also exposes an unauthenticated token endpoint on localhost, which any container in the same pod can call.
 

Test the 2 options and revert ,if you encounter new errors  please share for further analysis

Translate