Skip to content

Commit 00eb128

Browse files
authored
fix: disable RAB lookup for Domain-Wide Delegation (#17763)
Updates credentials classes to skip building the Regional Access Boundary lookup URL when Domain-Wide Delegation (DWD) is active, as RAB does not apply to Workspace User Accounts via DWD. Fixes #17703
1 parent fd44326 commit 00eb128

6 files changed

Lines changed: 54 additions & 5 deletions

File tree

packages/google-auth/google/auth/impersonated_credentials.py

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -362,8 +362,12 @@ def _build_regional_access_boundary_lookup_url(
362362
363363
Returns:
364364
Optional[str]: The URL for the Regional Access Boundary lookup endpoint, or None
365-
if the service account email is missing.
365+
if the service account email is missing. Returns None if the subject is populated.
366366
"""
367+
if self._subject:
368+
# RAB does not apply to Workspace User Accounts via Domain-wide Delegation.
369+
return None
370+
367371
if not self.service_account_email:
368372
_LOGGER.error(
369373
"Service account email is required to build the Regional Access Boundary lookup URL for impersonated credentials."

packages/google-auth/google/auth/jwt.py

Lines changed: 11 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -585,7 +585,17 @@ def _perform_refresh_token(self, request):
585585
self.token, self.expiry = self._make_jwt()
586586

587587
def _build_regional_access_boundary_lookup_url(self, request=None):
588-
"""Builds the lookup URL using the service account's email address."""
588+
"""Builds the lookup URL using the service account's email address.
589+
590+
Returns None if the subject is populated.
591+
"""
592+
# In jwt.Credentials, subject defaults to client_email (which is the issuer).
593+
# We must check self._subject != self._issuer to correctly determine if
594+
# Domain-Wide Delegation is active.
595+
if self._subject and self._subject != self._issuer:
596+
# RAB does not apply to Workspace User Accounts via Domain-wide Delegation.
597+
return None
598+
589599
if not self.signer_email:
590600
return None
591601

packages/google-auth/google/oauth2/service_account.py

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -514,8 +514,12 @@ def _build_regional_access_boundary_lookup_url(
514514
515515
Returns:
516516
Optional[str]: The URL for the Regional Access Boundary lookup endpoint, or None
517-
if the service account email is missing.
517+
if the service account email is missing. Returns None if the subject is populated.
518518
"""
519+
if self._subject:
520+
# RAB does not apply to Workspace User Accounts via Domain-wide Delegation.
521+
return None
522+
519523
if not self.service_account_email:
520524
_LOGGER.error(
521525
"Service account email is required to build the Regional Access Boundary lookup URL for service account credentials."

packages/google-auth/tests/oauth2/test_service_account.py

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -290,6 +290,10 @@ def test_build_regional_access_boundary_lookup_url_mtls(self, monkeypatch):
290290
)
291291
assert url == expected_url
292292

293+
def test_build_regional_access_boundary_lookup_url_with_subject(self):
294+
credentials = self.make_credentials().with_subject("user@example.com")
295+
assert credentials._build_regional_access_boundary_lookup_url() is None
296+
293297
def test_with_token_uri(self):
294298
credentials = self.make_credentials()
295299
new_token_uri = "https://example2.com/oauth2/token"

packages/google-auth/tests/test_impersonated_credentials.py

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -759,6 +759,10 @@ def test_build_regional_access_boundary_lookup_url_success_mtls(self, monkeypatc
759759
)
760760
assert url == expected_url
761761

762+
def test_build_regional_access_boundary_lookup_url_with_subject(self):
763+
credentials = self.make_credentials(subject="user@example.com")
764+
assert credentials._build_regional_access_boundary_lookup_url() is None
765+
762766
def test_with_scopes_provide_default_scopes(self):
763767
credentials = self.make_credentials()
764768
credentials._target_scopes = []

packages/google-auth/tests/test_jwt.py

Lines changed: 25 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -559,7 +559,14 @@ def test_build_regional_access_boundary_lookup_url_standard(self, monkeypatch):
559559
# Mock check_use_client_cert to return False to simulate standard TLS
560560
monkeypatch.setattr(_mtls_helper, "check_use_client_cert", lambda: False)
561561

562-
url = self.credentials._build_regional_access_boundary_lookup_url()
562+
credentials = jwt.Credentials(
563+
self.credentials._signer,
564+
self.credentials.signer_email,
565+
self.credentials.signer_email,
566+
self.credentials._audience,
567+
)
568+
569+
url = credentials._build_regional_access_boundary_lookup_url()
563570
expected_url = "https://iamcredentials.googleapis.com/v1/projects/-/serviceAccounts/{}/allowedLocations".format(
564571
self.SERVICE_ACCOUNT_EMAIL
565572
)
@@ -571,12 +578,28 @@ def test_build_regional_access_boundary_lookup_url_mtls(self, monkeypatch):
571578
# Mock check_use_client_cert to return True to simulate mTLS
572579
monkeypatch.setattr(_mtls_helper, "check_use_client_cert", lambda: True)
573580

574-
url = self.credentials._build_regional_access_boundary_lookup_url()
581+
credentials = jwt.Credentials(
582+
self.credentials._signer,
583+
self.credentials.signer_email,
584+
self.credentials.signer_email,
585+
self.credentials._audience,
586+
)
587+
588+
url = credentials._build_regional_access_boundary_lookup_url()
575589
expected_url = "https://iamcredentials.mtls.googleapis.com/v1/projects/-/serviceAccounts/{}/allowedLocations".format(
576590
self.SERVICE_ACCOUNT_EMAIL
577591
)
578592
assert url == expected_url
579593

594+
def test_build_regional_access_boundary_lookup_url_with_subject(self):
595+
credentials = jwt.Credentials(
596+
self.credentials._signer,
597+
self.credentials._issuer,
598+
"user@example.com",
599+
self.credentials._audience,
600+
)
601+
assert credentials._build_regional_access_boundary_lookup_url() is None
602+
580603
def test_cloning_retains_rab_manager_data(self):
581604
self.credentials._rab_manager._data = mock.sentinel.rab_data
582605

0 commit comments

Comments
 (0)