Skip to content

chore(auth): add compare_universe_domains helper in _helpers - #19220

Merged
parthea merged 3 commits into
mainfrom
fix/auth-impersonated-top-level-universe
Nov 27, 2026
Merged

parthea merged 3 commits into
mainfrom
fix/auth-impersonated-top-level-universe

Conversation

@ohmayr

@ohmayr ohmayr commented Nov 25, 2026 •

Copy link
Copy Markdown
Contributor

Context & Problem

Wrapper credentials such as impersonated and downscoped credentials need a consistent helper in google.auth._helpers to verify that a configured universe_domain matches an expected universe domain (for example, from wrapped source credentials or an endpoint host).

Summary of Changes

  • Add compare_universe_domains(universe_domain, expected_universe_domain) in packages/google-auth/google/auth/_helpers.py right after validate_universe_domain().
  • Add unit tests for matching and mismatching universe domains in packages/google-auth/tests/test__helpers.py.

Verification

  • ruff check, ruff check --select I, ruff format --check, and mypy --config-file=../../mypy.ini passed with zero issues.
  • pytest passed (131 passed) with 100% statement and branch coverage on google/auth/_helpers.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 support for universe_domain in impersonated_credentials.py. It adds the universe_domain parameter to the Credentials constructor and the from_impersonated_service_account_info method, along with validation logic to ensure consistency between the impersonated and source credentials' universe domains. Corresponding unit tests have been added to verify these validation checks. There are no review comments to assess, and I have no feedback to provide.

@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-top-level-universe branch from fba6668 to 79d9927 Compare November 25, 2026 23:07
@ohmayr ohmayr changed the title fix(auth): honor top-level universe_domain in impersonated creds fix(auth): propagate top-level universe_domain in impersonated creds Nov 25, 2026
Base automatically changed from refactor/auth-validate-universe-domain to main November 25, 2026 23:18
@ohmayr
ohmayr force-pushed the fix/auth-impersonated-top-level-universe branch 4 times, most recently from 4adec48 to 53c324d Compare November 25, 2026 23:51
@ohmayr ohmayr changed the title fix(auth): propagate top-level universe_domain in impersonated creds fix(auth): add compare_universe_domains helper in _helpers Nov 25, 2026
@ohmayr
ohmayr force-pushed the fix/auth-impersonated-top-level-universe branch from 53c324d to f35db0b Compare November 25, 2026 23:55
@ohmayr
ohmayr marked this pull request as ready for review November 25, 2026 23:57
@ohmayr
ohmayr requested review from a team as code owners November 25, 2026 23:57
@ohmayr ohmayr changed the title fix(auth): add compare_universe_domains helper in _helpers chore(auth): add compare_universe_domains helper in _helpers Nov 26, 2026
@parthea

parthea commented Nov 27, 2026

Copy link
Copy Markdown
Contributor

I'm going to click the rebase stack button. If you see something that says the branch was force pushed, it was caused by rebase stack.

Wrapper credentials such as impersonated and downscoped credentials
need a consistent helper to verify that a configured universe_domain
matches an expected universe domain (for example, from wrapped source
credentials or an endpoint host).

Add _helpers.compare_universe_domains() next to
_helpers.validate_universe_domain() along with unit tests.

b/589828921
@parthea
parthea force-pushed the fix/auth-impersonated-top-level-universe branch from 072fbe1 to 9fc0026 Compare November 27, 2026 15:48
@parthea
parthea enabled stacked auto-merge (squash) November 27, 2026 15:53
@parthea
parthea merged commit a4bec90 into main Nov 27, 2026
148 checks passed
@parthea
parthea deleted the fix/auth-impersonated-top-level-universe branch November 27, 2026 16:04
ohmayr added a commit that referenced this pull request Nov 30, 2026
…19221)

## 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 #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
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