Skip to content

Commit

Permalink
AWS: avoid static global credentials provider which doesn't play well…
Browse files Browse the repository at this point in the history
… with lifecycle management (#8677) (#8843)

Co-authored-by: Kristin Cowalcijk <[email protected]>
  • Loading branch information
nastra and Kontinuation authored Oct 18, 2023
1 parent 1e1c67e commit 445664f
Show file tree
Hide file tree
Showing 4 changed files with 19 additions and 3 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -226,7 +226,8 @@ static AwsCredentialsProvider credentialsProvider(
AwsSessionCredentials.create(accessKeyId, secretAccessKey, sessionToken));
}
} else {
return DefaultCredentialsProvider.create();
// Create a new credential provider for each client
return DefaultCredentialsProvider.builder().build();
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -150,7 +150,8 @@ public AwsCredentialsProvider credentialsProvider(
return credentialsProvider(this.clientCredentialsProvider);
}

return DefaultCredentialsProvider.create();
// Create a new credential provider for each client
return DefaultCredentialsProvider.builder().build();
}

private AwsCredentialsProvider credentialsProvider(String credentialsProviderClass) {
Expand Down
3 changes: 2 additions & 1 deletion aws/src/main/java/org/apache/iceberg/aws/AwsProperties.java
Original file line number Diff line number Diff line change
Expand Up @@ -485,7 +485,8 @@ private AwsCredentialsProvider credentialsProvider(
return credentialsProvider(this.clientCredentialsProvider);
}

return DefaultCredentialsProvider.create();
// Create a new credential provider for each client
return DefaultCredentialsProvider.builder().build();
}

private AwsCredentialsProvider credentialsProvider(String credentialsProviderClass) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -61,6 +61,19 @@ public void testDefaultCredentialsConfiguration() {
.isTrue();
}

@Test
public void testCreatesNewInstanceOfDefaultCredentialsConfiguration() {
AwsClientProperties awsClientProperties = new AwsClientProperties();
AwsCredentialsProvider credentialsProvider =
awsClientProperties.credentialsProvider(null, null, null);
AwsCredentialsProvider credentialsProvider2 =
awsClientProperties.credentialsProvider(null, null, null);

Assertions.assertThat(credentialsProvider)
.withFailMessage("Should create a new instance in each call")
.isNotSameAs(credentialsProvider2);
}

@Test
public void testBasicCredentialsConfiguration() {
AwsClientProperties awsClientProperties = new AwsClientProperties();
Expand Down

0 comments on commit 445664f

Please sign in to comment.