smaheshwar-pltr commented on code in PR #18081:
URL: https://github.com/apache/iceberg/pull/18081#discussion_r4740700140


##########
docs/docs/rest-catalog.md:
##########
@@ -85,6 +85,7 @@ at connection time through
 | `scan-planning-mode`                  | `client`          | Controls where 
scan planning is performed. Supported values: `client` (client-side planning), 
`server` (server-side planning). Can be overridden per-table by the server in 
LoadTableResponse. |
 | `rest-scan-planning.poll-timeout-ms`  | `300000` (5 min)  | Maximum time in 
milliseconds to wait when polling for async server-side scan planning results.  
                                                                                
               |
 | `rest-scan-planning.poll-num-retries` | `10`              | Extra poll 
attempts after the first fetch of a submitted plan. `0` means a single fetch 
with no retries.                                                                
                       |
+| `rest.encryption.access-delegation-enabled` | `false`     | Whether a 
catalog with a client-side KMS (`encryption.kms-type` or `encryption.kms-impl`) 
may request delegated storage access through `X-Iceberg-Access-Delegation`. 
When `false`, the catalog fails to initialize if that header requests anything 
other than `none`. Only read from client properties. |

Review Comment:
   Should we also update 
https://github.com/apache/iceberg/blob/d9d0b79d5d0f359ce8ba3c8c33d855ef5f8a8a99/docs/docs/encryption.md?plain=1#L34
 in this PR?



##########
core/src/test/java/org/apache/iceberg/rest/TestRESTCatalog.java:
##########
@@ -4182,6 +4182,43 @@ void clientKmsAllowsNoAccessDelegation() {
         .doesNotThrowAnyException();
   }
 
+  @Test
+  void clientKmsAllowsAccessDelegationWhenEnabled() {
+    assertThatCode(
+            () ->
+                catalogWithConfig(
+                        ConfigResponse.builder().build(),
+                        ImmutableMap.of(
+                            CatalogProperties.ENCRYPTION_KMS_IMPL,
+                            UnitestKMS.class.getName(),
+                            "header.X-Iceberg-Access-Delegation",
+                            "vended-credentials",
+                            
RESTCatalogProperties.ENCRYPTION_ACCESS_DELEGATION_ENABLED,
+                            "true"))
+                    .close())
+        .doesNotThrowAnyException();
+  }
+
+  @Test
+  void clientKmsIgnoresAccessDelegationEnabledFromServerConfig() {
+    assertThatThrownBy(
+            () ->
+                catalogWithConfig(
+                    ConfigResponse.builder()
+                        .withOverride(
+                            
RESTCatalogProperties.ENCRYPTION_ACCESS_DELEGATION_ENABLED, "true")
+                        .build(),
+                    ImmutableMap.of(
+                        CatalogProperties.ENCRYPTION_KMS_IMPL,
+                        UnitestKMS.class.getName(),
+                        "header.X-Iceberg-Access-Delegation",
+                        "vended-credentials")))
+        .isInstanceOf(IllegalArgumentException.class)
+        .hasMessage(
+            "Cannot request access delegation with a client-side KMS: "
+                + "header.X-Iceberg-Access-Delegation=vended-credentials (must 
be none or unset)");

Review Comment:
   Should we name `RESTCatalogProperties.ENCRYPTION_ACCESS_DELEGATION_ENABLED` 
in the error message?



##########
core/src/main/java/org/apache/iceberg/rest/RESTSessionCatalog.java:
##########
@@ -238,8 +238,17 @@ public void initialize(String name, Map<String, String> 
unresolved) {
 
     if (mergedProps.containsKey(CatalogProperties.ENCRYPTION_KMS_TYPE)
         || mergedProps.containsKey(CatalogProperties.ENCRYPTION_KMS_IMPL)) {
-      // REST can't delegate KMS access, so storage access must also come from 
the client
-      RESTUtil.checkNoAccessDelegation(RESTUtil.configHeaders(mergedProps));
+      // REST can't delegate KMS access, so storage access must also come from 
the client unless
+      // the client opts in; the opt-in is read from client properties so the 
server can't set it

Review Comment:
   I wonder if there's an argument for allowing the server to set it, if we 
want to support this use case in the first place? (Given the spec anyway leaves 
vending up to the server so it could circumvent it, or even override this 
header)



##########
core/src/main/java/org/apache/iceberg/rest/RESTCatalogProperties.java:
##########
@@ -68,6 +68,11 @@ private RESTCatalogProperties() {}
       "rest-scan-planning.poll-num-retries";
   public static final int REST_SCAN_PLANNING_POLL_NUM_RETRIES_DEFAULT = 10;
 
+  // Allow requesting delegated storage access while using a client-side KMS.
+  public static final String ENCRYPTION_ACCESS_DELEGATION_ENABLED =
+      "rest.encryption.access-delegation-enabled";

Review Comment:
   Minor, we usually use the `enabled` suffix to _switch a behaviour on_ (e.g. 
`rest-metrics-reporting-enabled`, `s3.remote-signing-enabled`) but that isn't 
quite the case here. Maybe `rest.encryption.access-delegation-allowed`?



##########
core/src/test/java/org/apache/iceberg/rest/TestRESTCatalog.java:
##########
@@ -4182,6 +4182,43 @@ void clientKmsAllowsNoAccessDelegation() {
         .doesNotThrowAnyException();
   }
 
+  @Test
+  void clientKmsAllowsAccessDelegationWhenEnabled() {

Review Comment:
   I wonder if we could actually test the hybrid mode here - so that some later 
change which does some check (e.g. on credentials) doesn't break this 
property's documented semantics without warning.
   
   E.g. 
https://github.com/apache/iceberg/blob/d9d0b79d5d0f359ce8ba3c8c33d855ef5f8a8a99/core/src/test/java/org/apache/iceberg/rest/TestRESTCatalog.java#L3896
   
   has some example wiring that we could potentially use to test an actual 
encrypted table used with vended storage credentials and the client's KMS?



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