From 445664fb8d82950215872cbfec91e37c5fa0920f Mon Sep 17 00:00:00 2001 From: Eduard Tudenhoefner Date: Wed, 18 Oct 2023 08:14:22 +0200 Subject: [PATCH] AWS: avoid static global credentials provider which doesn't play well with lifecycle management (#8677) (#8843) Co-authored-by: Kristin Cowalcijk --- .../org/apache/iceberg/aws/AwsClientFactories.java | 3 ++- .../org/apache/iceberg/aws/AwsClientProperties.java | 3 ++- .../java/org/apache/iceberg/aws/AwsProperties.java | 3 ++- .../apache/iceberg/aws/AwsClientPropertiesTest.java | 13 +++++++++++++ 4 files changed, 19 insertions(+), 3 deletions(-) diff --git a/aws/src/main/java/org/apache/iceberg/aws/AwsClientFactories.java b/aws/src/main/java/org/apache/iceberg/aws/AwsClientFactories.java index 1ec982225449..501c7ca8b3b4 100644 --- a/aws/src/main/java/org/apache/iceberg/aws/AwsClientFactories.java +++ b/aws/src/main/java/org/apache/iceberg/aws/AwsClientFactories.java @@ -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(); } } } diff --git a/aws/src/main/java/org/apache/iceberg/aws/AwsClientProperties.java b/aws/src/main/java/org/apache/iceberg/aws/AwsClientProperties.java index d85764c499cb..1d03a0acbd2c 100644 --- a/aws/src/main/java/org/apache/iceberg/aws/AwsClientProperties.java +++ b/aws/src/main/java/org/apache/iceberg/aws/AwsClientProperties.java @@ -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) { diff --git a/aws/src/main/java/org/apache/iceberg/aws/AwsProperties.java b/aws/src/main/java/org/apache/iceberg/aws/AwsProperties.java index 7bc2ba70dc4f..849445f86f3a 100644 --- a/aws/src/main/java/org/apache/iceberg/aws/AwsProperties.java +++ b/aws/src/main/java/org/apache/iceberg/aws/AwsProperties.java @@ -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) { diff --git a/aws/src/test/java/org/apache/iceberg/aws/AwsClientPropertiesTest.java b/aws/src/test/java/org/apache/iceberg/aws/AwsClientPropertiesTest.java index b763def5167a..7f57fbcb2d10 100644 --- a/aws/src/test/java/org/apache/iceberg/aws/AwsClientPropertiesTest.java +++ b/aws/src/test/java/org/apache/iceberg/aws/AwsClientPropertiesTest.java @@ -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();