OAuth Configuration Reference for Confluent Cloud Clients
This section provides a comprehensive reference for OAuth configuration parameters across different client types and platforms.
Java client parameters
Parameter |
Description |
Default |
Required |
|---|---|---|---|
|
SASL mechanism for OAuth authentication |
OAUTHBEARER |
Yes |
|
JAAS configuration for OAuth login module |
None |
Yes |
|
OAuth callback handler class. Set to
|
None |
Yes |
|
OAuth token endpoint URL |
None |
Yes |
|
Connection timeout for token requests |
10000 |
No |
|
Read timeout for token requests |
10000 |
No |
|
Initial retry backoff for failed requests |
100 |
No |
|
Maximum retry backoff for failed requests |
10000 |
No |
|
OAuth client ID. Requires Kafka client 4.1.0 or later. Replaces the
deprecated |
None |
Conditional |
|
OAuth client secret. Requires Kafka client 4.1.0 or later. Replaces the
deprecated |
None |
Conditional |
|
OAuth scopes for token request. Requires Kafka client 4.1.0 or later.
Replaces the deprecated |
None |
No |
|
Logical cluster ID for Confluent Cloud. Set as an option in
|
None |
Optional |
|
Identity pool ID for Confluent Cloud. Set as an option in
|
None |
Optional |
JAAS configuration parameters
Set these options on the
org.apache.kafka.common.security.oauthbearer.OAuthBearerLoginModule in the
sasl.jaas.config property. The clientId, clientSecret, and scope
options are required only for Kafka client 4.0.x. Starting with Kafka client
4.1.0, they’re deprecated in favor of the corresponding sasl.oauthbearer.*
properties and will be removed in a future version.
Parameter |
Description |
Default |
Required |
|---|---|---|---|
|
Deprecated. OAuth client ID for Kafka client 4.0.x. For 4.1.0 and later,
use |
None |
Conditional |
|
Deprecated. OAuth client secret for Kafka client 4.0.x. For 4.1.0 and
later, use |
None |
Conditional |
|
Deprecated. OAuth scopes for token request for Kafka client 4.0.x. For
4.1.0 and later, use |
None |
No |
|
Logical cluster ID for Confluent Cloud. |
None |
Optional |
|
Identity pool ID for Confluent Cloud. If omitted, auto pool mapping applies. For more information, see Use auto pool mapping with OAuth identity pools. |
None |
Optional |
Python client parameters
Parameter |
Description |
Default |
Required |
|---|---|---|---|
|
SASL mechanism for OAuth authentication |
OAUTHBEARER |
Yes |
|
OAuth token endpoint URL |
None |
Yes |
|
OAuth client ID |
None |
Yes |
|
OAuth client secret |
None |
Yes |
|
OAuth scopes for token request |
None |
No |
.NET client parameters
Parameter |
Description |
Default |
Required |
|---|---|---|---|
|
SASL mechanism for OAuth authentication |
OAUTHBEARER |
Yes |
|
OAuth token endpoint URL |
None |
Yes |
|
OAuth client ID |
None |
Yes |
|
OAuth client secret |
None |
Yes |
|
OAuth scopes for token request |
None |
No |
|
Logical cluster ID for Confluent Cloud.
|
None |
Conditional |
|
Identity pool ID for Confluent Cloud |
None |
No |
|
Connection timeout for token requests |
10000 |
No |
|
Read timeout for token requests |
10000 |
No |
Go client parameters
Parameter |
Description |
Default |
Required |
|---|---|---|---|
|
SASL mechanism for OAuth authentication |
OAUTHBEARER |
Yes |
|
OAuth token endpoint URL |
None |
Yes |
|
OAuth client ID |
None |
Yes |
|
OAuth client secret |
None |
Yes |
|
OAuth scopes for token request |
None |
No |
|
Logical cluster ID for Confluent Cloud.
|
None |
Conditional |
|
Identity pool ID for Confluent Cloud |
None |
No |
|
Connection timeout for token requests |
10000 |
No |
|
Read timeout for token requests |
10000 |
No |
Schema Registry client parameters
Parameter |
Description |
Default |
Required |
|---|---|---|---|
|
Authentication method. Use |
None |
Yes |
|
OAuth token endpoint URL |
None |
Yes |
|
OAuth client ID |
None |
Yes |
|
OAuth client secret |
None |
Yes |
|
OAuth scopes for token request |
None |
No |
|
Schema Registry logical cluster ID ( Java clients can omit it over AWS PrivateLink. Go and Python clients require it. |
None |
Yes |
|
Identity pool ID for Confluent Cloud Accepts a comma-separated list of pool
IDs. If omitted, auto pool mapping applies.
|
None |
No |
Configuration validation
When configuring OAuth authentication, validate your configuration:
Required parameters: Ensure all required parameters are provided.
URL format: Verify token endpoint URLs are properly formatted
Credentials: Validate client ID and secret are correct
Network access: Confirm network connectivity to OAuth provider
Permissions: Verify client has appropriate scopes and permissions
// Configuration validation example
public static void validateOAuthConfig(Properties props) {
// Check required parameters
String[] required = {
"sasl.mechanism",
"sasl.jaas.config",
"sasl.login.callback.handler.class",
"sasl.oauthbearer.token.endpoint.url"
};
for (String param : required) {
if (!props.containsKey(param)) {
throw new IllegalArgumentException("Missing required parameter: " + param);
}
}
// Validate timeout values
int connectTimeout = Integer.parseInt(props.getProperty("sasl.login.connect.timeout.ms", "10000"));
int readTimeout = Integer.parseInt(props.getProperty("sasl.login.read.timeout.ms", "10000"));
if (connectTimeout < 1000 || readTimeout < 1000) {
throw new IllegalArgumentException("Timeout values must be at least 1000ms");
}
}
Configuration templates
Use configuration templates for consistent setup:
# oauth-config-template.yaml
kafka:
oauth:
token_endpoint: ${OAUTH_TOKEN_ENDPOINT}
client_id: ${OAUTH_CLIENT_ID}
client_secret: ${OAUTH_CLIENT_SECRET}
scope: ${OAUTH_SCOPE}
logical_cluster: ${LOGICAL_CLUSTER_ID}
identity_pool: ${IDENTITY_POOL_ID}
timeouts:
connect: 10000
read: 10000
retry_backoff: 100
retry_max: 10000
Environment-specific configurations
The following examples use librdkafka property names, which apply to Python, .NET, Go, and JavaScript clients. For Java clients, use the properties in Configure Java Clients for OAuth/OIDC on Confluent Cloud.
Development environment
# Development OAuth configuration
sasl.oauthbearer.token.endpoint.url=https://dev-auth.example.com/oauth2/token
sasl.oauthbearer.client.id=dev-kafka-client
sasl.oauthbearer.client.secret=${DEV_CLIENT_SECRET}
sasl.oauthbearer.scope=kafka:dev
Staging environment
# Staging OAuth configuration
sasl.oauthbearer.token.endpoint.url=https://staging-auth.example.com/oauth2/token
sasl.oauthbearer.client.id=staging-kafka-client
sasl.oauthbearer.client.secret=${STAGING_CLIENT_SECRET}
sasl.oauthbearer.scope=kafka:staging
Production environment
# Production OAuth configuration
sasl.oauthbearer.token.endpoint.url=https://prod-auth.example.com/oauth2/token
sasl.oauthbearer.client.id=prod-kafka-client
sasl.oauthbearer.client.secret=${PROD_CLIENT_SECRET}
sasl.oauthbearer.scope=kafka:prod
Advanced configuration options
Custom token providers
To use your own token retrieval logic with a Java Schema Registry client, implement a
custom BearerAuthCredentialProvider and set
bearer.auth.credentials.source=CUSTOM. For the requirements and a complete
example, see Custom OAuth implementations.
Retry and circuit breaker patterns
The Java client already retries failed token requests with exponential
backoff, which you control with the sasl.login.retry.backoff.ms and
sasl.login.retry.backoff.max.ms properties. You don’t need to add retry
logic around the client’s built-in token retrieval.
If you write your own token retrieval code, such as a custom Schema Registry token
provider, you can use patterns like the following generic examples. They use
only the Java standard library (java.util.concurrent.atomic and
java.util.function.Supplier):
public class CircuitBreaker {
private final AtomicInteger failureCount = new AtomicInteger(0);
private final AtomicLong lastFailureTime = new AtomicLong(0);
private final int threshold;
private final long timeout;
public CircuitBreaker(int threshold, long timeout) {
this.threshold = threshold;
this.timeout = timeout;
}
public boolean isOpen() {
long now = System.currentTimeMillis();
if (failureCount.get() >= threshold) {
if (now - lastFailureTime.get() < timeout) {
return true; // Circuit is open
} else {
// Reset after timeout
failureCount.set(0);
return false;
}
}
return false;
}
public void recordFailure() {
failureCount.incrementAndGet();
lastFailureTime.set(System.currentTimeMillis());
}
public void recordSuccess() {
failureCount.set(0);
}
}
public class RetryTemplate {
private final int maxRetries;
private final long backoffMs;
public RetryTemplate(int maxRetries, long backoffMs) {
this.maxRetries = maxRetries;
this.backoffMs = backoffMs;
}
public <T> T execute(Supplier<T> operation) throws Exception {
int attempts = 0;
while (attempts < maxRetries) {
try {
return operation.get();
} catch (Exception e) {
attempts++;
if (attempts >= maxRetries) {
throw e;
}
Thread.sleep(backoffMs * attempts);
}
}
throw new RuntimeException("Max retries exceeded");
}
}
Deployment considerations
Container deployment
Starting with Kafka client 4.0.0, a Java client accesses only the OAuth URLs that
you allow in the org.apache.kafka.sasl.oauthbearer.allowed.urls JVM system
property. In a container, set this property in the JAVA_TOOL_OPTIONS
environment variable, which the JVM reads at startup. Don’t put the client
secret in the image. Supply it at runtime, for example from a Kubernetes secret
as shown in the next example.
# Dockerfile for OAuth-enabled Kafka client
FROM eclipse-temurin:17-jre
# Copy application
COPY target/oauth-kafka-client.jar /app/
# Non-secret settings
ENV OAUTH_TOKEN_ENDPOINT=https://your-oauth-provider.com/oauth2/token
ENV OAUTH_SCOPE="kafka:read kafka:write"
ENV LOGICAL_CLUSTER_ID=lkc-xxxxx
ENV IDENTITY_POOL_ID=pool-xxxxx
# Allow the client to call the token endpoint (Kafka client 4.0.0 and later)
ENV JAVA_TOOL_OPTIONS="-Dorg.apache.kafka.sasl.oauthbearer.allowed.urls=https://your-oauth-provider.com/oauth2/token"
# Run application
CMD ["java", "-jar", "/app/oauth-kafka-client.jar"]
Kubernetes deployment
# kubernetes-deployment.yaml
apiVersion: apps/v1
kind: Deployment
metadata:
name: oauth-kafka-client
spec:
replicas: 3
selector:
matchLabels:
app: oauth-kafka-client
template:
metadata:
labels:
app: oauth-kafka-client
spec:
containers:
- name: kafka-client
image: your-registry/oauth-kafka-client:latest
env:
- name: OAUTH_TOKEN_ENDPOINT
valueFrom:
secretKeyRef:
name: oauth-secrets
key: token-endpoint
- name: OAUTH_CLIENT_ID
valueFrom:
secretKeyRef:
name: oauth-secrets
key: client-id
- name: OAUTH_CLIENT_SECRET
valueFrom:
secretKeyRef:
name: oauth-secrets
key: client-secret
- name: OAUTH_SCOPE
value: "kafka:read kafka:write"
- name: LOGICAL_CLUSTER_ID
value: "lkc-xxxxx"
- name: IDENTITY_POOL_ID
value: "pool-xxxxx"
# Must contain the same URL as the token-endpoint secret
- name: JAVA_TOOL_OPTIONS
value: "-Dorg.apache.kafka.sasl.oauthbearer.allowed.urls=https://your-oauth-provider.com/oauth2/token"
CI/CD integration
# .github/workflows/deploy.yml
name: Deploy OAuth Kafka Client
on:
push:
branches: [main]
jobs:
deploy:
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v2
- name: Set up JDK
uses: actions/setup-java@v2
with:
java-version: '11'
- name: Build with Maven
run: mvn clean package
- name: Build Docker image
run: docker build -t oauth-kafka-client .
- name: Deploy to Kubernetes
run: |
kubectl apply -f kubernetes-deployment.yaml
kubectl rollout restart deployment/oauth-kafka-client
Integration testing
To test your OAuth configuration without an identity provider or a Kafka
cluster, run your client against a mock token endpoint. When you create a
producer or consumer that uses OAUTHBEARER, the client logs in, which
requests a token from the token endpoint. The following JUnit 5 test uses the
HTTP server that’s included in the JDK as the mock token endpoint, and checks
that the producer requests a token with the configured client credentials. It
requires the dependencies listed in Configure Java Clients for OAuth/OIDC on Confluent Cloud and
JUnit 5:
import com.sun.net.httpserver.HttpServer;
import org.apache.kafka.clients.producer.KafkaProducer;
import org.apache.kafka.common.serialization.StringSerializer;
import org.junit.jupiter.api.Test;
import java.net.InetSocketAddress;
import java.nio.charset.StandardCharsets;
import java.time.Instant;
import java.util.Base64;
import java.util.Properties;
import java.util.concurrent.atomic.AtomicInteger;
import java.util.concurrent.atomic.AtomicReference;
import static org.junit.jupiter.api.Assertions.assertEquals;
class OAuthIntegrationTest {
private static final String ALLOWED_URLS = "org.apache.kafka.sasl.oauthbearer.allowed.urls";
@Test
void producerRequestsTokenWithClientCredentials() throws Exception {
AtomicInteger tokenRequests = new AtomicInteger();
AtomicReference<String> authorization = new AtomicReference<>();
// Mock identity provider. The Kafka client checks the structure and
// claims of the token, but not its signature.
HttpServer idp = HttpServer.create(new InetSocketAddress("127.0.0.1", 0), 0);
idp.createContext("/oauth2/token", exchange -> {
tokenRequests.incrementAndGet();
authorization.set(exchange.getRequestHeaders().getFirst("Authorization"));
exchange.getRequestBody().readAllBytes();
byte[] body = ("{\"access_token\":\"" + testJwt("test-client") + "\","
+ "\"token_type\":\"Bearer\",\"expires_in\":3600}")
.getBytes(StandardCharsets.UTF_8);
exchange.getResponseHeaders().add("Content-Type", "application/json");
exchange.sendResponseHeaders(200, body.length);
exchange.getResponseBody().write(body);
exchange.close();
});
idp.start();
String tokenEndpoint = "http://127.0.0.1:" + idp.getAddress().getPort() + "/oauth2/token";
// Kafka client 4.0.0 and later calls only allowed token endpoints
System.setProperty(ALLOWED_URLS, tokenEndpoint);
Properties props = new Properties();
props.put("bootstrap.servers", "localhost:9092"); // No broker is needed
props.put("key.serializer", StringSerializer.class.getName());
props.put("value.serializer", StringSerializer.class.getName());
props.put("security.protocol", "SASL_PLAINTEXT"); // Use SASL_SSL with Confluent Cloud
props.put("sasl.mechanism", "OAUTHBEARER");
props.put("sasl.login.callback.handler.class",
"org.apache.kafka.common.security.oauthbearer.OAuthBearerLoginCallbackHandler");
props.put("sasl.oauthbearer.token.endpoint.url", tokenEndpoint);
props.put("sasl.oauthbearer.client.credentials.client.id", "test-client");
props.put("sasl.oauthbearer.client.credentials.client.secret", "test-secret");
props.put("sasl.jaas.config",
"org.apache.kafka.common.security.oauthbearer.OAuthBearerLoginModule required "
+ "extension_logicalCluster=\"lkc-test\";");
// Creating the producer logs in, which requests a token
try (KafkaProducer<String, String> producer = new KafkaProducer<>(props)) {
assertEquals(1, tokenRequests.get());
String expected = "Basic " + Base64.getEncoder()
.encodeToString("test-client:test-secret".getBytes(StandardCharsets.UTF_8));
assertEquals(expected, authorization.get());
} finally {
idp.stop(0);
System.clearProperty(ALLOWED_URLS);
}
}
// Builds a JWT with the claims that the Kafka client requires
private static String testJwt(String subject) {
Base64.Encoder encoder = Base64.getUrlEncoder().withoutPadding();
long now = Instant.now().getEpochSecond();
String header = "{\"alg\":\"RS256\",\"typ\":\"JWT\"}";
String payload = "{\"sub\":\"" + subject + "\",\"iat\":" + now
+ ",\"exp\":" + (now + 3600) + "}";
return encoder.encodeToString(header.getBytes(StandardCharsets.UTF_8)) + "."
+ encoder.encodeToString(payload.getBytes(StandardCharsets.UTF_8)) + "."
+ encoder.encodeToString("test-signature".getBytes(StandardCharsets.UTF_8));
}
}
Azure User-Assigned Managed Identity (UAMI)
Confluent Cloud supports using Azure User-Assigned Managed Identity (UAMI) for OAuth authentication, eliminating the need for static client IDs and secrets. This feature leverages Azure’s built-in identity management to automatically retrieve authentication tokens.
For complete documentation on configuring and using UAMI with OAuth, including step-by-step setup instructions and client examples, see Configure Azure User Assigned Managed Identity OAuth for Confluent Cloud.