Skip to content

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

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

blink1073 wants to merge 3 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
_extract _async_wrap_socket_tls / _wrap_socket_tls so TLS can be applied
to sockets obtained from a KMS connect callback, and shield the executor
handshake so cancellation cannot orphan the wrapped socket.
Add KMSConnectContext and the kms_connect_callback option to
AutoEncryptionOpts and ClientEncryption so callers can route KMS
connections through an HTTP proxy. The driver performs the KMS TLS
handshake over the returned socket, so verification still targets the
KMS host, and CSOT deadlines cover the callback. For ordinary proxies,
callers can pass the new HTTPProxyKMSConnect or AsyncHTTPProxyKMSConnect
helper instead of writing a callback. Enforce the CSOT deadline across
the proxy tunnel, relay, and TLS handshake, and make the async callback
contract strict: coroutine functions for the async API, plain callables
rejected.
Cover the callback contract, proxy tunnel and relay, CONNECT status
handling, CSOT deadline enforcement, and cancellation safety.

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.

1 participant