Kafka Authorization with ACLs
Kafka ACL authorization decides what an authenticated client may do: which topics it can read or write, which consumer groups it can join, and whether it may create topics or change configuration. Authentication tells Kafka who is connecting; access control lists (ACLs) decide what that principal is allowed to do.
This tutorial explains how the ACL model works in a KRaft cluster, how the broker evaluates a request, which ACLs typical producers, consumers, transactional producers and Kafka Streams applications need, and how to manage ACLs safely with kafka-acls.sh.
1. The ACL Model
Every Kafka ACL has the same shape:
P is Allowed or Denied operation O from host H on any resource R matching resource pattern RP.For example: User:orders-service is allowed Write from any host on topic orders. The principal is what authentication produced, for example the SCRAM user name, the OAuth sub claim, or the mapped name from a TLS certificate (see SSL and SASL authentication). Clients on a PLAINTEXT listener all share the principal User:ANONYMOUS, which is why ACLs only make sense together with authentication.
2. Enabling Authorization in KRaft
Authorization is off until an authorizer is configured. In KRaft clusters, Kafka’s built-in StandardAuthorizer stores ACLs in the cluster metadata log, so they replicate to every broker and controller automatically:
authorizer.class.name=org.apache.kafka.metadata.authorizer.StandardAuthorizer
# brokers, controllers and the admin tooling identity bypass ACL checks
super.users=User:kafka-broker;User:kafka-controller;User:platform-admin
# default: false = deny access to resources that have no ACLs at all
allow.everyone.if.no.acl.found=false
Configure the authorizer on controllers as well as brokers. In KRaft, admin requests such as CreateTopics are sent to a broker, which forwards them to the active controller together with the client’s principal, and the controller performs the authorization. The principals that brokers and controllers use to talk to each other must be super users (or have the necessary cluster ACLs), otherwise the cluster cannot operate once authorization is on.
3. How the Broker Evaluates a Request
- Deny wins. If any matching ACL denies the operation, the request is rejected even when another ACL allows it. Deny ACLs are therefore useful for exceptions, such as blocking one user from a topic that a wildcard allows.
- Default deny. Without a matching allow ACL the request is rejected.
allow.everyone.if.no.acl.found=trueonly opens resources that have no ACLs at all; it is meant for migrations, not as a permanent setting. - Implied operations.
Read,Write,DeleteandAlterimplyDescribe, andAlterConfigsimpliesDescribeConfigs, so you rarely need separate Describe ACLs.
Failed authorizations are logged by the authorizer logger, which is the first place to look when a client receives an authorization error.
4. Resources, Operations and Pattern Types
| Resource type | Typical operations | Example use |
|---|---|---|
Topic | Read, Write, Describe, Create, Delete, Alter, DescribeConfigs, AlterConfigs | Produce to or consume from orders |
Group | Read, Describe, Delete | Join consumer group billing and commit offsets |
TransactionalId | Write, Describe | Use transactional.id values starting with payments- |
Cluster | Create, Alter, Describe, ClusterAction, DescribeConfigs, AlterConfigs, IdempotentWrite | Create topics anywhere; cluster-wide administration |
DelegationToken | Describe | Manage delegation tokens |
The resource name can be matched in three ways:
- Literal (default): exactly
orders; the special literal name*matches every resource of that type. - Prefixed: every name starting with the prefix, for example
billing.for all of the billing team’s topics.
Prefixed ACLs make team-based ownership easy: a naming convention such as <team>.<domain>.<event> plus one prefixed ACL per team replaces hundreds of literal ACLs.
5. ACL Recipes for Common Applications
| Application | Required ACLs |
|---|---|
| Producer | Write on the topic (Describe is implied). Idempotence, enabled by default, needs no extra ACL in modern Kafka. |
| Consumer in a group | Read on the topic and Read on the consumer group |
| Transactional producer | Write on the topics and Write on the TransactionalId (prefixed ACLs suit generated IDs) |
| Consume–transform–produce with transactions | All of the above, plus Read on the group whose offsets are committed in the transaction |
| Kafka Streams application | Read/Write on its input and output topics, and All on topics and groups with the prefix of its application.id, which covers internal changelog and repartition topics |
| Application that creates its own topics | Create on those topic names (or prefix), or on the cluster |
6. Managing ACLs with kafka-acls.sh
Run the tool with an admin identity; admin.properties holds that identity’s security settings:
K="bin/kafka-acls.sh --bootstrap-server kafka-1.example.com:9094 --command-config admin.properties"
# producer: --producer adds Write, Describe and Create on the topic
$K --add --allow-principal User:orders-service --producer --topic orders
# consumer: --consumer adds Read and Describe on the topic and Read on the group
$K --add --allow-principal User:billing-service --consumer --topic orders --group billing
# transactional producer with generated IDs payments-0, payments-1, ...
$K --add --allow-principal User:payments-service --operation Write \
--transactional-id payments- --resource-pattern-type prefixed
# Kafka Streams application with application.id=fraud-detector
$K --add --allow-principal User:fraud-detector --operation All \
--topic fraud-detector --group fraud-detector --resource-pattern-type prefixed
# review and remove
$K --list --topic orders
$K --remove --allow-principal User:orders-service --operation Create --topic orders
The --producer shortcut also grants Create, so the producer could create the topic if it does not exist. If topics are created centrally, remove that ACL as shown in the last command, or grant Write explicitly instead of using the shortcut.
7. Managing ACLs from Java
Platform teams often manage ACLs as code, for example from a deployment job. The Admin client creates them programmatically:
package com.javabytechie.platform;
import java.util.List;
import java.util.Properties;
import org.apache.kafka.clients.admin.Admin;
import org.apache.kafka.clients.admin.AdminClientConfig;
import org.apache.kafka.common.acl.AccessControlEntry;
import org.apache.kafka.common.acl.AclBinding;
import org.apache.kafka.common.acl.AclOperation;
import org.apache.kafka.common.acl.AclPermissionType;
import org.apache.kafka.common.resource.PatternType;
import org.apache.kafka.common.resource.ResourcePattern;
import org.apache.kafka.common.resource.ResourceType;
public class GrantConsumerAcls {
public static void main(String[] args) throws Exception {
Properties props = new Properties();
props.put(AdminClientConfig.BOOTSTRAP_SERVERS_CONFIG, "kafka-1.example.com:9094");
// plus security.protocol, sasl.* settings of the admin identity
var allowRead = new AccessControlEntry("User:billing-service", "*",
AclOperation.READ, AclPermissionType.ALLOW);
List<AclBinding> acls = List.of(
new AclBinding(new ResourcePattern(ResourceType.TOPIC, "orders", PatternType.LITERAL), allowRead),
new AclBinding(new ResourcePattern(ResourceType.GROUP, "billing", PatternType.LITERAL), allowRead));
try (Admin admin = Admin.create(props)) {
admin.createAcls(acls).all().get();
System.out.println("Created " + acls.size() + " ACLs");
}
}
}
Created 2 ACLs
For a job that runs on every deployment, compare the desired ACLs with the current ones from admin.describeAcls(...) first, then create the missing ones and delete those that are no longer wanted. Keep the desired ACLs in version control and review changes like code.
8. What Spring Boot Applications Need
Spring for Apache Kafka has no ACL configuration of its own; it uses the principal from the client’s security settings. A few Spring features do need extra permissions:
NewTopicbeans makeKafkaAdmincreate topics at startup, which needsCreateandDescribe. Without them, startup logs an authorization error.- Transactions (
spring.kafka.producer.transaction-id-prefix) needWriteonTransactionalIdwith that prefix. - Dead-letter and retry topics are written by the application, so it needs
Writeon them (andReadplus group access to consume retry topics).
Authorization failures surface as TopicAuthorizationException, GroupAuthorizationException or TransactionalIdAuthorizationException. They are not retriable: the listener container or producer fails until an ACL is added.
9. Common Mistakes
- Forgetting the group ACL. A consumer with
Readon the topic but not on its group fails withGroupAuthorizationException. - Enabling the authorizer before the brokers’ own principals are super users. Replication and controller traffic is then denied and the cluster stops working.
- Wildcard allow ACLs such as
--topic '*'for convenience, which silently grant access to every future topic. - Leaving
allow.everyone.if.no.acl.found=trueafter a migration, so every new topic is open until someone adds an ACL to it. - Missing ACLs for Kafka Streams internal topics, which appear under the
application.idprefix. - Sharing one principal across applications, which makes least privilege and auditing impossible.
10. Best Practices
- Least privilege: grant only the operations each application needs on the topics it owns or consumes.
- Naming conventions plus prefixed ACLs keep the number of ACLs small and ownership clear.
- Manage ACLs as code, applied by a pipeline, and review them like any other change.
- Create topics centrally and do not give applications
Createunless they really manage their own topics. - Audit regularly: list ACLs, remove those of retired applications, and watch the authorizer log for denials.
11. Summary
Kafka ACLs grant or deny operations on topics, groups, transactional IDs and the cluster to authenticated principals. In KRaft clusters the StandardAuthorizer stores them in the metadata log. Requests from super users are allowed; otherwise any matching deny wins, a matching allow grants access, and everything else is denied by default. Typical applications need only a handful of ACLs: Write for producers, Read on topic and group for consumers, TransactionalId access for transactions, and prefixed ACLs on the application.id for Kafka Streams.
12. Related Reading
- SSL and SASL authentication: how principals are established
- Kafka security overview: the complete security picture
- Kafka transactions: what the transactional ID is used for
- Kafka CLI commands: other administration tools
13. References
Kafka ACL Authorization Interview Questions and Answers
Common interview questions on Kafka ACL Authorization, from basic to scenario-based, with short answers you can explain in your own words.
Basic questions
Q. What does a Kafka ACL consist of?
Answer: A principal (such as User:orders-service), a permission type (allow or deny), an operation (Read, Write, Create and so on), a host (or * for any host) and a resource pattern: a resource type such as Topic, Group, TransactionalId or Cluster, a name, and a pattern type, literal or prefixed. In words: principal P is allowed or denied operation O from host H on resources matching pattern RP.
Q. How do you enable ACL authorization in a KRaft cluster?
Answer: Set authorizer.class.name=org.apache.kafka.metadata.authorizer.StandardAuthorizer on brokers and controllers, and list the principals of brokers, controllers and administrators in super.users. ACLs are then stored in the cluster metadata log and replicated to all nodes. Keep allow.everyone.if.no.acl.found=false so resources without ACLs are denied.
Intermediate questions
Q. A principal has an allow ACL and a deny ACL that both match a request. What happens?
Answer: The request is denied: a matching deny ACL always wins over allow ACLs. Only super users bypass this. Deny ACLs are therefore used for exceptions, such as excluding one principal or host from access that a broader allow ACL grants.
Q. What is the difference between literal and prefixed resource patterns, and when are prefixed ACLs useful?
Answer: A literal pattern matches exactly one name (or every name if the literal is *); a prefixed pattern matches every name that starts with the prefix. Prefixed ACLs combine well with naming conventions, for example all topics starting with billing. for the billing team, transactional IDs generated with a common prefix, or the internal topics of a Kafka Streams application, which all start with its application.id.
Q. Which ACLs does a transactional consume–transform–produce application need?
Answer: Read on the input topic and on its consumer group, Write on the output topics, and Write on its TransactionalId resources, usually as a prefixed ACL because the IDs are generated from a prefix. The group Read permission also covers committing offsets inside the transaction with sendOffsetsToTransaction().
Tricky and scenario questions
Q. After enabling the authorizer on a running cluster, replication stops and brokers log authorization errors. What went wrong?
Answer: The principals that brokers and controllers use to communicate with each other were not made super users and had no ACLs, so inter-broker and controller requests were denied. Add them to super.users (or grant the required cluster ACLs) on all nodes before enabling authorization, and roll the change out carefully, checking the authorizer log after each step.
Q. A Spring Boot service fails at startup with an authorization error, although it can produce to its topic in production. What should you check?
Answer: Whether the application declares NewTopic beans: KafkaAdmin then tries to create or describe topics at startup, which needs Create (and Describe) permissions that a pure producer does not have. Either grant those, or remove the beans and let a central process create topics. Also check retry and dead-letter topics and transactional IDs, which need their own ACLs.