You are viewing a plain text version of this content. The canonical link for it is here.
Posted to issues@iceberg.apache.org by "szlta (via GitHub)" <gi...@apache.org> on 2025/05/23 11:07:48 UTC
[PR] AWS: KeyManagementClient implementation that works with AWS KMS [iceberg]
szlta opened a new pull request, #13136:
URL: https://github.com/apache/iceberg/pull/13136
To be used in table encryption for:
- wrapping/unwrapping encryption keys
- generating data keys (available specs: AES_256, AES_128)
Added integration test for verification.
--
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-unsubscribe@iceberg.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
---------------------------------------------------------------------
To unsubscribe, e-mail: issues-unsubscribe@iceberg.apache.org
For additional commands, e-mail: issues-help@iceberg.apache.org
Re: [PR] AWS: KeyManagementClient implementation that works with AWS KMS [iceberg]
Posted by "smaheshwar-pltr (via GitHub)" <gi...@apache.org>.
smaheshwar-pltr commented on code in PR #13136:
URL: https://github.com/apache/iceberg/pull/13136#discussion_r2134655837
##########
core/src/main/java/org/apache/iceberg/encryption/KeyManagementClient.java:
##########
@@ -24,7 +24,7 @@
import java.util.Map;
/** A minimum client interface to connect to a key management service (KMS). */
-interface KeyManagementClient extends Serializable, Closeable {
+public interface KeyManagementClient extends Serializable, Closeable {
Review Comment:
Also, I believe that it being public allows catalogs / table operations in other packages *use* the KMS client - e.g. https://github.com/apache/iceberg/pull/13066 / https://github.com/apache/iceberg/pull/13225.
--
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-unsubscribe@iceberg.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
---------------------------------------------------------------------
To unsubscribe, e-mail: issues-unsubscribe@iceberg.apache.org
For additional commands, e-mail: issues-help@iceberg.apache.org
Re: [PR] AWS: KeyManagementClient implementation that works with AWS KMS [iceberg]
Posted by "jbonofre (via GitHub)" <gi...@apache.org>.
jbonofre commented on PR #13136:
URL: https://github.com/apache/iceberg/pull/13136#issuecomment-2915277304
I will take a look as well. Thanks !
--
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-unsubscribe@iceberg.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
---------------------------------------------------------------------
To unsubscribe, e-mail: issues-unsubscribe@iceberg.apache.org
For additional commands, e-mail: issues-help@iceberg.apache.org
Re: [PR] AWS: KeyManagementClient implementation that works with AWS KMS [iceberg]
Posted by "szlta (via GitHub)" <gi...@apache.org>.
szlta commented on code in PR #13136:
URL: https://github.com/apache/iceberg/pull/13136#discussion_r2216354049
##########
aws/src/integration/java/org/apache/iceberg/aws/TestKeyManagementClient.java:
##########
@@ -0,0 +1,133 @@
+/*
+ * 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.aws;
+
+import static org.assertj.core.api.Assertions.assertThat;
+
+import java.nio.ByteBuffer;
+import java.util.Map;
+import org.apache.iceberg.encryption.KeyManagementClient;
+import org.apache.iceberg.relocated.com.google.common.collect.ImmutableMap;
+import org.junit.jupiter.api.AfterAll;
+import org.junit.jupiter.api.BeforeAll;
+import org.junit.jupiter.api.Test;
+import org.junit.jupiter.api.condition.EnabledIfEnvironmentVariable;
+import org.junit.jupiter.api.condition.EnabledIfEnvironmentVariables;
+import org.junit.jupiter.params.ParameterizedTest;
+import org.junit.jupiter.params.provider.EnumSource;
+import org.junit.jupiter.params.provider.NullSource;
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
+import software.amazon.awssdk.services.kms.KmsClient;
+import software.amazon.awssdk.services.kms.model.CreateKeyRequest;
+import software.amazon.awssdk.services.kms.model.CreateKeyResponse;
+import software.amazon.awssdk.services.kms.model.DataKeySpec;
+import software.amazon.awssdk.services.kms.model.KeySpec;
+import software.amazon.awssdk.services.kms.model.ScheduleKeyDeletionRequest;
+import software.amazon.awssdk.services.kms.model.ScheduleKeyDeletionResponse;
+
+@EnabledIfEnvironmentVariables({
+ @EnabledIfEnvironmentVariable(named = AwsIntegTestUtil.AWS_ACCESS_KEY_ID, matches = ".*"),
+ @EnabledIfEnvironmentVariable(named = AwsIntegTestUtil.AWS_SECRET_ACCESS_KEY, matches = ".*"),
+ @EnabledIfEnvironmentVariable(named = AwsIntegTestUtil.AWS_SESSION_TOKEN, matches = ".*"),
+ @EnabledIfEnvironmentVariable(named = AwsIntegTestUtil.AWS_TEST_ACCOUNT_ID, matches = "\\d{12}")
+})
+public class TestKeyManagementClient {
+
+ private static final Logger LOG = LoggerFactory.getLogger(TestKeyManagementClient.class);
+
+ private static KmsClient kmsClient;
+ private static String keyId;
+
+ @BeforeAll
+ public static void beforeClass() {
+ kmsClient = AwsClientFactories.defaultFactory().kms();
+ CreateKeyRequest createKeyRequest =
+ CreateKeyRequest.builder()
+ .keySpec(KeySpec.SYMMETRIC_DEFAULT)
+ .description(
+ "Iceberg integration test key for " + TestKeyManagementClient.class.getName())
+ .build();
+ CreateKeyResponse response = kmsClient.createKey(createKeyRequest);
+ keyId = response.keyMetadata().keyId();
+ }
+
+ @Test
+ public void testKeyWrapping() {
+ AwsKeyManagementClient keyManagementClient = new AwsKeyManagementClient();
+ try {
Review Comment:
Makes sense, refactored.
--
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-unsubscribe@iceberg.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
---------------------------------------------------------------------
To unsubscribe, e-mail: issues-unsubscribe@iceberg.apache.org
For additional commands, e-mail: issues-help@iceberg.apache.org
Re: [PR] AWS: KeyManagementClient implementation that works with AWS KMS [iceberg]
Posted by "szlta (via GitHub)" <gi...@apache.org>.
szlta commented on PR #13136:
URL: https://github.com/apache/iceberg/pull/13136#issuecomment-2904218886
cc: @amogh-jahagirdar
--
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-unsubscribe@iceberg.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
---------------------------------------------------------------------
To unsubscribe, e-mail: issues-unsubscribe@iceberg.apache.org
For additional commands, e-mail: issues-help@iceberg.apache.org
Re: [PR] AWS: KeyManagementClient implementation that works with AWS KMS [iceberg]
Posted by "jbonofre (via GitHub)" <gi...@apache.org>.
jbonofre commented on PR #13136:
URL: https://github.com/apache/iceberg/pull/13136#issuecomment-2915276780
@nastra @Fokko ^^
--
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-unsubscribe@iceberg.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
---------------------------------------------------------------------
To unsubscribe, e-mail: issues-unsubscribe@iceberg.apache.org
For additional commands, e-mail: issues-help@iceberg.apache.org
Re: [PR] AWS: KeyManagementClient implementation that works with AWS KMS [iceberg]
Posted by "smaheshwar-pltr (via GitHub)" <gi...@apache.org>.
smaheshwar-pltr commented on code in PR #13136:
URL: https://github.com/apache/iceberg/pull/13136#discussion_r2134655837
##########
core/src/main/java/org/apache/iceberg/encryption/KeyManagementClient.java:
##########
@@ -24,7 +24,7 @@
import java.util.Map;
/** A minimum client interface to connect to a key management service (KMS). */
-interface KeyManagementClient extends Serializable, Closeable {
+public interface KeyManagementClient extends Serializable, Closeable {
Review Comment:
Also, I believe that it being public lets catalogs / table operations in other packages *use* the KMS client - e.g. https://github.com/apache/iceberg/pull/13066 / https://github.com/apache/iceberg/pull/13225.
--
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-unsubscribe@iceberg.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
---------------------------------------------------------------------
To unsubscribe, e-mail: issues-unsubscribe@iceberg.apache.org
For additional commands, e-mail: issues-help@iceberg.apache.org
Re: [PR] AWS: KeyManagementClient implementation that works with AWS KMS [iceberg]
Posted by "amogh-jahagirdar (via GitHub)" <gi...@apache.org>.
amogh-jahagirdar merged PR #13136:
URL: https://github.com/apache/iceberg/pull/13136
--
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-unsubscribe@iceberg.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
---------------------------------------------------------------------
To unsubscribe, e-mail: issues-unsubscribe@iceberg.apache.org
For additional commands, e-mail: issues-help@iceberg.apache.org
Re: [PR] AWS: KeyManagementClient implementation that works with AWS KMS [iceberg]
Posted by "smaheshwar-pltr (via GitHub)" <gi...@apache.org>.
smaheshwar-pltr commented on code in PR #13136:
URL: https://github.com/apache/iceberg/pull/13136#discussion_r2134663195
##########
aws/src/main/java/org/apache/iceberg/aws/AwsKeyManagementClient.java:
##########
@@ -0,0 +1,107 @@
+/*
+ * 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.aws;
+
+import java.nio.ByteBuffer;
+import java.util.Map;
+import org.apache.iceberg.encryption.KeyManagementClient;
+import software.amazon.awssdk.core.SdkBytes;
+import software.amazon.awssdk.services.kms.KmsClient;
+import software.amazon.awssdk.services.kms.model.DataKeySpec;
+import software.amazon.awssdk.services.kms.model.DecryptRequest;
+import software.amazon.awssdk.services.kms.model.DecryptResponse;
+import software.amazon.awssdk.services.kms.model.EncryptRequest;
+import software.amazon.awssdk.services.kms.model.EncryptResponse;
+import software.amazon.awssdk.services.kms.model.EncryptionAlgorithmSpec;
+import software.amazon.awssdk.services.kms.model.GenerateDataKeyRequest;
+import software.amazon.awssdk.services.kms.model.GenerateDataKeyResponse;
+
+/**
+ * Key management client implementation that uses AWS Key Management Service. To be used for
+ * encrypting/decrypting keys with a KMS-managed master key, (by referencing its key ID), and for
+ * the generation of new encryption keys.
+ */
+public class AwsKeyManagementClient implements KeyManagementClient {
Review Comment:
Yeah `KeyManagementClient` does implement `Serializable` as is (though looking at the implementation, wonder how necessary that is - it's transient in the `StandardEncryptionmanager` both now and after https://github.com/apache/iceberg/pull/7770, cc @ggershinsky)
--
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-unsubscribe@iceberg.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
---------------------------------------------------------------------
To unsubscribe, e-mail: issues-unsubscribe@iceberg.apache.org
For additional commands, e-mail: issues-help@iceberg.apache.org
Re: [PR] AWS: KeyManagementClient implementation that works with AWS KMS [iceberg]
Posted by "nastra (via GitHub)" <gi...@apache.org>.
nastra commented on code in PR #13136:
URL: https://github.com/apache/iceberg/pull/13136#discussion_r2216064942
##########
aws/src/integration/java/org/apache/iceberg/aws/TestKeyManagementClient.java:
##########
@@ -0,0 +1,133 @@
+/*
+ * 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.aws;
+
+import static org.assertj.core.api.Assertions.assertThat;
+
+import java.nio.ByteBuffer;
+import java.util.Map;
+import org.apache.iceberg.encryption.KeyManagementClient;
+import org.apache.iceberg.relocated.com.google.common.collect.ImmutableMap;
+import org.junit.jupiter.api.AfterAll;
+import org.junit.jupiter.api.BeforeAll;
+import org.junit.jupiter.api.Test;
+import org.junit.jupiter.api.condition.EnabledIfEnvironmentVariable;
+import org.junit.jupiter.api.condition.EnabledIfEnvironmentVariables;
+import org.junit.jupiter.params.ParameterizedTest;
+import org.junit.jupiter.params.provider.EnumSource;
+import org.junit.jupiter.params.provider.NullSource;
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
+import software.amazon.awssdk.services.kms.KmsClient;
+import software.amazon.awssdk.services.kms.model.CreateKeyRequest;
+import software.amazon.awssdk.services.kms.model.CreateKeyResponse;
+import software.amazon.awssdk.services.kms.model.DataKeySpec;
+import software.amazon.awssdk.services.kms.model.KeySpec;
+import software.amazon.awssdk.services.kms.model.ScheduleKeyDeletionRequest;
+import software.amazon.awssdk.services.kms.model.ScheduleKeyDeletionResponse;
+
+@EnabledIfEnvironmentVariables({
+ @EnabledIfEnvironmentVariable(named = AwsIntegTestUtil.AWS_ACCESS_KEY_ID, matches = ".*"),
+ @EnabledIfEnvironmentVariable(named = AwsIntegTestUtil.AWS_SECRET_ACCESS_KEY, matches = ".*"),
+ @EnabledIfEnvironmentVariable(named = AwsIntegTestUtil.AWS_SESSION_TOKEN, matches = ".*"),
+ @EnabledIfEnvironmentVariable(named = AwsIntegTestUtil.AWS_TEST_ACCOUNT_ID, matches = "\\d{12}")
+})
+public class TestKeyManagementClient {
+
+ private static final Logger LOG = LoggerFactory.getLogger(TestKeyManagementClient.class);
+
+ private static KmsClient kmsClient;
+ private static String keyId;
+
+ @BeforeAll
+ public static void beforeClass() {
+ kmsClient = AwsClientFactories.defaultFactory().kms();
+ CreateKeyRequest createKeyRequest =
+ CreateKeyRequest.builder()
+ .keySpec(KeySpec.SYMMETRIC_DEFAULT)
+ .description(
+ "Iceberg integration test key for " + TestKeyManagementClient.class.getName())
+ .build();
+ CreateKeyResponse response = kmsClient.createKey(createKeyRequest);
+ keyId = response.keyMetadata().keyId();
+ }
+
+ @Test
+ public void testKeyWrapping() {
+ AwsKeyManagementClient keyManagementClient = new AwsKeyManagementClient();
+ try {
Review Comment:
I would suggest to use try-with-resources block here which automatically closes the client
##########
aws/src/main/java/org/apache/iceberg/aws/AwsKeyManagementClient.java:
##########
@@ -0,0 +1,107 @@
+/*
+ * 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.aws;
+
+import java.nio.ByteBuffer;
+import java.util.Map;
+import org.apache.iceberg.encryption.KeyManagementClient;
+import software.amazon.awssdk.core.SdkBytes;
+import software.amazon.awssdk.services.kms.KmsClient;
+import software.amazon.awssdk.services.kms.model.DataKeySpec;
+import software.amazon.awssdk.services.kms.model.DecryptRequest;
+import software.amazon.awssdk.services.kms.model.DecryptResponse;
+import software.amazon.awssdk.services.kms.model.EncryptRequest;
+import software.amazon.awssdk.services.kms.model.EncryptResponse;
+import software.amazon.awssdk.services.kms.model.EncryptionAlgorithmSpec;
+import software.amazon.awssdk.services.kms.model.GenerateDataKeyRequest;
+import software.amazon.awssdk.services.kms.model.GenerateDataKeyResponse;
+
+/**
+ * Key management client implementation that uses AWS Key Management Service. To be used for
+ * encrypting/decrypting keys with a KMS-managed master key, (by referencing its key ID), and for
+ * the generation of new encryption keys.
+ */
+public class AwsKeyManagementClient implements KeyManagementClient {
+
+ private KmsClient kmsClient;
+ private EncryptionAlgorithmSpec encryptionAlgorithmSpec;
+ private DataKeySpec dataKeySpec;
+
+ public AwsKeyManagementClient() {}
+
+ @Override
+ public ByteBuffer wrapKey(ByteBuffer key, String wrappingKeyId) {
+ EncryptRequest request =
+ EncryptRequest.builder()
+ .keyId(wrappingKeyId)
+ .encryptionAlgorithm(encryptionAlgorithmSpec)
+ .plaintext(SdkBytes.fromByteBuffer(key))
+ .build();
+
+ EncryptResponse result = kmsClient.encrypt(request);
+ return result.ciphertextBlob().asByteBuffer();
+ }
+
+ @Override
+ public boolean supportsKeyGeneration() {
+ return true;
+ }
+
+ @Override
+ public KeyGenerationResult generateKey(String wrappingKeyId) {
+ GenerateDataKeyRequest request =
+ GenerateDataKeyRequest.builder().keyId(wrappingKeyId).keySpec(dataKeySpec).build();
+
+ GenerateDataKeyResponse response = kmsClient.generateDataKey(request);
+ KeyGenerationResult result =
+ new KeyGenerationResult(
+ response.plaintext().asByteBuffer(), response.ciphertextBlob().asByteBuffer());
+ return result;
+ }
+
+ @Override
+ public ByteBuffer unwrapKey(ByteBuffer wrappedKey, String wrappingKeyId) {
+ DecryptRequest request =
+ DecryptRequest.builder()
+ .keyId(wrappingKeyId)
+ .encryptionAlgorithm(encryptionAlgorithmSpec)
+ .ciphertextBlob(SdkBytes.fromByteBuffer(wrappedKey))
+ .build();
+
+ DecryptResponse result = kmsClient.decrypt(request);
+ return result.plaintext().asByteBuffer();
+ }
+
+ @Override
+ public void initialize(Map<String, String> properties) {
Review Comment:
can you please move this to the top so that initialization code comes first
##########
aws/src/integration/java/org/apache/iceberg/aws/TestKeyManagementClient.java:
##########
@@ -0,0 +1,133 @@
+/*
+ * 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.aws;
+
+import static org.assertj.core.api.Assertions.assertThat;
+
+import java.nio.ByteBuffer;
+import java.util.Map;
+import org.apache.iceberg.encryption.KeyManagementClient;
+import org.apache.iceberg.relocated.com.google.common.collect.ImmutableMap;
+import org.junit.jupiter.api.AfterAll;
+import org.junit.jupiter.api.BeforeAll;
+import org.junit.jupiter.api.Test;
+import org.junit.jupiter.api.condition.EnabledIfEnvironmentVariable;
+import org.junit.jupiter.api.condition.EnabledIfEnvironmentVariables;
+import org.junit.jupiter.params.ParameterizedTest;
+import org.junit.jupiter.params.provider.EnumSource;
+import org.junit.jupiter.params.provider.NullSource;
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
+import software.amazon.awssdk.services.kms.KmsClient;
+import software.amazon.awssdk.services.kms.model.CreateKeyRequest;
+import software.amazon.awssdk.services.kms.model.CreateKeyResponse;
+import software.amazon.awssdk.services.kms.model.DataKeySpec;
+import software.amazon.awssdk.services.kms.model.KeySpec;
+import software.amazon.awssdk.services.kms.model.ScheduleKeyDeletionRequest;
+import software.amazon.awssdk.services.kms.model.ScheduleKeyDeletionResponse;
+
+@EnabledIfEnvironmentVariables({
+ @EnabledIfEnvironmentVariable(named = AwsIntegTestUtil.AWS_ACCESS_KEY_ID, matches = ".*"),
+ @EnabledIfEnvironmentVariable(named = AwsIntegTestUtil.AWS_SECRET_ACCESS_KEY, matches = ".*"),
+ @EnabledIfEnvironmentVariable(named = AwsIntegTestUtil.AWS_SESSION_TOKEN, matches = ".*"),
+ @EnabledIfEnvironmentVariable(named = AwsIntegTestUtil.AWS_TEST_ACCOUNT_ID, matches = "\\d{12}")
+})
+public class TestKeyManagementClient {
+
+ private static final Logger LOG = LoggerFactory.getLogger(TestKeyManagementClient.class);
+
+ private static KmsClient kmsClient;
+ private static String keyId;
+
+ @BeforeAll
+ public static void beforeClass() {
+ kmsClient = AwsClientFactories.defaultFactory().kms();
+ CreateKeyRequest createKeyRequest =
+ CreateKeyRequest.builder()
+ .keySpec(KeySpec.SYMMETRIC_DEFAULT)
+ .description(
+ "Iceberg integration test key for " + TestKeyManagementClient.class.getName())
+ .build();
+ CreateKeyResponse response = kmsClient.createKey(createKeyRequest);
+ keyId = response.keyMetadata().keyId();
+ }
+
+ @Test
+ public void testKeyWrapping() {
+ AwsKeyManagementClient keyManagementClient = new AwsKeyManagementClient();
+ try {
+ keyManagementClient.initialize(ImmutableMap.of());
+
+ ByteBuffer key = ByteBuffer.wrap(new String("super-secret-table-master-key").getBytes());
+ ByteBuffer encryptedKey = keyManagementClient.wrapKey(key, keyId);
+
+ assertThat(keyManagementClient.unwrapKey(encryptedKey, keyId)).isEqualTo(key);
+ } finally {
+ keyManagementClient.close();
+ }
+ }
+
+ @ParameterizedTest
+ @NullSource
+ @EnumSource(
+ value = DataKeySpec.class,
+ names = {"AES_128", "AES_256"})
+ public void testKeyGeneration(DataKeySpec dataKeySpec) {
+ AwsKeyManagementClient keyManagementClient = new AwsKeyManagementClient();
+ try {
+ Map<String, String> properties =
+ dataKeySpec == null
+ ? ImmutableMap.of()
+ : ImmutableMap.of(AwsProperties.KMS_DATA_KEY_SPEC, dataKeySpec.name());
+ keyManagementClient.initialize(properties);
+ KeyManagementClient.KeyGenerationResult result = keyManagementClient.generateKey(keyId);
+
+ assertThat(keyManagementClient.unwrapKey(result.wrappedKey(), keyId)).isEqualTo(result.key());
+ assertThat(result.key().limit()).isEqualTo(expectedLength(dataKeySpec));
+ } finally {
+ keyManagementClient.close();
+ }
+ }
+
+ private static int expectedLength(DataKeySpec spec) {
+ if (DataKeySpec.AES_128.equals(spec)) {
+ return 128 / 8;
+ } else {
+ return 256 / 8;
+ }
+ }
+
+ @AfterAll
+ public static void afterClass() {
Review Comment:
minor: can you please move this right after `beforeClass`?
##########
aws/src/main/java/org/apache/iceberg/aws/AwsKeyManagementClient.java:
##########
@@ -0,0 +1,107 @@
+/*
+ * 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.aws;
+
+import java.nio.ByteBuffer;
+import java.util.Map;
+import org.apache.iceberg.encryption.KeyManagementClient;
+import software.amazon.awssdk.core.SdkBytes;
+import software.amazon.awssdk.services.kms.KmsClient;
+import software.amazon.awssdk.services.kms.model.DataKeySpec;
+import software.amazon.awssdk.services.kms.model.DecryptRequest;
+import software.amazon.awssdk.services.kms.model.DecryptResponse;
+import software.amazon.awssdk.services.kms.model.EncryptRequest;
+import software.amazon.awssdk.services.kms.model.EncryptResponse;
+import software.amazon.awssdk.services.kms.model.EncryptionAlgorithmSpec;
+import software.amazon.awssdk.services.kms.model.GenerateDataKeyRequest;
+import software.amazon.awssdk.services.kms.model.GenerateDataKeyResponse;
+
+/**
+ * Key management client implementation that uses AWS Key Management Service. To be used for
+ * encrypting/decrypting keys with a KMS-managed master key, (by referencing its key ID), and for
+ * the generation of new encryption keys.
+ */
+public class AwsKeyManagementClient implements KeyManagementClient {
+
+ private KmsClient kmsClient;
+ private EncryptionAlgorithmSpec encryptionAlgorithmSpec;
+ private DataKeySpec dataKeySpec;
+
+ public AwsKeyManagementClient() {}
Review Comment:
can probably be removed
--
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-unsubscribe@iceberg.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
---------------------------------------------------------------------
To unsubscribe, e-mail: issues-unsubscribe@iceberg.apache.org
For additional commands, e-mail: issues-help@iceberg.apache.org
Re: [PR] AWS: KeyManagementClient implementation that works with AWS KMS [iceberg]
Posted by "szlta (via GitHub)" <gi...@apache.org>.
szlta commented on code in PR #13136:
URL: https://github.com/apache/iceberg/pull/13136#discussion_r2137650948
##########
aws/src/main/java/org/apache/iceberg/aws/AwsKeyManagementClient.java:
##########
@@ -0,0 +1,107 @@
+/*
+ * 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.aws;
+
+import java.nio.ByteBuffer;
+import java.util.Map;
+import org.apache.iceberg.encryption.KeyManagementClient;
+import software.amazon.awssdk.core.SdkBytes;
+import software.amazon.awssdk.services.kms.KmsClient;
+import software.amazon.awssdk.services.kms.model.DataKeySpec;
+import software.amazon.awssdk.services.kms.model.DecryptRequest;
+import software.amazon.awssdk.services.kms.model.DecryptResponse;
+import software.amazon.awssdk.services.kms.model.EncryptRequest;
+import software.amazon.awssdk.services.kms.model.EncryptResponse;
+import software.amazon.awssdk.services.kms.model.EncryptionAlgorithmSpec;
+import software.amazon.awssdk.services.kms.model.GenerateDataKeyRequest;
+import software.amazon.awssdk.services.kms.model.GenerateDataKeyResponse;
+
+/**
+ * Key management client implementation that uses AWS Key Management Service. To be used for
+ * encrypting/decrypting keys with a KMS-managed master key, (by referencing its key ID), and for
+ * the generation of new encryption keys.
+ */
+public class AwsKeyManagementClient implements KeyManagementClient {
Review Comment:
As @smaheshwar-pltr points it out the class implements `Serializable` by interface but I also have doubts whether that's actually needed. KMS interactions for table encryption only concerns the master key which I'd expect to take place on driver / coordinator nodes, encrypting/decrypting the metadata json or manifest lists. Everything else down to the data files will not require a 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: issues-unsubscribe@iceberg.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
---------------------------------------------------------------------
To unsubscribe, e-mail: issues-unsubscribe@iceberg.apache.org
For additional commands, e-mail: issues-help@iceberg.apache.org
Re: [PR] AWS: KeyManagementClient implementation that works with AWS KMS [iceberg]
Posted by "pvary (via GitHub)" <gi...@apache.org>.
pvary commented on code in PR #13136:
URL: https://github.com/apache/iceberg/pull/13136#discussion_r2215839933
##########
core/src/main/java/org/apache/iceberg/encryption/KeyManagementClient.java:
##########
@@ -24,7 +24,7 @@
import java.util.Map;
/** A minimum client interface to connect to a key management service (KMS). */
-interface KeyManagementClient extends Serializable, Closeable {
+public interface KeyManagementClient extends Serializable, Closeable {
Review Comment:
Definitely looks like something which needs to be public
--
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-unsubscribe@iceberg.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
---------------------------------------------------------------------
To unsubscribe, e-mail: issues-unsubscribe@iceberg.apache.org
For additional commands, e-mail: issues-help@iceberg.apache.org
Re: [PR] AWS: KeyManagementClient implementation that works with AWS KMS [iceberg]
Posted by "amogh-jahagirdar (via GitHub)" <gi...@apache.org>.
amogh-jahagirdar commented on code in PR #13136:
URL: https://github.com/apache/iceberg/pull/13136#discussion_r2151357425
##########
aws/src/integration/java/org/apache/iceberg/aws/TestKeyManagementClient.java:
##########
@@ -0,0 +1,125 @@
+/*
+ * 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.aws;
+
+import static org.assertj.core.api.Assertions.assertThat;
+
+import java.nio.ByteBuffer;
+import java.util.Map;
+import org.apache.iceberg.encryption.KeyManagementClient;
+import org.apache.iceberg.relocated.com.google.common.collect.ImmutableMap;
+import org.junit.jupiter.api.AfterAll;
+import org.junit.jupiter.api.BeforeAll;
+import org.junit.jupiter.api.Test;
+import org.junit.jupiter.api.condition.EnabledIfEnvironmentVariable;
+import org.junit.jupiter.api.condition.EnabledIfEnvironmentVariables;
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
+import software.amazon.awssdk.services.kms.KmsClient;
+import software.amazon.awssdk.services.kms.model.CreateKeyRequest;
+import software.amazon.awssdk.services.kms.model.CreateKeyResponse;
+import software.amazon.awssdk.services.kms.model.DataKeySpec;
+import software.amazon.awssdk.services.kms.model.KeySpec;
+import software.amazon.awssdk.services.kms.model.ScheduleKeyDeletionRequest;
+import software.amazon.awssdk.services.kms.model.ScheduleKeyDeletionResponse;
+
+@EnabledIfEnvironmentVariables({
+ @EnabledIfEnvironmentVariable(named = AwsIntegTestUtil.AWS_ACCESS_KEY_ID, matches = ".*"),
+ @EnabledIfEnvironmentVariable(named = AwsIntegTestUtil.AWS_SECRET_ACCESS_KEY, matches = ".*"),
+ @EnabledIfEnvironmentVariable(named = AwsIntegTestUtil.AWS_SESSION_TOKEN, matches = ".*"),
+ @EnabledIfEnvironmentVariable(named = AwsIntegTestUtil.AWS_TEST_ACCOUNT_ID, matches = "\\d{12}")
+})
+public class TestKeyManagementClient {
+
+ private static final Logger LOG = LoggerFactory.getLogger(TestKeyManagementClient.class);
+
+ private static KmsClient kmsClient;
+ private static String keyId;
+
+ @BeforeAll
+ public static void beforeClass() {
+ kmsClient = AwsClientFactories.defaultFactory().kms();
+ CreateKeyRequest createKeyRequest =
+ CreateKeyRequest.builder()
+ .keySpec(KeySpec.SYMMETRIC_DEFAULT)
+ .description(
+ "Iceberg integration test key for " + TestKeyManagementClient.class.getName())
+ .build();
+ CreateKeyResponse response = kmsClient.createKey(createKeyRequest);
+ keyId = response.keyMetadata().keyId();
+ }
+
+ @Test
+ public void testKeyWrapping() {
+ AwsKeyManagementClient keyManagementClient = new AwsKeyManagementClient();
+ try {
+ keyManagementClient.initialize(ImmutableMap.of());
+
+ ByteBuffer key = ByteBuffer.wrap(new String("super-secret-table-master-key").getBytes());
+ ByteBuffer encryptedKey = keyManagementClient.wrapKey(key, keyId);
+
+ assertThat(keyManagementClient.unwrapKey(encryptedKey, keyId)).isEqualTo(key);
+ } finally {
+ keyManagementClient.close();
+ }
+ }
+
+ @Test
+ public void testKeyGeneration() {
+ testKeyGenerationWithDataKeySpec(null);
+ testKeyGenerationWithDataKeySpec(DataKeySpec.AES_128);
+ testKeyGenerationWithDataKeySpec(DataKeySpec.AES_256);
+ }
+
+ private void testKeyGenerationWithDataKeySpec(DataKeySpec dataKeySpec) {
+ AwsKeyManagementClient keyManagementClient = new AwsKeyManagementClient();
+ try {
+ Map<String, String> properties =
+ dataKeySpec == null
+ ? ImmutableMap.of()
+ : ImmutableMap.of(AwsProperties.KMS_DATA_KEY_SPEC, dataKeySpec.name());
+ keyManagementClient.initialize(properties);
+ KeyManagementClient.KeyGenerationResult result = keyManagementClient.generateKey(keyId);
+
+ assertThat(keyManagementClient.unwrapKey(result.wrappedKey(), keyId)).isEqualTo(result.key());
+ assertThat(result.key().limit())
+ .isEqualTo(DataKeySpec.AES_128.equals(dataKeySpec) ? 128 / 8 : 256 / 8);
Review Comment:
Can we move this to a helper function `expectedBytes(DataKeySpec spec)`? I think it'd be easier to read that way
##########
aws/src/integration/java/org/apache/iceberg/aws/TestKeyManagementClient.java:
##########
@@ -0,0 +1,125 @@
+/*
+ * 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.aws;
+
+import static org.assertj.core.api.Assertions.assertThat;
+
+import java.nio.ByteBuffer;
+import java.util.Map;
+import org.apache.iceberg.encryption.KeyManagementClient;
+import org.apache.iceberg.relocated.com.google.common.collect.ImmutableMap;
+import org.junit.jupiter.api.AfterAll;
+import org.junit.jupiter.api.BeforeAll;
+import org.junit.jupiter.api.Test;
+import org.junit.jupiter.api.condition.EnabledIfEnvironmentVariable;
+import org.junit.jupiter.api.condition.EnabledIfEnvironmentVariables;
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
+import software.amazon.awssdk.services.kms.KmsClient;
+import software.amazon.awssdk.services.kms.model.CreateKeyRequest;
+import software.amazon.awssdk.services.kms.model.CreateKeyResponse;
+import software.amazon.awssdk.services.kms.model.DataKeySpec;
+import software.amazon.awssdk.services.kms.model.KeySpec;
+import software.amazon.awssdk.services.kms.model.ScheduleKeyDeletionRequest;
+import software.amazon.awssdk.services.kms.model.ScheduleKeyDeletionResponse;
+
+@EnabledIfEnvironmentVariables({
+ @EnabledIfEnvironmentVariable(named = AwsIntegTestUtil.AWS_ACCESS_KEY_ID, matches = ".*"),
+ @EnabledIfEnvironmentVariable(named = AwsIntegTestUtil.AWS_SECRET_ACCESS_KEY, matches = ".*"),
+ @EnabledIfEnvironmentVariable(named = AwsIntegTestUtil.AWS_SESSION_TOKEN, matches = ".*"),
+ @EnabledIfEnvironmentVariable(named = AwsIntegTestUtil.AWS_TEST_ACCOUNT_ID, matches = "\\d{12}")
+})
+public class TestKeyManagementClient {
+
+ private static final Logger LOG = LoggerFactory.getLogger(TestKeyManagementClient.class);
+
+ private static KmsClient kmsClient;
+ private static String keyId;
+
+ @BeforeAll
+ public static void beforeClass() {
+ kmsClient = AwsClientFactories.defaultFactory().kms();
+ CreateKeyRequest createKeyRequest =
+ CreateKeyRequest.builder()
+ .keySpec(KeySpec.SYMMETRIC_DEFAULT)
+ .description(
+ "Iceberg integration test key for " + TestKeyManagementClient.class.getName())
+ .build();
+ CreateKeyResponse response = kmsClient.createKey(createKeyRequest);
+ keyId = response.keyMetadata().keyId();
+ }
+
+ @Test
+ public void testKeyWrapping() {
+ AwsKeyManagementClient keyManagementClient = new AwsKeyManagementClient();
+ try {
+ keyManagementClient.initialize(ImmutableMap.of());
+
+ ByteBuffer key = ByteBuffer.wrap(new String("super-secret-table-master-key").getBytes());
+ ByteBuffer encryptedKey = keyManagementClient.wrapKey(key, keyId);
+
+ assertThat(keyManagementClient.unwrapKey(encryptedKey, keyId)).isEqualTo(key);
+ } finally {
+ keyManagementClient.close();
+ }
+ }
+
+ @Test
Review Comment:
Could we parameterize this with `@ParameterizedTest`?
--
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-unsubscribe@iceberg.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
---------------------------------------------------------------------
To unsubscribe, e-mail: issues-unsubscribe@iceberg.apache.org
For additional commands, e-mail: issues-help@iceberg.apache.org
Re: [PR] AWS: KeyManagementClient implementation that works with AWS KMS [iceberg]
Posted by "szlta (via GitHub)" <gi...@apache.org>.
szlta commented on code in PR #13136:
URL: https://github.com/apache/iceberg/pull/13136#discussion_r2166601226
##########
aws/src/integration/java/org/apache/iceberg/aws/TestKeyManagementClient.java:
##########
@@ -0,0 +1,125 @@
+/*
+ * 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.aws;
+
+import static org.assertj.core.api.Assertions.assertThat;
+
+import java.nio.ByteBuffer;
+import java.util.Map;
+import org.apache.iceberg.encryption.KeyManagementClient;
+import org.apache.iceberg.relocated.com.google.common.collect.ImmutableMap;
+import org.junit.jupiter.api.AfterAll;
+import org.junit.jupiter.api.BeforeAll;
+import org.junit.jupiter.api.Test;
+import org.junit.jupiter.api.condition.EnabledIfEnvironmentVariable;
+import org.junit.jupiter.api.condition.EnabledIfEnvironmentVariables;
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
+import software.amazon.awssdk.services.kms.KmsClient;
+import software.amazon.awssdk.services.kms.model.CreateKeyRequest;
+import software.amazon.awssdk.services.kms.model.CreateKeyResponse;
+import software.amazon.awssdk.services.kms.model.DataKeySpec;
+import software.amazon.awssdk.services.kms.model.KeySpec;
+import software.amazon.awssdk.services.kms.model.ScheduleKeyDeletionRequest;
+import software.amazon.awssdk.services.kms.model.ScheduleKeyDeletionResponse;
+
+@EnabledIfEnvironmentVariables({
+ @EnabledIfEnvironmentVariable(named = AwsIntegTestUtil.AWS_ACCESS_KEY_ID, matches = ".*"),
+ @EnabledIfEnvironmentVariable(named = AwsIntegTestUtil.AWS_SECRET_ACCESS_KEY, matches = ".*"),
+ @EnabledIfEnvironmentVariable(named = AwsIntegTestUtil.AWS_SESSION_TOKEN, matches = ".*"),
+ @EnabledIfEnvironmentVariable(named = AwsIntegTestUtil.AWS_TEST_ACCOUNT_ID, matches = "\\d{12}")
+})
+public class TestKeyManagementClient {
+
+ private static final Logger LOG = LoggerFactory.getLogger(TestKeyManagementClient.class);
+
+ private static KmsClient kmsClient;
+ private static String keyId;
+
+ @BeforeAll
+ public static void beforeClass() {
+ kmsClient = AwsClientFactories.defaultFactory().kms();
+ CreateKeyRequest createKeyRequest =
+ CreateKeyRequest.builder()
+ .keySpec(KeySpec.SYMMETRIC_DEFAULT)
+ .description(
+ "Iceberg integration test key for " + TestKeyManagementClient.class.getName())
+ .build();
+ CreateKeyResponse response = kmsClient.createKey(createKeyRequest);
+ keyId = response.keyMetadata().keyId();
+ }
+
+ @Test
+ public void testKeyWrapping() {
+ AwsKeyManagementClient keyManagementClient = new AwsKeyManagementClient();
+ try {
+ keyManagementClient.initialize(ImmutableMap.of());
+
+ ByteBuffer key = ByteBuffer.wrap(new String("super-secret-table-master-key").getBytes());
+ ByteBuffer encryptedKey = keyManagementClient.wrapKey(key, keyId);
+
+ assertThat(keyManagementClient.unwrapKey(encryptedKey, keyId)).isEqualTo(key);
+ } finally {
+ keyManagementClient.close();
+ }
+ }
+
+ @Test
+ public void testKeyGeneration() {
+ testKeyGenerationWithDataKeySpec(null);
+ testKeyGenerationWithDataKeySpec(DataKeySpec.AES_128);
+ testKeyGenerationWithDataKeySpec(DataKeySpec.AES_256);
+ }
+
+ private void testKeyGenerationWithDataKeySpec(DataKeySpec dataKeySpec) {
+ AwsKeyManagementClient keyManagementClient = new AwsKeyManagementClient();
+ try {
+ Map<String, String> properties =
+ dataKeySpec == null
+ ? ImmutableMap.of()
+ : ImmutableMap.of(AwsProperties.KMS_DATA_KEY_SPEC, dataKeySpec.name());
+ keyManagementClient.initialize(properties);
+ KeyManagementClient.KeyGenerationResult result = keyManagementClient.generateKey(keyId);
+
+ assertThat(keyManagementClient.unwrapKey(result.wrappedKey(), keyId)).isEqualTo(result.key());
+ assertThat(result.key().limit())
+ .isEqualTo(DataKeySpec.AES_128.equals(dataKeySpec) ? 128 / 8 : 256 / 8);
Review Comment:
Sure, added `int expectedLength(DataKeySpec spec)` for better readability.
--
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-unsubscribe@iceberg.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
---------------------------------------------------------------------
To unsubscribe, e-mail: issues-unsubscribe@iceberg.apache.org
For additional commands, e-mail: issues-help@iceberg.apache.org
Re: [PR] AWS: KeyManagementClient implementation that works with AWS KMS [iceberg]
Posted by "szlta (via GitHub)" <gi...@apache.org>.
szlta commented on PR #13136:
URL: https://github.com/apache/iceberg/pull/13136#issuecomment-3092440288
Thanks everyone for the reviews!
--
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-unsubscribe@iceberg.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
---------------------------------------------------------------------
To unsubscribe, e-mail: issues-unsubscribe@iceberg.apache.org
For additional commands, e-mail: issues-help@iceberg.apache.org
Re: [PR] AWS: KeyManagementClient implementation that works with AWS KMS [iceberg]
Posted by "amogh-jahagirdar (via GitHub)" <gi...@apache.org>.
amogh-jahagirdar commented on PR #13136:
URL: https://github.com/apache/iceberg/pull/13136#issuecomment-2953431155
Sorry for the delay, I'm taking a look
--
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-unsubscribe@iceberg.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
---------------------------------------------------------------------
To unsubscribe, e-mail: issues-unsubscribe@iceberg.apache.org
For additional commands, e-mail: issues-help@iceberg.apache.org
Re: [PR] AWS: KeyManagementClient implementation that works with AWS KMS [iceberg]
Posted by "amogh-jahagirdar (via GitHub)" <gi...@apache.org>.
amogh-jahagirdar commented on code in PR #13136:
URL: https://github.com/apache/iceberg/pull/13136#discussion_r2134377764
##########
aws/src/main/java/org/apache/iceberg/aws/AwsKeyManagementClient.java:
##########
@@ -0,0 +1,107 @@
+/*
+ * 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.aws;
+
+import java.nio.ByteBuffer;
+import java.util.Map;
+import org.apache.iceberg.encryption.KeyManagementClient;
+import software.amazon.awssdk.core.SdkBytes;
+import software.amazon.awssdk.services.kms.KmsClient;
+import software.amazon.awssdk.services.kms.model.DataKeySpec;
+import software.amazon.awssdk.services.kms.model.DecryptRequest;
+import software.amazon.awssdk.services.kms.model.DecryptResponse;
+import software.amazon.awssdk.services.kms.model.EncryptRequest;
+import software.amazon.awssdk.services.kms.model.EncryptResponse;
+import software.amazon.awssdk.services.kms.model.EncryptionAlgorithmSpec;
+import software.amazon.awssdk.services.kms.model.GenerateDataKeyRequest;
+import software.amazon.awssdk.services.kms.model.GenerateDataKeyResponse;
+
+/**
+ * Key management client implementation that uses AWS Key Management Service. To be used for
+ * encrypting/decrypting keys with a KMS-managed master key, (by referencing its key ID), and for
+ * the generation of new encryption keys.
+ */
+public class AwsKeyManagementClient implements KeyManagementClient {
Review Comment:
I think this will need to be serializable so that it can be used in a distributed setting (since an `EncryptionManager` instance can also be serialized, and generally we'd expect an `EncryptionManager` to also contain an instance of `KeyManagementClient`
##########
aws/src/main/java/org/apache/iceberg/aws/AwsProperties.java:
##########
@@ -230,6 +243,8 @@ public class AwsProperties implements Serializable {
private String restAccessKeyId;
private String restSecretAccessKey;
private String restSessionToken;
+ private String kmsEncryptionAlgorithmSpec;
+ private String kmsDataKeySpec;
Review Comment:
I think it would be better if these fields were the actual types, `EncryptionAlgorithmSpec` and `DataKeySpec` so that in case invalid values are configured, it fails in the constructor, instead of an accessor later on.
##########
core/src/main/java/org/apache/iceberg/encryption/KeyManagementClient.java:
##########
@@ -24,7 +24,7 @@
import java.util.Map;
/** A minimum client interface to connect to a key management service (KMS). */
-interface KeyManagementClient extends Serializable, Closeable {
+public interface KeyManagementClient extends Serializable, Closeable {
Review Comment:
I think this will necessarily need to be public so that implementations can reside in other modules, so I do agree with this change.
It'd be good if @rdblue can confirm that or if some other implementation pattern was intended here.
--
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-unsubscribe@iceberg.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
---------------------------------------------------------------------
To unsubscribe, e-mail: issues-unsubscribe@iceberg.apache.org
For additional commands, e-mail: issues-help@iceberg.apache.org
Re: [PR] AWS: KeyManagementClient implementation that works with AWS KMS [iceberg]
Posted by "szlta (via GitHub)" <gi...@apache.org>.
szlta commented on code in PR #13136:
URL: https://github.com/apache/iceberg/pull/13136#discussion_r2166599796
##########
aws/src/integration/java/org/apache/iceberg/aws/TestKeyManagementClient.java:
##########
@@ -0,0 +1,125 @@
+/*
+ * 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.aws;
+
+import static org.assertj.core.api.Assertions.assertThat;
+
+import java.nio.ByteBuffer;
+import java.util.Map;
+import org.apache.iceberg.encryption.KeyManagementClient;
+import org.apache.iceberg.relocated.com.google.common.collect.ImmutableMap;
+import org.junit.jupiter.api.AfterAll;
+import org.junit.jupiter.api.BeforeAll;
+import org.junit.jupiter.api.Test;
+import org.junit.jupiter.api.condition.EnabledIfEnvironmentVariable;
+import org.junit.jupiter.api.condition.EnabledIfEnvironmentVariables;
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
+import software.amazon.awssdk.services.kms.KmsClient;
+import software.amazon.awssdk.services.kms.model.CreateKeyRequest;
+import software.amazon.awssdk.services.kms.model.CreateKeyResponse;
+import software.amazon.awssdk.services.kms.model.DataKeySpec;
+import software.amazon.awssdk.services.kms.model.KeySpec;
+import software.amazon.awssdk.services.kms.model.ScheduleKeyDeletionRequest;
+import software.amazon.awssdk.services.kms.model.ScheduleKeyDeletionResponse;
+
+@EnabledIfEnvironmentVariables({
+ @EnabledIfEnvironmentVariable(named = AwsIntegTestUtil.AWS_ACCESS_KEY_ID, matches = ".*"),
+ @EnabledIfEnvironmentVariable(named = AwsIntegTestUtil.AWS_SECRET_ACCESS_KEY, matches = ".*"),
+ @EnabledIfEnvironmentVariable(named = AwsIntegTestUtil.AWS_SESSION_TOKEN, matches = ".*"),
+ @EnabledIfEnvironmentVariable(named = AwsIntegTestUtil.AWS_TEST_ACCOUNT_ID, matches = "\\d{12}")
+})
+public class TestKeyManagementClient {
+
+ private static final Logger LOG = LoggerFactory.getLogger(TestKeyManagementClient.class);
+
+ private static KmsClient kmsClient;
+ private static String keyId;
+
+ @BeforeAll
+ public static void beforeClass() {
+ kmsClient = AwsClientFactories.defaultFactory().kms();
+ CreateKeyRequest createKeyRequest =
+ CreateKeyRequest.builder()
+ .keySpec(KeySpec.SYMMETRIC_DEFAULT)
+ .description(
+ "Iceberg integration test key for " + TestKeyManagementClient.class.getName())
+ .build();
+ CreateKeyResponse response = kmsClient.createKey(createKeyRequest);
+ keyId = response.keyMetadata().keyId();
+ }
+
+ @Test
+ public void testKeyWrapping() {
+ AwsKeyManagementClient keyManagementClient = new AwsKeyManagementClient();
+ try {
+ keyManagementClient.initialize(ImmutableMap.of());
+
+ ByteBuffer key = ByteBuffer.wrap(new String("super-secret-table-master-key").getBytes());
+ ByteBuffer encryptedKey = keyManagementClient.wrapKey(key, keyId);
+
+ assertThat(keyManagementClient.unwrapKey(encryptedKey, keyId)).isEqualTo(key);
+ } finally {
+ keyManagementClient.close();
+ }
+ }
+
+ @Test
Review Comment:
Yep, refactored.
--
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-unsubscribe@iceberg.apache.org
For queries about this service, please contact Infrastructure at:
users@infra.apache.org
---------------------------------------------------------------------
To unsubscribe, e-mail: issues-unsubscribe@iceberg.apache.org
For additional commands, e-mail: issues-help@iceberg.apache.org