Skip to content

Commit 1094417

Browse files
Merge branch 'master' into SNOW-1943242-jdbc-caches-closeablehttpclient-indefinitely
2 parents 6a5d28e + 4eebd72 commit 1094417

5 files changed

Lines changed: 15 additions & 131 deletions

File tree

src/main/java/net/snowflake/client/core/SessionUtil.java

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -391,6 +391,9 @@ private static boolean isNativeOAuthOriginalAuthenticator(SFLoginInput loginInpu
391391

392392
private static WorkloadIdentityAttestation getWorkloadIdentityAttestation(SFLoginInput loginInput)
393393
throws SFException {
394+
if (loginInput.getWorkloadIdentityProvider() == null) {
395+
return null;
396+
}
394397
WorkloadIdentityAttestationProvider attestationProvider =
395398
new WorkloadIdentityAttestationProvider(
396399
new AwsIdentityAttestationCreator(new AwsAttestationService()),
Lines changed: 1 addition & 52 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,5 @@
11
package net.snowflake.client.core.auth.wif;
22

3-
import com.google.common.base.Strings;
4-
import java.util.function.Supplier;
53
import net.snowflake.client.core.SFException;
64
import net.snowflake.client.core.SnowflakeJdbcInternalApi;
75
import net.snowflake.client.jdbc.ErrorCode;
@@ -31,12 +29,7 @@ public WorkloadIdentityAttestationProvider(
3129
}
3230

3331
public WorkloadIdentityAttestation getAttestation(String identityProvider) throws SFException {
34-
if (Strings.isNullOrEmpty(identityProvider)) {
35-
logger.debug("Workload Identity Provider has not been specified. Using autodetect...");
36-
return createAutodetectAttestation();
37-
} else {
38-
return getCreator(identityProvider).createAttestation();
39-
}
32+
return getCreator(identityProvider).createAttestation();
4033
}
4134

4235
WorkloadIdentityAttestationCreator getCreator(String identityProvider) throws SFException {
@@ -54,48 +47,4 @@ WorkloadIdentityAttestationCreator getCreator(String identityProvider) throws SF
5447
"Unknown Workload Identity provider specified: " + identityProvider);
5548
}
5649
}
57-
58-
private WorkloadIdentityAttestation createAutodetectAttestation() throws SFException {
59-
WorkloadIdentityAttestation oidcAttestation =
60-
getAttestationForAutodetect(
61-
oidcAttestationCreator::createAttestation, WorkloadIdentityProviderType.OIDC);
62-
if (oidcAttestation != null) {
63-
return oidcAttestation;
64-
}
65-
WorkloadIdentityAttestation awsAttestation =
66-
getAttestationForAutodetect(
67-
awsAttestationCreator::createAttestation, WorkloadIdentityProviderType.AWS);
68-
if (awsAttestation != null) {
69-
return awsAttestation;
70-
}
71-
WorkloadIdentityAttestation gcpAttestation =
72-
getAttestationForAutodetect(
73-
gcpAttestationCreator::createAttestation, WorkloadIdentityProviderType.GCP);
74-
if (gcpAttestation != null) {
75-
return gcpAttestation;
76-
}
77-
WorkloadIdentityAttestation azureAttestation =
78-
getAttestationForAutodetect(
79-
azureAttestationCreator::createAttestation, WorkloadIdentityProviderType.AZURE);
80-
if (azureAttestation != null) {
81-
return azureAttestation;
82-
}
83-
throw new SFException(
84-
ErrorCode.WORKLOAD_IDENTITY_FLOW_ERROR,
85-
"Unable to autodetect Workload Identity. None of supported Workload Identity environments has been identified.");
86-
}
87-
88-
/**
89-
* Method needed in case of autodetect feature. Drivers has to keep on trying next WIF providers,
90-
* even if exceptions are thrown
91-
*/
92-
private WorkloadIdentityAttestation getAttestationForAutodetect(
93-
Supplier<WorkloadIdentityAttestation> supplier, WorkloadIdentityProviderType providerType) {
94-
try {
95-
return supplier.get();
96-
} catch (Exception e) {
97-
logger.debug("Unable to create identity attestation for {}, error: {}", providerType, e);
98-
return null;
99-
}
100-
}
10150
}

