You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
Repository navigation
SSL routines:tls_process_server_certificate:certificate verify failed when trying to connect to MongoDB Atlas #69
after some debugging, it seems like the OpenSSL artifact that Mongoc uses doesn't come with certificates. specifying the certificate dir via env variable seems to solve the issue
export SSL_CERT_DIR=/etc/ssl/certs/
but it's kind of not intuitive.
I guess it should either use the system certificates by default, or at least raise some error when it can't find any.
Reacted by Extra Dosages, Christian Rorvik and Felix Benning
Heads-up, the fix of manually setting SSL_CERT_DIR=/etc/ssl/certs/ Seems to be getting in the way of some of Julia's package-repository API (i.e. Pkg). Needing to use Mongoc to connect to Atlas and also needing to add certain updated packages has thus become untenable. There might be a second-order fix, but I don't really know anything about SSL so I can't help out there.
This worked perfectly for me. Thanks @ancapdev for posting.
For example on a Mac setup with julia...
$ brew install openssl
$ ls /usr/local/etc/openssl/cert.pem
$ julia
] add Mongoc
julia> using Mongoc
julia> suffix = "&tlsCAFile=/usr/local/etc/openssl/cert.pem" # or use "?tlsCAFile=" if you don't have any other params already
julia> mongo_uri = "mongodb://myDBReader:D1fficultP%40ssw0rd@mongodb0.example.com:27017/?authSource=admin"
julia> client = Mongoc.Client(mongo_uri*suffix)
julia> collect(Mongoc.find_databases(client))
The CA cert file on Monterey seems to have moved over to /etc/ssl/cert.pem, so you need to use export SSL_CERT_FILE=/etc/ssl/cert.pem on Monterey in able to get it to work.
Maybe -- I'm not sure exactly what I'd say there since I don't quite understand the problem here. What certificates are used if not the ones in /etc/ssl/certs?
Root cause: libmongoc's OpenSSL looks for CA certificates in the directory compiled into OpenSSL_jll, /workspace/destdir/ssl. That path is on the build machine, so on Linux and macOS libmongoc has no CA certificates by default. On Windows, libmongoc reads the system certificate store instead, so Windows is not affected.
I checked this with Mongoc 0.10.2 and libmongoc 1.30.8 on macOS and Linux. A TLS URI without tlsCAFile fails with certificate verify failed (20): unable to get local issuer certificate. This works today, and uses the same CA bundle as Julia's package manager:
SSL_CERT_FILE or SSL_CERT_DIR also work, because OpenSSL reads them.
#168 makes this the default. When a TLS URI does not set tlsCAFile, Mongoc uses NetworkOptions.ca_roots_path(). To use other CA certificates, set JULIA_SSL_CA_ROOTS_PATH or tlsCAFile.
Activity
felipenoris commentedon Jun 23, 2020
@quatrix thanks for reporting! Can you check if the same error happens on version 0.4.2 of this package?
quatrix commentedon Jun 24, 2020
@felipenoris thanks for the quick reply!
yes, same error with
0.4.2extradosages commentedon Jul 10, 2020
I can confirm that this is a problem for us as well.
extradosages commentedon Sep 3, 2020
Heads-up, the fix of manually setting
SSL_CERT_DIR=/etc/ssl/certs/Seems to be getting in the way of some of Julia's package-repository API (i.e.Pkg). Needing to use Mongoc to connect to Atlas and also needing to add certain updated packages has thus become untenable. There might be a second-order fix, but I don't really know anything about SSL so I can't help out there.ancapdev commentedon Aug 16, 2021
I found you can configure this in the connection string with the
tlsCAFileoption, e.g.,SSL_CERT_FILEenvironment variable also works, but I'm not sure if that interferes with the Julia package manager same asSSL_CERT_DIR.peteristhegreat commentedon Oct 19, 2021
This worked perfectly for me. Thanks @ancapdev for posting.
For example on a Mac setup with julia...
Additional references:
Also solves the similar ticket:
ResRipper commentedon Aug 10, 2022
I also had a similar issue while trying to connect to Azure Cosmos DB on macOS Monterey, with Mongoc
v0.8.0:The CA cert file on Monterey seems to have moved over to
/etc/ssl/cert.pem, so you need to useexport SSL_CERT_FILE=/etc/ssl/cert.pemon Monterey in able to get it to work.edyu commentedon May 4, 2023
Still same problem using WSL2. The workarounds don't work.
The following is from
Mongoc.ping(client)Also when adding to the end of URI:
edyu commentedon May 4, 2023
Ok. I do need to export the environment variable instead of passing via the URI.
edyu commentedon May 4, 2023
I found that I cannot pass it via URI but can do so via environment variable as of 0.9.0
just-cameron commentedon Aug 28, 2023
For folks running into this issue, I was able to address this within Julia by adding
to my code. Alternatively, setting the environment variable as normal works:
felipenoris commentedon Aug 28, 2023
Anything worth mentioning in the docs about this issue?
just-cameron commentedon Aug 31, 2023
Maybe -- I'm not sure exactly what I'd say there since I don't quite understand the problem here. What certificates are used if not the ones in
/etc/ssl/certs?quinnj-bot commentedon Nov 19, 2026
[comment generated via AI]
Root cause: libmongoc's OpenSSL looks for CA certificates in the directory compiled into OpenSSL_jll,
/workspace/destdir/ssl. That path is on the build machine, so on Linux and macOS libmongoc has no CA certificates by default. On Windows, libmongoc reads the system certificate store instead, so Windows is not affected.I checked this with Mongoc 0.10.2 and libmongoc 1.30.8 on macOS and Linux. A TLS URI without
tlsCAFilefails withcertificate verify failed (20): unable to get local issuer certificate. This works today, and uses the same CA bundle as Julia's package manager:SSL_CERT_FILEorSSL_CERT_DIRalso work, because OpenSSL reads them.#168 makes this the default. When a TLS URI does not set
tlsCAFile, Mongoc usesNetworkOptions.ca_roots_path(). To use other CA certificates, setJULIA_SSL_CA_ROOTS_PATHortlsCAFile.