szlta commented on code in PR #13186:
URL: https://github.com/apache/iceberg/pull/13186#discussion_r2166620209


##########
azure/src/main/java/org/apache/iceberg/azure/keymanagement/AzureKeyManagementClient.java:
##########
@@ -0,0 +1,70 @@
+/*
+ * 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.iceberg.azure.keymanagement;
+
+import com.azure.identity.DefaultAzureCredentialBuilder;
+import com.azure.security.keyvault.keys.KeyClient;
+import com.azure.security.keyvault.keys.KeyClientBuilder;
+import com.azure.security.keyvault.keys.cryptography.models.KeyWrapAlgorithm;
+import com.azure.security.keyvault.keys.cryptography.models.UnwrapResult;
+import com.azure.security.keyvault.keys.cryptography.models.WrapResult;
+import java.nio.ByteBuffer;
+import java.util.Map;
+import org.apache.iceberg.azure.AzureProperties;
+import org.apache.iceberg.encryption.KeyManagementClient;
+import org.apache.iceberg.util.ByteBuffers;
+
+/** Azure key management client which connects to Azure Key Vault. */
+public class AzureKeyManagementClient implements KeyManagementClient {
+  private KeyClient keyClient;
+  private KeyWrapAlgorithm keyWrapAlgorithm;
+
+  @Override
+  public ByteBuffer wrapKey(ByteBuffer key, String wrappingKeyId) {
+    WrapResult wrapResult =
+        keyClient
+            .getCryptographyClient(wrappingKeyId)
+            .wrapKey(keyWrapAlgorithm, ByteBuffers.toByteArray(key));
+    return ByteBuffer.wrap(wrapResult.getEncryptedKey());
+  }
+
+  @Override
+  public ByteBuffer unwrapKey(ByteBuffer wrappedKey, String wrappingKeyId) {
+    UnwrapResult unwrapResult =
+        keyClient
+            .getCryptographyClient(wrappingKeyId)
+            .unwrapKey(keyWrapAlgorithm, ByteBuffers.toByteArray(wrappedKey));
+    return ByteBuffer.wrap(unwrapResult.getKey());

Review Comment:
   Looking at the PR's by @ggershinsky it is expected that in `unwrapKey()` 
method `wrappedKey` is reset after use. (Same applies to `key` in `wrapKey()`.) 
 Can you please make sure the position of these BBs is reset to 0?



##########
build.gradle:
##########
@@ -550,6 +550,7 @@ project(':iceberg-azure') {
 
     compileOnly platform(libs.azuresdk.bom)
     compileOnly "com.azure:azure-storage-file-datalake"
+    compileOnly "com.azure:azure-security-keyvault-keys"

Review Comment:
   I suspect we probably want to include this into `iceberg-azure-bundle` too?



##########
azure/src/main/java/org/apache/iceberg/azure/keymanagement/AzureKeyManagementClient.java:
##########
@@ -0,0 +1,70 @@
+/*
+ * 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.iceberg.azure.keymanagement;
+
+import com.azure.identity.DefaultAzureCredentialBuilder;
+import com.azure.security.keyvault.keys.KeyClient;
+import com.azure.security.keyvault.keys.KeyClientBuilder;
+import com.azure.security.keyvault.keys.cryptography.models.KeyWrapAlgorithm;
+import com.azure.security.keyvault.keys.cryptography.models.UnwrapResult;
+import com.azure.security.keyvault.keys.cryptography.models.WrapResult;
+import java.nio.ByteBuffer;
+import java.util.Map;
+import org.apache.iceberg.azure.AzureProperties;
+import org.apache.iceberg.encryption.KeyManagementClient;
+import org.apache.iceberg.util.ByteBuffers;
+
+/** Azure key management client which connects to Azure Key Vault. */
+public class AzureKeyManagementClient implements KeyManagementClient {
+  private KeyClient keyClient;
+  private KeyWrapAlgorithm keyWrapAlgorithm;
+
+  @Override
+  public ByteBuffer wrapKey(ByteBuffer key, String wrappingKeyId) {
+    WrapResult wrapResult =
+        keyClient
+            .getCryptographyClient(wrappingKeyId)
+            .wrapKey(keyWrapAlgorithm, ByteBuffers.toByteArray(key));
+    return ByteBuffer.wrap(wrapResult.getEncryptedKey());
+  }
+
+  @Override
+  public ByteBuffer unwrapKey(ByteBuffer wrappedKey, String wrappingKeyId) {
+    UnwrapResult unwrapResult =
+        keyClient
+            .getCryptographyClient(wrappingKeyId)
+            .unwrapKey(keyWrapAlgorithm, ByteBuffers.toByteArray(wrappedKey));
+    return ByteBuffer.wrap(unwrapResult.getKey());
+  }
+
+  @Override
+  public void initialize(Map<String, String> properties) {
+    String vaultUrl = properties.get(AzureProperties.KEYVAULT_URI);
+    keyClient =
+        new KeyClientBuilder()
+            .vaultUrl(vaultUrl)
+            .credential(new DefaultAzureCredentialBuilder().build())
+            .buildClient();
+    this.keyWrapAlgorithm =
+        KeyWrapAlgorithm.fromString(
+            properties.getOrDefault(
+                AzureProperties.KEYVAULT_KEY_WRAPPING_ALGORITHM,
+                KeyWrapAlgorithm.RSA_OAEP_256.getValue()));

Review Comment:
   Would it not make sense to handle the defaulting logic inside 
AzureProperties instead?



-- 
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: issues-unsubscr...@iceberg.apache.org

For queries about this service, please contact Infrastructure at:
us...@infra.apache.org


---------------------------------------------------------------------
To unsubscribe, e-mail: issues-unsubscr...@iceberg.apache.org
For additional commands, e-mail: issues-h...@iceberg.apache.org

Reply via email to