Kafka
SASL Authentication
Zookeeper
Distributed Systems
Data Security

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.

Practice system design

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

  1. Enable SASL in Kafka and ZooKeeper: Configuration changes need to be made in both Kafka and ZooKeeper to enable SASL.
  2. Configure the ZooKeeper SASL client: Kafka brokers act as ZooKeeper clients. Hence, Kafka’s zookeeper.set.acl should be true when ZooKeeper is secured with SASL.
  3. 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:

properties
1Server {
2KafkaServer {
3org.apache.kafka.common.security.plain.PlainLoginModule required
4username="kafka"
5password="kafka-secret"
6user_kafka="kafka-secret";
7};
8};

Key Configuration Elements in ZooKeeper

To set up ZooKeeper for SASL authentication with GSSAPI (Kerberos), you need the following in your zoo.cfg:

properties
1authProvider.1=org.apache.zookeeper.server.auth.SASLAuthenticationProvider
2jaasLoginRenew=3600000
3kerberos.removeHostFromPrincipal=true
4kerberos.removeRealmFromPrincipal=true

Additionally, ZooKeeper's JAAS config might look like:

properties
1Server {
2com.sun.security.auth.module.Krb5LoginModule required
3useKeyTab=true
4storeKey=true
5keyTab="/etc/security/keytabs/zk_server.keytab"
6principal="zoo@[REALM]";
7};

Technical Steps to Integrate SASL with ZooKeeper in Kafka

  1. ZooKeeper and Kafka Version Compatibility: Check that the versions of Kafka and ZooKeeper in use support SASL.
  2. Kerberos Environment: Set up a Kerberos server if using GSSAPI.
  3. Modify Kafka and ZooKeeper Configuration Files: As illustrated in earlier sections, modify the respective configuration settings.
  4. Restart Services: After changes, restart Kafka and ZooKeeper to apply new settings.
  5. Test Authentication: Validate the setup by checking the ZooKeeper logs for authentication entries and by producing and consuming messages in Kafka.

Summary Table

ComponentConfiguration FileKey PropertyPurpose
Kafkaserver.propertieszookeeper.set.aclEnable ACLs in ZooKeeper connection
Kafka JAASkafka_server_jaas.confKafkaServerAuthentication for Kafka Broker
ZooKeeperzoo.cfgauthProvider.1Set SASL Authentication provider
ZooKeeper JAASzookeeper_jaas.confKerberosPrincipalKerberos 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
Course
Beginner
27 lessons
10 hours
System Design Fundamentals

Build a strong foundation in designing scalable, reliable distributed systems.

View the course
Track 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.

Practice system design

All Rights Reserved.