Conversation
…mail in PluggableAuthCredentials
There was a problem hiding this comment.
Code Review
This pull request updates ExternalAccountCredentials and PluggableAuthCredentials to properly handle and preserve the impersonated service account email when cloning or creating scoped credentials. It introduces a lazy initializer getImpersonatedCredentials() in ExternalAccountCredentials, adds the impersonatedServiceAccountEmail field and builder methods to PluggableAuthCredentials, and overrides getServiceAccountEmail() to fall back to this email. Additionally, corresponding unit tests have been updated and added to verify that the impersonated email is correctly set in the environment and preserved during scoping. There are no review comments to address, and I have no additional feedback to provide.
Summary
Fixes two issues when
PluggableAuthCredentialsis configured with service account impersonation (service_account_impersonation_url):PluggableAuthCredentials.refreshAccessToken()unconditionally calledretrieveSubjectToken()on the outer credential before delegating toexchangeExternalCredentialForAccessToken(...), which immediately delegated toimpersonatedCredentials.refreshAccessToken()and discarded the outer subject token.refreshAccessToken()now checksgetImpersonatedCredentials()upfront and delegates directly toimpersonated.refreshAccessToken(), running the executable only once.GOOGLE_EXTERNAL_ACCOUNT_IMPERSONATED_EMAILon the inner source credential:ExternalAccountCredentials.buildImpersonatedCredentials()clonessourceCredentialswith.setServiceAccountImpersonationUrl(null)to prevent infinite recursion, which previously causedgetServiceAccountEmail()onsourceCredentials(and its scoped copy) to returnnulland omitGOOGLE_EXTERNAL_ACCOUNT_IMPERSONATED_EMAILfrom the executable environment map.buildImpersonatedCredentials()now passes.setImpersonatedServiceAccountEmail(targetPrincipal)to thePluggableAuthCredentialsbuilder, andPluggableAuthCredentials.getServiceAccountEmail()falls back toimpersonatedServiceAccountEmailwhensuper.getServiceAccountEmail()isnull.Testing
refreshAccessToken_withServiceAccountImpersonationandrefreshAccessToken_withServiceAccountImpersonationOptionsinPluggableAuthCredentialsTestto assert that the executable handler is invoked exactly once and receivesGOOGLE_EXTERNAL_ACCOUNT_IMPERSONATED_EMAILequal tocredential.getServiceAccountEmail().createScoped_preservesImpersonatedServiceAccountEmailto verify preservation acrosscreateScoped()and reset whensetServiceAccountImpersonationUrl(...)is called.