Kafka brokers are refusing client connections because they can’t verify the client’s identity and permissions.
Common Causes:
-
Incorrect SASL Configuration on Brokers: The brokers aren’t set up to understand the authentication mechanism the clients are using.
- Diagnosis: Check
server.propertieson your Kafka brokers forsasl.enabled.mechanisms. Ensure it lists the mechanism your clients are configured for (e.g.,PLAIN,SCRAM-SHA-256,SCRAM-SHA-512). Also, checkauthorizer.class.nameand ensure it’s set tokafka.security.authorizer.AclAuthorizeror a custom authorizer that’s correctly configured. - Fix: If
sasl.enabled.mechanismsis missing or incorrect, add or correct it. For example, to enable PLAIN authentication:
This tells the broker which SASL protocols it should advertise and attempt to use for client authentication.sasl.enabled.mechanisms=PLAIN - Why it works: The broker needs to know which authentication "language" to speak with clients. If it doesn’t advertise the correct mechanism, clients will fail to authenticate.
- Diagnosis: Check
-
Missing or Incorrect SASL JAAS Configuration on Brokers: Even if the broker advertises a mechanism, its JAAS configuration might be broken, preventing it from loading the necessary authentication plugins.
- Diagnosis: Look for the
java.security.auth.login.configJVM argument when starting your Kafka brokers. This points to the JAAS configuration file. Examine this file for the correct entry forKafkaServer. - Fix: Ensure the JAAS file has an entry like this for
KafkaServer(example for PLAIN):
ReplaceKafkaServer { org.apache.kafka.common.security.plain.PlainLoginModule required username="your_broker_user" password="your_broker_password"; };your_broker_userandyour_broker_passwordwith credentials that Kafka brokers use to authenticate themselves to ZooKeeper or other services if applicable, or configure it for internal broker authentication if that’s your setup. This allows the broker to load and use the specified SASL login module. - Why it works: JAAS (Java Authentication and Authorization Service) is the underlying framework Kafka uses to plug in different security mechanisms. If the JAAS config is wrong, the SASL modules won’t load, and authentication will fail.
- Diagnosis: Look for the
-
Incorrect SASL Configuration on Clients: Clients are configured to use a SASL mechanism that the brokers don’t support or are not configured for.
- Diagnosis: Check the client’s
producer.propertiesorconsumer.properties(or equivalent programmatic configuration) forsasl.mechanism. - Fix: Ensure
sasl.mechanismon the client matches one of thesasl.enabled.mechanismslisted on the broker. For example, if brokers havesasl.enabled.mechanisms=SCRAM-SHA-512, clients must also setsasl.mechanism=SCRAM-SHA-512. This synchronizes the authentication protocol between client and server. - Why it works: Client and server must agree on the authentication method. Mismatch leads to immediate failure.
- Diagnosis: Check the client’s
-
Missing or Incorrect JAAS Configuration on Clients: Similar to brokers, clients need their own JAAS configuration to perform SASL authentication.
- Diagnosis: Check the
java.security.auth.login.configJVM argument for your client applications. Examine the contents of this file. - Fix: Ensure the JAAS file has an entry for
KafkaClientthat matches thesasl.mechanism. For SCRAM-SHA-512:
ReplaceKafkaClient { org.apache.kafka.common.security.scram.ScramLoginModule required username="your_client_user" password="your_client_password"; };your_client_userandyour_client_passwordwith the actual credentials for the client. This enables the client to authenticate using the configured SASL module. - Why it works: The client needs its own JAAS configuration to present its credentials and perform the SASL handshake correctly.
- Diagnosis: Check the
-
ZooKeeper Authentication Issues (if using SASL with ZooKeeper): If your Kafka brokers are configured to authenticate with ZooKeeper using SASL, and this fails, it can indirectly lead to authorization errors.
- Diagnosis: Check Kafka broker logs for any errors related to ZooKeeper connections or authentication. Examine the
server.propertiesforzookeeper.connectand any SASL-related properties for ZooKeeper authentication (e.g.,zookeeper.sasl.client.username,zookeeper.sasl.client.passwordor a JAAS config file for ZooKeeper). - Fix: Ensure the ZooKeeper JAAS configuration on the brokers is correct, and that the credentials used by brokers to connect to ZooKeeper are valid and have the necessary permissions within ZooKeeper to read/write Kafka’s metadata. For example, if using a JAAS file for ZooKeeper:
This allows brokers to establish a secure and authenticated session with ZooKeeper, which is essential for cluster operation and metadata management.KafkaClient { org.apache.kafka.common.security.plain.PlainLoginModule required username="zk_user" password="zk_password"; }; - Why it works: Kafka relies heavily on ZooKeeper for cluster coordination and storing metadata. If brokers can’t authenticate to ZooKeeper, they can’t operate correctly, leading to downstream errors like
TopicAuthorizationFailed.
- Diagnosis: Check Kafka broker logs for any errors related to ZooKeeper connections or authentication. Examine the
-
Incorrect ACLs (Access Control Lists): The user authenticated successfully, but they simply don’t have permission to perform the requested operation on the topic.
- Diagnosis: Use the
kafka-acls.shtool to check existing ACLs. For example, to see ACLs for topicmy-topicfor userUser:my_client_user:kafka-acls.sh --bootstrap-server localhost:9092 --list --topic my-topic --authorizer kafka.authorizer.AclAuthorizer - Fix: Grant the necessary permissions using
kafka-acls.sh. For example, to allowUser:my_client_usertoREADandWRITEtomy-topic:
This explicitly grants the authenticated user the rights required to interact with the specified resource.kafka-acls.sh --bootstrap-server localhost:9092 --add --allow-principal User:my_client_user --operation READ --topic my-topic --authorizer kafka.authorizer.AclAuthorizer kafka-acls.sh --bootstrap-server localhost:9092 --add --allow-principal User:my_client_user --operation WRITE --topic my-topic --authorizer kafka.authorizer.AclAuthorizer - Why it works: ACLs are the gatekeepers. If authentication succeeds but authorization fails, it means the identity verified by SASL doesn’t have the specific rights for the requested action.
- Diagnosis: Use the
-
SSL/TLS Configuration Mismatch (if using SSL/TLS for authentication): If you’re using SSL/TLS for client authentication (mutual TLS), certificate issues or configuration mismatches will prevent authentication.
- Diagnosis: Check broker logs for SSL handshake errors. Verify
ssl.client.authis set torequiredon brokers if using mTLS. Check if clients are configured withssl.truststore.location,ssl.truststore.password,ssl.keystore.location,ssl.keystore.password, andssl.key.password. - Fix: Ensure that the client’s certificate is trusted by the broker (i.e., signed by a CA that the broker trusts) and that the broker’s certificate is trusted by the client. Correct any path or password errors in the keystore/truststore configurations for both client and broker.
- Why it works: For mTLS, both parties must cryptographically verify each other’s identity using their certificates. Any failure in this chain breaks authentication.
- Diagnosis: Check broker logs for SSL handshake errors. Verify
The next error you’ll likely see if all authorization issues are resolved is a LeaderNotAvailable error if the topic itself has no partitions or if partition leaders are in a bad state.