Skip to content

fix(oauth2): reject P12 and OAuth in non-GDU - #16761

Open
scotthart wants to merge 1 commit into
googleapis:mainfrom
scotthart:oauth2_p12_gdu
Open

scotthart wants to merge 1 commit into
googleapis:mainfrom
scotthart:oauth2_p12_gdu

Conversation

@scotthart

Copy link
Copy Markdown
Member

Legacy PKCS#12 (.p12) service account keys do not carry universe_domain or
token_uri metadata and cannot mint self-signed JWTs (private_key_id is
unknown). Previously, both the OpenSSL and Win32 .p12 parsers hardcoded
https://oauth2.googleapis.com/token without consulting the configured universe
domain, so loading a .p12 key in a non-default universe environment caused
token refreshes to post RS256 JWT assertions signed with the service account
private key to https://oauth2.googleapis.com/token.

Additionally, ServiceAccountCredentials::UseOAuth() checked
DisableSelfSignedJWTOption before checking whether the credential specifies a
non-default universe_domain, which could override self-signed JWT selection
and route non-GDU service account credentials through OAuth2 token exchange.
ParseServiceAccountCredentials() also defaulted an omitted token_uri to
https://oauth2.googleapis.com/token even for non-GDU service accounts.

@scotthart
scotthart requested a review from a team as a code owner December 5, 2026 01:46

@gemini-code-assist gemini-code-assist Bot left a comment

Copy link
Copy Markdown

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 non-default universe domains in service account credentials. Key changes include the addition of a resolution mechanism for universe domains, updates to credential parsing to reject legacy PKCS#12 (.p12) files in non-default universes, and modifications to service account credential logic to prevent unsupported OAuth2 token exchanges for non-default domains. Extensive testing has been added to verify these constraints and ensure correct behavior across different environments. I have no feedback to provide on these changes.

@codecov

codecov Bot commented Dec 5, 2026

Copy link
Copy Markdown

Codecov Report

❌ Patch coverage is 98.31325% with 7 lines in your changes missing coverage. Please review.
✅ Project coverage is 92.99%. Comparing base (42aafa2) to head (f7618b3).

Files with missing lines Patch % Lines
...oud/internal/oauth2_service_account_credentials.cc 84.61% 6 Missing ⚠️
...nternal/oauth2_service_account_credentials_test.cc 99.54% 1 Missing ⚠️
Additional details and impacted files
@@            Coverage Diff             @@
##             main   #16761      +/-   ##
==========================================
+ Coverage   92.96%   92.99%   +0.03%     
==========================================
  Files        2284     2284              
  Lines      234824   235229     +405     
==========================================
+ Hits       218303   218755     +452     
+ Misses      16521    16474      -47     

☔ View full report in Codecov by Harness.
📢 Have feedback on the report? Share it here.

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.

This branch has not been deployed

No deployments
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.

1 participant