Skip to content

Commit 0da00d3

Browse files
SNOW-3643369: Always set explicit GCS credentials to prevent ADC probe in SPCS
1 parent 4993be9 commit 0da00d3

2 files changed

Lines changed: 11 additions & 10 deletions

File tree

src/main/java/net/snowflake/client/internal/jdbc/cloud/storage/GCSDefaultAccessStrategy.java

Lines changed: 7 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -51,20 +51,18 @@ class GCSDefaultAccessStrategy implements GCSAccessStrategy {
5151
StorageOptions.Builder builder = StorageOptions.newBuilder();
5252
overrideHost(stage, builder);
5353

54-
if (SnowflakeGCSClient.areDisabledGcsDefaultCredentials(session)) {
55-
logger.debug(
56-
"Adding explicit credentials to avoid default credential lookup by the GCS client");
57-
builder.setCredentials(GoogleCredentials.create(new AccessToken(accessToken, null)));
58-
}
54+
// Always set explicit credentials to prevent Application Default Credentials (ADC) lookup.
55+
// Without this, StorageOptions.build().getService() probes metadata.google.internal which
56+
// is unreachable in environments like SPCS, causing an opaque "invalid_gcs_credentials"
57+
// error.
58+
// Actual API authentication is handled by the Authorization header below, not this credential
59+
// object — it exists solely to suppress the ADC probe.
60+
builder.setCredentials(GoogleCredentials.create(new AccessToken(accessToken, null)));
5961

6062
if (transportFactory != null) {
6163
builder.setTransportOptions(
6264
HttpTransportOptions.newBuilder().setHttpTransportFactory(transportFactory).build());
6365
}
64-
65-
// Using GoogleCredential with access token will cause IllegalStateException when the token
66-
// is expired and trying to refresh, which cause error cannot be caught. Instead, set a
67-
// header so we can caught the error code.
6866
this.gcsClient =
6967
builder
7068
.setHeaderProvider(

src/main/java/net/snowflake/client/internal/jdbc/cloud/storage/SnowflakeGCSClient.java

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1262,8 +1262,11 @@ private void setupGCSClient(
12621262
encryptionKeySize);
12631263
}
12641264
}
1265+
} catch (SnowflakeSQLException ex) {
1266+
throw ex;
12651267
} catch (Exception ex) {
1266-
throw new IllegalArgumentException("invalid_gcs_credentials");
1268+
logger.debug("Failed to initialize GCS client", ex);
1269+
throw new IllegalArgumentException("invalid_gcs_credentials", ex);
12671270
}
12681271
}
12691272

0 commit comments

Comments
 (0)