Skip to content

Commit a34f1fb

Browse files
Merge branch 'master' into SNOW-2161718-JDBC-fix-permission-check-for-toml-config
2 parents d48db6c + 3b23be4 commit a34f1fb

23 files changed

+161
-108
lines changed

CHANGELOG.rst

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,7 @@
1+
**JDBC Driver 3.26.0**
2+
3+
- \||Please Refer to Release Notes at https://docs.snowflake.com/en/release-notes/clients-drivers/jdbc
4+
15
**JDBC Driver 3.25.1**
26

37
- \||Please Refer to Release Notes at https://docs.snowflake.com/en/release-notes/clients-drivers/jdbc

FIPS/pom.xml

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -5,12 +5,12 @@
55
<parent>
66
<groupId>net.snowflake</groupId>
77
<artifactId>snowflake-jdbc-parent</artifactId>
8-
<version>3.25.2-SNAPSHOT</version>
8+
<version>3.26.0</version>
99
<relativePath>../parent-pom.xml</relativePath>
1010
</parent>
1111

1212
<artifactId>snowflake-jdbc-fips</artifactId>
13-
<version>3.25.2-SNAPSHOT</version>
13+
<version>3.26.0</version>
1414
<packaging>jar</packaging>
1515

1616
<name>snowflake-jdbc-fips</name>

parent-pom.xml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@
55

66
<groupId>net.snowflake</groupId>
77
<artifactId>snowflake-jdbc-parent</artifactId>
8-
<version>3.25.2-SNAPSHOT</version>
8+
<version>3.26.0</version>
99
<packaging>pom</packaging>
1010

1111
<modules>

pom.xml

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -6,13 +6,13 @@
66
<parent>
77
<groupId>net.snowflake</groupId>
88
<artifactId>snowflake-jdbc-parent</artifactId>
9-
<version>3.25.2-SNAPSHOT</version>
9+
<version>3.26.0</version>
1010
<relativePath>./parent-pom.xml</relativePath>
1111
</parent>
1212

1313
<!-- Maven complains about using property here, but it makes install and deploy process easier to override final package names and localization -->
1414
<artifactId>${artifactId}</artifactId>
15-
<version>3.25.2-SNAPSHOT</version>
15+
<version>3.26.0</version>
1616
<packaging>jar</packaging>
1717

