SSL/TLS encryption in Kafka - Commands & Configuration
listeners=SSL://:9093 advertised.listeners=SSL://localhost:9093 ssl.keystore.location=/var/private/ssl/kafka.server.keystore.jks ssl.keystore.password=keystorepassword ssl.key.password=keypassword ssl.truststore.location=/var/private/ssl/kafka.server.truststore.jks ssl.truststore.password=truststorepassword security.inter.broker.protocol=SSL ssl.client.auth=required
listeners: Defines Kafka to listen on SSL port 9093.
advertised.listeners: How Kafka advertises its SSL address to clients.
ssl.keystore.location: Path to the broker's keystore file containing its private key and certificate.
ssl.keystore.password and ssl.key.password: Passwords to access the keystore and key.
ssl.truststore.location: Path to truststore containing trusted CA certificates.
ssl.truststore.password: Password for the truststore.
security.inter.broker.protocol: Protocol used between brokers, set to SSL for encrypted communication.
ssl.client.auth: Requires clients to present certificates for authentication.
kafka-server-start.sh /opt/kafka/config/server.properties
kafka-console-producer.sh --broker-list localhost:9093 --topic my-topic --producer.config client-ssl.properties--broker-list - Specifies the Kafka broker address with SSL port--producer.config - Points to SSL configuration for the producer clientkafka-console-consumer.sh --bootstrap-server localhost:9093 --topic my-topic --from-beginning --consumer.config client-ssl.properties--bootstrap-server - Specifies the Kafka broker address with SSL port--consumer.config - Points to SSL configuration for the consumer clientIf you remember nothing else from this pattern, remember: SSL/TLS encrypts Kafka traffic and authenticates clients and brokers using certificates to keep data safe in transit.
Practice
Solution
Step 1: Understand SSL/TLS role in Kafka
SSL/TLS encryption is used to secure data by encrypting communication between Kafka clients and brokers.Step 2: Identify the main benefit
This encryption prevents unauthorized reading or tampering of data during transmission.Final Answer:
To protect data from being read or altered by unauthorized parties -> Option AQuick Check:
SSL/TLS protects data confidentiality and integrity [OK]
- Thinking SSL/TLS improves performance
- Confusing SSL/TLS with offline mode
- Assuming SSL/TLS reduces memory use
Solution
Step 1: Recall Kafka SSL configuration
Kafka uses the propertysecurity.protocolto define the communication protocol, including SSL.Step 2: Verify other options
Properties likessl.enabled,encryption.method, andkafka.sslare not valid Kafka config keys.Final Answer:
security.protocol -> Option AQuick Check:
security.protocol sets SSL usage [OK]
- Using non-existent properties like ssl.enabled
- Confusing encryption.method with Kafka config
- Assuming kafka.ssl is a valid property
security.protocol=SSL ssl.keystore.location=/path/client.keystore.jks ssl.truststore.location=/path/client.truststore.jks
What will happen if the truststore file path is incorrect?
Solution
Step 1: Understand truststore role
The truststore contains certificates to verify the broker's identity. If missing or incorrect, verification fails.Step 2: Predict client behavior on truststore error
Kafka client will fail to establish SSL connection if truststore cannot be loaded or is invalid.Final Answer:
The client will fail to connect due to truststore loading error -> Option DQuick Check:
Incorrect truststore causes connection failure [OK]
- Assuming client connects without encryption
- Thinking client uses default certificates automatically
- Believing connection succeeds with warnings
Solution
Step 1: Check client SSL configuration
Even if broker is configured for SSL, clients must also setsecurity.protocol=SSLto use SSL.Step 2: Understand effect of missing client SSL setting
If clients do not specify SSL, they connect using plaintext, ignoring broker SSL setup.Final Answer:
Clients did not set security.protocol to SSL -> Option BQuick Check:
Client SSL setting required for encrypted connection [OK]
- Assuming broker config alone enforces SSL
- Blaming missing broker keystore without checking client
- Confusing truststore errors with client SSL setting
Solution
Step 1: Understand client authentication in Kafka SSL
To require client authentication, broker must setssl.client.auth=requiredand clients must provide keystore with their certificates.Step 2: Verify correct protocol settings
Both broker and client must usesecurity.protocol=SSLto enable SSL communication.Step 3: Eliminate incorrect options
Options with PLAINTEXT protocol orssl.client.auth=nonedo not enforce client authentication.Final Answer:
Broker: security.protocol=SSL, ssl.client.auth=required; Client: security.protocol=SSL, ssl.keystore.location set -> Option CQuick Check:
Client auth requires ssl.client.auth=required and client keystore [OK]
- Setting broker to PLAINTEXT while client uses SSL
- Not setting ssl.client.auth to required on broker
- Forgetting client keystore for authentication
Ready to prove it?
Pass the test and this pattern moves unknown
