Skip to content

Commit f4402bf

Browse files
authored
fix: Disable automatically retrieving Universe Domain from Metadata Server (#3272)
See internal ticket b/349488459 for more info. External info: ComputeEngineCredentials in client libraries should not validate the universe domain. Validating the universe domain requires retrieving it from Metadata Server (MDS) and this will be temporarily disabled. For users that using client libraries, there will be no automatic call to MDS. For users that use the Credentials directly and manually call `ComputeEngineCredentials.getUniverseDomain()` and the universe domain is not explicitly set, it will make a call to MDS.
1 parent 6d85864 commit f4402bf

File tree

2 files changed

+23
-0
lines changed

2 files changed

+23
-0
lines changed

gax-java/gax/src/main/java/com/google/api/gax/rpc/EndpointContext.java

+6
Original file line numberDiff line numberDiff line change
@@ -32,6 +32,7 @@
3232
import com.google.api.core.InternalApi;
3333
import com.google.api.gax.rpc.mtls.MtlsProvider;
3434
import com.google.auth.Credentials;
35+
import com.google.auth.oauth2.ComputeEngineCredentials;
3536
import com.google.auto.value.AutoValue;
3637
import com.google.common.annotations.VisibleForTesting;
3738
import com.google.common.base.Strings;
@@ -145,6 +146,11 @@ public void validateUniverseDomain(
145146
// GDC-H has no universe domain, return
146147
return;
147148
}
149+
// (TODO: b/349488459) - Disable automatic requests to MDS until 01/2025
150+
// If MDS is required for Universe Domain, do not do any validation
151+
if (credentials instanceof ComputeEngineCredentials) {
152+
return;
153+
}
148154
String credentialsUniverseDomain = Credentials.GOOGLE_DEFAULT_UNIVERSE;
149155
// If credentials is not NoCredentialsProvider, use the Universe Domain inside Credentials
150156
if (credentials != null) {

gax-java/gax/src/test/java/com/google/api/gax/rpc/EndpointContextTest.java

+17
Original file line numberDiff line numberDiff line change
@@ -29,12 +29,14 @@
2929
*/
3030
package com.google.api.gax.rpc;
3131

32+
import static org.junit.jupiter.api.Assertions.assertDoesNotThrow;
3233
import static org.junit.jupiter.api.Assertions.assertThrows;
3334

3435
import com.google.api.gax.core.NoCredentialsProvider;
3536
import com.google.api.gax.rpc.mtls.MtlsProvider;
3637
import com.google.api.gax.rpc.testing.FakeMtlsProvider;
3738
import com.google.auth.Credentials;
39+
import com.google.auth.oauth2.ComputeEngineCredentials;
3840
import com.google.common.truth.Truth;
3941
import io.grpc.Status;
4042
import java.io.IOException;
@@ -437,4 +439,19 @@ void hasValidUniverseDomain_credentialsInGDU_configNonGDU() throws IOException {
437439
UnauthenticatedException.class,
438440
() -> endpointContext.validateUniverseDomain(credentials, statusCode));
439441
}
442+
443+
// (TODO: b/349488459) - Disable automatic requests to MDS until 01/2025
444+
// Test is to ensure that no validation is being run for ComputeEngineCredentials
445+
@Test
446+
void hasValidUniverseDomain_computeEngineCredentials_noValidationOnUniverseDomain()
447+
throws IOException {
448+
Credentials credentials = Mockito.mock(ComputeEngineCredentials.class);
449+
Mockito.when(credentials.getUniverseDomain()).thenReturn(Credentials.GOOGLE_DEFAULT_UNIVERSE);
450+
EndpointContext endpointContext =
451+
defaultEndpointContextBuilder
452+
// Set a custom Universe Domain that doesn't match
453+
.setUniverseDomain("test.com")
454+
.build();
455+
assertDoesNotThrow(() -> endpointContext.validateUniverseDomain(credentials, statusCode));
456+
}
440457
}

0 commit comments

Comments
 (0)