1818
<name>${artifactId}</name>

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

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -391,9 +391,6 @@ 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-
}
397394
WorkloadIdentityAttestationProvider attestationProvider =
398395
new WorkloadIdentityAttestationProvider(
399396
new AwsIdentityAttestationCreator(new AwsAttestationService()),

src/main/java/net/snowflake/client/core/auth/wif/AwsAttestationService.java

Lines changed: 12 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,9 @@ public class AwsAttestationService {
2323

2424
public AwsAttestationService() {
2525
aws4Signer = new AWS4Signer();
26+
}
27+
28+
void initializeSignerRegion() {
2629
aws4Signer.setRegionName(getAWSRegion());
2730
}
2831

@@ -31,18 +34,18 @@ AWSCredentials getAWSCredentials() {
3134
}
3235

3336
String getAWSRegion() {
34-
try {
35-
if (!regionInitialized) {
36-
String envRegion = SnowflakeUtil.systemGetEnv(EnvironmentVariables.AWS_REGION.getName());
37-
region = envRegion != null ? envRegion : new InstanceMetadataRegionProvider().getRegion();
37+
if (!regionInitialized) {
38+
logger.debug("Getting AWS region from environment variable");
39+
String envRegion = SnowflakeUtil.systemGetEnv(EnvironmentVariables.AWS_REGION.getName());
40+
if (envRegion != null) {
41+
region = envRegion;
42+
} else {
43+
logger.debug("Getting AWS region from EC2 metadata service");
44+
region = new InstanceMetadataRegionProvider().getRegion();
3845
}
39-
return region;
40-
} catch (Exception e) {
41-
logger.debug("Could not get AWS region", e);
42-
return null;
43-
} finally {
4446
regionInitialized = true;
4547
}
48+
return region;
4649
}
4750

4851
void signRequestWithSigV4(Request<Void> signableRequest, AWSCredentials awsCredentials) {

src/main/java/net/snowflake/client/core/auth/wif/AwsIdentityAttestationCreator.java

Lines changed: 7 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,9 @@
1010
import java.util.Base64;
1111
import java.util.Collections;
1212
import net.minidev.json.JSONObject;
13+
import net.snowflake.client.core.SFException;
1314
import net.snowflake.client.core.SnowflakeJdbcInternalApi;
15+
import net.snowflake.client.jdbc.ErrorCode;
1416
import net.snowflake.client.log.SFLogger;
1517
import net.snowflake.client.log.SFLoggerFactory;
1618

@@ -29,17 +31,17 @@ public AwsIdentityAttestationCreator(AwsAttestationService attestationService) {
2931
}
3032

3133
@Override
32-
public WorkloadIdentityAttestation createAttestation() {
34+
public WorkloadIdentityAttestation createAttestation() throws SFException {
3335
logger.debug("Creating AWS identity attestation...");
36+
attestationService.initializeSignerRegion();
3437
AWSCredentials awsCredentials = attestationService.getAWSCredentials();
3538
if (awsCredentials == null) {
36-
logger.debug("No AWS credentials were found.");
37-
return null;
39+
throw new SFException(
40+
ErrorCode.WORKLOAD_IDENTITY_FLOW_ERROR, "No AWS credentials were found");
3841
}
3942
String region = attestationService.getAWSRegion();
4043
if (region == null) {
41-
logger.debug("No AWS region was found.");
42-
return null;
44+
throw new SFException(ErrorCode.WORKLOAD_IDENTITY_FLOW_ERROR, "No AWS region was found");
4345
}
4446

4547
String stsHostname = getStsHostname(region);

src/main/java/net/snowflake/client/core/auth/wif/AzureAttestationService.java

Lines changed: 8 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,9 @@
11
package net.snowflake.client.core.auth.wif;
22

3+
import net.snowflake.client.core.SFException;
34
import net.snowflake.client.core.SFLoginInput;
45
import net.snowflake.client.core.SnowflakeJdbcInternalApi;
6+
import net.snowflake.client.jdbc.ErrorCode;
57
import net.snowflake.client.jdbc.SnowflakeUtil;
68
import net.snowflake.client.log.SFLogger;
79
import net.snowflake.client.log.SFLoggerFactory;
@@ -27,12 +29,15 @@ String getClientId() {
2729
return SnowflakeUtil.systemGetEnv("MANAGED_IDENTITY_CLIENT_ID");
2830
}
2931

30-
String fetchTokenFromMetadataService(HttpRequestBase tokenRequest, SFLoginInput loginInput) {
32+
String fetchTokenFromMetadataService(HttpRequestBase tokenRequest, SFLoginInput loginInput)
33+
throws SFException {
3134
try {
3235
return WorkloadIdentityUtil.performIdentityRequest(tokenRequest, loginInput);
3336
} catch (Exception e) {
34-
logger.debug("Azure metadata server request was not successful: {}", e);
35-
return null;
37+
logger.error("Azure metadata server request failed", e);
38+
throw new SFException(
39+
ErrorCode.WORKLOAD_IDENTITY_FLOW_ERROR,
40+
"Azure metadata server request was not successful: " + e.getMessage());
3641
}
3742
}
3843
}

src/main/java/net/snowflake/client/core/auth/wif/AzureIdentityAttestationCreator.java

Lines changed: 14 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -7,8 +7,10 @@
77
import com.fasterxml.jackson.databind.JsonNode;
88
import com.fasterxml.jackson.databind.ObjectMapper;
99
import com.google.common.base.Strings;
10+
import net.snowflake.client.core.SFException;
1011
import net.snowflake.client.core.SFLoginInput;
1112
import net.snowflake.client.core.SnowflakeJdbcInternalApi;
13+
import net.snowflake.client.jdbc.ErrorCode;
1214
import net.snowflake.client.log.SFLogger;
1315
import net.snowflake.client.log.SFLoggerFactory;
1416
import org.apache.http.client.methods.HttpGet;
@@ -48,7 +50,7 @@ public AzureIdentityAttestationCreator(
4850
}
4951

5052
@Override
51-
public WorkloadIdentityAttestation createAttestation() {
53+
public WorkloadIdentityAttestation createAttestation() throws SFException {
5254
logger.debug("Creating Azure identity attestation...");
5355
String identityEndpoint = azureAttestationService.getIdentityEndpoint();
5456
HttpGet request;
@@ -57,28 +59,24 @@ public WorkloadIdentityAttestation createAttestation() {
5759
} else {
5860
String identityHeader = azureAttestationService.getIdentityHeader();
5961
if (Strings.isNullOrEmpty(identityHeader)) {
60-
logger.warn("Managed identity is not enabled on this Azure function.");
61-
return null;
62+
throw new SFException(
63+
ErrorCode.WORKLOAD_IDENTITY_FLOW_ERROR,
64+
"Managed identity is not enabled on this Azure function.");
6265
}
6366
request =
6467
createAzureFunctionsIdentityRequest(
6568
identityEndpoint, identityHeader, azureAttestationService.getClientId());
6669
}
6770
String tokenJson = azureAttestationService.fetchTokenFromMetadataService(request, loginInput);
6871
if (tokenJson == null) {
69-
logger.debug("Could not fetch Azure token.");
70-
return null;
72+
throw new SFException(ErrorCode.WORKLOAD_IDENTITY_FLOW_ERROR, "Could not fetch Azure token.");
7173
}
7274
String token = extractTokenFromJson(tokenJson);
7375
if (token == null) {
74-
logger.error("No access token found in Azure response.");
75-
return null;
76+
throw new SFException(
77+
ErrorCode.WORKLOAD_IDENTITY_FLOW_ERROR, "No access token found in Azure response.");
7678
}
7779
SubjectAndIssuer claims = extractClaimsWithoutVerifyingSignature(token);
78-
if (claims == null) {
79-
logger.error("Could not extract claims from token");
80-
return null;
81-
}
8280
return new WorkloadIdentityAttestation(
8381
WorkloadIdentityProviderType.AZURE, token, claims.toMap());
8482
}
@@ -91,13 +89,15 @@ private String getEntraResource(SFLoginInput loginInput) {
9189
}
9290
}
9391

94-
private String extractTokenFromJson(String tokenJson) {
92+
private String extractTokenFromJson(String tokenJson) throws SFException {
9593
try {
9694
JsonNode jsonNode = objectMapper.readTree(tokenJson);
9795
return jsonNode.get("access_token").asText();
9896
} catch (Exception e) {
99-
logger.error("Unable to extract token from Azure metadata response: {}", e.getMessage());
100-
return null;
97+
logger.error("Unable to extract token from Azure metadata response", e);
98+
throw new SFException(
99+
ErrorCode.WORKLOAD_IDENTITY_FLOW_ERROR,
100+
"Unable to extract token from Azure metadata response: " + e.getMessage());
101101
}
102102
}
103103

src/main/java/net/snowflake/client/core/auth/wif/GcpIdentityAttestationCreator.java

Lines changed: 9 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -4,8 +4,10 @@
44
import static net.snowflake.client.core.auth.wif.WorkloadIdentityUtil.performIdentityRequest;
55

66
import java.util.Collections;
7+
import net.snowflake.client.core.SFException;
78
import net.snowflake.client.core.SFLoginInput;
89
import net.snowflake.client.core.SnowflakeJdbcInternalApi;
10+
import net.snowflake.client.jdbc.ErrorCode;
911
import net.snowflake.client.log.SFLogger;
1012
import net.snowflake.client.log.SFLoggerFactory;
1113
import org.apache.http.client.methods.HttpGet;
@@ -35,28 +37,23 @@ public GcpIdentityAttestationCreator(SFLoginInput loginInput) {
3537
}
3638

3739
@Override
38-
public WorkloadIdentityAttestation createAttestation() {
40+
public WorkloadIdentityAttestation createAttestation() throws SFException {
3941
logger.debug("Creating GCP identity attestation...");
4042
String token = fetchTokenFromMetadataService();
4143
if (token == null) {
42-
logger.debug("No GCP token was found.");
43-
return null;
44+
throw new SFException(ErrorCode.WORKLOAD_IDENTITY_FLOW_ERROR, "No GCP token was found.");
4445
}
4546
// if the token has been returned, we can assume that we're on GCP environment
4647
WorkloadIdentityUtil.SubjectAndIssuer claims =
4748
WorkloadIdentityUtil.extractClaimsWithoutVerifyingSignature(token);
48-
if (claims == null) {
49-
logger.error("Could not extract claims from token");
50-
return null;
51-
}
5249

5350
return new WorkloadIdentityAttestation(
5451
WorkloadIdentityProviderType.GCP,
5552
token,
5653
Collections.singletonMap("sub", claims.getSubject()));
5754
}
5855

59-
private String fetchTokenFromMetadataService() {
56+
private String fetchTokenFromMetadataService() throws SFException {
6057
String uri =
6158
gcpMetadataServiceBaseUrl
6259
+ "/computeMetadata/v1/instance/service-accounts/default/identity?audience="
@@ -66,8 +63,10 @@ private String fetchTokenFromMetadataService() {
6663
try {
6764
return performIdentityRequest(tokenRequest, loginInput);
6865
} catch (Exception e) {
69-
logger.debug("GCP metadata server request was not successful: {}" + e);
70-
return null;
66+
logger.error("GCP metadata server request was not successful", e);
67+
throw new SFException(
68+
ErrorCode.WORKLOAD_IDENTITY_FLOW_ERROR,
69+
"GCP metadata server request was not successful: " + e.getMessage());
7170
}
7271
}
7372
}

0 commit comments

Comments
 (0)