Skip to content

fix(auth): propagate top-level universe_domain in impersonated creds - #19221

Merged
ohmayr merged 2 commits into
mainfrom
fix/auth-impersonated-url-host
Nov 30, 2026
Merged

ohmayr merged 2 commits into
mainfrom
fix/auth-impersonated-url-host

Conversation

@ohmayr

@ohmayr ohmayr commented Nov 25, 2026 •

Copy link
Copy Markdown
Contributor

Context & Problem

impersonated_credentials.Credentials.from_impersonated_service_account_info() ignored a top-level universe_domain field and delegated _universe_domain solely to source_credentials. When source_credentials omitted universe_domain, impersonated credentials defaulted to googleapis.com and sent source tokens to iamcredentials.googleapis.com.

Summary of Changes

  • Add an optional universe_domain parameter to impersonated_credentials.Credentials.__init__() in packages/google-auth/google/auth/impersonated_credentials.py (validated via _helpers.validate_universe_domain() and compared against source_credentials.universe_domain via _helpers.compare_universe_domains() from chore(auth): add compare_universe_domains helper in _helpers #19220) and forward it in _make_copy().
  • Propagate top-level universe_domain into a shallow copy of source_credentials_info in from_impersonated_service_account_info() when the nested source config omits it, without mutating caller input.
  • Add unit tests in packages/google-auth/tests/test_impersonated_credentials.py.

Verification

  • ruff check, ruff check --select I, ruff format --check, and mypy --config-file=../../mypy.ini passed with zero issues.
  • pytest passed (470 passed) with 100% statement and branch coverage on google/auth/impersonated_credentials.py.

b/589828921

@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 introduces validation and parsing of the service_account_impersonation_url within impersonated_credentials.py to extract the target principal, hostname, and universe domain, while ensuring they align with the configured universe domain. It also adds extensive unit tests to verify various URL formats and validation errors. The feedback suggests stripping trailing dots from the resolved explicit universe domain to prevent validation failures when comparing it against the stripped URL host.

@ohmayr
ohmayr added this pull request to stack #19222 November 25, 2026 22:59
@ohmayr
ohmayr removed this pull request from stack #19222 November 25, 2026 23:04
@ohmayr
ohmayr added this pull request to stack #19223 November 25, 2026 23:05
@ohmayr
ohmayr force-pushed the fix/auth-impersonated-url-host branch from 5ce410a to 0ca93b8 Compare November 25, 2026 23:07
@ohmayr ohmayr changed the title fix(auth): validate and honor impersonation URL host fix(auth): validate and use service_account_impersonation_url host Nov 25, 2026
@ohmayr
ohmayr force-pushed the fix/auth-impersonated-url-host branch from 0ca93b8 to 5d9a79e Compare November 25, 2026 23:18
@ohmayr
ohmayr force-pushed the fix/auth-impersonated-url-host branch 2 times, most recently from 33f6123 to eb7d546 Compare November 25, 2026 23:40
@ohmayr
ohmayr force-pushed the fix/auth-impersonated-url-host branch from eb7d546 to b2f625b Compare November 25, 2026 23:51
@ohmayr ohmayr changed the title fix(auth): validate and use service_account_impersonation_url host fix(auth): propagate top-level universe_domain in impersonated creds Nov 25, 2026
@ohmayr
ohmayr force-pushed the fix/auth-impersonated-url-host branch 2 times, most recently from 23d5ec1 to f5a7368 Compare November 27, 2026 15:35
@parthea
parthea force-pushed the fix/auth-impersonated-url-host branch from f5a7368 to 6212227 Compare November 27, 2026 15:48
@ohmayr
ohmayr force-pushed the fix/auth-impersonated-url-host branch from 6212227 to c2e3ae7 Compare November 27, 2026 15:50
Base automatically changed from fix/auth-impersonated-top-level-universe to main November 27, 2026 16:04
@parthea
parthea force-pushed the fix/auth-impersonated-url-host branch from c2e3ae7 to 00ac5bb Compare November 27, 2026 16:04
@ohmayr
ohmayr marked this pull request as ready for review November 27, 2026 16:07
@ohmayr
ohmayr requested review from a team as code owners November 27, 2026 16:07
@parthea parthea self-assigned this Nov 30, 2026
Credentials.from_impersonated_service_account_info() ignored a
top-level universe_domain field and delegated _universe_domain solely
to source_credentials. When source_credentials omitted universe_domain,
impersonated credentials defaulted to googleapis.com and sent source
tokens to iamcredentials.googleapis.com.

Add an optional universe_domain parameter to Credentials.__init__()
(validated via _helpers.validate_universe_domain() and compared against
source_credentials.universe_domain via
_helpers.compare_universe_domains()), forward it in _make_copy(), and
propagate top-level universe_domain into a shallow copy of
source_credentials_info in from_impersonated_service_account_info()
without mutating caller input.

b/589828921
@ohmayr
ohmayr force-pushed the fix/auth-impersonated-url-host branch from 00ac5bb to 7a30b38 Compare November 30, 2026 20:09

@parthea parthea 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.

Note: The review comments below are AI-generated.

Validate source_credentials.universe_domain in Credentials.__init__ even
when universe_domain is omitted, defaulting explicit None or missing
attributes to DEFAULT_UNIVERSE_DOMAIN without coercing empty strings.
Validate nested source_credentials["universe_domain"] in
from_impersonated_service_account_info before constructing source
credentials, document the early universe_domain validation check, and
add external_account_authorized_user propagation test coverage.
@ohmayr
ohmayr merged commit 751d5b3 into main Nov 30, 2026
148 of 149 checks passed
@ohmayr
ohmayr deleted the fix/auth-impersonated-url-host branch November 30, 2026 23:28
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.

2 participants