Skip to content

feat(auth): add mTLS helper methods and endpoint configuration for ha…#1

Closed
nbayati wants to merge 1 commit into
remove-pyopenssl-dependencyfrom
implement-python-mtls-helpers
Closed

feat(auth): add mTLS helper methods and endpoint configuration for ha…#1
nbayati wants to merge 1 commit into
remove-pyopenssl-dependencyfrom
implement-python-mtls-helpers

Conversation

@nbayati

@nbayati nbayati commented Jun 17, 2026

Copy link
Copy Markdown
Owner

This PR builds on top of PR googleapis#16976. It provides helper methods to allow custom HTTP and WebSocket connection pools (such as those in google-genai and google-adk) to load default client certificates and resolve the GOOGLE_API_USE_MTLS_ENDPOINT env var. Changes include:

  • Introduced GOOGLE_API_USE_MTLS_ENDPOINT environment variable to control whether an mTLS endpoint should be used (always, never, or auto).
  • Added several new helper functions in google.auth.transport.mtls to facilitate SSL context creation and client certificate loading:
    • load_client_cert_into_context: Loads a client certificate and key into a provided SSL context.
    • make_client_cert_ssl_context: Creates a default SSL context loaded with a specific client certificate and key.
    • load_default_client_cert: Discovers and loads the default client certificate into a provided SSL context if mTLS is enabled.
    • get_default_ssl_context: Returns a default SSL context pre-loaded with the default client certificate, or None if unavailable.
    • should_use_mtls_endpoint: Determines if an mTLS endpoint should be used based on the new environment variable and certificate availability.
  • Fixed outdated docstrings for default_client_cert_source and default_client_encrypted_cert_source to correctly state they raise MutualTLSChannelError instead of DefaultClientCertSourceError.
  • Updated default_client_cert_source to also catch ClientCertError when loading credentials.
  • Added comprehensive unit tests for the new mTLS helper methods.

…ndwritten SDK mTLS support

- Introduced `GOOGLE_API_USE_MTLS_ENDPOINT` environment variable to control whether an mTLS endpoint should be used (`always`, `never`, or `auto`).
- Added several new helper functions in `google.auth.transport.mtls` to facilitate SSL context creation and client certificate loading:
  - `load_client_cert_into_context`: Loads a client certificate and key into a provided SSL context.
  - `make_client_cert_ssl_context`: Creates a default SSL context loaded with a specific client certificate and key.
  - `load_default_client_cert`: Discovers and loads the default client certificate into a provided SSL context if mTLS is enabled.
  - `get_default_ssl_context`: Returns a default SSL context pre-loaded with the default client certificate, or `None` if unavailable.
  - `should_use_mtls_endpoint`: Determines if an mTLS endpoint should be used based on the new environment variable and certificate availability.
- Fixed outdated docstrings for `default_client_cert_source` and `default_client_encrypted_cert_source` to correctly state they raise `MutualTLSChannelError` instead of `DefaultClientCertSourceError`.
- Updated `default_client_cert_source` to also catch `ClientCertError` when loading credentials.
- Added comprehensive unit tests for the new mTLS helper methods.
@nbayati nbayati force-pushed the implement-python-mtls-helpers branch from ab43dea to bc6d2b8 Compare June 17, 2026 17:55
@nbayati

nbayati commented Jun 17, 2026

Copy link
Copy Markdown
Owner Author

closing as the base has to be upstream not my fork and it cannot be changed.

@nbayati nbayati closed this Jun 17, 2026
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