Security
Locking down a cluster: TLS in transit, SASL authentication, ACL authorization, the listener matrix, and quotas. Interviewers ask because Kafka is wide open by default and usually holds the company's data.
part ofApache Kafkaoverview, primer and where to startread it →on this pageshowhide
explore
- TLS/SSL Encryption in Transit5 questions
- Mutual TLS Client Authentication5 questions
- SASL PLAIN and SCRAM Authentication5 questions
- SASL Kerberos (GSSAPI)5 questions
- SASL OAUTHBEARER and Delegation Tokens5 questions
- Authorization and ACLs6 questions
- Super Users and Authorizer Defaults5 questions
- Security Protocol and Listener Matrix6 questions
- Quotas as a Control Plane5 questions
- Encryption at Rest and Governance5 questions
- ZooKeeper and KRaft Metadata Hardening5 questions
- Security Auditing and Monitoring5 questions
questions
62 · 12 sectionsWhat does TLS/SSL encryption in transit protect in Kafka, and which broker and client configs enable it?
basics
~20 sTLS encrypts data moving between clients and brokers (and between brokers) so it can't be read or tampered with on the wire. You set security.protocol=SSL and point clients at a truststore (ssl.truststore.location/password); brokers add an SSL listener plus a keystore.
What does ssl.endpoint.identification.algorithm control, and why is disabling it dangerous?
basics
~20 sIt controls TLS hostname verification — whether the client checks that the broker's certificate actually matches the hostname it connected to. The default is https (enabled). Setting it to empty disables that check, which lets an attacker with any valid-looking cert impersonate the broker (man-in-the-middle).
What is the difference between JKS and PEM store formats in Kafka, and how do you configure each?
basics
~20 sJKS is a binary Java keystore file (password-protected, holds cert+key) configured via ssl.keystore.location plus ssl.keystore.type=JKS. PEM is plain text Base64 cert/key data; set ssl.keystore.type=PEM and you can pass the material inline or by file. PEM avoids the keytool step.
How do you control which TLS protocol versions and cipher suites Kafka negotiates, and what are sane defaults?
basics
~10 sUse ssl.enabled.protocols to allow versions (e.g. TLSv1.2,TLSv1.3) and ssl.protocol for the default context; restrict algorithms with ssl.cipher.suites. Sane defaults: enable only TLSv1.2 and TLSv1.3, disable TLSv1.0/1.1, and rely on strong AEAD ciphers (GCM/ChaCha20).
How do you rotate broker TLS keys/certificates and CA trust without downtime?
basics
~20 sRotate leaf certs by updating each broker's keystore and reloading without a full restart — Kafka watches the keystore/truststore files and reloads them when the file changes (KIP-226 dynamic config / file watch). Rotate the CA by adding the new CA to every truststore first, migrating certs, then removing the old CA last.
What is mutual TLS (mTLS) client authentication in Kafka, and how does it differ from plain TLS encryption?
basics
~20 sWith plain TLS, only the broker proves its identity with a certificate. With mutual TLS, the client ALSO presents its own certificate, so the broker authenticates the client. The client's certificate identity becomes its Kafka principal.
How do you configure a Kafka client to authenticate with mTLS, and what keystore/truststore settings are required?
basics
~10 sSet security.protocol=SSL, point ssl.keystore.location/password (and ssl.key.password) at the client's keystore holding its cert+private key, and ssl.truststore.location/password at the truststore holding the broker's CA. The broker side must have ssl.client.auth=required.
How does Kafka derive a principal from a client certificate, and how do ssl.principal.mapping.rules let you customize it?
basics
~20 sBy default the principal is the full certificate Subject DN, e.g. User:CN=svc,OU=apps,O=Acme. ssl.principal.mapping.rules is an ordered list of RULE: regex transforms (like Kerberos auth_to_local) that rewrite the DN into a shorter principal such as User:svc.
Why are CA-signed client certificates preferred over self-signed ones for Kafka mTLS, and how does the broker truststore relate to client certs?
basics
~20 sWith a CA-signed model the broker truststore only needs the one CA cert; any client cert signed by that CA is trusted automatically. With self-signed certs you'd have to add every individual client cert to every broker's truststore, which doesn't scale.
What are the operational challenges of certificate revocation and renewal for Kafka mTLS, and how do you handle them?
basics
~20 sCerts expire, so you must renew client certs before expiry or clients drop off. Revocation (killing a compromised cert early) is hard: Kafka's TLS layer doesn't check CRLs/OCSP by default, so teams often rely on short-lived certs and rotating the CA/truststore instead.
What is SASL in Kafka, and what is the difference between the PLAIN and SCRAM SASL mechanisms?
basics
~10 sSASL is Kafka's pluggable authentication framework. PLAIN sends a username and password (must run over TLS). SCRAM uses a salted challenge-response so the raw password never travels the wire.
How do you create, list, and delete a SCRAM user with kafka-configs, and what gets stored?
basics
~10 sUse kafka-configs.sh --alter --add-config 'SCRAM-SHA-256=[password=secret]' --entity-type users --entity-name alice. Kafka stores a salted, iterated hash (not the password). Delete with --delete-config; list with --describe.
How do you configure sasl.jaas.config on a Kafka client and broker for PLAIN vs SCRAM, and what login modules are used?
basics
~10 sSet sasl.jaas.config inline. PLAIN uses PlainLoginModule, SCRAM uses ScramLoginModule, each with username/password. On the broker, the KafkaServer JAAS section defines accepted users (PLAIN) or the inter-broker login.
Explain the SCRAM salted challenge-response handshake and why it resists credential theft better than PLAIN over SASL_SSL.
basics
~20 sIn SCRAM the client and server exchange nonces; the client derives a salted PBKDF2 key and sends a proof, never the password. The broker stores only StoredKey/ServerKey, so even a server breach or absent TLS doesn't directly leak the password.
When would you choose SASL/PLAIN vs SASL/SCRAM (vs mTLS or OAUTHBEARER) for a production Kafka cluster, and what are the operational trade-offs?
basics
~20 sUse SCRAM for self-managed username/password auth with live user management. Use PLAIN only when an external system (e.g. LDAP via a custom callback) validates credentials. Prefer OAUTHBEARER/mTLS for identity-provider or certificate-based auth. Always wrap in TLS.
What is SASL/GSSAPI in Kafka, and what does it let a client and broker prove to each other?
basics
~20 sSASL/GSSAPI is Kafka's way of authenticating with Kerberos. Clients get a ticket from a Kerberos KDC and present it to the broker, so both sides prove who they are without sending passwords over the wire.
How do you configure a Kafka client and broker for GSSAPI using a keytab, principal, and sasl.kerberos.service.name?
basics
~10 sSet security.protocol=SASL_SSL, sasl.mechanism=GSSAPI, and sasl.kerberos.service.name=kafka. Provide a JAAS config (via sasl.jaas.config) pointing useKeyTab to a keytab file and the principal that keytab contains.
What does krb5.conf contain for a Kafka deployment, and how do clock skew and DNS affect GSSAPI authentication?
basics
~10 skrb5.conf tells the JVM the default realm, where the KDCs are, and how DNS domains map to realms. Kerberos also requires synchronized clocks (within ~5 minutes) and consistent forward/reverse DNS, or authentication fails.
How does Kafka handle Kerberos ticket renewal, and what does sasl.kerberos.ticket.renew.window.factor control?
basics
~20 sKafka runs a background login thread that re-logs in or renews the Kerberos ticket before it expires. sasl.kerberos.ticket.renew.window.factor (default 0.8) sets how far into the ticket's lifetime to wait before renewing — at 80% of its life.
How do you integrate Kafka GSSAPI with enterprise Active Directory, and how do you map Kerberos principals to Kafka users for ACLs?
basics
~20 sPoint krb5.conf at the AD domain controllers (AD is a KDC), create service accounts and SPNs in AD, export keytabs, and use sasl.kerberos.principal.to.local.rules (or a custom KafkaPrincipalBuilder) to turn full principals like [email protected] into Kafka users like alice for ACL matching.
What is the SASL/OAUTHBEARER mechanism in Kafka, and how does a client authenticate with it?
basics
~10 sOAUTHBEARER is a Kafka SASL mechanism where the client presents an OAuth2 bearer token (usually a JWT) instead of a username/password. Kafka validates the token to authenticate the connection.
How does a Kafka broker validate an OAUTHBEARER JWT, and which sasl.oauthbearer.* configs control it?
basics
~10 sThe broker fetches the IdP's public keys from a JWKS endpoint and checks the JWT's signature, issuer, audience, and expiry. Configs like sasl.oauthbearer.jwks.endpoint.url, expected.issuer, expected.audience, and sub.claim.name control this.
How does a Kafka client refresh its OAUTHBEARER token, and what happens to a long-lived connection when the token expires?
basics
~20 sThe client's login manager proactively re-acquires a new token before the old one expires, based on a fraction of the token lifetime. Established connections stay open after a token expires; expiry mainly gates new connections (re-authentication can enforce expiry on live ones).
What are Kafka delegation tokens (KIP-48), and what problem do they solve for distributed workers and jobs?
basics
~20 sDelegation tokens are lightweight shared-secret credentials a client first authenticates (e.g. via Kerberos or OAUTHBEARER), then requests from the broker. Workers/tasks use the token to authenticate to Kafka without distributing the original credential, simplifying secret distribution in distributed jobs.
For a multi-tenant job platform that runs short-lived jobs against Kafka, how would you choose between OAUTHBEARER, delegation tokens, and per-tenant credentials for worker/job impersonation?
basics
~20 sUse OAUTHBEARER when each job/worker can talk to your IdP for its own short-lived token (best for centralized identity and revocation). Use delegation tokens when a coordinator authenticates once and must fan out cheap, revocable credentials to many executors without contacting the IdP per task.
What are Kafka's four security protocols, and what does each one provide in terms of encryption and authentication?
basics
~10 sKafka has four security protocols: PLAINTEXT (no encryption, no auth), SSL (TLS encryption, optional client cert auth), SASL_PLAINTEXT (SASL auth, no encryption), and SASL_SSL (SASL auth plus TLS encryption).
What is the difference between listeners and advertised.listeners, and why does a misconfigured advertised.listeners break clients even when the broker starts fine?
basics
~20 slisteners is where the broker binds and accepts connections. advertised.listeners is the address the broker hands back to clients in metadata so they can reconnect. If the advertised address is unreachable, clients connect once for metadata, then fail to reach the broker.
How does listener.security.protocol.map work, and how do you use named listeners to run multiple security protocols on one broker?
basics
~20 slistener.security.protocol.map maps each named listener to one of the four security protocols. With custom listener names you must define this map; it lets one broker expose, for example, an SSL internal listener and a SASL_SSL external listener at the same time.
What does inter.broker.listener.name configure, how does it relate to security.inter.broker.protocol, and what are the constraints when separating broker-to-broker traffic onto its own listener?
basics
~20 sinter.broker.listener.name selects which named listener brokers use to talk to each other (replication, controller coordination). It is mutually exclusive with security.inter.broker.protocol — you set one or the other. It lets broker-to-broker traffic run on a dedicated, often more-trusted listener separate from client traffic.
Design the listener and security configuration for a broker that must serve internal services on a private network and external clients over the internet, with appropriately differentiated hardening.
basics
~10 sDefine two named listeners: INTERNAL (private network) and EXTERNAL (internet). Map INTERNAL to SSL/mTLS and EXTERNAL to SASL_SSL via listener.security.protocol.map, advertise each with its reachable address, and point inter.broker.listener.name at INTERNAL.
What are Kafka client quotas, and what problem do they solve in a multi-tenant cluster?
basics
~10 sQuotas are per-client limits that Kafka brokers enforce to cap how much produce/fetch traffic (bytes per second) or broker request time a client can use, stopping one noisy client from starving others.
How do you set a produce byte-rate quota for a specific user using kafka-configs, and how do default quotas interact with specific ones?
basics
~10 sUse kafka-configs.sh --alter --add-config 'producer_byte_rate=...' against --entity-type users --entity-name <user>. A specific entity quota overrides the cluster --entity-default for that level.
When would byte-rate quotas fail to protect a broker, and how do request-percentage quotas address that?
basics
~20 sByte-rate quotas only limit data volume, so a client sending many tiny but expensive requests can saturate broker CPU without moving many bytes. request_percentage caps the share of broker IO/network thread time a client uses, covering that gap.
Explain how the broker measures rate and computes the throttle delay, including the role of quota.window.size.seconds and quota.window.num.
basics
~20 sThe broker tracks each client's rate over a sliding window of quota.window.num samples, each quota.window.size.seconds long. When the average exceeds the quota, it computes a delay = how long the client must pause to bring the windowed average back under the limit, then delays the response by that much.
What are controller mutation quotas (KIP-599), what do they protect, and how do they differ from request-percentage quotas?
basics
~20 sController mutation quotas limit how fast a user/client-id can create or delete topics and partitions, protecting the controller from a flood of metadata changes. They throttle metadata-mutation rate, whereas request_percentage throttles general request CPU on data-path brokers.
Does Apache Kafka natively encrypt the data it writes to disk (log segments)? If not, how do teams achieve encryption at rest?
basics
~20 sNo. Open-source Kafka has no built-in encryption of log segment files on disk. Encryption at rest is provided externally: encrypt the broker's volume/disk (LUKS or a cloud KMS-backed encrypted EBS volume), or encrypt the message payload before producing it.
How would you implement client-side (application-level) encryption for PII fields in Kafka messages, and what are the trade-offs?
basics
~20 sEncrypt the sensitive payload in the producer before send() and decrypt in the consumer after poll(), typically via a custom Serializer or interceptor using envelope encryption: a KMS issues a data key that encrypts the message, and the wrapped data key travels alongside. The broker stores only ciphertext.
How do you audit authentication and authorization (ACL) decisions in Kafka for governance and compliance?
basics
~20 sKafka's authorizer logs allowed/denied authorization decisions. Enable the authorizer logger (kafka.authorizer.logger) at INFO/DEBUG to capture which principal was allowed or denied which operation on which resource. Ship those logs to a central, tamper-evident store. Enterprise distributions (Confluent) add structured audit-log topics.
A GDPR erasure request requires deleting all of a user's data from a compacted Kafka topic. How do tombstones and retention/compaction make this work, and what are the caveats?
basics
~20 sOn a compacted topic, produce a tombstone — a record with the user's key and a null value. Log compaction eventually removes all prior records for that key and then drops the tombstone after delete.retention.ms. Deletion is asynchronous, not immediate, and only works per key.
Compare KMS-backed volume encryption versus client-side payload encryption for Kafka: which threats does each address, and when would you mandate both?
basics
~20 sVolume encryption (KMS-backed EBS, LUKS) protects against stolen disks and leaked snapshots but the running broker still sees plaintext. Client-side payload encryption protects PII even from the broker/operator but breaks content-based features and adds key-management cost. Mandate both for regulated PII: defense-in-depth plus operator-proof confidentiality.
Why does a Kafka cluster's ZooKeeper ensemble need to be secured, and what is the risk of leaving it open to unauthenticated access?
basics
~10 sIn ZooKeeper-based Kafka, ZooKeeper stores critical metadata: topic configs, ACLs, SCRAM credentials, and broker registrations. An unauthenticated client can read or delete this metadata directly, bypassing Kafka entirely, so ZooKeeper must require authentication.
In KRaft mode, how do you secure the controller quorum, and why is the controller listener security distinct from the broker's client listeners?
basics
~20 sKRaft controllers form a Raft quorum that replicates the metadata log. You secure their listener (named in controller.listener.names) with its own SSL/SASL entry in listener.security.protocol.map, separate from client listeners, because that channel carries all cluster metadata.
How do you configure SASL and TLS between Kafka brokers and ZooKeeper, and what do zookeeper.set.acl and zookeeper.ssl.client.enable control?
basics
~10 sSASL is set up via a JAAS Client section so brokers authenticate to ZooKeeper. zookeeper.set.acl=true makes Kafka write znodes with restrictive ACLs. zookeeper.ssl.client.enable=true plus keystore/truststore turns on TLS encryption to ZooKeeper.
How are sensitive metadata items like SCRAM credentials and ACLs protected from unauthenticated access in both ZooKeeper-mode and KRaft, and what's the bootstrap challenge for SCRAM in KRaft?
basics
~20 sIn ZK-mode, SCRAM hashes and ACLs live in znodes protected by ZooKeeper ACLs (zookeeper.set.acl) plus SASL/TLS. In KRaft they live in the __cluster_metadata log, protected by securing the controller listener. KRaft's bootstrap challenge: seed the first SCRAM credential with kafka-storage --add-scram.
What are the security implications of migrating a live cluster from ZooKeeper to KRaft, and how do you keep the dual-write/bridge period secure?
basics
~20 sDuring ZK→KRaft migration (KIP-866) both systems run together and metadata is dual-written, so you must keep ZooKeeper hardened (SASL/TLS/ACLs) AND secure the new controller listener at the same time. The migration controllers still connect to ZK, so neither attack surface can be relaxed until ZK is removed.
How do you turn on an audit log of allowed and denied authorization decisions in Apache Kafka, and where does that output go?
basics
~20 sKafka's authorizer writes an audit trail via a dedicated logger named kafka.authorizer.logger. Set that log4j logger to DEBUG to see allowed requests too; at INFO you only see denials. Route it to its own file appender.
A client suddenly can't produce to a topic. How do you tell from monitoring whether it's an authentication failure or an authorization (ACL) denial?
basics
~20 sCheck two different sources. If failed-authentication-total is climbing on that listener, it's an authentication problem (bad cert/credential). If the authorizer log shows a 'Denied' Write line for that principal and topic, it's an ACL/authorization problem. They're surfaced separately.
Which JMX metrics expose failed authentications and SSL/SASL handshake failures on a Kafka broker, and how would you alert on them?
basics
~10 sThe broker exposes per-listener authentication counters under kafka.server:type=socket-server-metrics, including failed-authentication-total / failed-authentication-rate and successful-authentication-total. Scrape them via JMX (e.g. JMX exporter to Prometheus) and alert when the failed rate spikes.
What does Kafka's expired-connections-killed-count metric measure, and which configuration drives it?
basics
~10 sexpired-connections-killed-count counts connections the broker closed because a SASL credential (e.g. an OAuth token or Kerberos ticket) expired and the client did not re-authenticate in time. It is driven by connections.max.reauth.ms (KIP-368).
Design an end-to-end audit pipeline that ships Kafka authorization denials and authentication failures to a central SIEM. What sources do you tap and what are the pitfalls?
basics
~20 sTap two sources: the authorizer audit log (kafka.authorizer.logger, allow/deny lines) and the broker authentication metrics (failed-authentication, expired-connections-killed). Ship logs via a forwarder and metrics via a JMX/Prometheus exporter into the SIEM, normalizing principal, resource, listener, and result.