Learn Labs
Operations

Security

Encryption with TLS, authentication with SASL, and authorization with ACLs

This lab cluster uses PLAINTEXT listeners: no encryption, no authentication, every client can do anything. That keeps the labs simple, and it is how many internal clusters still run, which is exactly the problem. The book's Securing Kafka chapter is the full reference; this lesson is the practical checklist.

Three layers

LayerQuestionMechanism
EncryptionCan someone on the network read the data?TLS on listeners
AuthenticationWho is this client?mTLS certificates, or SASL (SCRAM, OAUTHBEARER, GSSAPI/Kerberos)
AuthorizationWhat may they do?ACLs (StandardAuthorizer in KRaft)

Each listener has a security protocol: PLAINTEXT, SSL, SASL_PLAINTEXT, or SASL_SSL. This lab maps every listener to PLAINTEXT in KAFKA_LISTENER_SECURITY_PROTOCOL_MAP; a secured cluster would use SASL_SSL for clients.

Encryption: TLS

listeners=EXTERNAL://:9092,INTERNAL://:19092,CONTROLLER://:29093
listener.security.protocol.map=EXTERNAL:SASL_SSL,INTERNAL:SASL_SSL,CONTROLLER:SSL
ssl.keystore.location=/etc/kafka/secrets/broker.keystore.p12
ssl.keystore.password=...
ssl.truststore.location=/etc/kafka/secrets/truststore.p12
ssl.client.auth=none               # or "required" for mutual TLS

TLS disables zero-copy (sendfile) on that listener, because data must be encrypted in the JVM, so expect higher broker CPU. It's usually worth it.

Authentication: SASL/SCRAM

SCRAM stores salted password hashes in the cluster metadata and needs no external system:

# create a user (credentials live in KRaft metadata)
kafka-configs.sh --bootstrap-server ... --alter --entity-type users --entity-name billing-svc \
--add-config 'SCRAM-SHA-512=[password=change-me]'

# broker
sasl.enabled.mechanisms=SCRAM-SHA-512
sasl.mechanism.inter.broker.protocol=SCRAM-SHA-512

# client (librdkafka names)
security.protocol=SASL_SSL
sasl.mechanisms=SCRAM-SHA-512
sasl.username=billing-svc
sasl.password=change-me

OAUTHBEARER (OIDC tokens from your identity provider) is the common choice in larger organisations; managed Kafka services often use their cloud's IAM.

Authorization: ACLs

With an authorizer enabled, everything is denied unless an ACL allows it:

authorizer.class.name=org.apache.kafka.metadata.authorizer.StandardAuthorizer
super.users=User:admin;User:broker
allow.everyone.if.no.acl.found=false
billing may read "orders" as group "billing"kafka-acls.sh --bootstrap-server ... --add --allow-principal User:billing-svc \--operation Read --topic orders --group billingthe order service may write "orders", transactionally and idempotentlykafka-acls.sh ... --add --allow-principal User:order-svc --operation Write --topic orderskafka-acls.sh ... --add --allow-principal User:order-svc --operation Write --transactional-id order-svc- \--resource-pattern-type prefixedlistkafka-acls.sh --bootstrap-server ... --list --topic orders

Consumers need Read on the topic and on the group. Transactional producers need Write on their transactional id. Missing one of these gives TopicAuthorizationFailed or GroupAuthorizationFailed. Prefixed ACLs (--resource-pattern-type prefixed) let one rule cover orders.* topics.

Other controls

  • Quotas limit a client's produce/fetch bandwidth and request rate, so one misbehaving service can't saturate brokers: kafka-configs.sh --alter --entity-type clients --entity-name analytics --add-config producer_byte_rate=10485760.
  • Secure the ecosystem too: Schema Registry, Connect's REST API (it can run arbitrary connectors with stored credentials), kafka-ui, and the JMX ports all need auth.
  • Don't put secrets in connector configs in plain text. Use Connect's config providers (${file:/secrets/db.properties:password}).

Checklist

  1. TLS on every listener that leaves a trusted host.
  2. SASL (SCRAM or OAUTHBEARER) or mTLS per service; no shared credentials.
  3. An authorizer with deny-by-default and least-privilege ACLs.
  4. Quotas for noisy clients.
  5. Auth on Schema Registry, Connect, and the UI.
  6. Credentials rotated through a secret store.

Lab

On this cluster, add a quota and watch it bite (security changes to the lab cluster would break the other labs):

kafka-configs.sh --bootstrap-server localhost:19092 --alter --entity-type clients \
--entity-name perf --add-config producer_byte_rate=1048576     # 1 MB/s

kafka-producer-perf-test.sh --topic demo --num-records 80000 --record-size 1000 --throughput -1 \
--command-property bootstrap.servers=localhost:19092 client.id=perf
80000 records sent, 3413 records/sec (3.26 MB/sec), 6532 ms avg latency ...

# remove it afterwards
kafka-configs.sh --bootstrap-server localhost:19092 --alter --entity-type clients \
--entity-name perf --delete-config producer_byte_rate

Two things the first attempts at this lab showed:

  • Quotas are per broker. 1 MB/s on each of 3 brokers gave 3.26 MB/s in total.
  • Rates are averaged over a window (quota.window.num × 1 s, 11 s by default). Runs of 5 MB and 20 MB finished at full speed (15-30 MB/s), because their average over the window stayed under the limit. Only sustained traffic is throttled, and brokers throttle by delaying responses, which is why latency jumped to seconds.

On this page