Commit 57269d5
fix(auth): configure mTLS for impersonated credentials (#17404)
### 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.
---------
Co-authored-by: google-labs-jules[bot] <161369871+google-labs-jules[bot]@users.noreply.github.com>
Co-authored-by: amtk3 <254821816+amtk3@users.noreply.github.com>1 parent 59fe7cf commit 57269d5Copy full SHA for 57269d5
2 files changed
+45Lines changed: 45 additions & 0 deletions
File tree
Expand file treeCollapse file tree
Open diff view settings
Filter options
- packages/google-auth
- google/auth
- tests
Expand file treeCollapse file tree
Open diff view settings
Collapse file
packages/google-auth/google/auth/impersonated_credentials.py
Copy file name to clipboardExpand all lines: packages/google-auth/google/auth/impersonated_credentials.py+2Lines changed: 2 additions & 0 deletions
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| ||
388 | 388 | |
389 | 389 | |
390 | 390 | |
| 391 | + |
391 | 392 | |
392 | 393 | |
393 | 394 | |
| ||
627 | 628 | |
628 | 629 | |
629 | 630 | |
| 631 | + |
630 | 632 | |
631 | 633 | |
632 | 634 | |
|
Collapse file
packages/google-auth/tests/test_impersonated_credentials.py
Copy file name to clipboardExpand all lines: packages/google-auth/tests/test_impersonated_credentials.py+43Lines changed: 43 additions & 0 deletions
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| ||
639 | 639 | |
640 | 640 | |
641 | 641 | |
| 642 | + |
| 643 | + |
| 644 | + |
| 645 | + |
| 646 | + |
| 647 | + |
| 648 | + |
| 649 | + |
| 650 | + |
| 651 | + |
| 652 | + |
| 653 | + |
| 654 | + |
| 655 | + |
| 656 | + |
| 657 | + |
| 658 | + |
| 659 | + |
| 660 | + |
| 661 | + |
642 | 662 | |
643 | 663 | |
644 | 664 | |
| ||
751 | 771 | |
752 | 772 | |
753 | 773 | |
| 774 | + |
| 775 | + |
| 776 | + |
| 777 | + |
| 778 | + |
| 779 | + |
| 780 | + |
| 781 | + |
| 782 | + |
| 783 | + |
| 784 | + |
| 785 | + |
| 786 | + |
| 787 | + |
| 788 | + |
| 789 | + |
| 790 | + |
| 791 | + |
| 792 | + |
| 793 | + |
| 794 | + |
| 795 | + |
| 796 | + |
754 | 797 | |
755 | 798 | |
756 | 799 | |
|
0 commit comments