Configuring Apache Kafka OAuth connectivity in Flow Designer

Cloudera Data Flow connects Apache NiFi flows in Flow Designer to OAuth-secured Apache Kafka clusters in Cloudera Streams Messaging on Cloudera Anywhere Cloud through TLS and OAuth controller services.

Apache Kafka clusters deployed with Cloudera Streams Messaging in Cloudera Anywhere Cloud use OAuth authentication over TLS/SSL (SASL_SSL with the OAUTHBEARER mechanism) for external client access. To connect an Apache NiFi flow in Flow Designer to a Kafka cluster, you obtain OAuth client credentials from Anywhere Cloud Console, download the Kafka client configuration bundle from Cloudera Surveyor, build a single PKCS12 truststore from the bundled CA certificates, supply the truststore to your draft, and configure controller services for TLS, OAuth token retrieval, and Kafka broker connectivity.

Principal binding and Apache Ranger authorization

The Anywhere Cloud Console user that you log in as when generating OAuth client credentials determines what your NiFi flow is authorized to access in Kafka. Client credentials are permanently bound to that user's principal. When a NiFi processor connects to Kafka, Apache Ranger evaluates authorization policies against this bound principal instead of a separate client identity.

Ensure that the user account used to generate credentials exists in Apache Ranger and is assigned to the required policies in the csm-kafka service. For production data flows, Cloudera recommends logging in to Anywhere Cloud Console with a dedicated identity provider account configured with only the Ranger permissions that your flow requires.

Options for supplying the PKCS12 truststore

You can provide the PKCS12 truststore file (truststore.p12) and truststore password to your flow draft by using either of the following approaches:

Shared parameter group
Create a shared parameter group in Shared Parameter Groups containing truststore.p12 as a file parameter and the truststore password as a sensitive parameter, and then import the group into your flow draft. Uploading file parameters to a shared parameter group does not require a running test session, and you can reuse the group across multiple flow drafts and deployments.
Draft parameters in an active test session
Start a test session in Flow Designer, convert Truststore Filename on StandardRestrictedSSLContextService to a draft parameter, and upload truststore.p12 directly. Flow Designer requires an active test session to upload file-type draft parameters. Use this option when you already have a running test session to develop and validate your flow with live data without creating a shared resource.

Prerequisites

Ensure that your environment meets the following prerequisites before configuring Kafka connectivity in Flow Designer:

  • Cloudera Data Flow is deployed in Cloudera Anywhere Cloud, and your user account has the cdf-flow-admin role assigned for that instance.
  • You have prepared your Flow Designer draft for one of the two options for adding the truststore:
    • Shared parameter group option – You have created a flow draft in Flow Designer (an active test session is optional unless you want to enable controller services and validate the flow with live data). For instructions, see Creating a new draft.
    • Test session option – You have created a flow draft with an active test session in Flow Designer so that you can upload the truststore file directly as a draft parameter. For instructions, see Starting a test session.
  • Cloudera Streams Messaging is deployed and integrated with Cloudera Unified Data Fabric. For deployment instructions, see Deploying Cloudera Streams Messaging.
  • Your Anywhere Cloud Console user account is assigned to the required Apache Ranger policies in the csm-kafka service, including Describe permission on the cluster resource and Publish or Consume permissions on target topics.
  • You have access to a Bash-compatible shell environment with the Java keytool utility.

Configuration workflow

Connecting a NiFi flow in Flow Designer to an OAuth-secured Kafka cluster involves the following tasks:

  1. Generate an OAuth client_id and client_secret pair from Anywhere Cloud Console. For instructions, see Access keys and API tokens.
  2. Download the Kafka client configuration bundle from Cloudera Surveyor to obtain the CA certificates and broker connection details.
  3. Combine the downloaded PEM certificates into a single PKCS12 truststore file (truststore.p12) using keytool.
  4. If you are using the shared parameter group scenario, create a shared parameter group containing truststore.p12 and a sensitive truststore password parameter, and import the group into your flow draft. Skip this step if you are uploading truststore.p12 directly in an active test session.
  5. Configure a StandardRestrictedSSLContextService controller service by referencing your imported shared parameter group or uploading truststore.p12 in an active test session.
  6. Configure a StandardOauth2AccessTokenProvider controller service to retrieve OAuth access tokens.
  7. Configure a Kafka3ConnectionService controller service that references both the token provider and SSL context services.
  8. Reference the Kafka3ConnectionService in your Kafka processors, such as PublishKafka or ConsumeKafka.

Downloading Apache Kafka client truststore certificates

Download the Apache Kafka client configuration bundle from Cloudera Surveyor to obtain the CA certificates and broker connection properties required in Cloudera Data Flow Flow Designer.

Cloudera Surveyor provides a downloadable client configuration bundle for each monitored Kafka cluster. The bundle includes CA certificate files (kafka-ca.crt and oauth-ca.crt) and an external.properties file containing broker addresses and the OAuth token endpoint URL.

Because Apache NiFi processors manage Kafka properties through controller services, you do not pass external.properties directly to NiFi. Instead, you use the CA certificates to build a truststore and copy the broker and token endpoint values from external.properties into your Flow Designer controller services.

To view your Kafka cluster in Cloudera Surveyor, your logged-in Anywhere Cloud Console user must be included in the Apache Ranger access policies for the csm-kafka service, including Describe permission on the cluster resource.

Figure 1. Apache Ranger policies for the csm-kafka service
Apache Ranger KAFKA Policies page for the csm-kafka service showing enabled policies assigned to the console user
  • Cloudera Streams Messaging is deployed with Cloudera Surveyor in Cloudera Anywhere Cloud.
  • Your logged-in Anywhere Cloud Console user has Apache Ranger Describe permission on the Kafka cluster resource in the csm-kafka service.
  1. Open Cloudera Surveyor from Anywhere Cloud Console.
    1. In Anywhere Cloud Console, navigate to Admin Center > Apps > Engine instances.
    2. Select the entry for your Cloudera Surveyor instance.
    3. In the Endpoints table, click the URL in the surveyorLandingPage row to open the Cloudera Surveyor UI.
  2. Download the client configuration bundle from Cloudera Surveyor.
    1. In Cloudera Surveyor, select Clusters in the left navigation pane and click your Kafka cluster.
      Figure 2. Clusters page in Cloudera Surveyor
      Cloudera Surveyor Clusters page listing a healthy Kafka cluster
    2. Select the Client Configurations tab.
    3. Click Download All to download the client configuration archive.
      Figure 3. Client Configurations tab in Cloudera Surveyor
      Cloudera Surveyor Client Configurations tab showing the Download All button and bundle preview
    4. Extract the downloaded ZIP archive to a local working directory.
      Confirm that the extracted directory contains kafka-ca.crt, oauth-ca.crt, and external.properties.

Creating a PKCS12 truststore file

Combine the downloaded Apache Kafka and OAuth CA certificates into a single PKCS12 truststore file using the Java keytool utility for TLS connections in Cloudera Data Flow.

In Cloudera Streams Messaging on Cloudera Anywhere Cloud, the OAuth server (central Apache Knox) and the Kafka brokers use different certificate authorities (CAs). Importing both PEM certificates (kafka-ca.crt and oauth-ca.crt) from the Cloudera Surveyor client configuration bundle into a single PKCS12 truststore file (truststore.p12) enables one SSL context service in Flow Designer to validate TLS connections to both endpoints.

  • You extracted kafka-ca.crt and oauth-ca.crt from the Cloudera Surveyor client configuration bundle.
  • The Java keytool utility is installed in your local shell environment.
  1. Open a terminal and change to the directory where you extracted the Cloudera Surveyor client configuration bundle.
  2. Import the PEM certificate files into a single PKCS12 truststore file (truststore.p12) by using keytool.

    Run the following commands, replacing [***STORE PASSWORD***] with a truststore password of your choice:

    STOREPASS='[***STORE PASSWORD***]'
    
    keytool -importcert -noprompt \
      -alias kafka-ca \
      -file kafka-ca.crt \
      -keystore truststore.p12 \
      -storetype PKCS12 \
      -storepass "$STOREPASS"
    
    keytool -importcert -noprompt \
      -alias oauth-ca \
      -file oauth-ca.crt \
      -keystore truststore.p12 \
      -storetype PKCS12 \
      -storepass "$STOREPASS"

    These commands generate truststore.p12 trusting both certificate authorities.

  3. Optional: Verify that truststore.p12 contains both certificate entries.
    keytool -list -keystore truststore.p12 -storetype PKCS12 -storepass "$STOREPASS"

    Confirm that the output lists two trustedCertEntry aliases: kafka-ca and oauth-ca.

  4. Record the truststore password that you set in STOREPASS in a secure location.
    You must provide this password as a sensitive parameter when creating a shared parameter group or configuring the SSL context service in Flow Designer.
if you want to supply truststore.p12 and its password to Flow Designer through a shared parameter group instead of uploading the file directly in an active test session, proceed to Creating a shared parameter group for the PKCS12 truststore.

If you prefer to upload truststore.p12 directly as a draft parameter during an active test session, proceed to Creating an SSL context service.

Creating a shared parameter group for the PKCS12 truststore

Create a shared parameter group with your PKCS12 truststore file and sensitive password to supply TLS truststore credentials to Cloudera Data Flow drafts without a test session.

Perform this task if you want to supply truststore.p12 and its password to Flow Designer through a shared parameter group instead of uploading the file directly in an active test session. Shared parameter groups let you upload file-type parameters without starting a test session and reuse the same truststore across multiple flow drafts and deployments.

If you prefer to upload truststore.p12 directly as a draft parameter during an active test session, skip this task and proceed to configuring the SSL context service.

  • You created truststore.p12 and recorded its truststore password.
  • Your user account has the cdf-flow-admin role assigned (or cdf-admin or cdf-deployment-admin if you are creating the parameter group without importing it to a flow draft).
  • You created a flow draft in Cloudera Data Flow Flow Designer.
  1. Select Shared Parameter Groups from the left navigation pane.
  2. In the Parameter Groups view, click Create Parameter Group.
  3. In the Create New Parameter Group dialog, enter a unique Parameter Group Name (for example, kafka-oauth-truststore), optionally enter a Description, and click Create.
    The Manage Parameter Group view is displayed on the Parameters tab.
  4. Add truststore.p12 to the group as a file parameter.
    1. Click Add Parameter , and then select Add Parameter.
    2. Enter a unique parameter Name, such as Truststore Filename.
    3. Under Value, click Select File and select truststore.p12, or drag and drop truststore.p12 onto the Select File tile.
    4. Optionally enter a Description, and click Apply.
  5. Add the truststore password to the group as a sensitive parameter.
    1. Click Add Parameter , and then select Add Sensitive Parameter.
    2. Enter a unique parameter Name, such as Truststore Password.
    3. In Value, enter the truststore password that you set in STOREPASS when generating truststore.p12.
    4. Optionally enter a Description, and click Apply.
  6. Click Apply Changes to save the shared parameter group.
  7. Import the shared parameter group into your flow draft.
    1. In the Manage Parameter Group header, click Actions > Import to Flow Draft.
    2. In the Import to Flow Draft dialog, select your target Flow Draft and click Import.

Creating an SSL context service

Configure a StandardRestrictedSSLContextService controller service in Cloudera Data Flow Flow Designer to trust your Apache Kafka and OAuth server CA certificates.

TLS-enabled controller services and processors in Apache NiFi require an SSL context service to supply truststores and keystores. You configure StandardRestrictedSSLContextService with your truststore.p12 file and truststore password either by referencing parameters from an imported shared parameter group or by converting the properties to draft parameters in an active test session.

  • You created a single PKCS12 truststore file (truststore.p12) and recorded its truststore password.
  • You opened your flow draft in Cloudera Data Flow Flow Designer and completed one of the following prerequisites:
    • You imported the shared parameter group containing the truststore.p12 file parameter and sensitive truststore password parameter into your draft.
    • You started an active test session in your draft so that you can upload truststore.p12 directly when converting Truststore Filename to a draft parameter.
  1. In Flow Designer, click Flow Options > Services > Add Service, select StandardRestrictedSSLContextService, and click Add.
  2. In the Properties table for StandardRestrictedSSLContextService, configure Truststore Filename and Truststore Password by using the method that matches your setup.
    • If you imported a shared parameter group into your draft, reference the shared parameters:

      1. Click the Value field for Truststore Filename, enter #{[***TRUSTSTORE FILE PARAMETER NAME***]} (for example, #{Truststore Filename}), and save the value.
      2. Click the Value field for Truststore Password, enter #{[***TRUSTSTORE PASSWORD PARAMETER NAME***]} (for example, #{Truststore Password}), and save the value.
    • If you are uploading truststore.p12 directly in an active test session, convert both properties to draft parameters:

      1. Locate Truststore Filename and click [Options] > Convert To Parameter.
        Figure 4. Converting a controller service property to a parameter
        Flow Designer Services page showing StandardRestrictedSSLContextService with the Convert To Parameter menu option
      2. In the Add Parameter dialog, click Select File under Value, upload truststore.p12, and click Apply.
        Figure 5. Uploading truststore.p12 in the Add Parameter dialog
        Add Parameter dialog with Truststore Filename as the name and truststore.p12 uploaded as the value
      3. Locate Truststore Password, click [Options] > Convert To Parameter, enter the truststore password that you used when generating truststore.p12, and click Apply.
  3. Set Truststore Type to PKCS12 and confirm that TLS Protocol is set to TLS.
    Figure 6. Configured StandardRestrictedSSLContextService properties
    StandardRestrictedSSLContextService properties showing parameterized Truststore Filename and Truststore Password, Truststore Type set to PKCS12, and TLS Protocol set to TLS
  4. Click Apply Changes to save the controller service configuration.
  5. Optional: If you have an active test session, click Enable to enable the StandardRestrictedSSLContextService controller service.
    Enabling controller services in Flow Designer requires an active test session. If you are building your draft without a test session by using a shared parameter group, Cloudera Data Flow enables configured controller services automatically when you deploy the published flow definition.

Creating an OAuth2 access token provider service

Configure a StandardOauth2AccessTokenProvider controller service in Cloudera Data Flow Flow Designer to retrieve OAuth bearer tokens for Apache Kafka client authentication.

