How to use Kafka with TLS peer verification turned off
System Design practice on Codemia
Work through 120+ system design problems with detailed solutions, from rate limiters to multi-region storage.
Apache Kafka is a widely-used event streaming platform designed to handle data feeds in real-time. Security and data integrity are paramount in such systems, especially when they involve sensitive or private information. Transport Layer Security (TLS) can be used to secure data as it moves between clients and the Kafka brokers. By default, Kafka supports mutual authentication to confirm the identity of clients and brokers during the TLS handshake, but there may be scenarios where turning off TLS peer verification on the client side is required or desired.
Understanding TLS in Kafka
TLS (formerly SSL) is critical for protecting the integrity and privacy of data as it moves across networks. In Kafka, TLS can be implemented to not only encrypt data but also to authenticate communicating parties using digital certificates to ensure that the data is sent and received by trusted entities.
Configuring Kafka with TLS Peer Verification Disabled
Disabling TLS peer verification is generally not recommended as it makes the communication susceptible to man-in-the-middle attacks. However, in development environments or for internal testing where security isn't a concern, this configuration can simplify setups.
Kafka Server Setup
First, ensure your Kafka server is set up to use TLS. This involves generating a key store and trust store, then configuring your Kafka server to use these files. Here’s a brief guide on setting up the server:
- Generate a key store for the Kafka server:
- Create a self-signed certificate for the Kafka server:
- Configure server properties (
server.properties):
Kafka Client Setup with TLS Peer Verification Disabled
To disable TLS peer verification on the client side, you can adjust the client's configuration to not verify the server certificate:
- Configure client properties to disable hostname verification and not check the server's CA chain:
- Your client is now configured to trust all certificates presented by servers, which is potential security risk if used in production.
Security Implications
Disabling TLS peer verification removes critical checks that validate the identity of the Kafka broker. This should be avoided in production environments as it exposes clients to potential security risks, such as data interception or manipulation.
Summary Table
| Configuration | Description | Security Level |
ssl.endpoint.identification.algorithm set to blank | Disables hostname verification | Less secure |
ssl.truststore.location | Path to the client trust store file | Required for TLS |
ssl.truststore.password | Password for accessing trust store | Necessary for access |
In conclusion, while disabling TLS peer verification in Kafka can be beneficial for test or development environments to simplify configurations, it significantly reduces security. Always ensure that peer verification is enabled in production environments to protect data integrity and confidentiality.
Related reading
- How to use kafkacat with message-hub
- How to use kafka.group.id and checkpoints in spark 3.0 structured streaming to continue to read from Kafka where it left off after restart?
- How to use multi-thread consumer in kafka 0.9.0?
- How to use priority in celery task.apply_async
- How to use MFA with AWS CLI?
- How to use NSURLConnection to connect with SSL for an untrusted cert?
- How to use Rabbit inside a gitlab-ci.yml file?
- How to use rabbitmqctl to connect to the rabbitmqserver in the docker container?

System Design Fundamentals
Build a strong foundation in designing scalable, reliable distributed systems.
View the courseTrack what you have practised
A free account saves your progress, solutions and study plan across every problem on Codemia.
System Design practice on Codemia
Work through 120+ system design problems with detailed solutions, from rate limiters to multi-region storage.