GV

GeezerVison

The World Wide Web, restored to 800 pixels of glory.

Home|About|Gaming cabinet|Archives|How it works|Starter sites

On this site

  • Sign in
  • ActionsCI/CD and automation
  • CodespacesCloud development environments
  • All Features
  • Documentation
  • Training
  • Certifications
  • Build with Copilot
  • Customize Copilot
  • Integrations
  • Trending repos
  • GitHub Sponsors
  • Developer articles
  • Enterprises

This view

  • Original page
  • New address

GeezerVison is showing github.com — feat: enable self-signed JWTs by default in ServiceOptions by whowes · Pull Request #13338 · googleapis/google-cloud-java

feat: enable self-signed JWTs by default in ServiceOptions #13338

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

Sign up for GitHub

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
whowes merged 5 commits into main from whowes/ssjwt
Jun 12, 2026

Uh oh!

There was an error while loading. Please reload this page.

Merged

feat: enable self-signed JWTs by default in ServiceOptions #13338

Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
5 commits
Select commit Hold shift + click to select a range
767fa89
feat: enable self-signed JWTs by default in ServiceOptions
whowes Jun 2, 2026
7e19520
add new test cases to ServiceOptionsTest
whowes Jun 5, 2026
7e04774
address review comments
whowes Jun 10, 2026
ac8cf3e
opt out StorageOptions and add unit tests
whowes Jun 10, 2026
9c1e827
address review comments
whowes Jun 10, 2026
File filter
Filter by extension

Clear filters
Conversations
Failed to load comments.
Loading

Uh oh!

There was an error while loading. Please reload this page.

Jump to
Jump to file
Failed to load files.
Loading

Uh oh!

There was an error while loading. Please reload this page.

Diff view
Diff view

There are no files selected for viewing

4 changes: 3 additions & 1 deletion 4 ...gquery/google-cloud-bigquery/src/main/java/com/google/cloud/bigquery/BigQueryOptions.java
Show comments
View file
Open in desktop
Original file line number Diff line number Diff line change
Expand Up @@ -77,7 +77,9 @@ public static class Builder extends ServiceOptions.Builder<BigQuery, BigQueryOpt
private Tracer openTelemetryTracer;
private ResultRetryAlgorithm<?> resultRetryAlgorithm;

private Builder() {}
private Builder() {
setUseJwtAccessWithScope(false);
Comment thread

@lqiu96 lqiu96 Jun 12, 2026

Copy link
Copy Markdown
Member

There was a problem hiding this comment.

Choose a reason for hiding this comment

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

For BQ and Storage, are there any internal tracking tickets that we can link for these exceptions (e.g. default false)? IIRC, these are more so temporary and not permanent as we want this for default. I think would be helpful for future context

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

All reactions

@whowes whowes Jun 12, 2026

Copy link
Copy Markdown
Contributor Author

There was a problem hiding this comment.

Choose a reason for hiding this comment

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

Good suggestion, I added tracking tickets to the PR description.

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

All reactions
}

