Repository navigation
fix(oauth2): fail closed on universe_domain - #16757
Conversation
There was a problem hiding this comment.
Code Review
This pull request refactors the Credentials base class by making universe_domain() pure virtual, ensuring all derived credential types explicitly implement it. It adds custom universe domain support to AccessTokenCredentials and AuthorizedUserCredentials, validates token_uri requirements for non-default domains, and introduces extensive unit tests to cover these scenarios. As there are no review comments to evaluate, I have no feedback to provide.
scotthart
left a comment
There was a problem hiding this comment.
Thanks for tightening up universe_domain() to fail closed and forwarding client_factory in ImpersonateServiceAccountCredentials! A few items to address/discuss:
-
Build failure (
-Werror=range-loop-construct) ingoogle/cloud/internal/oauth2_authorized_user_credentials_test.cc:433(ParseNonStringTokenUriFails):
for (std::string const& bad_value : {"123", "null", "[]", "{}"})bindsstd::string const&to a temporary constructed fromchar const*, failing the Fedora/GCC builds (cmake-gcs-rest-pr,noex-pr,openssl-4-pr). Switching the loop variable tochar const* const bad_value(withstd::string(...)concatenation) orstd::string_view const bad_value(withabsl::StrCat) will fix this. -
Breaking change for GDU REST
MakeImpersonateServiceAccountCredentials(MakeAccessTokenCredentials(...), ...):
ReturningkNotFoundfromAccessTokenCredentials::universe_domain()wheninternal::UniverseDomainOptionis absent breaks existing GDU callers that impersonate a service account usingMakeAccessTokenCredentials()over REST (as reflected in the updatedImpersonateServiceAccounttest inunified_rest_credentials_test.cc:478-480). BecauseUniverseDomainOptionis still ingoogle::cloud::internal(TODO(#13115)), public callers currently have no public API option to restore the previous behavior, and gRPC impersonation (MakeMinimalIamCredentialsOptions) still defaults toiamcredentials.googleapis.com. Could we confirm whether this breaking change is intended prior to exposing a publicUniverseDomainOption(and/or aligning gRPC behavior)? -
Empty
info_.universe_domaincheck inAuthorizedUserCredentials::universe_domain()(google/cloud/internal/oauth2_authorized_user_credentials.cc:147-149):
WhileParseAuthorizedUserCredentials()always populatesuniverse_domain,AuthorizedUserCredentialsInfois an aggregate struct that can be constructed with an emptyuniverse_domain. Checkingif (info_.universe_domain.empty())and returninginternal::InvalidArgumentError(...)(consistent withAccessTokenCredentials::universe_domain()) ensuresAuthorizedUserCredentialsalso fails closed and cannot return an OK empty string. -
Nit (Docs): Consider updating the Doxygen comments on
GetUniverseDomain()/AddUniverseDomainOption()ingoogle/cloud/universe_domain.hto note that credential types without a universe domain (such as API key, GDCH, or access token credentials withoutUniverseDomainOption) return non-OK statuses (kUnimplemented/kNotFound).
Codecov Report❌ Patch coverage is Additional details and impacted files@@ Coverage Diff @@
## main #16757 +/- ##
==========================================
- Coverage 92.93% 92.93% -0.01%
==========================================
Files 2282 2282
Lines 232838 233330 +492
==========================================
+ Hits 216399 216839 +440
- Misses 16439 16491 +52 ☔ View full report in Codecov by Harness. 🚀 New features to boost your workflow:
|
Previously,
oauth2_internal::Credentials::universe_domain()provided a default implementation returning"googleapis.com". Any credential subclass that omitted an override silently reported the Google Default Universe (GDU), which could misrouteAddUniverseDomainOption()or REST service account impersonation requests togoogleapis.comendpoints in non-GDU / TPC environments.Additionally,
AuthorizedUserCredentialsparseduniverse_domainintoAuthorizedUserCredentialsInfowithout exposing it viauniverse_domain(), andParseAuthorizedUserCredentials()defaulted an omittedtoken_uritohttps://oauth2.googleapis.com/tokeneven when a non-GDUuniverse_domainwas specified.