fix(build): configure bundled CA for binary HTTPS#19
Closed
117503445 wants to merge 1 commit into
Closed
Conversation
Signed-off-by: 117503445 <t117503445@gmail.com>
There was a problem hiding this comment.
Pull request overview
This PR ensures PyInstaller-built (frozen) AgentRun CLI binaries automatically use the bundled certifi CA bundle for HTTPS verification by setting SSL_CERT_FILE during frozen startup, while preserving user overrides.
Changes:
- Add a
configure_default_ca_bundle()helper to setSSL_CERT_FILEwhen running as a frozen binary. - Add a PyInstaller runtime hook to invoke the CA setup early in the frozen process lifecycle.
- Add unit tests covering frozen/non-frozen behavior and user-provided overrides; add
certifias a direct dependency.
Reviewed changes
Copilot reviewed 5 out of 5 changed files in this pull request and generated 2 comments.
Show a summary per file
| File | Description |
|---|---|
src/agentrun_cli/_utils/certificates.py |
Implements frozen-binary CA bundle environment setup. |
src/agentrun_cli/_utils/pyinstaller_certifi_hook.py |
PyInstaller runtime hook to apply CA setup on startup. |
agentrun.spec |
Registers the runtime hook so frozen binaries run the CA setup. |
pyproject.toml |
Adds certifi to runtime dependencies. |
tests/unit/test_certificates.py |
Adds unit coverage for frozen-binary CA behavior. |
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
Comment on lines
+11
to
+15
| if not getattr(sys, "frozen", False): | ||
| return | ||
| if os.environ.get("SSL_CERT_FILE"): | ||
| return | ||
| os.environ["SSL_CERT_FILE"] = certifi.where() |
Comment on lines
+16
to
+31
| def test_preserves_user_ssl_cert_file(self, monkeypatch): | ||
| monkeypatch.setattr(certificates.sys, "frozen", True, raising=False) | ||
| monkeypatch.setenv("SSL_CERT_FILE", "/custom/ca.pem") | ||
| monkeypatch.setattr(certificates.certifi, "where", lambda: "/tmp/cacert.pem") | ||
|
|
||
| certificates.configure_default_ca_bundle() | ||
|
|
||
| assert certificates.os.environ["SSL_CERT_FILE"] == "/custom/ca.pem" | ||
|
|
||
| def test_skips_regular_python_runtime(self, monkeypatch): | ||
| monkeypatch.delattr(certificates.sys, "frozen", raising=False) | ||
| monkeypatch.delenv("SSL_CERT_FILE", raising=False) | ||
|
|
||
| certificates.configure_default_ca_bundle() | ||
|
|
||
| assert "SSL_CERT_FILE" not in certificates.os.environ |
Collaborator
Author
|
Closing in favor of #20, which implements the requested simpler business-code approach: default SSL_CERT_FILE to certifi when the user has not set it. |
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.
Summary
certifiCA bundle by defaultSSL_CERT_FILEunchangedRoot Cause
The v0.1.2 standalone binary includes
certifidata, but the frozen runtime does not automatically point Python/OpenSSL at that CA bundle. As a result, the FC TempBucket HTTPS request can fail withCERTIFICATE_VERIFY_FAILEDunless users manually setSSL_CERT_FILE.Validation
.venv/bin/ruff check src/ tests/.venv/bin/ruff format --check src/ tests/.venv/bin/mypy src/agentrun_cli.venv/bin/pytest tests/unit/test_certificates.py tests/unit/test_main.py tests/integration/test_main.py.venv/bin/pytest tests/unit tests/integration(591 passed)make buildSSL_CERT_FILE/REQUESTS_CA_BUNDLE:skill createreturnedCREATING, first poll returnedREADY, then test skill was deleted