Add configurable TLS verification for all HTTP transports#43
Open
arseniy-pplx wants to merge 1 commit into
Open
Add configurable TLS verification for all HTTP transports#43arseniy-pplx wants to merge 1 commit into
arseniy-pplx wants to merge 1 commit into
Conversation
Introduce a single TLS verification contract shared by the requests client, the httpx schema/operation transport, and the dynamic-discovery client. TANGLE_API_CA_BUNDLE verifies against a custom CA bundle and TANGLE_API_VERIFY_TLS toggles verification, with verification enabled by default. Precedence is explicit argument, CA bundle, verify flag, then the secure default; unset settings preserve requests' environment and caller-supplied session behavior.
arseniy-pplx
marked this pull request as ready for review
July 20, 2026 18:10
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
Adds global, process-wide TLS verification controls to the CLI so a single trust policy applies uniformly across every HTTP transport: the static
requestsclient, the dynamichttpxoperation requests, and the OpenAPI schema fetch/refresh that runs during command construction.Two global options are accepted before any subcommand:
--ca-bundle PATH— use a PEM CA bundle as the TLS trust store.--verify-tls/--no-verify-tls— enable or disable certificate verification. Absence is an unset sentinel (not implicitTrue), so it does not override environment configuration.Resolution is centralized in
api_transport.resolve_verify(). Precedence: explicit Pythonverify=argument > global CLI flags >TANGLE_API_CA_BUNDLE>TANGLE_API_VERIFY_TLS> secure default. A defaulted (absent) flag never overrides the environment.Context
The schema discovery that builds the dynamic
apicommands runs before normal Cyclopts dispatch, so the global flags are pre-parsed fromargvinbuild_app()and installed viaconfigure_cli_verify()before theapiapp is constructed. This makes the chosen trust policy reach even the pre-dispatch network call, without threading averifyargument through every call site.Validation happens before any network request: an invalid, missing, or directory
--ca-bundlepath fails fast with one concise error;--ca-bundlecombined with an explicit--no-verify-tlsis rejected as contradictory, while--ca-bundlewith--verify-tlsis redundant but accepted.--no-verify-tls(andTANGLE_API_VERIFY_TLS=0) is for local development only and intentionally preserves the urllib3InsecureRequestWarning. The root help and README document the flags, environment variables, full precedence, accepted placement (before the subcommand), examples, and the security warning.Testing
uv run pytest tests/test_tls_verification.py tests/test_packaging.pyconfigure_cli_verifyprecedence/conflict/invalid-CA/reset; argv pre-parse and stop-at-subcommand; override propagation to the static client,request_operation, andfetch_schema; real-HTTPS private-CA success, default-trust failure, and verify-off success for the schema/dynamic/requests paths; and CLI subprocess tests forapi refreshunder CA-bundle / default / no-verify, the ca-bundle+no-verify conflict, and root help listing the global flagsuvx ruff checkon the touched filesuv lock --check;uv build; CLI smoke checkgit diff --check