Repository navigation
Verify TLS servers against Julia's CA roots by default - #168
Merged
Merged
Conversation
TLS URIs without tlsCAFile should verify server certificates against NetworkOptions.ca_roots_path(). Without that default, libmongoc's OpenSSL looks under the JLL build prefix and finds no CA certificates. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
libmongoc's OpenSSL uses the CA paths compiled into OpenSSL_jll, which point at the BinaryBuilder prefix (/workspace/destdir/ssl). TLS connections from Linux and macOS therefore fail with "certificate verify failed" unless the user sets tlsCAFile or SSL_CERT_FILE. When a URI enables TLS and has no tlsCAFile, set it to NetworkOptions.ca_roots_path() if that is a file. Windows keeps libmongoc's system certificate store. Fixes #69 Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Codecov Report✅ All modified and coverable lines are covered by tests. Additional details and impacted files@@ Coverage Diff @@
## master #168 +/- ##
==========================================
+ Coverage 85.30% 85.84% +0.54%
==========================================
Files 11 11
Lines 1660 1674 +14
==========================================
+ Hits 1416 1437 +21
+ Misses 244 237 -7 ☔ View full report in Codecov by Harness. 🚀 New features to boost your workflow:
|
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Why
On Linux and macOS, TLS connections fail with
certificate verify failedunless the user addstlsCAFile=...to the URI or setsSSL_CERT_FILE(#69). This affects every MongoDB Atlas user, becausemongodb+srv://turns TLS on. The cause: libmongoc's OpenSSL looks for CA certificates under the directory compiled into OpenSSL_jll,/workspace/destdir/ssl. That is the BinaryBuilder build prefix, and it does not exist on users' machines. On Windows, libmongoc reads the system certificate store, so Windows is not affected.What changed
mongodb+srv://) and does not settlsCAFile,Mongoc.URIsetstlsCAFiletoNetworkOptions.ca_roots_path(). Julia's other network clients (Downloads, LibGit2) use the same CA roots, andJULIA_SSL_CA_ROOTS_PATHoverrides them.ClientandClientPoolboth build onURI, so both get the default. TheClientdocstring describes it.Scope
tlsCAFile, including the legacysslCertificateAuthorityFile, is kept as given.ca_roots_path()is a directory (the user setSSL_CERT_DIR), the URI is unchanged. OpenSSL already reads that variable.Blast Radius
The change applies only to TLS URIs on Linux, macOS, and FreeBSD. Those connections failed before unless the user set
tlsCAFileorSSL_CERT_FILE, and both of those still work the same way. Project.toml adds the NetworkOptions stdlib to[deps]. That line is next to theOrderedCollectionsline that #152 adds, so whichever PR merges second has a one-line conflict: keep both lines.Verification
?tls=true, notlsCAFile). On master, it fails withcertificate verify failed (20): unable to get local issuer certificate(macOS arm64 and Linux arm64 Docker). On this branch, the handshake succeeds and fails later withInvalid reply from server, because that server does not speak MongoDB.--tlsMode requireTLSand a test CA, withJULIA_SSL_CA_ROOTS_PATHset to that CA. On master,pingfails certificate verification. On this branch,pingreturnsokfor bothClientandClientPool. WithtlsAllowInvalidCertificates=trueit still connects, and an explicittlsCAFilestill wins.SSL_CERT_DIR=/etc/ssl/certs, the handshake succeeds on both master and this branch.Fixes #69
🤖 Generated with Claude Code