private Builder(BigQueryOptions options) {
super(options);
Expand Down
7 changes: 7 additions & 0 deletions 7 ...ry/google-cloud-bigquery/src/test/java/com/google/cloud/bigquery/BigQueryOptionsTest.java
Show comments
View file
Open in desktop
Original file line number Diff line number Diff line change
Expand Up @@ -92,4 +92,11 @@ void dataFormatOptionsSetterHasPrecedence() {

assertTrue(options.getDataFormatOptions().useInt64Timestamp());
}

@Test
void testUseJwtAccessWithScope_defaultsToFalse() {
BigQueryOptions options = BigQueryOptions.newBuilder().setProjectId("project-id").build();

assertFalse(options.getUseJwtAccessWithScope());
}
}
4 changes: 3 additions & 1 deletion 4 java-storage/google-cloud-storage/src/main/java/com/google/cloud/storage/StorageOptions.java
Show comments
View file
Open in desktop
Original file line number Diff line number Diff line change
Expand Up @@ -112,7 +112,9 @@ public DefaultStorageRpcFactory() {
public abstract static class Builder
extends ServiceOptions.Builder<Storage, StorageOptions, Builder> {

Builder() {}
Builder() {
setUseJwtAccessWithScope(false);
}

Builder(StorageOptions options) {
super(options);
Expand Down
9 changes: 9 additions & 0 deletions 9 ...oogle-cloud-storage/src/test/java/com/google/cloud/storage/StorageOptionsBuilderTest.java
Show comments
View file
Open in desktop
Original file line number Diff line number Diff line change
Expand Up @@ -69,6 +69,15 @@ public void grpc() throws Exception {
() -> assertThat(rebuilt.hashCode()).isEqualTo(base.hashCode()));
}

@Test
public void useJwtAccessWithScope_defaultsToFalse() {
HttpStorageOptions httpOptions = HttpStorageOptions.http().build();
GrpcStorageOptions grpcOptions = GrpcStorageOptions.grpc().build();

assertThat(httpOptions.getUseJwtAccessWithScope()).isFalse();
assertThat(grpcOptions.getUseJwtAccessWithScope()).isFalse();
}

private static class MyStorageRetryStrategy implements StorageRetryStrategy {

@Override
Expand Down
30 changes: 30 additions & 0 deletions 30 ...tform-java/java-core/google-cloud-core/src/main/java/com/google/cloud/ServiceOptions.java
Show comments
View file
Open in desktop
Original file line number Diff line number Diff line change
Expand Up @@ -106,6 +106,7 @@ public abstract class ServiceOptions<
private final TransportOptions transportOptions;
private final HeaderProvider headerProvider;
private final String quotaProjectId;
private final boolean useJwtAccessWithScope;

private transient ServiceRpcFactory<OptionsT> serviceRpcFactory;
private transient ServiceFactory<ServiceT, OptionsT> serviceFactory;
Expand Down Expand Up @@ -140,6 +141,7 @@ public abstract static class Builder<
private HeaderProvider headerProvider;
private String clientLibToken = ServiceOptions.getGoogApiClientLibName();
private String quotaProjectId;
private boolean useJwtAccessWithScope = true;

private ApiTracerFactory apiTracerFactory;

Expand All @@ -159,6 +161,7 @@ protected Builder(ServiceOptions<ServiceT, OptionsT> options) {
transportOptions = options.transportOptions;
clientLibToken = options.clientLibToken;
quotaProjectId = options.quotaProjectId;
useJwtAccessWithScope = options.useJwtAccessWithScope;
apiTracerFactory = options.apiTracerFactory;
}

Expand Down Expand Up @@ -313,6 +316,18 @@ public B setQuotaProjectId(String quotaProjectId) {
return self();
}

/**
* Sets the configuration determining whether self-signed JWT with scopes are used for service
* account credentials.
*
* @param useJwtAccessWithScope whether to use self-signed JWT with scopes
* @return the builder
*/
public B setUseJwtAccessWithScope(final boolean useJwtAccessWithScope) {
this.useJwtAccessWithScope = useJwtAccessWithScope;
return self();
}

/**
* Sets the {@link ApiTracerFactory}. It will be used to create an {@link ApiTracer} that is
* annotated throughout the lifecycle of an RPC operation.
Expand Down Expand Up @@ -365,6 +380,7 @@ protected ServiceOptions(
builder.quotaProjectId != null
? builder.quotaProjectId
: getValueFromCredentialsFile(getCredentialsPath(), "quota_project_id");
useJwtAccessWithScope = builder.useJwtAccessWithScope;
apiTracerFactory = builder.apiTracerFactory;
}

Expand Down Expand Up @@ -650,6 +666,11 @@ public Credentials getScopedCredentials() {
&& ((GoogleCredentials) credentials).createScopedRequired()) {
credentialsToReturn = ((GoogleCredentials) credentials).createScoped(getScopes());
}
if (credentialsToReturn instanceof ServiceAccountCredentials) {
credentialsToReturn =
((ServiceAccountCredentials) credentialsToReturn)
.createWithUseJwtAccessWithScope(getUseJwtAccessWithScope());
}
return credentialsToReturn;
}

Expand Down Expand Up @@ -823,6 +844,15 @@ public String getQuotaProjectId() {
return quotaProjectId;
}

/**
* Returns true when self-signed JWT with scopes are used for service account credentials.
*
* @return true when self-signed JWT with scopes are used
*/
public boolean getUseJwtAccessWithScope() {
return useJwtAccessWithScope;
}

/**
* Returns the resolved host for the Service to connect to Google Cloud
*
Expand Down
40 changes: 40 additions & 0 deletions 40 ...m-java/java-core/google-cloud-core/src/test/java/com/google/cloud/ServiceOptionsTest.java
Show comments
View file
Open in desktop
Original file line number Diff line number Diff line change
Expand Up @@ -630,6 +630,46 @@ void testIsValidUniverseDomain_userUniverseDomainConfig_nonGDUCredentials() thro
assertThat(options.hasValidUniverseDomain()).isTrue();
}

@Test
void testGetScopedCredentials_useJwtAccessWithScope_enablesByDefault() {
TestServiceOptions options =
TestServiceOptions.newBuilder()
.setProjectId("project-id")
.setCredentials(credentials)
.build();
com.google.auth.Credentials scoped = options.getScopedCredentials();
assertThat(scoped).isInstanceOf(ServiceAccountCredentials.class);
assertThat(((ServiceAccountCredentials) scoped).getUseJwtAccessWithScope()).isTrue();
}

@Test
void testGetScopedCredentials_useJwtAccessWithScope_canBeDisabled() {
TestServiceOptions options =
new TestServiceOptions.Builder()
.setProjectId("project-id")
.setCredentials(credentials)
.setUseJwtAccessWithScope(false)
.build();
com.google.auth.Credentials scoped = options.getScopedCredentials();
assertThat(scoped).isInstanceOf(ServiceAccountCredentials.class);
assertThat(((ServiceAccountCredentials) scoped).getUseJwtAccessWithScope()).isFalse();
}

@Test
void testGetScopedCredentials_useJwtAccessWithScope_overridesCredentials() {
ServiceAccountCredentials trueCredentials =
((ServiceAccountCredentials) credentials).createWithUseJwtAccessWithScope(true);
TestServiceOptions options =
new TestServiceOptions.Builder()
.setProjectId("project-id")
.setCredentials(trueCredentials)
.setUseJwtAccessWithScope(false)
.build();
com.google.auth.Credentials scoped = options.getScopedCredentials();
assertThat(scoped).isInstanceOf(ServiceAccountCredentials.class);
assertThat(((ServiceAccountCredentials) scoped).getUseJwtAccessWithScope()).isFalse();
}

private HttpResponse createHttpResponseWithHeader(final Multimap<String, String> headers)
throws Exception {
HttpTransport mockHttpTransport =
Expand Down
Loading
Oops, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

Add this suggestion to a batch that can be applied as a single commit. This suggestion is invalid because no changes were made to the code. Suggestions cannot be applied while the pull request is closed. Suggestions cannot be applied while viewing a subset of changes. Only one suggestion per line can be applied in a batch. Add this suggestion to a batch that can be applied as a single commit. Applying suggestions on deleted lines is not supported. You must change the existing code in this line in order to create a valid suggestion. Outdated suggestions cannot be applied. This suggestion has been applied or marked resolved. Suggestions cannot be applied from pending reviews. Suggestions cannot be applied on multi-line comments. Suggestions cannot be applied while the pull request is queued to merge. Suggestion cannot be applied right now. Please check back later.
You are visitor 01402775 — GeezerVison does not store the pages you look up.
Best viewed with Netscape Navigator 4.7 or Internet Explorer 6 at 800×600. No cookies required.