Skip to content

Conversation

@lqiu96
Copy link
Member

@lqiu96 lqiu96 commented Oct 9, 2025

See b/450322374 for more information

Changes

  • Updates ImpersonatedCredentials to accept the scopes value from the JSON file
  • User configured scopes takes precedence over the JSON file

Lots of smaller changes in test files from smaller refactors related to create a CLOUD_PLATFORM_SCOPE constant and such.

@product-auto-label product-auto-label bot added the size: m Pull request size is medium. label Oct 9, 2025
@lqiu96 lqiu96 force-pushed the impersonated-cred-scopes branch from 4ec205f to 7705a7b Compare October 10, 2025 15:23
@sonarqubecloud
Copy link

Quality Gate Failed Quality Gate failed

Failed conditions
0.0% Coverage on New Code (required ≥ 80%)

See analysis details on SonarQube Cloud

Comment on lines +406 to +408
if (json.containsKey("scopes")) {
scopes = ImmutableList.copyOf((List<String>) json.get("scopes"));
}
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This scopes field was recently added and may not exist in existing ImpersonatedCred Json files. Check if it exists

*/
@CanIgnoreReturnValue
public Builder setScopes(List<String> scopes) {
Preconditions.checkNotNull(scopes, "Scopes cannot be null");
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Constructor has a null check that threw a IllegalStateException runtime exception. Enforce this on the setter so users don't pass in an invalid data.

This never worked, so we don't expect any breakages or changes in behavior.

@lqiu96 lqiu96 marked this pull request as ready for review October 10, 2025 16:10
@lqiu96 lqiu96 requested review from a team as code owners October 10, 2025 16:10
@lqiu96 lqiu96 requested a review from zhumin8 October 10, 2025 16:10
Copy link
Contributor

@zhumin8 zhumin8 left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Change LGTM.
Got question about CLOUD_PLATFORM_SCOPE used for sourceCredentials, but I think it does not block this change.

this.sourceCredentials =
this.sourceCredentials.createScoped(Arrays.asList(CLOUD_PLATFORM_SCOPE));
this.sourceCredentials.createScoped(
Collections.singletonList(OAuth2Utils.CLOUD_PLATFORM_SCOPE));
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Does it work or is it better to switch to https://www.googleapis.com/auth/iam?

Copy link
Member Author

@lqiu96 lqiu96 Oct 13, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think either should work: https://cloud.google.com/iam/docs/reference/credentials/rest/v1/projects.serviceAccounts/generateAccessToken#authorization-scopes

Not sure if there is a preference. I can update if there is.

@lqiu96 lqiu96 merged commit 84fc566 into main Oct 13, 2025
38 of 40 checks passed
@lqiu96 lqiu96 deleted the impersonated-cred-scopes branch October 13, 2025 20:11
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

size: m Pull request size is medium.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants