Connecting Kafka clients

Connect your Kafka client to a Cloudera Streams Messaging cluster in Cloudera Anywhere Cloud using the client configuration bundle from Cloudera Surveyor and the client credentials you generate.

Kafka clusters deployed with Cloudera Streams Messaging in Cloudera Anywhere Cloud use OAuth over TLS/SSL for external client access. To connect successfully, your local client configuration must match the OAuth authentication and TLS/SSL encryption (SASL_SSL) settings applied to the cluster during deployment.

Cloudera Surveyor provides a client configuration bundle on the Client Configurations tab for your cluster. The bundle includes a client properties file (external.properties), CA certificates, and connection instructions.

To complete the connection, you generate OAuth client credentials, download and extract the bundle, fill in the credential placeholders in external.properties, configure the OAuth token endpoint allowlist on your JVM, and connect your client.

When you perform this task, the Anywhere Cloud Console user you are logged in as determines what your Kafka client will be authorized to access. The client credentials you generate are strictly bound to that user's principal. Therefore, your client will have the same access as the user you are logged in as. This is because when your Kafka client connects, Apache Ranger evaluates authorization against this specific principal, instead of a separate, dedicated client identity.

Because of this direct binding, the user you log in as must explicitly exist in Ranger and have the appropriate Kafka policies assigned. Completing Ranger setup for the cluster does not grant every user access. If an administrator has not added the user you log in as to the required Ranger policies, your client connection might be denied.

