Fix SSL cert verification failures behind enterprise inspection proxies#168
Open
edurdevic wants to merge 1 commit into
Open
Fix SSL cert verification failures behind enterprise inspection proxies#168edurdevic wants to merge 1 commit into
edurdevic wants to merge 1 commit into
Conversation
Python's urllib does not load the OS trust store on all platforms, so workspaces behind a corporate TLS inspection proxy (which injects a self-signed CA) fail with CERTIFICATE_VERIFY_FAILED even though curl succeeds. Honor REQUESTS_CA_BUNDLE, CURL_CA_BUNDLE, and SSL_CERT_FILE — the same env vars respected by curl and the requests library — so customers can point ucode at their enterprise CA bundle. Co-authored-by: Isaac
rohita5l
reviewed
Jun 18, 2026
| ctx.load_verify_locations(cafile=ca_bundle) | ||
| except ssl.SSLError: | ||
| pass | ||
| break |
Collaborator
There was a problem hiding this comment.
Bug — break fires even when load_verify_locations fails (_make_ssl_context, line ~214)
try:
ctx.load_verify_locations(cafile=ca_bundle)
except ssl.SSLError:
pass
break # ← outside try/except, always executes
rohita5l
reviewed
Jun 18, 2026
| _debug(f"databrickscfg ({cfg_path})", f"read error: {exc}") | ||
|
|
||
|
|
||
| def _make_ssl_context() -> ssl.SSLContext: |
Collaborator
There was a problem hiding this comment.
Minor — _make_ssl_context() called on every request, should be cached
It hits the env vars + filesystem on every urlopen call. The rest of the file already uses @functools.cache for this pattern. Adding @functools.cache makes it a one-shot per process.
rohita5l
reviewed
Jun 18, 2026
| try: | ||
| ctx.load_verify_locations(cafile=ca_bundle) | ||
| except ssl.SSLError: | ||
| pass |
Collaborator
There was a problem hiding this comment.
OSError (e.g. permission denied) is not caught here — Path.is_file() returns True for files the current user cannot read, but load_verify_locations will then raise OSError: Permission denied, which propagates uncaught and crashes the process.
Suggest broadening the except catch
rohita5l
requested changes
Jun 18, 2026
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.
Problem
ucode initfails withCERTIFICATE_VERIFY_FAILED: self-signed certificate in certificate chainon networks with a corporate TLS inspection proxy, even thoughcurlto the same AI Gateway endpoint succeeds.Root cause: Python's
urllib.request.urlopendoes not load the OS trust store on all platforms. The proxy injects a self-signed CA thatcurlfinds via the system keychain, but Python's default SSL context misses it. The error surfaces as:Fix
Add
_make_ssl_context()indatabricks.pythat creates a default SSL context and additionally loads any CA bundle pointed to byREQUESTS_CA_BUNDLE,CURL_CA_BUNDLE, orSSL_CERT_FILE— the same env vars honored bycurland therequestslibrary. All threeurlopencall sites (_http_get_json,_http_post_json,discover_sql_warehouse_http_path) now use this context.Workaround for affected customers (before this ships)
export REQUESTS_CA_BUNDLE=/path/to/enterprise-ca.pem ucode initTest plan
uv run pytest)uv run ruff check .+uv run ruff format --check)This pull request and its description were written by Isaac.