Skip to content

fix(auth): avoid redundant executable run and preserve impersonated email in PluggableAuthCredentials - #14446

Draft
lsirac wants to merge 2 commits into
mainfrom
fix/pluggable-auth-redundant-executable
Draft

lsirac wants to merge 2 commits into
mainfrom
fix/pluggable-auth-redundant-executable

Conversation

@lsirac

@lsirac lsirac commented Sep 19, 2026

Copy link
Copy Markdown
Contributor

Summary

Fixes two issues when PluggableAuthCredentials is configured with service account impersonation (service_account_impersonation_url):

  1. Avoids redundant executable invocation: Previously, PluggableAuthCredentials.refreshAccessToken() unconditionally called retrieveSubjectToken() on the outer credential before delegating to exchangeExternalCredentialForAccessToken(...), which immediately delegated to impersonatedCredentials.refreshAccessToken() and discarded the outer subject token. refreshAccessToken() now checks getImpersonatedCredentials() upfront and delegates directly to impersonated.refreshAccessToken(), running the executable only once.
  2. Preserves GOOGLE_EXTERNAL_ACCOUNT_IMPERSONATED_EMAIL on the inner source credential: ExternalAccountCredentials.buildImpersonatedCredentials() clones sourceCredentials with .setServiceAccountImpersonationUrl(null) to prevent infinite recursion, which previously caused getServiceAccountEmail() on sourceCredentials (and its scoped copy) to return null and omit GOOGLE_EXTERNAL_ACCOUNT_IMPERSONATED_EMAIL from the executable environment map. buildImpersonatedCredentials() now passes .setImpersonatedServiceAccountEmail(targetPrincipal) to the PluggableAuthCredentials builder, and PluggableAuthCredentials.getServiceAccountEmail() falls back to impersonatedServiceAccountEmail when super.getServiceAccountEmail() is null.

Testing

  • Updated refreshAccessToken_withServiceAccountImpersonation and refreshAccessToken_withServiceAccountImpersonationOptions in PluggableAuthCredentialsTest to assert that the executable handler is invoked exactly once and receives GOOGLE_EXTERNAL_ACCOUNT_IMPERSONATED_EMAIL equal to credential.getServiceAccountEmail().
  • Added createScoped_preservesImpersonatedServiceAccountEmail to verify preservation across createScoped() and reset when setServiceAccountImpersonationUrl(...) is called.

@lsirac
lsirac requested review from a team as code owners September 19, 2026 14:45

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

@lsirac
lsirac marked this pull request as draft September 19, 2026 14:52
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