Skip to content

fix(auth): configure mTLS for impersonated credentials#17404

Open
amtk3 wants to merge 3 commits into
googleapis:mainfrom
amtk3:main
Open

fix(auth): configure mTLS for impersonated credentials#17404
amtk3 wants to merge 3 commits into
googleapis:mainfrom
amtk3:main

Conversation

@amtk3

@amtk3 amtk3 commented Jun 9, 2026

Copy link
Copy Markdown
Contributor

Description

This PR configures AuthorizedSession to 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 with 401 UNAUTHENTICATED (specifically ACCESS_TOKEN_TYPE_UNSUPPORTED).

Although the endpoint correctly resolves to the mTLS domain (iamcredentials.mtls.googleapis.com), the underlying AuthorizedSession created in impersonated_credentials.py is never configured with the client certificate, causing the TLS handshake to lack the required client cert.

Changes

  • google/auth/impersonated_credentials.py:
    • Added authed_session.configure_mtls_channel() in Credentials.sign_bytes right after the session is created.
    • Added authed_session.configure_mtls_channel() in IDTokenCredentials.refresh right after the session is created.
  • tests/test_impersonated_credentials.py:
    • Added test_sign_bytes_configures_mtls and test_id_token_refresh_configures_mtls unit tests to verify configure_mtls_channel is invoked.

google-labs-jules Bot and others added 3 commits June 9, 2026 02:06
…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
@amtk3 amtk3 requested review from a team as code owners June 9, 2026 03:31

@gemini-code-assist gemini-code-assist Bot left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

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.

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