๐ŸŽ‰ 75% of content is free forever โ€” Unlock Premium from $10/mo โ†’
CW
NEWSLIVESearch All Content
๐Ÿ’ผ Servicesโ„น๏ธ Aboutโœ‰๏ธ ContactView Pricing Plansfrom $10

Kafka Security: SASL, TLS and Least-Privilege ACLs

Apache KafkaSecurityโญ Premium

Kafka Security: SASL, TLS and Least-Privilege ACLs

Senior level ยท Turning three separate controls into one coherent production posture.

Prerequisites

  • !Broker listeners and advertised addresses
  • !How producers and consumers authenticate to a broker

What You'll Learn

  • 1Separate encryption, authentication and authorization concerns
  • 2Configure a broker for mutual TLS and for SASL over TLS
  • 3Grant the minimum ACL set a service actually needs
  • 4Rotate credentials and certificates without a cluster restart

Three controls, and the order to think about them

Security on a broker comes down to three independent questions. Is the channel encrypted, so a passive observer sees nothing. Who is speaking, so you know which principal to judge. What is that principal allowed to do, so a compromised service account cannot read every topic in the cluster. They compose, and skipping any one leaves a specific gap.

ControlMechanismProtects againstCost if skipped
Encryption in transitSSL or TLS listenersEavesdropping and tampering on the wireCredentials and payloads readable on the network
AuthenticationSASL mechanism or mutual TLSImpersonation and unauthenticated accessAnyone who can reach the port can produce
AuthorizationACLs on resourcesLateral movement after a credential leaksOne leaked key exposes the whole cluster

The most common production pattern is SASL_SSL: TLS carries the connection and SASL authenticates the principal inside it. Plaintext SASL sends credentials in the clear, and SSL without SASL authenticates only certificates, which is fine for broker-to-broker traffic but awkward for clients whose identity lives in a directory rather than a certificate.

Encryption in transit

# server.properties - dedicated encrypted listener
listeners=INTERNAL://0.0.0.0:9092,SSL://0.0.0.0:9093
advertised.listeners=INTERNAL://kafka1.internal:9092,SSL://kafka1.example.com:9093
listener.security.protocol.map=INTERNAL:SSL,SSL:SSL
security.inter.broker.protocol=SSL

ssl.keystore.location=/etc/kafka/secrets/kafka.keystore.jks
ssl.keystore.password=${KEYSTORE_PASS}
ssl.key.password=${KEY_PASS}
ssl.truststore.location=/etc/kafka/secrets/kafka.truststore.jks
ssl.truststore.password=${TRUSTSTORE_PASS}
ssl.client.auth=requested
ssl.endpoint.identification.algorithm=https

Two settings carry most of the risk. ssl.endpoint.identification.algorithm must stay enabled so the client verifies the broker certificate against the hostname it dialled; disabling it to work around a certificate mismatch removes the only protection against a machine-in-the-middle presenting any valid certificate. And ssl.client.auth=requested asks for a client certificate without rejecting those that do not send one, while required rejects them; use required once every client has a certificate.

Keeping internal and external listeners on separate ports lets you run broker replication in plaintext on a private network while exposing only the encrypted listener publicly, which removes a round of TLS from the replication path without weakening anything an outside client can reach.

Choosing a SASL mechanism

# server.properties - SCRAM over TLS for application clients
listeners=SASL_SSL://0.0.0.0:9094
advertised.listeners=SASL_SSL://kafka1.example.com:9094
sasl.enabled.mechanisms=SCRAM-SHA-512
sasl.mechanism.inter.broker.protocol=SCRAM-SHA-512
security.inter.broker.protocol=SASL_SSL

sasl.jaas.config=org.apache.kafka.common.security.scram.ScramLoginModule required \
  username="broker" \
  password="${BROKER_PASS}";
# Provision credentials stored as SCRAM hashes in ZooKeeper or KRaft
kafka-configs.sh --bootstrap-server kafka1:9094 --alter \
  --add-config 'SCRAM-SHA-512=[iterations=8192,password=app-secret]' \
  --entity-type users --entity-name orders-service

# Client side
# security.protocol=SASL_SSL
# sasl.mechanism=SCRAM-SHA-512
# sasl.jaas.config=...ScramLoginModule required username="orders-service" password="...";

