fix(auth): configure mTLS for impersonated credentials#17404
Open
amtk3 wants to merge 3 commits into
Open
Conversation
…resh Adds mTLS configuration to AuthorizedSession instances used in impersonated_credentials.py for `Credentials.sign_bytes` and `IDTokenCredentials.refresh`. This ensures that when impersonating credentials in environments enforcing mTLS, the client certificate is presented during the TLS handshake. Corresponding tests are added to verify this behavior. Co-authored-by: amtk3 <254821816+amtk3@users.noreply.github.com>
Adds mTLS configuration to AuthorizedSession instances used in impersonated_credentials.py for `Credentials.sign_bytes` and `IDTokenCredentials.refresh`. This ensures that when impersonating credentials in environments enforcing mTLS, the client certificate is presented during the TLS handshake. Corresponding tests are added to verify this behavior. Co-authored-by: amtk3 <254821816+amtk3@users.noreply.github.com>
…4737746463131592670 fix(auth): enable mTLS on AuthorizedSession in impersonated credentials
Contributor
There was a problem hiding this comment.
Code Review
This pull request configures mTLS channels on the authorized sessions used during byte signing and ID token refresh operations in impersonated_credentials.py. It also adds corresponding unit tests to verify that configure_mtls_channel is called. No review comments were provided, so there is no feedback to address.
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.
Description
This PR configures
AuthorizedSessionto support mutual TLS (mTLS) when refreshing impersonated ID tokens or signing bytes.Context
When using impersonated credentials (e.g., via
gcloud auth print-identity-token --impersonate-service-account=...) in environments where mTLS is enforced by Context Aware Access (CAA) policies, the requests fail with401 UNAUTHENTICATED(specificallyACCESS_TOKEN_TYPE_UNSUPPORTED).Although the endpoint correctly resolves to the mTLS domain (
iamcredentials.mtls.googleapis.com), the underlyingAuthorizedSessioncreated inimpersonated_credentials.pyis never configured with the client certificate, causing the TLS handshake to lack the required client cert.Changes
google/auth/impersonated_credentials.py:authed_session.configure_mtls_channel()inCredentials.sign_bytesright after the session is created.authed_session.configure_mtls_channel()inIDTokenCredentials.refreshright after the session is created.tests/test_impersonated_credentials.py:test_sign_bytes_configures_mtlsandtest_id_token_refresh_configures_mtlsunit tests to verifyconfigure_mtls_channelis invoked.