GeezerVisonThe World Wide Web, restored to 800 pixels of glory. | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| Home|About|Gaming cabinet|Archives|How it works|Starter sites | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
GeezerVison is showing github.com — feat: ComputeEngineCredential supports specifying scopes by ahmedtd · Pull Request #457 · googleapis/google-auth-library-java
This repository was archived by the owner on May 12, 2026. It is now read-only.
Conversation
|
|
@chingor13 This is the patch we discussed. |
Sorry, something went wrong.
There was an error while loading. Please reload this page.
There was a problem hiding this comment.
The reason will be displayed to describe this comment to others. Learn more.
It really helps if changes like this are associated with a detailed issue.
Sorry, something went wrong.
There was an error while loading. Please reload this page.
There was an error while loading. Please reload this page.
| */ | ||
| public static ComputeEngineCredentials create() { | ||
| return new ComputeEngineCredentials(null); | ||
| return new ComputeEngineCredentials(ImmutableSet.<String>of(), null); |
There was a problem hiding this comment.
The reason will be displayed to describe this comment to others. Learn more.
Should this default to null instead?
An empty collection of scopes might make the url something like https://some-url/?scopes= which may be correct if you ask for no scopes, but if you pass null, it should exclude the scopes param.
Sorry, something went wrong.
There was an error while loading. Please reload this page.
There was a problem hiding this comment.
The reason will be displayed to describe this comment to others. Learn more.
Yes, you're right. I originally wrote this so that an empty collection would result in not sending the ?scopes param, but then changed it to null.
Sorry, something went wrong.
There was an error while loading. Please reload this page.
There was a problem hiding this comment.
The reason will be displayed to describe this comment to others. Learn more.
Done
Sorry, something went wrong.
There was an error while loading. Please reload this page.
Sorry, something went wrong.
There was an error while loading. Please reload this page.
The existing behavior of ComputeEngineCredentials is to not provide the `?scopes` parameter in its access token request to the metadata server. This is workable on GCE, which has the concept of a scope lock / default scopes applied to the VM. However, neither new AppEngine nor GKE Workload Identity have this concept; they just return a hardcoded set of default scopes if no specific scopes are requested. This makes usage of some Google APIs impossible using the Java client libraries. This change adds scope support to ComputeEngineCredentials. It's optional, so the current behavior will stay the default. However, if the user specifies scopes on the builder or using `createScoped`, then those scopes will be passed to the metadata server.
There was a problem hiding this comment.
The reason will be displayed to describe this comment to others. Learn more.
Also please run mvn com.coveo:fmt-maven-plugin:format to appease the linter.
Sorry, something went wrong.
There was an error while loading. Please reload this page.
| HttpResponse response = getMetadataResponse(getTokenServerEncodedUrl()); | ||
| GenericUrl url = new GenericUrl(getTokenServerEncodedUrl()); | ||
| if (scopes != null) { | ||
| url.set("scopes", String.join(",", scopes)); |
There was a problem hiding this comment.
The reason will be displayed to describe this comment to others. Learn more.
Looks like String.join was added in Java 8 and this library still currently support Java 7.
Sorry, something went wrong.
There was an error while loading. Please reload this page.
There was a problem hiding this comment.
The reason will be displayed to describe this comment to others. Learn more.
You can use Guava's Joiner in this class.
Sorry, something went wrong.
There was an error while loading. Please reload this page.
| HttpResponse response = getMetadataResponse(getTokenServerEncodedUrl()); | ||
| GenericUrl url = new GenericUrl(getTokenServerEncodedUrl()); | ||
| if (scopes != null) { | ||
| url.set("scopes", String.join(",", scopes)); |
There was a problem hiding this comment.
The reason will be displayed to describe this comment to others. Learn more.
You can use Guava's Joiner in this class.
Sorry, something went wrong.
There was an error while loading. Please reload this page.
| } | ||
|
|
||
| public Builder setScopes(Collection<String> scopes) { | ||
| this.scopes = scopes; |
There was a problem hiding this comment.
The reason will be displayed to describe this comment to others. Learn more.
You probably want a defensive copy to avoid exposing mutable internal state.
Sorry, something went wrong.
There was an error while loading. Please reload this page.
| return transportFactory; | ||
| } | ||
|
|
||
| public Collection<String> getScopes() { |
There was a problem hiding this comment.
The reason will be displayed to describe this comment to others. Learn more.
You probably want a defensive copy to avoid exposing mutable internal state.
Sorry, something went wrong.
There was an error while loading. Please reload this page.
| GenericUrl parsedURL = new GenericUrl(url); | ||
|
|
||
| if ("/computeMetadata/v1/instance/service-accounts/default/token".equals(parsedURL.getRawPath())) { | ||
| String scopes = (String)parsedURL.getFirst("scopes"); |
There was a problem hiding this comment.
The reason will be displayed to describe this comment to others. Learn more.
space after cast
Sorry, something went wrong.
There was an error while loading. Please reload this page.
|
Addressed in #514 |
Sorry, something went wrong.
There was an error while loading. Please reload this page.
There was an error while loading. Please reload this page.
Successfully merging this pull request may close these issues.
There was an error while loading. Please reload this page.