Skip to content

PYTHON-5805 CSFLE/QE Support for HTTP Proxies - #24

Draft
blink1073 wants to merge 26 commits into
mainfrom
PYTHON-5805
Draft

blink1073 wants to merge 26 commits into
mainfrom
PYTHON-5805

Conversation

@blink1073

@blink1073 blink1073 commented Sep 8, 2026 •

Copy link
Copy Markdown
Owner

PYTHON-5805

Changes in this PR

Lets CSFLE and Queryable Encryption route KMS traffic through an HTTP proxy via a user-supplied connect callback, while still performing the KMS TLS handshake end to end against the KMS host.

  • Adds kms_connect_callback to AutoEncryptionOpts, ClientEncryption, and AsyncClientEncryption, plus a KMSConnectContext.
  • Adds HTTPProxyKMSConnect/AsyncHTTPProxyKMSConnect helpers.
  • Adds internal tests and the required prose tests.
  • Splits TLS wrapping out of the connect helpers in pymongo/pool_shared.py, leaving existing connection paths unchanged.

Test Plan

Ran the encryption prose suite against the drivers-evergreen-tools proxies: 10 passed, 2 skipped. just lint, just typing, and just docs clean.

Checklist

Checklist for Author

  • Did you update the changelog (if necessary)?
  • Is there test coverage?
  • Is any followup work tracked in a JIRA ticket? If so, add link(s).

Checklist for Reviewer

  • Does the title of the PR reference a JIRA Ticket?
  • Do you fully understand the implementation? (Would you be comfortable explaining how this code works to someone else?)
  • Is all relevant documentation (README or docstring) updated?

Comment thread pymongo/asynchronous/encryption.py
Comment thread pymongo/asynchronous/encryption.py Outdated
Comment thread pymongo/asynchronous/encryption.py Outdated
Comment thread doc/changelog.rst Outdated
Comment thread pymongo/encryption_options.py Outdated
Comment thread pymongo/encryption_options.py Outdated
Comment thread pymongo/encryption_options.py Outdated
Comment thread pymongo/encryption_options.py Outdated
Comment thread pymongo/encryption_options.py Outdated
Comment thread pymongo/encryption_options.py Outdated
@blink1073
blink1073 force-pushed the PYTHON-5805 branch 2 times, most recently from d6ea9c2 to 47e250c Compare September 25, 2026 13:44
dependabot Bot and others added 14 commits September 25, 2026 09:13
Signed-off-by: dependabot[bot] <support@github.com>
Co-authored-by: dependabot[bot] <49699333+dependabot[bot]@users.noreply.github.com>
…odb#3051)

Co-authored-by: Copilot Autofix powered by AI <175728472+Copilot@users.noreply.github.com>
Co-authored-by: Jeffrey 'Alex' Clark <aclark@aclark.net>
Co-authored-by: mongodb-drivers-pr-bot[bot] <147046816+mongodb-drivers-pr-bot[bot]@users.noreply.github.com>
Co-authored-by: Steven Silvester <steve.silvester@mongodb.com>
…k into _AgnosticClientBulkBase/_AgnosticBulkBase (mongodb#3087)
Add a kms_connect_callback option to AutoEncryptionOpts,
ClientEncryption, and AsyncClientEncryption. The callable receives a
KMSConnectContext (host, port, timeout) and returns a connected,
unwrapped socket over which the driver performs the KMS TLS handshake,
so verification still targets the KMS host rather than the peer
reached. This enables routing KMS requests through custom channels
such as proxies.

Split TLS wrapping out of the configured socket helpers so the
callback path reuses it, and shield the async wrap so a cancelled or
timed-out wait still closes a late-produced socket.
- Add a regression test that the KMS TLS handshake verifies against the
  KMS address, not the callback's connected peer.
- Drop the stale prose-test references in test_encryption.py comments;
  prose tests moved with the PYTHON-6147 split.
- Correct the KMSConnectContext.timeout docstring: it is the default KMS
  connect timeout capped by any active operation timeout.
Extract the repeated listener/socketpair setup, TLS context construction,
and the flavor-aware run-blocking wrapper into shared helpers, and collapse
the fixed-value callbacks into a factory.
The synchronous API waits for the callback without enforcing the CSOT
deadline; state the flavor-neutral contract instead (callback honors
context.timeout). Addresses Copilot review discussion_r4185118746.

This branch has not been deployed

No deployments
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.

2 participants