singhpk234 commented on code in PR #4052:
URL: https://github.com/apache/polaris/pull/4052#discussion_r3022120213


##########
polaris-core/src/main/java/org/apache/polaris/core/storage/aws/AwsS3TablesStorageConfigurationInfo.java:
##########
@@ -0,0 +1,92 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements.  See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership.  The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License.  You may obtain a copy of the License at
+ *
+ *   http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied.  See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+package org.apache.polaris.core.storage.aws;
+
+import com.fasterxml.jackson.annotation.JsonIgnore;
+import com.fasterxml.jackson.annotation.JsonTypeName;
+import com.fasterxml.jackson.databind.annotation.JsonDeserialize;
+import com.fasterxml.jackson.databind.annotation.JsonSerialize;
+import jakarta.annotation.Nullable;
+import java.net.URI;
+import java.util.List;
+import org.apache.polaris.core.storage.PolarisStorageConfigurationInfo;
+import org.apache.polaris.immutables.PolarisImmutable;
+import org.immutables.value.Value;
+
+/** AWS S3 Tables storage configuration information. */
+@PolarisImmutable
+@JsonSerialize(as = ImmutableAwsS3TablesStorageConfigurationInfo.class)
+@JsonDeserialize(as = ImmutableAwsS3TablesStorageConfigurationInfo.class)
+@JsonTypeName("AwsS3TablesStorageConfigurationInfo")
+public abstract class AwsS3TablesStorageConfigurationInfo extends 
PolarisStorageConfigurationInfo {

Review Comment:
   why not extend AWSS3StorageIntegrations ?



##########
polaris-core/src/main/java/org/apache/polaris/core/storage/aws/AwsCredentialsStorageIntegration.java:
##########
@@ -393,6 +399,36 @@ private static String arnKeyAll(String region, String 
accountId) {
     return String.format("arn:aws:kms:%s:%s:key/*", region, accountId);
   }
 
+  private boolean isS3TablesRequest(CredentialVendingContext context) {
+    return context.signingName().map("s3tables"::equals).orElse(false);
+  }
+
+  /**
+   * Generates an IAM session policy for S3 Tables access. Read access always 
includes GetTableData
+   * and GetTableMetadataLocation. Write access additionally includes 
UpdateTableMetadataLocation
+   * and PutTableData. Resources are scoped to the specific table ARN(s) from 
the context.
+   */
+  private IamPolicy s3TablesPolicyString(CredentialVendingContext context, 
boolean canWrite) {
+    IamStatement.Builder statement =
+        IamStatement.builder()
+            .effect(IamEffect.ALLOW)
+            .addAction("s3tables:GetTableData")
+            .addAction("s3tables:GetTableMetadataLocation");
+
+    if (canWrite) {
+      statement
+          .addAction("s3tables:UpdateTableMetadataLocation")
+          .addAction("s3tables:PutTableData");
+    }
+
+    List<String> arns = context.resourceArns().orElse(List.of());
+    for (String arn : arns) {
+      statement.addResource(IamResource.create(arn));
+    }
+
+    return IamPolicy.builder().addStatement(statement.build()).build();

Review Comment:
   I think having a dedidcated storage integration would be really helpful than 
writing if else for s3 tables 



##########
polaris-core/src/main/java/org/apache/polaris/core/entity/CatalogEntity.java:
##########
@@ -200,6 +202,18 @@ private StorageConfigInfo getStorageInfo(Map<String, 
String> internalProperties)
             .setStorageName(fileConfigModel.getStorageName())
             .build();
       }
+      if (configInfo instanceof AwsS3TablesStorageConfigurationInfo 
s3TablesConfig) {
+        return AwsS3TablesStorageConfigInfo.builder()
+            .setRoleArn(s3TablesConfig.getRoleARN())
+            .setExternalId(s3TablesConfig.getExternalId())
+            .setRegion(s3TablesConfig.getRegion())
+            .setCurrentKmsKey(s3TablesConfig.getCurrentKmsKey())
+            .setAllowedKmsKeys(s3TablesConfig.getAllowedKmsKeys())
+            .setStorageType(StorageConfigInfo.StorageTypeEnum.S3_TABLES)
+            .setAllowedLocations(s3TablesConfig.getAllowedLocations())
+            .setStorageName(s3TablesConfig.getStorageName())
+            .build();
+      }

Review Comment:
   lets keep this just next to S3 ? 



##########
polaris-core/src/main/java/org/apache/polaris/core/storage/PolarisStorageConfigurationInfo.java:
##########
@@ -200,6 +202,7 @@ public enum StorageType {
     AZURE(List.of("abfs://", "wasb://", "abfss://", "wasbs://")),
     GCS("gs://"),
     FILE("file://"),
+    S3_TABLES("arn:"),

Review Comment:
   how about specifying this till : `arn:aws:s3tables`



##########
runtime/service/src/main/java/org/apache/polaris/service/catalog/iceberg/ConfigCapturingHTTPClient.java:
##########
@@ -0,0 +1,120 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements.  See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership.  The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License.  You may obtain a copy of the License at
+ *
+ *   http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied.  See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+package org.apache.polaris.service.catalog.iceberg;
+
+import java.io.IOException;
+import java.util.Map;
+import java.util.function.Consumer;
+import org.apache.iceberg.rest.RESTClient;
+import org.apache.iceberg.rest.RESTRequest;
+import org.apache.iceberg.rest.RESTResponse;
+import org.apache.iceberg.rest.responses.ErrorResponse;
+import org.apache.iceberg.rest.responses.LoadTableResponse;
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
+
+/**
+ * A delegating wrapper around the Iceberg {@link RESTClient} that intercepts 
responses to extract
+ * the {@code config} section from loadTable responses. When a {@link 
LoadTableResponse} is
+ * received, the config map (containing {@code tableId} for S3 Tables) is 
captured and stored in the
+ * request-scoped {@link CapturedConfigHolder}.
+ */
+public class ConfigCapturingHTTPClient implements RESTClient {

Review Comment:
   rather than overriding the rest client i wonder if we can inject the 
`@RequestScopedBean` we introduced i.e `CapturedConfigHolder` where we are 
doing actual loadTable ? i am assuming as part of federaton we would be calling 
irc's loadTable anyways ?



##########
runtime/service/src/main/java/org/apache/polaris/service/catalog/iceberg/IcebergCatalogHandler.java:
##########
@@ -855,8 +865,35 @@ private LoadTableResponse.Builder 
buildLoadTableResponseWithDelegationCredential
 
       Set<String> tableLocations = 
StorageUtil.getLocationsUsedByTable(tableMetadata);
 
-      // For non polaris' catalog, validate that table locations are within 
allowed locations
-      if (!(baseCatalog instanceof IcebergCatalog)) {
+      // For S3 Tables catalogs, replace s3:// table locations with the 
constructed table ARN.
+      // s3tables:* IAM actions require ARN resources, not s3:// paths.
+      CatalogEntity catalogEntity = 
CatalogEntity.of(getResolvedCatalogEntity());
+      boolean isS3Tables =
+          catalogEntity.getStorageConfigurationInfo() != null
+              && catalogEntity.getStorageConfigurationInfo().getStorageType()
+                  == PolarisStorageConfigurationInfo.StorageType.S3_TABLES;

Review Comment:
   lets move to a private function below, also lets writes an assumption, i 
would say that call to federated catalog has succeeded and now we want to ..... 
   I don't fully understand the contextConfigholder requirement though let me 
think more about that as well meanwhile. 



-- 
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]

Reply via email to