How to run Kafka with SASL_SSL
System Design practice on Codemia
Work through 120+ system design problems with detailed solutions, from rate limiters to multi-region storage.
Apache Kafka is a powerful distributed streaming platform capable of handling trillions of events a day. Implementing security in Kafka is essential to prevent unauthorized access to data. One common security configuration is SASL_SSL, which combines SASL (Simple Authentication and Security Layer) for authentication and SSL (Secure Sockets Layer) for encryption. This article walks through the steps and components involved in setting up Kafka with SASL_SSL.
Step 1: Configure Kafka Server
1. Configure server.properties
First, you need to set up the Kafka broker configuration to use SASL_SSL. Modify the server.properties file as follows:
Step 2: Configure JAAS for Kafka Brokers
You must create a JAAS file that Kafka will use for SASL configuration. Typically named kafka_server_jaas.conf, it might look like this:
Set the environment variable KAFKA_OPTS to ensure Kafka uses this JAAS configuration:
Step 3: Configure Kafka Client
Clients need to authenticate with the Kafka server using SASL_SSL. Update your client's client.properties file:
Create a JAAS config file for the client kafka_client_jaas.conf:
Set the environment variable to use this file:
Step 4: Generate SSL Key and Certificate
For both the Kafka server and clients, you need to create a keystore and a truststore. Use keytool for this purpose:
Step 5: Starting Kafka Server
With configurations done, start your Kafka broker:
Step 6: Testing Kafka with SASL_SSL
To ensure everything is functioning as expected, produce and consume messages with your SSL and SASL settings:
Key Configuration Parameters
| Parameter | Description |
listeners | Listener protocol and address |
security.inter.broker.protocol | Protocol used for broker communication |
sasl.mechanism.inter.broker.protocol | SASL mechanism used for broker communication |
ssl.keystore.location | Path to SSL keystore |
ssl.truststore.location | Path to SSL truststore |
sasl.enabled.mechanisms | Enabled SASL mechanisms |
Conclusion
Implementing SASL_SSL in Kafka enhances security by combining authentication and encryption, essential for protecting sensitive data in transit. By carefully configuring each component and testing connectivity, you can ensure a robust security setup in your Kafka deployment.
Related reading
- how to run task at scheduled time with RabbitMQ
- How to save latest offset that Spark consumed to ZK or Kafka and can read back after restart
- How to scale k8s pods according to rabbitmq queue message rate?
- How to scale Kafka Connect effectively?
- How to run kubernetes cronjob immediately
- How to run Nginx within a Docker container without halting?
- How to send an email in .Net according to new security policies?
- How to set encrypt false in Camel Debezium SQL server connector for JDBC connection

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.