Resolving SSL certificate verify error in ClickHouse
Resolving code 210 SSL certificate verify error in ClickHouse
The error is typically reported as:
Code: 210. DB::NetException: SSL Exception: error:1000007d:SSL routines:OPENSSL_internal:CERTIFICATE_VERIFY_FAILED
Cause of the Error
This error occurs while trying to connect to a ClickHouse server using clickhouse-client. The cause of the error is either:
- the client configuration file
config.xmlis missing the root certificate in the machine CA default store, or - there is a self-signed or internal CA certificate that is not configured
Solution
If using an internal or self-signed CA, configure the CA root certificate in config.xml in the client directory (e.g. /etc/clickhouse-client) and disable the loading of the default root CA certificates from the default location.
Here is an example configuration:
Python clients on macOS
Python clients report this error differently, typically as:
ssl.SSLCertVerificationError: [SSL: CERTIFICATE_VERIFY_FAILED] certificate verify failed: unable to get local issuer certificate
On macOS, the Python build from python.org verifies certificates through OpenSSL's default paths rather than the system keychain. On a fresh install, those paths point to no root certificate bundle: the installer ships certifi but doesn't link it into OpenSSL's default location until you run the bundled Install Certificates.command script. Until then, the client can't validate the ClickHouse Cloud server certificate, even though that certificate is valid. This affects python.org macOS builds generally (Python 3.6 and later), not just Python 3.11.
Run Install Certificates.command to link certifi into OpenSSL's default certificate path (adjust the version in the path to match your install):
Alternatively, point your client at the certifi bundle directly. clickhouse-connect doesn't fall back to certifi on its own, so pass the bundle through the ca_cert parameter:
Additional resources
View https://clickhouse.com/docs/interfaces/cli/#configuration_files