Lesson 14 of 17 · Operating Kafka
Security: TLS, authentication, ACLs and quotas
Securing Kafka the way you secure any shared platform: encrypt every connection with TLS, give every client its own identity (mTLS certificates, SASL/SCRAM, OAuth tokens or cloud IAM), authorise with ACLs (prefixes per team, least privilege, super users kept rare), limit each client with quotas so no tenant can starve the others, and handle encryption at rest, secrets and auditing. With the client configuration and CLI commands for each.
Four layers
| Layer | Question | Kafka feature |
|---|---|---|
| Encryption in transit | Can anyone read the traffic? | TLS on every listener |
| Authentication | Who is this client? | mTLS, SASL/SCRAM, OAuth, cloud IAM |
| Authorization | What may it do? | ACLs |
| Fair use | Can it hurt others? | Quotas |
Out of the box, a listener can be PLAINTEXT: no encryption, no identity, anyone on the network can read and write everything. Fine for a laptop lab, never for shared environments.
Listeners and protocols
A broker can expose several listeners, each with a security protocol:
| Protocol | Encryption | Authentication |
|---|---|---|
PLAINTEXT |
None | None |
SSL |
TLS | Optional client certificate (mTLS when required) |
SASL_PLAINTEXT |
None | SASL (never use for real credentials) |
SASL_SSL |
TLS | SASL: SCRAM, OAUTHBEARER, GSSAPI (Kerberos), PLAIN |
Typical setup: an internal listener for brokers and in-cluster clients, an external listener for everything else, both with TLS and authentication.
Authentication options
| Method | How the client proves itself | Good for |
|---|---|---|
| mTLS | A client certificate signed by a CA the brokers trust; the principal comes from the certificate subject | Service-to-service; fits a PKI or Strimzi's User Operator |
| SASL/SCRAM-SHA-512 | Username and password, hashed on the broker | Simple setups; remember to rotate passwords |
| SASL/OAUTHBEARER | A short-lived token from your identity provider (OIDC) | Central identity, short-lived credentials, no secrets in Kafka |
| Cloud IAM (MSK IAM) | Signed requests with the workload's cloud role | AWS workloads using IRSA or Pod Identity |
An mTLS client configuration:
security.protocol=SSL
ssl.truststore.type=PEM
ssl.truststore.location=/etc/kafka/ca.crt
ssl.keystore.type=PEM
ssl.keystore.location=/etc/kafka/client.pem
ssl.endpoint.identification.algorithm=https
Prefer short-lived, automatically issued credentials (certificates from an operator or PKI, OAuth tokens, cloud IAM) over long-lived passwords copied into config. That is the same workload-identity principle used in service meshes.
The Kafka cluster is a library with many rooms. TLS is the covered walkway, so nobody outside can see what you carry. Authentication is the library card at the door. ACLs are the rules on the card: "may borrow from the science room only". Quotas are "no more than five books a day", so one reader can't empty the shelves for everyone else.
Authorization with ACLs
Enable an authorizer (in KRaft: authorizer.class.name=org.apache.kafka.metadata.authorizer.StandardAuthorizer; Strimzi: authorization: { type: simple }). With allow.everyone.if.no.acl.found=false (the default), anything not explicitly allowed is denied.
An ACL is: principal + allow/deny + operation + resource (+ host).
| Resource | Common operations |
|---|---|
| Topic | Read, Write, Describe, Create, Delete, Alter |
| Group | Read (needed to consume with a group), Describe |
| Cluster | Create (topics), Alter, IdempotentWrite (older clients) |
| TransactionalId | Write, Describe |
A team with the prefix orders.:
$ kafka-acls.sh --bootstrap-server kafka:9093 --command-config admin.properties --add \
--allow-principal User:orders-svc --operation Write --operation Describe \
--topic orders. --resource-pattern-type prefixed
$ kafka-acls.sh --bootstrap-server kafka:9093 --command-config admin.properties --add \
--allow-principal User:billing-svc --operation Read --operation Describe \
--topic orders.events --resource-pattern-type literal
$ kafka-acls.sh --bootstrap-server kafka:9093 --command-config admin.properties --add \
--allow-principal User:billing-svc --operation Read --group billing. --resource-pattern-type prefixed
Rules of thumb:
- One identity per service, never a shared "app" user.
- Prefixed ACLs follow the topic naming convention, so teams self-serve within their prefix.
- Consumers need Read on the topic and on their group.
- Keep
super.usersto brokers and a break-glass admin; every change by a super user should be audited. - Manage ACLs as code (Strimzi
KafkaUser, Terraform providers), not by hand.
Quotas: protecting tenants from each other
Quotas limit clients by principal, client ID, or both:
| Quota | Limits |
|---|---|
producer_byte_rate |
Bytes per second a client may write (per broker) |
consumer_byte_rate |
Bytes per second a client may read (per broker) |
request_percentage |
Share of broker request-handler time |
controller_mutation_rate |
Topic and partition creations and deletions |
$ kafka-configs.sh --bootstrap-server kafka:9093 --command-config admin.properties --alter \
--add-config producer_byte_rate=1048576,consumer_byte_rate=2097152 \
--entity-type users --entity-name orders-svc
$ kafka-configs.sh --bootstrap-server kafka:9093 --command-config admin.properties --alter \
--add-config producer_byte_rate=524288 --entity-type users --entity-default
A client over its quota is throttled: the broker delays its responses rather than failing them. Clients expose produce-throttle-time-avg and fetch-throttle-time-avg, so teams can see they hit a limit. Set a default quota for every user, and larger ones for services that need them.
Encryption at rest, secrets and audit
- At rest: Kafka stores data unencrypted on disk. Use encrypted volumes (cloud disk encryption, LUKS) or a managed service with KMS encryption. For very sensitive fields, encrypt the payload in the producer (field-level encryption) so even admins can't read it.
- Secrets: keep keystores and passwords in a secret manager or let the operator issue them; never bake them into images.
- Audit: enable authorizer logging (allowed and denied decisions), ship it to your log system, and alert on repeated denials, new super-user activity and ACL changes.
- Network: restrict listeners with network policies and security groups; Kafka is not meant to face the internet directly.
Try it: lock down the lab cluster
- Using the Strimzi project cluster (mTLS-only listener), create two
KafkaUsers with prefixesorders.andbilling.. - Produce to
orders.eventsasorders-svc(allowed), then asbilling-svc(denied). Read the error message. - Give
billing-svcread access toorders.eventsand its own group prefix; consume successfully. - Set a 100 KB/s producer quota on
orders-svc, run the perf test, and watch throughput flatten andthrottle-timeappear.
Going deeper
- Map external identities to principals with
ssl.principal.mapping.rulesor OAuth claim settings, so principals are readable (User:orders-svc, not a full certificate subject). - Rotate the CA with an overlap period: trust old and new CAs, reissue certificates, then remove the old CA (the same pattern as for a service mesh).
- Consider data classification per topic (public, internal, PII) and require stricter ACL review and encryption for PII topics.
Recap
- TLS everywhere;
PLAINTEXTonly for local labs. - Every client gets its own identity: mTLS, SCRAM, OAuth or cloud IAM; prefer short-lived credentials.
- ACLs deny by default; use prefixes per team, one identity per service, few super users.
- Quotas throttle noisy clients and protect a shared cluster.
- Encrypt at rest, manage secrets properly, and audit authorization decisions.
This site is a public version of my personal engineering knowledge hub. It intentionally excludes confidential company information and internal operational details.