Skip to content

Commit c7d614a

Browse files
authored
fix: DirectPath non-default SA requires creds (#2281)
Spanner tries to set the `allowNonDefaultServiceAccount` option in its client library, which makes some tests fail. In these tests, client and server are running on the same machine, and no credentials are provided. DirectPath is not supposed to be tested by these tests, so we add a requirement that if the client wants to use non-default service account for DirectPath, the credential associated with the service account must be provided.
1 parent a0f3ea1 commit c7d614a

File tree

2 files changed

+16
-3
lines changed

2 files changed

+16
-3
lines changed

gax-java/gax-grpc/src/main/java/com/google/api/gax/grpc/InstantiatingGrpcChannelProvider.java

+8-3
Original file line numberDiff line numberDiff line change
@@ -282,7 +282,7 @@ private void logDirectPathMisconfig() {
282282
+ " attemptDirectPathXds option.");
283283
} else {
284284
// Case 2: credential is not correctly set
285-
if (!isNonDefaultServiceAccountAllowed()) {
285+
if (!isCredentialDirectPathCompatible()) {
286286
LOG.log(
287287
Level.WARNING,
288288
"DirectPath is misconfigured. Please make sure the credential is an instance of "
@@ -303,7 +303,12 @@ private void logDirectPathMisconfig() {
303303
}
304304
}
305305

306-
private boolean isNonDefaultServiceAccountAllowed() {
306+
@VisibleForTesting
307+
boolean isCredentialDirectPathCompatible() {
308+
// DirectPath requires a call credential during gRPC channel construction.
309+
if (needsCredentials()) {
310+
return false;
311+
}
307312
if (allowNonDefaultServiceAccount != null && allowNonDefaultServiceAccount) {
308313
return true;
309314
}
@@ -365,7 +370,7 @@ private ManagedChannel createSingleChannel() throws IOException {
365370
// Check DirectPath traffic.
366371
boolean useDirectPathXds = false;
367372
if (isDirectPathEnabled()
368-
&& isNonDefaultServiceAccountAllowed()
373+
&& isCredentialDirectPathCompatible()
369374
&& isOnComputeEngine()
370375
&& canUseDirectPathWithUniverseDomain()) {
371376
CallCredentials callCreds = MoreCallCredentials.from(credentials);

gax-java/gax-grpc/src/test/java/com/google/api/gax/grpc/InstantiatingGrpcChannelProviderTest.java

+8
Original file line numberDiff line numberDiff line change
@@ -284,6 +284,14 @@ public void testDirectPathXdsDisableByDefault() throws IOException {
284284
assertThat(provider.isDirectPathXdsEnabled()).isFalse();
285285
}
286286

287+
@Test
288+
public void testDirectPathDisallowNullCredentials() throws IOException {
289+
InstantiatingGrpcChannelProvider provider =
290+
InstantiatingGrpcChannelProvider.newBuilder().build();
291+
292+
assertThat(provider.isCredentialDirectPathCompatible()).isFalse();
293+
}
294+
287295
@Test
288296
public void testDirectPathXdsEnabled() throws IOException {
289297
InstantiatingGrpcChannelProvider provider =

0 commit comments

Comments
 (0)