Skip to content

AxonOps — AI-Native Control Plane for Open Source Data Platforms

Kafka Authentication

Authentication verifies the identity of clients connecting to Kafka brokers and brokers communicating with each other. Kafka supports multiple authentication mechanisms to integrate with different security infrastructures.


MechanismProtocolDescriptionDocumentation
SASL/SCRAMSASLSalted challenge-response with SHA-256/512SASL/SCRAM Guide
SASL/PLAINSASLSimple username/passwordSASL/PLAIN Guide
SASL/GSSAPISASLKerberos authenticationKerberos Guide
SASL/OAUTHBEARERSASLOAuth 2.0 / OIDC tokensOAuth Guide
mTLSSSL/TLSMutual TLS certificatesmTLS Guide
Delegation TokensSASLLightweight token-based authDelegation Tokens

RequirementSCRAMPLAINKerberosOAuthmTLS
No external infrastructure
Enterprise SSO integration
Cloud-native environments
Certificate-based identity
Password-based auth
Token refresh support
Simple to set up⚠️⚠️
Choose Authentication MechanismSASL/SCRAMSASL/PLAINKerberosOAuth/OIDCmTLSMost common forself-managed KafkaModern cloud-nativedeploymentsProduction withoutexternal IdPDevelopmentonlyActive DirectoryenterpriseCloud IdP(Okta, Azure AD)PKI infrastructureavailable
EnvironmentRecommended MechanismRationale
DevelopmentSASL/PLAIN or SASL/SCRAMSimple setup, no external dependencies
Production (standalone)SASL/SCRAM-SHA-512Secure, no external infrastructure needed
Enterprise (AD/Kerberos)SASL/GSSAPIIntegrates with existing Kerberos KDC
Cloud-nativeSASL/OAUTHBEARERIntegrates with cloud identity providers
PKI environmentmTLSCertificate-based, no passwords
Managed KafkaProvider-specificFollow provider recommendations

Kafka combines authentication mechanisms with transport security:

Security ProtocolAuthenticationEncryptionUse Case
PLAINTEXTNoneNoneDevelopment only
SSLmTLS (optional)TLSCertificate auth or encryption only
SASL_PLAINTEXTSASLNoneInternal networks (not recommended)
SASL_SSLSASLTLSProduction recommended

Never Use PLAINTEXT in Production

PLAINTEXT and SASL_PLAINTEXT transmit data unencrypted. Always use SSL or SASL_SSL in production.

# Encryption only (no authentication)
security.protocol=SSL
# SASL authentication with encryption (recommended)
security.protocol=SASL_SSL
# mTLS authentication with encryption
security.protocol=SSL
ssl.client.auth=required

Kafka supports different authentication mechanisms on different listeners, enabling separate configurations for internal and external traffic.

# Define listeners
listeners=INTERNAL://0.0.0.0:9092,EXTERNAL://0.0.0.0:9093,REPLICATION://0.0.0.0:9094
# Map listener names to security protocols
listener.security.protocol.map=INTERNAL:SASL_PLAINTEXT,EXTERNAL:SASL_SSL,REPLICATION:SASL_SSL
# Inter-broker communication
inter.broker.listener.name=REPLICATION
# Different mechanisms per listener
listener.name.internal.sasl.enabled.mechanisms=PLAIN
listener.name.external.sasl.enabled.mechanisms=SCRAM-SHA-512,OAUTHBEARER
listener.name.replication.sasl.enabled.mechanisms=SCRAM-SHA-512
Kafka BrokerINTERNAL:9092SASL_PLAINTEXTPLAINEXTERNAL:9093SASL_SSLSCRAM/OAuthREPLICATION:9094SASL_SSLSCRAMInternal AppsExternal ClientsOther BrokersPrivate networkPublic/DMZBroker-to-broker

Java Authentication and Authorization Service (JAAS) provides the authentication framework for SASL mechanisms.

MethodScopeUse Case
Broker propertyPer-listener, per-mechanismRecommended for brokers
Static JAAS fileJVM-wideLegacy, complex setups
ProgrammaticPer-clientApplication code
# Per-listener, per-mechanism JAAS config
listener.name.sasl_ssl.scram-sha-512.sasl.jaas.config=\
org.apache.kafka.common.security.scram.ScramLoginModule required \
username="broker" \
password="broker-secret";
kafka_server_jaas.conf
KafkaServer {
org.apache.kafka.common.security.scram.ScramLoginModule required
username="broker"
password="broker-secret";
};
Terminal window
# JVM parameter
-Djava.security.auth.login.config=/etc/kafka/kafka_server_jaas.conf
props.put("sasl.jaas.config",
"org.apache.kafka.common.security.scram.ScramLoginModule required " +
"username=\"app\" password=\"app-secret\";");

See individual mechanism guides for detailed JAAS configuration.


FeatureKafka Version
SASL/PLAIN0.9.0+
SASL/SCRAM0.10.2+
SASL/GSSAPI0.9.0+
SASL/OAUTHBEARER2.0.0+
OAUTHBEARER OIDC support3.1.0+
Delegation tokens1.1.0+
mTLS0.9.0+
Re-authentication2.2.0+
KRaft SCRAM bootstrap3.5.0+

# SASL handshake timeout
sasl.login.connect.timeout.ms=10000
# SASL login retry
sasl.login.retry.backoff.ms=100
sasl.login.retry.backoff.max.ms=10000

Enable periodic re-authentication for long-running connections:

# Broker: force re-authentication every hour
connections.max.reauth.ms=3600000

Use FQDNs

SASL authentication performs reverse DNS lookups. Use fully qualified domain names in bootstrap.servers and advertised.listeners to avoid slow handshakes.


IssueSymptomSolution
Authentication failedSaslAuthenticationExceptionVerify credentials, check JAAS config
Mechanism not enabledUnsupportedSaslMechanismExceptionAdd mechanism to sasl.enabled.mechanisms
SSL handshake failedSSLHandshakeExceptionVerify truststore contains broker CA
Principal not foundAuthorization failuresCheck principal mapping rules
Slow connectionsHigh connection latencyUse FQDNs, check DNS resolution
# Enable SASL debug logging
log4j.logger.org.apache.kafka.common.security=DEBUG
# Enable SSL debug (JVM parameter)
-Djavax.net.debug=ssl:handshake
Terminal window
# Test SASL authentication
kafka-broker-api-versions.sh --bootstrap-server kafka:9093 \
--command-config client.properties
# List SCRAM users
kafka-configs.sh --bootstrap-server kafka:9092 \
--describe --entity-type users