Kafka SASL zookeeper authentication
System Design practice on Codemia
Work through 120+ system design problems with detailed solutions, from rate limiters to multi-region storage.
Apache Kafka is an open-source stream-processing software platform developed by the Apache Software Foundation, written in Scala and Java. It is designed to handle data feeds in real-time. Kafka employs several methods to ensure data security and integrity, among which authentication and authorization are key components. In Kafka, along with its own internal mechanisms, ZooKeeper — used for managing and coordinating Kafka broker nodes — also requires secure configuration. One of the methods to secure ZooKeeper is via SASL (Simple Authentication and Security Layer).
Understanding SASL
SASL is a protocol that provides a mechanism for authentication and optional establishment of a security layer between client and server. It decouples authentication procedures from application protocols, enabling developers to integrate authentication into their applications without having to specifically handle it at the application level.
Kafka SASL Zookeeper Authentication
When Kafka uses ZooKeeper, it stores sensitive data such as access control lists (ACLs) and topic configurations. If an intruder accesses this data, it could lead to unauthorized topic manipulation or data leakage. Therefore, securing ZooKeeper is crucial and can be achieved using SASL.
Kafka supports multiple SASL mechanisms like GSSAPI (Kerberos), PLAIN, and SCRAM-SHA-256/512. For ZooKeeper, SASL with Kerberos is a common configuration, providing a strong authentication mechanism.
How Kafka Connects to a SASL-secured ZooKeeper
- Enable SASL in Kafka and ZooKeeper: Configuration changes need to be made in both Kafka and ZooKeeper to enable SASL.
- Configure the ZooKeeper SASL client: Kafka brokers act as ZooKeeper clients. Hence, Kafka’s
zookeeper.set.aclshould be true when ZooKeeper is secured with SASL. - Kafka Server Configuration: Within the Kafka server properties, specify the ZooKeeper SASL client config file using the system property
-Djava.security.auth.login.config=[path-to-jaas.conf].
JAAS Configuration for Kafka Brokers
The JAAS (Java Authentication and Authorization Service) configuration file for a Kafka broker connecting to SASL-enabled ZooKeeper might look something like this:
Key Configuration Elements in ZooKeeper
To set up ZooKeeper for SASL authentication with GSSAPI (Kerberos), you need the following in your zoo.cfg:
Additionally, ZooKeeper's JAAS config might look like:
Technical Steps to Integrate SASL with ZooKeeper in Kafka
- ZooKeeper and Kafka Version Compatibility: Check that the versions of Kafka and ZooKeeper in use support SASL.
- Kerberos Environment: Set up a Kerberos server if using GSSAPI.
- Modify Kafka and ZooKeeper Configuration Files: As illustrated in earlier sections, modify the respective configuration settings.
- Restart Services: After changes, restart Kafka and ZooKeeper to apply new settings.
- Test Authentication: Validate the setup by checking the ZooKeeper logs for authentication entries and by producing and consuming messages in Kafka.
Summary Table
| Component | Configuration File | Key Property | Purpose |
| Kafka | server.properties | zookeeper.set.acl | Enable ACLs in ZooKeeper connection |
| Kafka JAAS | kafka_server_jaas.conf | KafkaServer | Authentication for Kafka Broker |
| ZooKeeper | zoo.cfg | authProvider.1 | Set SASL Authentication provider |
| ZooKeeper JAAS | zookeeper_jaas.conf | KerberosPrincipal | Kerberos identity for ZooKeeper |
Conclusion
Securing Kafka’s interactions with ZooKeeper using SASL is essential for protecting sensitive data and preventing unauthorized access. By following the configurations and steps provided, one can establish a secure environment that maintains the integrity and confidentiality of the data streaming through Kafka.
Related reading
- Kafka Schema Registry getting error Unexpected character (''<'' (code 60)) expected a valid value (number, String, array, object, ''true'', ''false'')
- Kafka schema registry not compatible in the same topic
- Kafka schema registry RestClientException Unauthorized; error code 401
- kafka schema.registry.url was supplied but isn't a known config
- Kafka Should Number of Consumer Threads equal number of Topic Partitions
- Kafka single consumer failure in a group
- Kafka security and authentication
- Kafka Server - Could not find a 'KafkaServer' in JAAS

System Design Fundamentals
Build a strong foundation in designing scalable, reliable distributed systems.
View the courseTrack what you have practised
A free account saves your progress, solutions and study plan across every problem on Codemia.
System Design practice on Codemia
Work through 120+ system design problems with detailed solutions, from rate limiters to multi-region storage.