how to use kafka acls?
System Design practice on Codemia
Work through 120+ system design problems with detailed solutions, from rate limiters to multi-region storage.
Apache Kafka, a distributed streaming platform, provides a robust security framework which includes Access Control Lists (ACLs) to manage permissions over Kafka resources. ACLs are essential when you want to secure your Kafka cluster by specifying which users or applications are allowed to perform operations on topics, consumer groups, and other Kafka resources.
Understanding Kafka ACLs
ACLs in Kafka are used to grant or deny permissions to Kafka users. These permissions control the ability to read, write, and configure Kafka resources. Kafka uses an authorization module as part of its security features, which checks ACLs to determine whether a given action (produce, consume, admin operations) by a user or application is allowed.
Setting Up Kafka ACLs
To manage ACLs, Kafka provides a command-line tool called kafka-acls.sh. This tool interacts with the Kafka cluster to add, remove, or list ACLs.
Here's an overview of how to use the kafka-acls.sh utility:
Adding ACLs
To add an ACL, you will specify the allowed operation, the user or application it applies to, and the Kafka resource. Here is an example command:
This command allows the user alice to read from the my-topic topic.
Removing ACLs
To remove an ACL, you might use a command like this:
This command removes the read permission for alice on my-topic.
Listing ACLs
To list the ACLs active in your cluster:
This will show all ACLs currently configured in the cluster.
Different Types of Operations
ACLs in Kafka can control several types of operations such as:
- Read: Allows consuming messages from a topic.
- Write: Allows producing messages to a topic.
- Create: Allows creating a topic.
- Delete: Allows deleting a topic.
- Alter: Allows modifying topic configurations.
- Describe: Allows viewing topic configurations.
Practical Example
Suppose you want to set up ACLs for a scenario where user bob should only be able to write to my-topic, and user alice should be able to read from the same topic. You would execute:
Best Practices
- Principle of Least Privilege: Always grant the minimum permissions necessary for users and applications.
- Regular Audits: Periodically review and audit your ACL settings to ensure they still align with your security policies.
- Use Secure Connections: When modifying ACLs, ensure your connections are secure to prevent interception.
Summary Table
Here’s a quick reference table for common ACL commands:
| Command | Description | Example Command |
| Add ACL | Adds an ACL to a resource | bin/kafka-acls.sh --add --allow-principal User:alice --operation Read --topic my-topic |
| Remove ACL | Removes an ACL from a resource | bin/kafka-acls.sh --remove --allow-principal User:alice --operation Read --topic my-topic |
| List ACLs | Lists all ACLs in the Kafka cluster | bin/kafka-acls.sh --list |
Kafka ACLs are a powerful tool for securing your Kafka cluster. Understanding and utilizing them effectively can help you maintain robust security and operational efficiency.
Related reading
- How to use kafka and storm on cloudfoundry?
- How to use Kafka connect in Strimzi
- How to use Kafka with TLS peer verification turned off
- How to use kafkacat with message-hub
- How to use MDC with thread pools?
- How to use Micrometer Timer to record duration of async method returns Mono or Flux
- How to use MFA with AWS CLI?
- How to use NSURLConnection to connect with SSL for an untrusted cert?

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.