src/main/java/net/snowflake/client/jdbc/cloud/storage/S3HttpUtil.java

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,8 @@
44

55
import com.amazonaws.ClientConfiguration;
66
import com.amazonaws.Protocol;
7+
import com.amazonaws.ProxyAuthenticationMethod;
8+
import java.util.Arrays;
79
import java.util.Properties;
810
import net.snowflake.client.core.HttpClientSettingsKey;
911
import net.snowflake.client.core.HttpProtocol;
@@ -50,6 +52,10 @@ public static void setProxyForS3(HttpClientSettingsKey key, ClientConfiguration
5052
+ SFLoggerUtil.isVariableProvided(key.getProxyPassword());
5153
clientConfig.setProxyUsername(key.getProxyUser());
5254
clientConfig.setProxyPassword(key.getProxyPassword());
55+
// Force the use of BASIC authentication only for proxy authentication
56+
// This ensures that when multiple authentication schemes are offered by the proxy
57+
// (e.g., NEGOTIATE, NTLM, BASIC), we only use BASIC authentication
58+
clientConfig.setProxyAuthenticationMethods(Arrays.asList(ProxyAuthenticationMethod.BASIC));
5359
}
5460
logger.debug(logMessage);
5561
} else {
@@ -116,6 +122,11 @@ public static void setSessionlessProxyForS3(
116122
logMessage += ", user: " + proxyUser + " with password provided";
117123
clientConfig.setProxyUsername(proxyUser);
118124
clientConfig.setProxyPassword(proxyPassword);
125+
// Force the use of BASIC authentication only for proxy authentication
126+
// This ensures that when multiple authentication schemes are offered by the proxy
127+
// (e.g., NEGOTIATE, NTLM, BASIC), we only use BASIC authentication
128+
clientConfig.setProxyAuthenticationMethods(
129+
Arrays.asList(ProxyAuthenticationMethod.BASIC));
119130
}
120131
logger.debug(logMessage);
121132
} else {
Lines changed: 0 additions & 71 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,6 @@
11
package net.snowflake.client.core.auth.wif;
22

33
import static net.snowflake.client.core.auth.wif.WorkloadIdentityProviderType.AWS;
4-
import static net.snowflake.client.core.auth.wif.WorkloadIdentityProviderType.AZURE;
5-
import static net.snowflake.client.core.auth.wif.WorkloadIdentityProviderType.GCP;
6-
import static net.snowflake.client.core.auth.wif.WorkloadIdentityProviderType.OIDC;
74

85
import java.util.HashMap;
96
import net.snowflake.client.core.SFException;
@@ -53,72 +50,4 @@ public void shouldCreateProperAttestationCreatorByType() throws SFException {
5350
Assertions.assertThrows(
5451
SFException.class, () -> provider.getCreator("UNKNOWN_IDENTITY_PROVIDER"));
5552
}
56-
57-
@Test
58-
public void shouldAutodetectAwsProvider() throws SFException {
59-
WorkloadIdentityAttestationProvider provider = createMockProvider(AWS);
60-
WorkloadIdentityAttestation attestation = provider.getAttestation(null);
61-
62-
Assertions.assertNotNull(attestation);
63-
Assertions.assertEquals(AWS, attestation.getProvider());
64-
Assertions.assertEquals("aws_cred", attestation.getCredential());
65-
}
66-
67-
@Test
68-
public void shouldAutodetectGCPProvider() throws SFException {
69-
WorkloadIdentityAttestationProvider provider = createMockProvider(GCP);
70-
WorkloadIdentityAttestation attestation = provider.getAttestation(null);
71-
72-
Assertions.assertNotNull(attestation);
73-
Assertions.assertEquals(WorkloadIdentityProviderType.GCP, attestation.getProvider());
74-
Assertions.assertEquals("gcp_cred", attestation.getCredential());
75-
}
76-
77-
@Test
78-
public void shouldAutodetectAzureProvider() throws SFException {
79-
WorkloadIdentityAttestationProvider provider = createMockProvider(AZURE);
80-
WorkloadIdentityAttestation attestation = provider.getAttestation(null);
81-
82-
Assertions.assertNotNull(attestation);
83-
Assertions.assertEquals(WorkloadIdentityProviderType.AZURE, attestation.getProvider());
84-
Assertions.assertEquals("azure_cred", attestation.getCredential());
85-
}
86-
87-
@Test
88-
public void shouldAutodetectOidcProvider() throws SFException {
89-
WorkloadIdentityAttestationProvider provider = createMockProvider(OIDC);
90-
WorkloadIdentityAttestation attestation = provider.getAttestation(null);
91-
Assertions.assertNotNull(attestation);
92-
Assertions.assertEquals(WorkloadIdentityProviderType.OIDC, attestation.getProvider());
93-
Assertions.assertEquals("oidc_cred", attestation.getCredential());
94-
}
95-
96-
WorkloadIdentityAttestationProvider createMockProvider(
97-
WorkloadIdentityProviderType actualPresentType) {
98-
AwsIdentityAttestationCreator aws = Mockito.mock(AwsIdentityAttestationCreator.class);
99-
Mockito.when(aws.createAttestation())
100-
.thenReturn(
101-
actualPresentType == AWS
102-
? new WorkloadIdentityAttestation(AWS, "aws_cred", new HashMap<>())
103-
: null);
104-
GcpIdentityAttestationCreator gcp = Mockito.mock(GcpIdentityAttestationCreator.class);
105-
Mockito.when(gcp.createAttestation())
106-
.thenReturn(
107-
actualPresentType == GCP
108-
? new WorkloadIdentityAttestation(GCP, "gcp_cred", new HashMap<>())
109-
: null);
110-
OidcIdentityAttestationCreator oidc = Mockito.mock(OidcIdentityAttestationCreator.class);
111-
Mockito.when(oidc.createAttestation())
112-
.thenReturn(
113-
actualPresentType == OIDC
114-
? new WorkloadIdentityAttestation(OIDC, "oidc_cred", new HashMap<>())
115-
: null);
116-
AzureIdentityAttestationCreator azure = Mockito.mock(AzureIdentityAttestationCreator.class);
117-
Mockito.when(azure.createAttestation())
118-
.thenReturn(
119-
actualPresentType == AZURE
120-
? new WorkloadIdentityAttestation(AZURE, "azure_cred", new HashMap<>())
121-
: null);
122-
return new WorkloadIdentityAttestationProvider(aws, gcp, azure, oidc);
123-
}
12453
}

src/test/java/net/snowflake/client/wif/WIFLatestIT.java

Lines changed: 0 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -33,14 +33,6 @@ public class WIFLatestIT {
3333
private static final String HOST = System.getenv("SNOWFLAKE_TEST_WIF_HOST");
3434
private static final String PROVIDER = System.getenv("SNOWFLAKE_TEST_WIF_PROVIDER");
3535

36-
@Test
37-
void shouldAuthenticateUsingWIFWithProviderDetection() {
38-
Properties properties = new Properties();
39-
properties.put("account", ACCOUNT);
40-
properties.put("authenticator", "WORKLOAD_IDENTITY");
41-
connectAndExecuteSimpleQuery(properties);
42-
}
43-
4436
@Test
4537
void shouldAuthenticateUsingWIFWithDefinedProvider() {
4638
Properties properties = new Properties();

0 commit comments

Comments
 (0)