ggershinsky commented on code in PR #18210:
URL: https://github.com/apache/iceberg/pull/18210#discussion_r4090568670


##########
aliyun/src/main/java/org/apache/iceberg/aliyun/AliyunKeyManagementClient.java:
##########
@@ -0,0 +1,212 @@
+/*
+ * 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.aliyun;
+
+import com.aliyun.kms20160120.Client;
+import com.aliyun.kms20160120.models.DecryptRequest;
+import com.aliyun.kms20160120.models.DecryptResponse;
+import com.aliyun.kms20160120.models.EncryptRequest;
+import com.aliyun.kms20160120.models.EncryptResponse;
+import com.aliyun.kms20160120.models.GenerateDataKeyRequest;
+import com.aliyun.kms20160120.models.GenerateDataKeyResponse;
+import com.aliyun.kms20160120.models.GenerateDataKeyResponseBody;
+import com.aliyun.teautil.models.RuntimeOptions;
+import java.nio.ByteBuffer;
+import java.util.Base64;
+import java.util.Map;
+import org.apache.iceberg.encryption.KeyManagementClient;
+import org.apache.iceberg.relocated.com.google.common.base.Preconditions;
+import org.apache.iceberg.util.ByteBuffers;
+import org.apache.iceberg.util.PropertyUtil;
+import org.apache.iceberg.util.SerializableMap;
+
+/**
+ * Key management client implementation that uses Alibaba Cloud KMS. 
Encrypts/decrypts keys with a
+ * KMS-managed master key (referenced by its key id) and generates new data 
keys.
+ */
+public class AliyunKeyManagementClient implements KeyManagementClient {
+
+  /**
+   * Enables server-side data key generation. When enabled (the default), 
Iceberg calls {@link
+   * #generateKey(String)}; set to {@code false} to have Iceberg generate keys 
locally and {@link
+   * #wrapKey(ByteBuffer, String)} them via KMS.
+   */
+  public static final String ENABLE_KEY_GENERATION = 
"kms.client.aliyun.key.generation.enabled";
+
+  /** Maximum number of attempts (including the first) for each KMS call. */
+  public static final String CLIENT_MAX_ATTEMPTS = 
"kms.client.aliyun.max.attempts";
+
+  /** Connect timeout in milliseconds for KMS calls. */
+  public static final String CLIENT_CONNECT_TIMEOUT_MS = 
"kms.client.aliyun.connect.timeout.ms";
+
+  /** Read timeout in milliseconds for KMS calls. */
+  public static final String CLIENT_READ_TIMEOUT_MS = 
"kms.client.aliyun.read.timeout.ms";
+
+  private static final boolean DEFAULT_ENABLE_KEY_GENERATION = true;
+  private static final int DEFAULT_MAX_ATTEMPTS = 3;
+  private static final int DEFAULT_CONNECT_TIMEOUT_MS = 2_000;
+  private static final int DEFAULT_READ_TIMEOUT_MS = 30_000;
+  private static final int BACKOFF_PERIOD_MS = 100;
+  private static final String ALIAS_PREFIX = "alias/";
+  private static final String ARN_KEY_SEPARATOR = "key/";
+
+  private Map<String, String> allProperties;
+  private String dataKeySpec;
+  private boolean enableKeyGeneration = DEFAULT_ENABLE_KEY_GENERATION;
+  private int maxAttempts = DEFAULT_MAX_ATTEMPTS;
+  private int connectTimeoutMs = DEFAULT_CONNECT_TIMEOUT_MS;
+  private int readTimeoutMs = DEFAULT_READ_TIMEOUT_MS;
+
+  private transient volatile ClientState state;
+
+  @Override
+  public void initialize(Map<String, String> properties) {
+    this.allProperties = SerializableMap.copyOf(properties);
+    this.dataKeySpec = new AliyunProperties(properties).kmsDataKeySpec();
+    this.enableKeyGeneration =
+        PropertyUtil.propertyAsBoolean(
+            properties, ENABLE_KEY_GENERATION, DEFAULT_ENABLE_KEY_GENERATION);
+    this.maxAttempts =
+        PropertyUtil.propertyAsInt(properties, CLIENT_MAX_ATTEMPTS, 
DEFAULT_MAX_ATTEMPTS);
+    this.connectTimeoutMs =
+        PropertyUtil.propertyAsInt(
+            properties, CLIENT_CONNECT_TIMEOUT_MS, DEFAULT_CONNECT_TIMEOUT_MS);
+    this.readTimeoutMs =
+        PropertyUtil.propertyAsInt(properties, CLIENT_READ_TIMEOUT_MS, 
DEFAULT_READ_TIMEOUT_MS);
+  }
+
+  @Override
+  public boolean supportsKeyGeneration() {

Review Comment:
   It looks like this function is not currently called by Iceberg, 
https://github.com/apache/iceberg/blob/main/core/src/main/java/org/apache/iceberg/encryption/StandardEncryptionManager.java#L150.
 Can you add a few lines there? ("if kmsClient.supportsKeyGeneration() then .. 
else ..)



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