SCRAM is the pragmatic default: credentials are stored as salted hashes rather than reversibly encrypted, no external ticket infrastructure is required, and every client supports it. SASL_PLAINTEXT is acceptable only on a trusted private network, and SASL_PLAIN with a shared password across services fails the moment one service is compromised. GSSAPI buys single sign-on and central revocation at the price of a Kerberos estate, and OAUTHBEARER fits environments that already issue short-lived tokens.

Authorization and the ACL model

# server.properties - deny by default
authorizer.class.name=kafka.security.authorizer.AclAuthorizer
super.users=User:admin
allow.everyone.if.no.acl.found=false

That last line is the difference between a configured cluster and a secure one. With allow.everyone.if.no.acl.found left at its permissive value, any authenticated principal can operate on any resource that has no explicit rule, so a freshly created topic is world readable until someone remembers to lock it down.

# Producer: write to one topic only
kafka-acls.sh --bootstrap-server kafka1:9093 --add \
  --allow-principal User:orders-service \
  --operation Write --operation Describe --topic orders

# Consumer: read the topic and own its group
kafka-acls.sh --bootstrap-server kafka1:9093 --add \
  --allow-principal User:search-service \
  --operation Read --topic orders \
  --group search-consumer

# Audit what a principal can actually do
kafka-acls.sh --bootstrap-server kafka1:9093 \
  --list --allow-principal User:orders-service

Resource types are topic, group, cluster, transactional-id and delegation-token. Each operation is checked separately, so Write on a topic does not imply Describe, and a consumer that can read a topic but not read its group will fail at the first rebalance with an authorization error rather than a clear message.

Granting the minimum that still works

A service that produces to orders and consumes from enriched needs Write plus Describe on one topic and Read plus Describe on another, plus Read on its own consumer group. Nothing else. Transactional producers additionally need Describe and Write on a cluster-scoped transactional-id resource, which teams routinely forget and then debug as a mysterious ProducerFenced error.

Wildcards exist but change the blast radius: a rule on all topics means a leaked credential reads everything, including topics created after the rule was written. Prefer explicit topic names generated from a service catalogue, and review the ACL list as part of onboarding and offboarding rather than as a one-time setup task.

โš ๏ธAuthorization errors look like timeouts

A principal missing an ACL typically sees authorization failed errors during metadata or group operations rather than at the first fetch. When a client behaves as though the broker is unreachable, list its ACLs before checking the network.

Listener design and network boundaries

The listener layout is the first security boundary most teams get wrong, because it is usually inherited from a tutorial rather than designed. A production cluster almost always needs at least two listeners: one for internal replication and inter-broker traffic that never leaves the private network, and one for external clients that terminates TLS and authenticates through SASL. Splitting them lets you keep replication on a fast plaintext path while exposing only the encrypted, authenticated surface to anything outside the cluster's private subnet.

The advertised listener for each listener must resolve correctly from the client that is connecting, which is the source of a surprising number of production incidents. A client connecting through the external listener receives the advertised address of whichever listener the broker matched on the incoming connection; if that advertised address points at an internal hostname the client cannot resolve, the connection succeeds at the TCP level and then hangs during metadata fetch. Getting this wrong is not a security failure, but it is the most common configuration error teams hit when they add a second listener for the first time.

Network-level rules should enforce what the listeners express. The internal listener's port should only be reachable from the cluster's own subnet or VPC, verified with a network policy rather than assumed from a security group that was set once and never audited. The external listener should sit behind a load balancer that terminates TLS at the edge only if you also enable mutual TLS or SASL on the broker itself; edge termination without broker-side encryption simply moves the plaintext boundary to the load balancer and leaves the hop from load balancer to broker unencrypted unless that hop is also TLS.

A third listener pattern worth knowing is a separate listener for administrative tooling, used by operators running kafka-configs.sh, kafka-acls.sh and the like. Giving administrators a distinct port with its own authentication mechanism and its own ACL set means a leaked application credential can never be used to administer the cluster, and audit logs can distinguish operator actions from application traffic by listener. This is a small change in configuration and a large improvement in blast radius containment.

โ„น๏ธBroker-to-broker traffic still needs a story

Even when clients authenticate with SASL, inter-broker traffic uses its own security protocol, usually set through security.inter.broker.protocol. Decide whether that path is plaintext on a private network or mutually authenticated TLS, and document the decision; an unexamined default is how plaintext sneaks into an otherwise encrypted cluster.

Rotating without an outage