The StandardOauth2AccessTokenProvider controller service authenticates against the Anywhere Cloud Console OAuth token endpoint using your client_id and client_secret credentials and supplies bearer tokens to the Kafka connection service.

  • You generated and recorded an OAuth client_id and client_secret pair from Anywhere Cloud Console. For instructions, see Access keys and API tokens.
  • You extracted external.properties from the Cloudera Surveyor client configuration bundle.
  • You created and configured the StandardRestrictedSSLContextService controller service in your draft (and enabled it if you have an active test session).
  1. In Flow Designer, click Flow Options > Services > Add Service, select StandardOauth2AccessTokenProvider, and click Add.
  2. Configure the StandardOauth2AccessTokenProvider properties in the Configuration pane.

    Set the following property values, using [Options] > Convert To Parameter for environment-specific and sensitive values:

    • Authorization Server URL – Specify the OAuth token endpoint URL from the sasl.oauthbearer.token.endpoint.url key in external.properties (for example, https://console.[***DOMAIN***]/api/v1/auth/access-keys/token). Cloudera recommends converting this property to a parameter.
    • Client Authentication Strategy – Select BASIC_AUTHENTICATION.
    • Grant Type – Select Client Credentials.
    • Client ID – Enter the client_id value that you obtained from Anywhere Cloud Console. Cloudera recommends converting this property to a parameter.
    • Client Secret – Convert this property to a sensitive parameter and enter the client_secret value that you obtained from Anywhere Cloud Console.
    • SSL Context Service – Select the StandardRestrictedSSLContextService instance that you created earlier.
    Figure 7. Configured StandardOauth2AccessTokenProvider properties
    StandardOauth2AccessTokenProvider properties showing Authorization Server URL, BASIC_AUTHENTICATION, Client Credentials grant type, Client ID, parameterized Client Secret, and SSL Context Service
  3. Click Apply Changes to save the controller service configuration.
  4. Optional: If you have an active test session, click Enable to enable the StandardOauth2AccessTokenProvider controller service.

Creating a Kafka3ConnectionService for OAuth authentication

Configure a Kafka3ConnectionService controller service in Cloudera Data Flow Flow Designer to connect Apache NiFi processors to an OAuth-secured Apache Kafka cluster.

Apache Kafka processors in Flow Designer delegate broker connections, TLS encryption, and OAuth authentication to a Kafka3ConnectionService controller service. This service combines your Kafka bootstrap server address with the StandardOauth2AccessTokenProvider and StandardRestrictedSSLContextService instances.

  • You extracted external.properties from the Cloudera Surveyor client configuration bundle.
  • You created and configured both StandardRestrictedSSLContextService and StandardOauth2AccessTokenProvider in your draft (and enabled them if you have an active test session).
  1. In Flow Designer, click Flow Options > Services > Add Service, select Kafka3ConnectionService, and click Add.
  2. Configure the Kafka3ConnectionService properties in the Configuration pane.

    Set the following property values:

    • Bootstrap Servers – Specify the Kafka broker host and port from the bootstrap.servers key in external.properties (for example, [***KAFKA BROKER FQDN***]:8443). Cloudera recommends converting this property to a parameter for production flows.
    • Security Protocol – Select SASL_SSL.
    • SASL Mechanism – Select OAUTHBEARER.
    • OAuth2 Access Token Provider Service – Select the StandardOauth2AccessTokenProvider instance that you created earlier.
    • SSL Context Service – Select the StandardRestrictedSSLContextService instance that you created earlier.
    Figure 8. Configured Kafka3ConnectionService properties
    Kafka3ConnectionService properties showing Bootstrap Servers, Security Protocol set to SASL_SSL, SASL Mechanism set to OAUTHBEARER, OAuth2 Access Token Provider Service, and SSL Context Service
  3. Click Apply Changes to save the controller service configuration.
  4. Optional: If you have an active test session, click Enable to enable the Kafka3ConnectionService controller service.

Configuring Apache Kafka processors to use the connection service

Configure Apache Kafka processors such as PublishKafka on the Cloudera Data Flow Flow Designer canvas to authenticate using your Kafka3ConnectionService controller service.

After you configure and enable Kafka3ConnectionService, you can reference it in Apache Kafka processors such as PublishKafka or ConsumeKafka on the Flow Designer canvas.

  • You created and configured the Kafka3ConnectionService controller service in your Flow Designer draft (and enabled it if you have an active test session).
  1. Drag a Kafka processor, such as PublishKafka, from the Components sidebar onto the Flow Designer canvas.
  2. Select the processor on the canvas to open the Configuration pane and expand Properties.
  3. Set Kafka Connection Service to the Kafka3ConnectionService instance that you created, and specify the target Topic Name.

    Cloudera recommends converting Topic Name to a parameter so that you can set the target topic at deployment time.

    Figure 9. PublishKafka processor configured with Kafka3ConnectionService
    PublishKafka processor on the Flow Designer canvas with Properties showing Kafka Connection Service set to Kafka3ConnectionService and a parameterized Topic Name
  4. Configure any remaining processor settings and relationships for your data flow, and click Apply Changes.