confluent-kafka cannot load the CA file set in ssl.ca.location
Your error
KafkaException: KafkaError{code=_INVALID_ARG,val=-186,str="Failed to create consumer: ssl.ca.location failed: ..."}2 more lines it can showFix it fast
Most common cause, 1 of 3The path does not exist where the client runs
Give an absolute path, and make sure the file ships with the app: mount or COPY it into the container, and let the service user read it.
from confluent_kafka import Consumer
consumer = Consumer({
"bootstrap.servers": "broker1:9093",
"security.protocol": "SSL",
"ssl.ca.location": "/etc/kafka/certs/ca.pem",
"group.id": "orders-reader",
})Short answer
Failed to create consumer: ssl.ca.location failed means librdkafka, under confluent-kafka, could not load the CA file you named, so the client is never created. The path is missing from the process's view, or the file is a Java keystore or DER certificate instead of PEM. Use an absolute path to a PEM file. Applies to confluent-kafka 2.16 and librdkafka 2.16.
Which cause do you have?
Ask OpenSSL to read the exact file the config names, running inside the app's own container or host and from its working directory. If it cannot open the file, see cause 1; if it opens but finds no certificate, see cause 2; if it prints a subject, the file loads and cause 3 applies.
openssl x509 -in /path/from/your/config/ca.pem -noout -subject -enddateThen find the line you see in this list and open its fix:
- 1The path does not exist where the client runs
openssl cannot open the file, or ls on the same path from inside the container or service account fails - 2The file is a Java keystore or a DER certificate, not PEM
The file ends in .jks, .p12 or a binary .cer, and its first line is not -----BEGIN CERTIFICATE----- - 3The file loads, but it is not the CA that signed the broker certificate
The client is created, then every connection logs SSL handshake failed with broker certificate could not be verified
What does the error look like?
KafkaException: KafkaError{code=_INVALID_ARG,val=-186,str="Failed to create consumer: ssl.ca.location failed: ..."}Failed to create producer: ssl.ca.location failed:SSL handshake failed: error:0A000086:SSL routines::certificate verify failed: broker certificate could not be verified, verify that ssl.ca.location is correctly configured or root CA certificates are installed (install ca-certificates package)
Cause 1 of 3
The path does not exist where the client runs
You seeopenssl cannot open the file, or ls on the same path from inside the container or service account fails
Check
With security.protocol set to SSL or SASL_SSL, librdkafka hands ssl.ca.location to OpenSSL's SSL_CTX_load_verify_locations while the client is created, and any failure there becomes ssl.ca.location failed. A typo, a relative path that resolves against another working directory, or a certificate that never got copied into the Docker image all end this way.
ls -l /path/from/your/config/ca.pem
python -c "import os; print(os.getcwd(), os.path.isfile('certs/ca.pem'))"Fix
Give an absolute path, and make sure the file ships with the app: mount or COPY it into the container, and let the service user read it.
from confluent_kafka import Consumer
consumer = Consumer({
"bootstrap.servers": "broker1:9093",
"security.protocol": "SSL",
"ssl.ca.location": "/etc/kafka/certs/ca.pem",
"group.id": "orders-reader",
})Verify
The Consumer object is created without an exception and the first poll() reaches the broker.
python consumer.pyConfirmed by raw.githubusercontent.com
Cause 2 of 3
The file is a Java keystore or a DER certificate, not PEM
You seeThe file ends in .jks, .p12 or a binary .cer, and its first line is not -----BEGIN CERTIFICATE-----
Check
OpenSSL expects the CA file to hold certificates in PEM form, each between BEGIN CERTIFICATE and END CERTIFICATE lines. Kafka setups made for Java clients often hand out a JKS truststore, which librdkafka cannot read; its own SSL guide notes that the Java keystore is only for the Java clients.
head -1 /path/from/your/config/ca.pemFix
Export the CA from the truststore as PEM text, or convert a binary DER certificate, and point ssl.ca.location at the new file. Run keytool -list on the truststore first to see the real alias; caroot below is only an example.
# from a Java truststore (asks for the store password)
keytool -exportcert -rfc -alias caroot -keystore kafka.client.truststore.jks -file ca.pem
# from a binary DER certificate
openssl x509 -inform DER -in ca.cer -out ca.pemVerify
head -1 ca.pem prints -----BEGIN CERTIFICATE----- and the client starts.
openssl x509 -in ca.pem -noout -subjectConfirmed by docs.openssl.org
Cause 3 of 3
The file loads, but it is not the CA that signed the broker certificate
You seeThe client is created, then every connection logs SSL handshake failed with broker certificate could not be verified
Check
Once loading works, a wrong CA shows up later as a failed handshake. librdkafka appends a hint to that message asking you to check ssl.ca.location or install root certificates. A private CA needs its own file; brokers with public certificates usually need no ssl.ca.location at all, because the client then uses the system store (Windows Root store, probe on macOS, the ca-certificates package on Linux).
openssl s_client -connect broker1:9093 -CAfile /etc/kafka/certs/ca.pem -verify_return_error </dev/nullFix
Ask the broker admin for the CA certificate that issued the broker certificates, and include any intermediate CA in the same PEM file. For a public-CA broker, remove ssl.ca.location or set it to probe, and install ca-certificates on Linux.
# private CA: one PEM file, intermediate and root concatenated
cat intermediate-ca.pem root-ca.pem > /etc/kafka/certs/ca.pem
# public CA on Linux: rely on the system store
sudo apt-get install ca-certificatesVerify
openssl s_client with -verify_return_error completes the handshake, and the client log no longer shows the verify failure.
openssl s_client -connect broker1:9093 -CAfile /etc/kafka/certs/ca.pem -verify_return_error </dev/nullConfirmed by raw.githubusercontent.com
How do I stop it coming back?
- Build the CA path from an environment variable that holds an absolute path, and fail start-up with a clear message if os.path.isfile() is false.
- Keep a PEM copy of the CA in the same secret as the Java truststore, so non-Java clients never have to convert it during an outage.
- Add an openssl s_client -verify_return_error check against one broker to the deploy pipeline, so a rotated broker certificate shows up before the consumers restart.
Sources
How was this page made?
I drafted this page with AI assistance from the official documents listed under Sources. Every cause above names the document that confirms it. I have not reproduced this fix on a machine of my own yet, so read it as documented guidance, not a test report. Found a mistake? Tell me.
Which stack is behind this page?
Projects of mine on the same stack: stegnor.com, Menulo, ShopGo.