00:00

Kafka Authorization with ACLs

Last updated:

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:

Principal 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:

server.properties (brokers and controllers)
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

Kafka ACL authorization decisionA request arrives with an authenticated principal, an operation and a resource. If the principal is a super user, the request is allowed. Otherwise, if any matching ACL denies the operation, the request is denied. Otherwise, if a matching ACL allows the operation, directly or through an implied operation, the request is allowed. If no ACL matches, the request is denied, unless allow.everyone.if.no.acl.found is true and the resource has no ACLs at all. Requestprincipal, op,resource Super user? MatchingDENY ACL? MatchingALLOW ACL? DENY ALLOW DENY ALLOW yes no yes no yes no (unless no ACLs exist andallow.everyone... = true)
Deny ACLs win over allow ACLs, and without a matching allow ACL the request is denied.
  • 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=true only opens resources that have no ACLs at all; it is meant for migrations, not as a permanent setting.
  • Implied operations. Read, Write, Delete and Alter imply Describe, and AlterConfigs implies DescribeConfigs, 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 typeTypical operationsExample use
TopicRead, Write, Describe, Create, Delete, Alter, DescribeConfigs, AlterConfigsProduce to or consume from orders
GroupRead, Describe, DeleteJoin consumer group billing and commit offsets
TransactionalIdWrite, DescribeUse transactional.id values starting with payments-
ClusterCreate, Alter, Describe, ClusterAction, DescribeConfigs, AlterConfigs, IdempotentWriteCreate topics anywhere; cluster-wide administration
DelegationTokenDescribeManage 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

ApplicationRequired ACLs
ProducerWrite on the topic (Describe is implied). Idempotence, enabled by default, needs no extra ACL in modern Kafka.
Consumer in a groupRead on the topic and Read on the consumer group
Transactional producerWrite on the topics and Write on the TransactionalId (prefixed ACLs suit generated IDs)
Consume–transform–produce with transactionsAll of the above, plus Read on the group whose offsets are committed in the transaction
Kafka Streams applicationRead/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 topicsCreate 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:

Terminal
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:

GrantConsumerAcls.java
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");
        }
    }
}
Output
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:

  • NewTopic beans make KafkaAdmin create topics at startup, which needs Create and Describe. Without them, startup logs an authorization error.
  • Transactions (spring.kafka.producer.transaction-id-prefix) need Write on TransactionalId with that prefix.
  • Dead-letter and retry topics are written by the application, so it needs Write on them (and Read plus 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 Read on the topic but not on its group fails with GroupAuthorizationException.
  • 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=true after 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.id prefix.
  • 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 Create unless 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.

13. References