Repository navigation
fix(backend): default SSL_CERT_FILE to certifi on macOS/Windows - #2289
Open
liujianyeey-oss wants to merge 1 commit into
Open
liujianyeey-oss wants to merge 1 commit into
liujianyeey-oss wants to merge 1 commit into
Conversation
httpcore2 (the OpenAI SDK's HTTP transport) builds its TLS context via truststore on Darwin/Windows, so certificate chains are verified against the OS keychain instead of certifi. The keychain rejects some valid chains (e.g. api.kimi.com via RapidSSL) with errSSLBadCert, breaking all model API calls on affected machines. httpcore2 honors SSL_CERT_FILE with ssl.create_default_context() instead, so default it to certifi's CA bundle at server startup. A user-provided SSL_CERT_FILE always wins.
Author
This branch has not been deployed
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.


问题
macOS 上启动 Octop 后,模型 API 连接测试失败,界面提示「连接模型服务超时或网络异常」,底层错误为
OpenAIConnectionError('Connection error.'),TLS 握手返回 OSStatus -26276(errSSLBadCert)。curl、openssl s_client、标准 httpx(certifi 后端)访问同一地址均正常,只有 Octop 失败。根因
OpenAI SDK 的 HTTP 传输层
httpcore2在创建 SSL context 时,macOS / Windows 上使用truststore(系统钥匙串)替代 certifi 做证书链验证(httpcore2/_ssl.py):macOS 钥匙串对部分合法的证书链验证失败——实测
api.kimi.com(DigiCert Global Root G2 → RapidSSL TLS RSA CA G1 →*.kimi.com,服务器完整下发三张证书)在 openssl 和 certifi 下均验证通过,经 Security framework 验证却返回 errSSLBadCert。于是 macOS 上 Octop 对该 API 的全部 HTTPS 调用都会失败。httpcore2自身留有逃生通道:设置了SSL_CERT_FILE环境变量后会跳过 truststore 分支,走标准ssl.create_default_context(cafile=...)。修复
在
OctopServer.start()启动早期(apply_env_file之后)新增ensure_ssl_cert_file():仅在 macOS / Windows 且用户未自设SSL_CERT_FILE时,将其默认指向 certifi 的 CA 证书包。octop run与 CLI 内嵌服务(如octop provider test)都经过OctopServer.start(),一处生效全覆盖;用户显式配置始终优先。验证
tests/unit/infra/utils/test_ssl_cert_file.py:覆盖 macOS/Windows 默认设置、用户已设置时保留、Linux 不设置、无 certifi 时静默跳过 5 个场景POST /api/admin/providers/1/test报连接错误;修复后返回{"ok": true, "latency_ms": 1783}(截图:修复前连接测试失败弹窗 / 修复后测试通过,见评论区)
PR Checklist