CTTY commented on code in PR #16794:
URL: https://github.com/apache/iceberg/pull/16794#discussion_r3554772035


##########
aws/src/main/java/org/apache/iceberg/aws/AwsProperties.java:
##########
@@ -493,10 +510,55 @@ private AwsCredentialsProvider credentialsProvider(
       return credentialsProvider(this.clientCredentialsProvider);
     }
 
+    // When a role is configured to be assumed (e.g. via 
AssumeRoleAwsClientFactory), sign requests
+    // with the assumed-role credentials so that they do not diverge from the 
credentials used for
+    // S3, Glue, KMS and DynamoDB. See 
https://github.com/apache/iceberg/issues/16667.
+    if (!Strings.isNullOrEmpty(this.clientAssumeRoleArn)) {
+      if (!Strings.isNullOrEmpty(this.clientAssumeRoleRegion)) {
+        return assumeRoleCredentialsProvider();
+      }
+
+      LOG.warn(
+          "Cannot assume role {} to sign REST requests because {} is not set; "
+              + "falling back to the default credentials provider.",
+          this.clientAssumeRoleArn,
+          CLIENT_ASSUME_ROLE_REGION);
+    }
+
     // Create a new credential provider for each client
     return DefaultCredentialsProvider.builder().build();
   }
 
+  StsAssumeRoleCredentialsProvider assumeRoleCredentialsProvider() {
+    Preconditions.checkNotNull(
+        this.clientAssumeRoleRegion,
+        "Cannot create StsAssumeRoleCredentialsProvider with null region");
+    return StsAssumeRoleCredentialsProvider.builder()
+        .stsClient(
+            StsClient.builder()
+                
.applyMutation(httpClientProperties::applyHttpClientConfigurations)
+                .region(Region.of(this.clientAssumeRoleRegion))
+                .build())
+        .refreshRequest(createAssumeRoleRequest())
+        .build();
+  }
+
+  private AssumeRoleRequest createAssumeRoleRequest() {
+    Preconditions.checkNotNull(
+        this.clientAssumeRoleArn, "Cannot create AssumeRoleRequest with null 
role ARN");
+    String sessionName =
+        this.clientAssumeRoleSessionName != null
+            ? this.clientAssumeRoleSessionName
+            : String.format("iceberg-aws-%s", uuid);

Review Comment:
   why don't we just remove the uuid and finalize the session name here? My 
understanding is that the first session that reaches this line get to finalize 
the session name, and the following sessions will just reuse the existing 
session name? 
   
   For code that never reaches this line, if they call 
`clientAssumeRoleSessionName` by any chance, they still get `null` as expected



-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: [email protected]

For queries about this service, please contact Infrastructure at:
[email protected]


---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]

Reply via email to