Repository navigation
fix(auth): require explicit googleapis.com for RAB lookups #19208
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: main
Are you sure you want to change the base?
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change | ||||
|---|---|---|---|---|---|---|
|
|
@@ -38,6 +38,19 @@ | |||||
|
|
||||||
| DEFAULT_UNIVERSE_DOMAIN = _helpers.DEFAULT_UNIVERSE_DOMAIN | ||||||
|
|
||||||
|
|
||||||
| def _get_explicit_universe_domain(creds): | ||||||
| """Returns the explicitly configured universe domain from creds, or None.""" | ||||||
| # Read public universe_domain first so lazy credentials (such as Compute | ||||||
| # Engine) resolve metadata before we inspect _universe_domain. | ||||||
| universe_domain = getattr(creds, "universe_domain", DEFAULT_UNIVERSE_DOMAIN) | ||||||
| if universe_domain and universe_domain != DEFAULT_UNIVERSE_DOMAIN: | ||||||
| return universe_domain | ||||||
| if isinstance(creds, Credentials): | ||||||
| return getattr(creds, "_universe_domain", None) | ||||||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Can we do this, to avoid empty strings?
Suggested change
|
||||||
| return None | ||||||
|
|
||||||
|
|
||||||
| # These constants are deprecated and no longer used. | ||||||
| # They are kept solely for backward compatibility with older implementations. | ||||||
| NO_OP_TRUST_BOUNDARY_LOCATIONS: List[str] = [] | ||||||
|
|
@@ -77,8 +90,9 @@ def __init__(self): | |||||
| """Optional[dict]: Cache of a trust boundary response which has a list | ||||||
| of allowed regions and an encoded string representation of credentials | ||||||
| trust boundary.""" | ||||||
| self._universe_domain = DEFAULT_UNIVERSE_DOMAIN | ||||||
| """Optional[str]: The universe domain value, default is googleapis.com | ||||||
| self._universe_domain = None | ||||||
| """Optional[str]: The explicitly configured universe domain, or None | ||||||
| if omitted. | ||||||
| """ | ||||||
|
|
||||||
| self._use_non_blocking_refresh = False | ||||||
|
|
@@ -144,7 +158,7 @@ def quota_project_id(self): | |||||
| @property | ||||||
| def universe_domain(self): | ||||||
| """The universe domain value.""" | ||||||
| return self._universe_domain | ||||||
| return getattr(self, "_universe_domain", None) or DEFAULT_UNIVERSE_DOMAIN | ||||||
|
|
||||||
| def get_cred_info(self): | ||||||
| """The credential information JSON. | ||||||
|
|
@@ -503,9 +517,14 @@ def _is_regional_access_boundary_lookup_required(self): | |||||
| if not _regional_access_boundary_utils.is_regional_access_boundary_lookup_enabled(): | ||||||
| return False | ||||||
|
|
||||||
| # Skip for non-default universe domains. | ||||||
| # Skip unless the universe domain is explicitly confirmed to be | ||||||
| # googleapis.com. Checking self.universe_domain first lets lazy | ||||||
| # subclasses (such as Compute Engine) resolve metadata before we | ||||||
| # inspect _universe_domain. | ||||||
| if self.universe_domain != DEFAULT_UNIVERSE_DOMAIN: | ||||||
| return False | ||||||
| if getattr(self, "_universe_domain", None) != DEFAULT_UNIVERSE_DOMAIN: | ||||||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. nit: It feels a little risky to have an under-documented, private attribute doing such an important job here. Subclasses could implement their own version of universe_domain, and not realize they're silently skipping RAB lookups Maybe we should have a separate thin |
||||||
| return False | ||||||
|
|
||||||
| return True | ||||||
|
|
||||||
|
|
||||||
| Original file line number | Diff line number | Diff line change | ||||
|---|---|---|---|---|---|---|
|
|
@@ -95,7 +95,7 @@ def __init__( | |||||
| enable_reauth_refresh=False, | ||||||
| granted_scopes=None, | ||||||
| trust_boundary=None, | ||||||
| universe_domain=credentials.DEFAULT_UNIVERSE_DOMAIN, | ||||||
| universe_domain=None, | ||||||
| account=None, | ||||||
| ): | ||||||
| """ | ||||||
|
|
@@ -162,7 +162,7 @@ def __init__( | |||||
| self.refresh_handler = refresh_handler | ||||||
| self._enable_reauth_refresh = enable_reauth_refresh | ||||||
| self._trust_boundary = trust_boundary | ||||||
| self._universe_domain = universe_domain or credentials.DEFAULT_UNIVERSE_DOMAIN | ||||||
| self._universe_domain = universe_domain or None | ||||||
| self._account = account or "" | ||||||
| self._cred_file_path = None | ||||||
|
|
||||||
|
|
@@ -200,9 +200,7 @@ def __setstate__(self, d): | |||||
| self._rapt_token = d.get("_rapt_token") | ||||||
| self._enable_reauth_refresh = d.get("_enable_reauth_refresh") | ||||||
| self._trust_boundary = d.get("_trust_boundary") | ||||||
| self._universe_domain = ( | ||||||
| d.get("_universe_domain") or credentials.DEFAULT_UNIVERSE_DOMAIN | ||||||
| ) | ||||||
| self._universe_domain = d.get("_universe_domain") or None | ||||||
| self._cred_file_path = d.get("_cred_file_path") | ||||||
| # The refresh_handler setter should be used to repopulate this. | ||||||
| self._refresh_handler = None | ||||||
|
|
@@ -380,14 +378,14 @@ def _is_regional_access_boundary_lookup_required(self): | |||||
| return False | ||||||
|
|
||||||
| def _perform_refresh_token(self, request): | ||||||
| if self._universe_domain != credentials.DEFAULT_UNIVERSE_DOMAIN: | ||||||
| if self.universe_domain != credentials.DEFAULT_UNIVERSE_DOMAIN: | ||||||
| raise exceptions.RefreshError( | ||||||
| "User credential refresh is only supported in the default " | ||||||
| "googleapis.com universe domain, but the current universe " | ||||||
| "domain is {}. If you created the credential with an access " | ||||||
| "token, it's likely that the provided token is expired now, " | ||||||
| "please update your code with a valid token.".format( | ||||||
| self._universe_domain | ||||||
| self.universe_domain | ||||||
| ) | ||||||
| ) | ||||||
|
|
||||||
|
|
@@ -565,7 +563,7 @@ def to_json(self, strip=None): | |||||
| "client_secret": self.client_secret, | ||||||
| "scopes": self.scopes, | ||||||
| "rapt_token": self.rapt_token, | ||||||
| "universe_domain": self._universe_domain, | ||||||
| "universe_domain": self.universe_domain, | ||||||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Using
Suggested change
Contributor
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Kept |
||||||
| "account": self._account, | ||||||
| } | ||||||
| if self.expiry: # flatten expiry timestamp | ||||||
|
|
||||||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
nit: I feel like this could use some more elaboration. I missed at first that
universe_domainand_universe_domainwere differentMaybe something like: