Kafka SSL handshake failed issue
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 distributed streaming platform that facilitates high-throughput, fault-tolerant messaging. It is widely used in microservices architectures to ensure the decoupling of data streams and systems. However, one common problem encountered with it, especially when configuring secure communication channels, is the SSL handshake failure. This article provides a deep dive into the causes, implications, and solutions to the SSL handshake failure in Kafka.
Understanding SSL/TLS Handshake
SSL (Secure Sockets Layer) and its successor, TLS (Transport Layer Security), are protocols that provide communications security over a computer network. During the setup of a TLS connection, a protocol called the "handshake" occurs. This handshake involves:
- The negotiation of the version of TLS.
- Verification of the server and possibly the client with digital certificates.
- The agreement on session-specific keys to be used for encryption.
Common Causes of SSL Handshake Failures in Kafka
SSL handshake failures can occur due to one or several of the following reasons:
- Invalid Certificate: If either the client or server presents a certificate that is not trusted by the other side, the connection will fail.
- Expired Certificate: SSL certificates have an expiration date, and once they reach that date, they are no longer valid.
- Hostname Verification: During the handshake, the hostnames are verified against the certificate. If the actual hostname of the server or client does not match, the SSL handshake fails.
- Unsupported TLS Version: If either the client or server uses a TLS version that the other does not support or is configured to reject, the SSL handshake will fail.
- Cipher Suite Mismatches: The client and server must agree on a cipher suite that they both support. If there's no common cipher suite, the SSL handshake fails.
Diagnosing SSL Handshake Failures
The first step in diagnosing an SSL handshake failure is to look at the logs. Kafka logs SSL events, and these can often provide insights into what might be going wrong. Here's an example command to increase the verbosity of the SSL logs:
You should see logs that detail each step of the handshake process, which can indicate at which stage the process is failing.
Solutions to Resolve SSL Handshake Failures
Here are some general strategies to resolve SSL handshake issues:
- Verify the Certificates: Check that your certificates are valid and trusted by the other party. Ensure they haven't expired and are intended for the correct host.
- Check TLS Versions: Ensure both Kafka broker and clients support the TLS version being used. You might need to upgrade your clients or broker.
- Cipher Suites: Verify that the set of cipher suites enabled in your Kafka configuration matches what the clients support.
- Hostname Verification: Double-check the hostnames on the certificates. Any discrepancy can cause failure, so they must exactly match.
- Network Issues: Sometimes, the SSL handshake issues could be a result of underlying network problems like firewalls blocking ports or corrupting packets.
Useful Configuration Parameters
| Property | Description | Common Values |
ssl.keystore.location | Path to the keystore file | /var/private/ssl/kafka.keystore.jks |
ssl.keystore.password | Password for the keystore | password123 |
ssl.key.password | Password for the key in the keystore | keypassword |
ssl.truststore.location | Path to the truststore file | /var/private/ssl/kafka.truststore.jks |
ssl.truststore.password | Password for the truststore | trustpassword |
ssl.enabled.protocols | Protocols enabled, generally TLS protocols | TLSv1.2,TLSv1.3 |
ssl.endpoint.identification.algorithm | Hostname verification algorithm | https or an empty string to disable |
Conclusion
SSL/TLS configuration and management can be one of the trickier parts of setting up secure communications between Kafka brokers and clients. By understanding what the SSL/TLS handshake involves, what can go wrong, and how to diagnose and fix these issues, system administrators can ensure secure, reliable communication in their Kafka installations.
Related reading
- Kafka standalone error WARN Attempting to send response via channel for which there is no open connection, connection id 0 (kafka.network.Processor)
- Kafka startup fails with zookeeper timeout (remote server), yet the machine can connect to zookeeper directly
- Kafka Static IP and Service Discovery
- Kafka Static membership in AWS ECS
- Kafka stream TopicAuthorizationException Not authorized to access topics for an internal state store
- Kafka TOPIC_AUTHORIZATION_FAILED
- Kafka StickyAssignor breaking delivery to single consumer in the group
- kafka stop consuming message from new assigned partitions after rebalancing

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.