Kafka
TLS Verification
Peer Verification
Application Security
Network Protocols

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.

Practice system design

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:

  1. Generate a key store for the Kafka server:
bash
   keytool -keystore kafka.server.keystore.jks -alias localhost -validity 365 -genkey
  1. Create a self-signed certificate for the Kafka server:
bash
1   keytool -keystore kafka.server.keystore.jks -alias localhost -certreq -file cert-file
2   openssl x509 -req -CA ca-cert -CAkey ca-key -in cert-file -out cert-signed -days 365 -CAcreateserial
3   keytool -keystore kafka.server.keystore.jks -alias CARoot -import -file ca-cert
4   keytool -keystore kafka.server.keystore.jks -alias localhost -import -file cert-signed
  1. Configure server properties (server.properties):
properties
1   listeners=SSL://hostname:port
2   ssl.keystore.location=/path/to/kafka.server.keystore.jks
3   ssl.keystore.password=your-keystore-password
4   ssl.key.password=your-key-password
5   ssl.truststore.location=/path/to/kafka.server.truststore.jks
6   ssl.truststore.password=your-truststore-password
7   ssl.client.auth=required

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:

  1. Configure client properties to disable hostname verification and not check the server's CA chain:
java
1   properties.put("security.protocol", "SSL");
2   properties.put("ssl.endpoint.identification.algorithm", ""); // Disables hostname verification
3   properties.put("ssl.truststore.location", "/path/to/client.truststore.jks");
4   properties.put("ssl.truststore.password", "your-truststore-password");
  1. 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

ConfigurationDescriptionSecurity Level
ssl.endpoint.identification.algorithm set to blankDisables hostname verificationLess secure
ssl.truststore.locationPath to the client trust store fileRequired for TLS
ssl.truststore.passwordPassword for accessing trust storeNecessary 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
Course
Beginner
27 lessons
10 hours
System Design Fundamentals

Build a strong foundation in designing scalable, reliable distributed systems.

View the course
Track 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.

Practice system design

All Rights Reserved.