Kafka
SASL configuration
Kafka CLI
Big Data
Data Management

How to access SASL configure kafka from Kafka cli

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, an open-source stream-processing software platform, is used extensively for handling real-time data feeds. SASL (Simple Authentication and Security Layer) provides the mechanism for authentication and data security in Kafka. Configuring Kafka to use SASL can seem complex, but with a proper understanding and step-by-step guide, you can secure your Kafka deployment effectively.

Understanding SASL

Before diving into configuration, it's essential to understand what SASL is and why it's used in Kafka. SASL is a protocol that provides a way for application protocols to add authentication support in a standard manner. It supports multiple authentication mechanisms, such as GSSAPI (Kerberos), OAUTHBEARER, SCRAM-SHA-256, SCRAM-SHA-512, and more.

Step-by-Step Configuration

1. Kafka Server Configuration

To enable SASL authentication on the Kafka server:

  • Update the server properties: Modify the server.properties file to include SASL settings.
properties
1  # Enable SASL_PLAINTEXT
2  listeners=SASL_PLAINTEXT://:9092
3  security.inter.broker.protocol=SASL_PLAINTEXT
4  sasl.mechanism.inter.broker.protocol=PLAIN
5  sasl.enabled.mechanisms=PLAIN
  • Create JAAS configuration file: This file will be used to configure the SASL mechanism, such as PLAIN, which is simple username/password authentication.
java
1  // kafka_server_jaas.conf
2  KafkaServer {
3    org.apache.kafka.common.security.plain.PlainLoginModule required
4    username="admin"
5    password="admin-secret"
6    user_admin="admin-secret";
7  };
  • Set environment variable: Before starting the Kafka server, set the KAFKA_OPTS environment variable to point to the JAAS file.
bash
  export KAFKA_OPTS="-Djava.security.auth.login.config=/path/to/kafka_server_jaas.conf"

2. Kafka Client Configuration

Clients also need to be configured to use SASL for connecting to the Kafka cluster.

  • Update client properties: Modify your producer and consumer configuration to include SASL settings.
properties
1  # Producer/Consumer configuration
2  bootstrap.servers=localhost:9092
3  security.protocol=SASL_PLAINTEXT
4  sasl.mechanism=PLAIN
  • Create a client JAAS config: Similar to the server, clients need a JAAS configuration.
java
1  // kafka_client_jaas.conf
2  KafkaClient {
3    org.apache.kafka.common.security.plain.PlainLoginModule required
4    username="client"
5    password="client-secret";
6  };
  • Run Kafka client: Use the environment variable to point to your client JAAS file when starting your Kafka consumer or producer.
bash
  export KAFKA_OPTS="-Djava.security.auth.login.config=/path/to/kafka_client_jaas.conf"
  kafka-console-producer --broker-list localhost:9092 --topic test

Troubleshooting Common SASL Configuration Issues

  • Authentication failures: Ensure that usernames and passwords are correctly configured in both the server and client JAAS files.
  • Connection errors: Check that your listeners and security.protocol configurations match across your Kafka clients and servers.

Summary

Configuration ItemDescriptionExample Value
listenersKafka listener configurationSASL_PLAINTEXT://:9092
security.inter.broker.protocolSecurity protocol between Kafka brokersSASL_PLAINTEXT
sasl.mechanism.inter.broker.protocolSASL Mechanism for inter-broker communicationPLAIN
sasl.enabled.mechanismsEnabled SASL mechanismsPLAIN
security.protocolProtocol used to communicate between Kafka clients and serversSASL_PLAINTEXT
sasl.mechanismSASL mechanism used by Kafka clientsPLAIN

Conclusion

Configuring SASL for Kafka involves setting up proper authentication mechanisms on both the server and the client side. By following the steps outlined above and adjusting configurations as necessary, you can secure your Kafka installation and ensure that data transmitted between your Kafka brokers and clients is protected.


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.