# 1. Add the new SCRAM credential alongside the old one
kafka-configs.sh --bootstrap-server kafka1:9094 --alter \
  --add-config 'SCRAM-SHA-512=[password=new-app-secret]' \
  --entity-type users --entity-name orders-service

# 2. Roll clients to the new password, then remove the old credential
kafka-configs.sh --bootstrap-server kafka1:9094 --alter \
  --delete-config 'SCRAM-SHA-512' \
  --entity-type users --entity-name orders-service

# 3. Certificates: import the new chain into the truststore, roll brokers one at
#    a time, and confirm replication recovers before touching the next node
kafka-configs.sh --bootstrap-server kafka1:9094 --describe \
  --entity-type users --entity-name orders-service

The same two-phase shape applies to certificates: add the new certificate to the truststore first so both chains are accepted, then swap keystore material, then remove the old chain. Rolling one broker at a time keeps the ISR healthy, and the moment to stop is when under-replicated partitions do not clear before the next node starts.

Common Mistakes

Running SASL_PLAINTEXT in production because TLS was hard to set up

Fix: Use SASL_SSL. Passwords travel on the wire in plaintext SASL, and any host on the network can capture and replay them.

Leaving allow.everyone.if.no.acl.found at its permissive default

Fix: Set it to false and create explicit allow rules. Otherwise every new topic starts open to all authenticated principals.

Granting All operations to simplify onboarding

Fix: Enumerate the operations each service performs. All on a topic plus a wildcard topic pattern turns one leaked credential into full cluster access.

Disabling hostname verification to fix a certificate error

Fix: Issue a certificate with the correct subject alternative name instead. Disabled verification makes TLS decorative.

Best Practices

  • Run separate listeners for internal replication and external clients so each gets the protocol it needs
  • Store SCRAM credentials with a raised iteration count and rotate them on a schedule through configuration management
  • Generate ACLs from a service catalogue and diff the live ACL list in CI so drift is visible
  • Alert on authorization failures per principal; they are the first sign of a misconfigured deploy or a leaked credential
  • Keep a documented break-glass admin principal whose credentials are stored in a vault, not in a config file

Interview Questions

Q1: Difference between SASL_PLAINTEXT and SASL_SSL?

Both authenticate through a SASL mechanism, but only SASL_SSL wraps the exchange in TLS. On SASL_PLAINTEXT the password crosses the network in clear text and can be captured by anything able to observe the traffic.

Q2: What does allow.everyone.if.no.acl.found=false do?

It flips the default from allow to deny. Without an explicit ACL a principal is refused, so newly created topics are closed by default rather than open to every authenticated client.

Q3: How would you rotate a client password with no downtime?

Set the new credential on the user, roll the clients to it, then delete the old credential. Because the broker holds both values during the window, clients can authenticate throughout the rollout.

Q4: Why might a consumer fail with an authorization error before it fetches anything?

Membership requires Read on the consumer group and Describe on the topic. Either check runs during metadata and join, so the failure surfaces as a group problem rather than a fetch problem.

Q5: Which extra ACL does a transactional producer need?

Describe and Write on a cluster-scoped transactional-id resource. Missing it shows up as ProducerFenced or transaction timeouts rather than an obvious authorization message.

Key Takeaways

  • Encryption, authentication and authorization answer different questions and none substitutes for the others
  • SASL_SSL is the standard production combination; keep hostname verification enabled
  • SCRAM stores salted hashes and needs no ticket infrastructure, which makes it the pragmatic default
  • Deny-by-default with explicit per-operation ACLs is what limits blast radius after a credential leaks
  • Rotate credentials in two phases and certificates truststore-first, rolling one broker at a time
๐Ÿ”’

Premium Content

Kafka Security: SASL, TLS and Least-Privilege ACLs

You've previewed the first section. Unlock this full lesson and 900+ advanced tutorials with a Premium plan.

๐ŸŽฏEnd-to-end Projects
๐Ÿ’ผInterview Prep
๐Ÿ“œCertificates
๐ŸคCommunity Access

Already a member? Log in

CW

ChatWhole Learn Editorial Team

Written by experienced data scientists, software engineers, and educators. All content is reviewed by industry professionals to ensure accuracy and relevance.

Last reviewed: 2026-10-13

โ€”
โ˜†โ˜†โ˜†โ˜†โ˜†
0 ratings

Rate & Feedback

Advertisement