This episode covers encryption in Kafka: creating CAs and certificates, keystores and truststores, configuring TLS on brokers and clients, encrypting data in transit, encryption at rest, and certificate management from rotation to expiry monitoring.

SASL authenticates identity, but data passing by can still be read by anyone sniffing the network. For that, Kafka uses TLS/SSL: an encryption protocol that keeps data confidential and intact in transit between clients and brokers, and between brokers.
Episode 18 walks you through setting up the certificate infrastructure — CA, broker and client certificates, keystores and truststores — configuring TLS on both sides, understanding in-transit and at-rest encryption, and certificate management practices like rotation and expiry monitoring.
The standard flow: create a Certificate Authority (CA), then issue a certificate for every broker and client signed by that CA. Using keytool, which ships with the JDK:
keytool -genkeypair -alias ca -keyalg RSA -validity 3650 \
-keystore ca.jks -ext "SAN=dns:kafka-1.internal"
keytool -genkeypair -alias kafka-broker -keyalg RSA -validity 825 \
-keystore broker.jks -ext "SAN=dns:kafka-1.internal"
keytool -certreq -alias kafka-broker -keystore broker.jks -file broker.csr
keytool -gencert -alias ca -keystore ca.jks -infile broker.csr -outfile broker.cer
keytool -importcert -alias ca -keystore broker.jks -file ca.cer
keytool -importcert -alias kafka-broker -keystore broker.jks -file broker.cerkeytool -genkeypair creates a key pair, and keytool -gencert signs the broker CSR with the CA. The CA and broker aliases are stored in separate keystores.
Two key storage concepts:
broker.jks.Create a truststore for all nodes by importing the CA:
keytool -importcert -alias ca -keystore truststore.jks -file ca.cerkeytool -importcert -alias ca adds the CA to the truststore. Brokers need a keystore to present their certificate and a truststore to verify clients; clients need a truststore (and optionally a keystore for mutual TLS).
Enable an SSL listener in server.properties:
listeners=SASL_SSL://:9093
ssl.keystore.location=/etc/kafka/secrets/broker.jks
ssl.keystore.password=${file:/etc/kafka/secrets/pass}
ssl.key.password=${file:/etc/kafka/secrets/pass}
ssl.truststore.location=/etc/kafka/secrets/truststore.jks
ssl.truststore.password=${file:/etc/kafka/secrets/pass}
ssl.client.auth=requiredssl.keystore.location and ssl.truststore.location point to the key storage; passwords are read from files so they aren't written in the configuration. ssl.client.auth=required enables mutual TLS — clients must also present a valid certificate.
Clients verify the broker through a truststore:
security.protocol=SASL_SSL
ssl.truststore.location=/etc/ssl/certs/kafka/truststore.jks
ssl.truststore.password=changeitsecurity.protocol=SASL_SSL enables encryption (plus SASL if combined). With mutual TLS, clients also add their own ssl.keystore.location.
TLS encrypts all communication: client-to-broker and inter-broker. Every byte crossing the network — records, metadata, offsets, control — is secured. This is the basis of all secure production communication. Without TLS, sensitive data can be intercepted on the network path or at a load balancer.
TLS only protects data in motion. For data stored on broker disks, use at-rest encryption:
At-rest encryption is not a replacement for TLS; they handle different threats.
Certificates have a limited validity period. Periodic rotation prevents the use of leaked or expired certificates. The broker rotation process: issue a new certificate, update the keystore, then perform a rolling restart of brokers one by one. For clients, update the truststore before the new CA becomes valid.
The most common TLS failure is a certificate expiring unexpectedly. Automation is key:
Tip
Consider mutual TLS as a replacement for or complement to SASL: the client certificate becomes the identity (principal User:CN=...), so the ACLs from episode 17 can reference certificate identities directly without an additional user database.
In this episode 18 you've understood creating CAs and certificates with keytool, the difference between keystores and truststores, configuring TLS on brokers and clients, in-transit and at-rest data encryption, and certificate management with rotation and monitoring.
The key takeaways:
ssl.client.auth=required enables mutual TLS.In the next episode 19 we'll discuss quotas and rate limiting — limiting writes and reads per user or client-id. You'll learn quota types, configuration at the user and client-id levels, throttling mechanics, and their use for multi-tenancy and SLAs.