Skip to content

feat(certifi): user certifi as a fallback when system store is not present#6231

Open
chenghao-mou wants to merge 2 commits into
mainfrom
chenghao/feat/certifi-fallback
Open

feat(certifi): user certifi as a fallback when system store is not present#6231
chenghao-mou wants to merge 2 commits into
mainfrom
chenghao/feat/certifi-fallback

Conversation

@chenghao-mou

@chenghao-mou chenghao-mou commented Jun 25, 2026

Copy link
Copy Markdown
Member

LLM client uses httpx, which falls back to certifi's CA bundle, while STT/TTS plugins go through a shared aiohttp session that relied solely on the host's system trust store. On hosts without a resolvable system store (minimal containers, distroless images missing ca-certificates), aiohttp-based TLS would fail while the LLM client kept working.

The shared TCPConnector now builds its SSL context to: (1) honor SSL_CERT_FILE / SSL_CERT_DIR env overrides, (2) prefer the system trust store, and (3) fall back to certifi only when no system store is resolvable on disk. This gives consistent TLS trust roots across LLM, STT, and TTS without overriding custom system CAs when a store is present.

@chenghao-mou chenghao-mou requested a review from a team as a code owner June 25, 2026 17:52

@devin-ai-integration devin-ai-integration Bot left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

✅ Devin Review: No Issues Found

Devin Review analyzed this PR and found no bugs or issues to report.

Open in Devin Review

@devin-ai-integration devin-ai-integration Bot left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Devin Review found 1 new potential issue.

Open in Devin Review

Comment on lines +91 to +111
def test_ssl_context_falls_back_to_certifi_without_system_store(
monkeypatch: pytest.MonkeyPatch,
) -> None:
"""When the host has no resolvable system trust store, certifi is loaded."""
monkeypatch.delenv("SSL_CERT_FILE", raising=False)
monkeypatch.delenv("SSL_CERT_DIR", raising=False)
monkeypatch.setattr(
ssl,
"get_default_verify_paths",
lambda: ssl.DefaultVerifyPaths(
cafile="/nonexistent/cert.pem",
capath="/nonexistent/certs",
openssl_cafile_env="SSL_CERT_FILE",
openssl_cafile="/nonexistent/cert.pem",
openssl_capath_env="SSL_CERT_DIR",
openssl_capath="/nonexistent/certs",
),
)

ctx = http_context._create_ssl_context()
assert ctx.cert_store_stats()["x509"] >= _certifi_cert_count()

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🚩 Test for certifi fallback doesn't fully isolate from system store

In test_ssl_context_falls_back_to_certifi_without_system_store, ssl.get_default_verify_paths is monkeypatched to return nonexistent paths, but the ssl.create_default_context() call inside _create_ssl_context() (line 31 of http_context.py) still uses OpenSSL's compiled-in SSL_CTX_set_default_verify_paths at the C level, which is NOT affected by the Python-level monkeypatch. On a host WITH a system store, the context will contain system certs + certifi, making the >= assertion at line 111 pass for the wrong reason (system certs alone might already satisfy it). The test doesn't truly verify the certifi-only fallback path on hosts that have a system store.

Open in Devin Review

Was this helpful? React with 👍 or 👎 to provide feedback.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant