Skip to content

Conversation

@agrawalradhika-cell
Copy link
Contributor

@agrawalradhika-cell agrawalradhika-cell commented Oct 27, 2025

The Python SDK will use a hybrid approach for mTLS enablement:

  • If the GOOGLE_API_USE_CLIENT_CERTIFICATE environment variable is set (either true or false), the SDK will respect that setting. This is necessary for test scenarios and users who need to explicitly control mTLS behavior.
  • If the GOOGLE_API_USE_CLIENT_CERTIFICATE environment variable is not set, the SDK will automatically enable mTLS only if it detects Managed Workload Identity (MWID) or X.509 Workforce Identity Federation (WIF) certificate sources. In other cases where the variable is not set, mTLS will remain disabled.

** This change also adds the helper method check_use_client_cert and it's unit test, which will be used for checking the criteria for setting the mTLS to true
** This change is only for Auth-Library, other changes will be created for Client-Library use-cases.

@agrawalradhika-cell agrawalradhika-cell marked this pull request as ready for review October 27, 2025 23:56
@agrawalradhika-cell agrawalradhika-cell requested review from a team as code owners October 27, 2025 23:56
@agrawalradhika-cell agrawalradhika-cell changed the title feat: Autoupdate the GOOGLE_API_USE_CLIENT_CERTIFICATE flag to true if not set, if the MWID/X.509 cert sources detected feat: Enable mTLS if GOOGLE_API_USE_CLIENT_CERTIFICATE is not set, if the MWID/X.509 cert sources detected Oct 28, 2025
sai-sunder-s
sai-sunder-s previously approved these changes Oct 28, 2025
sai-sunder-s
sai-sunder-s previously approved these changes Oct 31, 2025
@nbayati nbayati added the kokoro:run Add this label to force Kokoro to re-run the tests. label Nov 1, 2025
@yoshi-kokoro yoshi-kokoro removed the kokoro:run Add this label to force Kokoro to re-run the tests. label Nov 1, 2025
…f not set, if the MWID/X.509 cert sources detected

Signed-off-by: Radhika Agrawal <[email protected]>
Signed-off-by: Radhika Agrawal <[email protected]>
…or updates to docsting and indentation

Signed-off-by: Radhika Agrawal <[email protected]>
…he json and return the exact value set by user, and not handling the case when user is setting value to an unsupported value

Signed-off-by: Radhika Agrawal <[email protected]>
…thod to catch exceptions and update docstring

Signed-off-by: Radhika Agrawal <[email protected]>
@nbayati nbayati added the kokoro:run Add this label to force Kokoro to re-run the tests. label Nov 3, 2025
andyrzhao
andyrzhao previously approved these changes Nov 3, 2025
Copy link
Contributor

@andyrzhao andyrzhao left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM overall. Please address other reviewer's comments. Thanks!

andyrzhao
andyrzhao previously approved these changes Nov 3, 2025
Copy link
Contributor

@andyrzhao andyrzhao left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM. Thanks!

@andyrzhao andyrzhao added the kokoro:run Add this label to force Kokoro to re-run the tests. label Nov 3, 2025
@yoshi-kokoro yoshi-kokoro removed the kokoro:run Add this label to force Kokoro to re-run the tests. label Nov 3, 2025
daniel-sanche
daniel-sanche previously approved these changes Nov 3, 2025
Copy link
Contributor

@daniel-sanche daniel-sanche left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Left a couple suggestions to consider, but LGTM

@nbayati nbayati added the kokoro:run Add this label to force Kokoro to re-run the tests. label Nov 3, 2025
@yoshi-kokoro yoshi-kokoro removed the kokoro:run Add this label to force Kokoro to re-run the tests. label Nov 3, 2025
return crypto.dump_privatekey(crypto.FILETYPE_PEM, pkey)


def check_use_client_cert():
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Please note: That here the function is emitting str instead of boolean because we want to also consider the value set by user for GOOGLE_API_USE_CLIENT_CERTIFICATE

@nbayati nbayati added the kokoro:run Add this label to force Kokoro to re-run the tests. label Nov 4, 2025
@yoshi-kokoro yoshi-kokoro removed the kokoro:run Add this label to force Kokoro to re-run the tests. label Nov 4, 2025
@nbayati nbayati enabled auto-merge (squash) November 4, 2025 00:26
@nbayati nbayati merged commit 395e405 into googleapis:main Nov 4, 2025
12 checks passed
agrawalradhika-cell added a commit that referenced this pull request Nov 5, 2025
… enables mTLS if GOOGLE_API_USE_CLIENT_CERTIFICATE is not set, when the MWID/X.509 cert sources detected (#1859)

Add public wrapper for check_use_client_cert which enables mTLS if
GOOGLE_API_USE_CLIENT_CERTIFICATE is not set, when the MWID/X.509 cert
sources detected. Also, fix check_use_client_cert to return boolean
value.

Change #1848 added the check_use_client_cert method that helps know if
client cert should be used for mTLS connection. However, that was in a
private class, thus, created a public wrapper of the same function so
that it can be used by python Client Libraries. Also, updated
check_use_client_cert to return a boolean value instead of existing
string value for better readability and future scope.

---------

Signed-off-by: Radhika Agrawal <[email protected]>
Co-authored-by: Daniel Sanche <[email protected]>
Linchin added a commit that referenced this pull request Nov 5, 2025
Librarian Version: v0.5.0
Language Image:
us-central1-docker.pkg.dev/cloud-sdk-librarian-prod/images-prod/python-librarian-generator:latest
<details><summary>google-auth: 2.43.0</summary>

##
[2.43.0](v2.42.1...v2.43.0)
(2025-11-05)

### Features

* Add public wrapper for _mtls_helper.check_use_client_cert which
enables mTLS if GOOGLE_API_USE_CLIENT_CERTIFICATE is not set, when the
MWID/X.509 cert sources detected (#1859)
([1535ecc](1535eccb))

* Enable mTLS if GOOGLE_API_USE_CLIENT_CERTIFICATE is not set, if the
MWID/X.509 cert sources detected (#1848)
([395e405](395e405b))

* onboard `google-auth` to librarian (#1838)
([c503eaa](c503eaa5))

</details>
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.

6 participants