When you test your first connection, log in to Anywhere Cloud Console as a user that you know has the Ranger permissions for the operations you want to verify. The steps in this task use listing topics as an example. Alternatively, for ongoing application workloads, you can log in to Anywhere Cloud Console as a dedicated identity provider account configured with the exact permissions your application requires.

  • You deployed and have access to an instance of Cloudera Streams Messaging, if not see Deploying Cloudera Streams Messaging.

  • You have your own Kafka client application that you can configure to connect to your newly deployed brokers. The client must use version 4.1 or later of the kafka-clients library.

    Alternatively, you have access to Apache Kafka command-line tools. If not, download the Kafka binaries from https://kafka.apache.org/community/downloads/. Cloudera recommends you download the latest available binaries (version 4.1 or later is required).

    The command-line tools are located in the bin directory of the downloaded archive. These steps will use kafka-topics.sh as an example to verify your connection. These steps also assume that Kafka command-line tools are available on your PATH.

  • You must have access to a Bash-compatible shell environment with curl.

  • Ranger policies are configured for Kafka. See Configuring Ranger policies for Cloudera Streams Messaging.

  • Perform the steps in this task while logged in to Anywhere Cloud Console as the user whose Kafka access the client should have.

  1. Gather the values required for credential provisioning.
    1. Log in to Anywhere Cloud Console.
    2. Look up and record your domain from your Anywhere Cloud Console console URL.
      Your domain is the portion of the URL that comes after console.. For example, if your console URL is https://console.my-awc.cloudera.com, your domain is my-awc.cloudera.com.
    3. Obtain and record the hadoop-jwt session cookie from your browser's developer tools.

      To do this, open browser developer tools and navigate to the Cookies section. Find the hadoop-jwt cookie and record its value.

      To open browser developer tools:

      • Chrome: Press F12 and go to Application > Cookies.
      • Firefox: Press F12 and go to Storage > Cookies.
      • Safari: Press Cmd+Option+I and go to Storage > Cookies.
    4. Open your local terminal and set your domain and hadoop-jwt session cookie as environment variables.

      The following command prompts you to enter each value. The cookie value is not displayed as you type.

      printf "Domain: " && read -r DOMAIN; \
        printf "Hadoop JWT cookie: " && read -rs HADOOP_JWT && echo; \
        export DOMAIN HADOOP_JWT
  2. Obtain client credentials.

    Client credentials are used by applications to authenticate directly with the OAuth server. You can request client credentials through a provisioning endpoint using your session cookie.

    1. Call the credential provisioning endpoint and save the response to a file.
      curl -sk \
        -H "Cookie: hadoop-jwt=${HADOOP_JWT}" \
        -H "Content-Type: application/json" \
        -X POST "https://console.${DOMAIN}/api/v1/auth/access-keys/credentials" \
        -d '{"description": "my automation keys"}' > credentials.json
    2. Record the client_id and client_secret values from credentials.json.

      You need these values in a later step. The response in credentials.json resembles the following example:

      {
        "client_id": "123e4567-e89b-12d3-a456-426614174000",
        "client_secret": "dGhpcy1pcy1hLXNhbXBsZS1zZWNyZXQtZm9yLWRvY3M=",
        "principal": "admin",
        "issued_at": "2026-04-13T22:24:40.330429188Z"
      }

      The client_id and client_secret fields are your client credentials. The principal field is the user principal those credentials are bound to. It matches the user you were logged in as in Anywhere Cloud Console when you obtained the hadoop-jwt session cookie used to call the provisioning endpoint. When your client connects, Apache Ranger authorizes it as this principal. The example shows admin; in your environment, the value is your Anywhere Cloud Console login username. The issued_at field is informational only.

    3. Optional: Save the client credentials from credentials.json to a password manager or another secure location for future use.
      Client credentials are long-lived and can be reused for other clients or programmatic API calls.
  3. Access Cloudera Surveyor.
    1. In Anywhere Cloud Console, go to Streams Messaging
    2. Find and click the entry for your Cloudera Surveyor instance.
  4. Download the client configuration bundle from Cloudera Surveyor.
    1. In Cloudera Surveyor, go to Clusters and select your Kafka cluster.
    2. Go to the Client Configurations tab.
    3. Click Download All.
    4. Extract the archive to a working directory and keep all files in the same directory.
      Some paths in the configuration files are relative, so all files must remain in the same directory.
  5. Open external.properties in an editor and replace the credential placeholders.

    You must replace the following placeholders with the client credentials you obtained and recorded in a previous step:

    • <CLIENT_ID> — the client_id from credentials.json.
    • <CLIENT_SECRET> — the client_secret from credentials.json.

    The sasl.oauthbearer.token.endpoint.url and all truststore paths are already set. The cert paths are relative to the bundle directory.

  6. Verify your client configuration.

    Your completed external.properties file should resemble the following example, with your specific values for the highlighted properties:

    bootstrap.servers=my-csm-kafka.test-cluster.my-awc.cloudera.com:8443
    security.protocol=SASL_SSL
    sasl.mechanism=OAUTHBEARER
    sasl.login.callback.handler.class=org.apache.kafka.common.security.oauthbearer.OAuthBearerLoginCallbackHandler
    sasl.oauthbearer.token.endpoint.url=https://console.my-awc.cloudera.com/api/v1/auth/access-keys/token
    sasl.jaas.config=org.apache.kafka.common.security.oauthbearer.OAuthBearerLoginModule required ssl.truststore.location=oauth-ca.crt ssl.truststore.type=PEM;
    sasl.oauthbearer.client.credentials.client.id=123e4567-e89b-12d3-a456-426614174000
    sasl.oauthbearer.client.credentials.client.secret=dGhpcy1pcy1hLXNhbXBsZS1zZWNyZXQtZm9yLWRvY3M=
    ssl.truststore.location=kafka-ca.crt
    ssl.truststore.type=PEM
  7. Configure the OAuth token endpoint allowlist.

    The Kafka client must be explicitly permitted to contact the OAuth token endpoint before it can request tokens. This is a JVM system property and cannot be set in a properties file. Set it to the value of sasl.oauthbearer.token.endpoint.url from external.properties. Choose the option that matches your client type and complete only that option.

    • Kafka console tools: Set the property using the KAFKA_OPTS environment variable before running the console tool. This passes the property as a JVM argument to the console tool at startup.
      export KAFKA_OPTS="-Dorg.apache.kafka.sasl.oauthbearer.allowed.urls=[***OAUTH TOKEN ENDPOINT***]"
    • Custom Java Kafka client applications: Set the property as a JVM flag at launch time or in code before instantiating your Kafka client.
      • As a JVM flag:
        java -Dorg.apache.kafka.sasl.oauthbearer.allowed.urls=[***OAUTH TOKEN ENDPOINT***] -jar [***YOUR APPLICATION JAR***]
      • In Java source code:
        System.setProperty(
            "org.apache.kafka.sasl.oauthbearer.allowed.urls",
            "[***OAUTH TOKEN ENDPOINT***]"
        );
  8. Connect your Kafka client.
    You can now connect your Kafka client to your cluster using the configuration you downloaded. With console tools, a simple way to verify the connection is working is to list the existing topics in your cluster.

    Run the following command from the working directory that contains external.properties and the bundled certificates, and use the bootstrap.servers value from external.properties as your bootstrap server.

    kafka-topics.sh --list \
      --command-config external.properties \
      --bootstrap-server [***BOOTSTRAP SERVERS***]

    If authentication and TLS are configured correctly, the command completes without a connection error. You should see a list of topics you are authorized to list. If an empty list is returned, the user you logged in as does not have list access in Ranger.