This is an automated email from the ASF dual-hosted git repository.

singhpk234 pushed a commit to branch main
in repository https://gitbox.apache.org/repos/asf/iceberg.git


The following commit(s) were added to refs/heads/main by this push:
     new fb08432422 GCP: Add support for configurable KMS endpoint in 
GcpKeyManagementClient (#17111)
fb08432422 is described below

commit fb08432422e0617124b83661bc5b7299346bc5a7
Author: Yuya Ebihara <[email protected]>
AuthorDate: Thu Nov 19 02:14:19 2026 +0900

    GCP: Add support for configurable KMS endpoint in GcpKeyManagementClient 
(#17111)
---
 .../java/org/apache/iceberg/gcp/GCPProperties.java | 14 ++++++
 .../apache/iceberg/gcp/GcpKeyManagementClient.java | 10 ++++-
 .../org/apache/iceberg/gcp/TestGCPProperties.java  |  8 ++++
 .../iceberg/gcp/TestGcpKeyManagementClient.java    | 50 ++++++++++++++++++++++
 4 files changed, 80 insertions(+), 2 deletions(-)

diff --git a/gcp/src/main/java/org/apache/iceberg/gcp/GCPProperties.java 
b/gcp/src/main/java/org/apache/iceberg/gcp/GCPProperties.java
index de736dc69b..0a9860747e 100644
--- a/gcp/src/main/java/org/apache/iceberg/gcp/GCPProperties.java
+++ b/gcp/src/main/java/org/apache/iceberg/gcp/GCPProperties.java
@@ -50,6 +50,14 @@ public class GCPProperties implements Serializable {
    */
   public static final String GCS_KMS_KEY_NAME = "gcs.kms-key-name";
 
+  /**
+   * Configure an alternative endpoint of the KMS service for 
GcpKeyManagementClient to access.
+   *
+   * <p>This could be used to use KMS key management with any KMS-compatible 
service that has a
+   * different endpoint
+   */
+  public static final String GCS_KMS_ENDPOINT = "gcs.kms.endpoint";
+
   public static final String GCS_CHANNEL_READ_CHUNK_SIZE = 
"gcs.channel.read.chunk-size-bytes";
   public static final String GCS_CHANNEL_WRITE_CHUNK_SIZE = 
"gcs.channel.write.chunk-size-bytes";
 
@@ -95,6 +103,7 @@ public class GCPProperties implements Serializable {
   private String gcsEncryptionKey;
   private String gcsKmsKeyName;
   private String gcsUserProject;
+  private String kmsEndpoint;
 
   private Integer gcsChannelReadChunkSize;
   private Integer gcsChannelWriteChunkSize;
@@ -160,6 +169,7 @@ public class GCPProperties implements Serializable {
     gcsEncryptionKey = properties.get(GCS_ENCRYPTION_KEY);
     gcsKmsKeyName = properties.get(GCS_KMS_KEY_NAME);
     gcsUserProject = properties.get(GCS_USER_PROJECT);
+    kmsEndpoint = properties.get(GCS_KMS_ENDPOINT);
 
     Preconditions.checkState(
         !(gcsEncryptionKey != null && gcsKmsKeyName != null),
@@ -249,6 +259,10 @@ public class GCPProperties implements Serializable {
     return Optional.ofNullable(gcsUserProject);
   }
 
+  public Optional<String> kmsEndpoint() {
+    return Optional.ofNullable(kmsEndpoint);
+  }
+
   public Optional<String> oauth2Token() {
     return Optional.ofNullable(gcsOAuth2Token);
   }
diff --git 
a/gcp/src/main/java/org/apache/iceberg/gcp/GcpKeyManagementClient.java 
b/gcp/src/main/java/org/apache/iceberg/gcp/GcpKeyManagementClient.java
index 22161f9e0a..173244a96b 100644
--- a/gcp/src/main/java/org/apache/iceberg/gcp/GcpKeyManagementClient.java
+++ b/gcp/src/main/java/org/apache/iceberg/gcp/GcpKeyManagementClient.java
@@ -19,6 +19,7 @@
 package org.apache.iceberg.gcp;
 
 import com.google.api.gax.core.FixedCredentialsProvider;
+import com.google.api.gax.core.NoCredentialsProvider;
 import com.google.auth.oauth2.OAuth2Credentials;
 import com.google.cloud.kms.v1.DecryptRequest;
 import com.google.cloud.kms.v1.DecryptResponse;
@@ -35,6 +36,7 @@ import org.apache.iceberg.common.DynMethods;
 import org.apache.iceberg.encryption.KeyManagementClient;
 import org.apache.iceberg.exceptions.RuntimeIOException;
 import org.apache.iceberg.io.CloseableGroup;
+import 
org.apache.iceberg.relocated.com.google.common.annotations.VisibleForTesting;
 import org.apache.iceberg.util.SerializableMap;
 
 /**
@@ -101,7 +103,8 @@ public class GcpKeyManagementClient implements 
KeyManagementClient {
     }
   }
 
-  private KeyManagementServiceClient kmsClient() {
+  @VisibleForTesting
+  KeyManagementServiceClient kmsClient() {
     if (kmsClient == null) {
       synchronized (this) {
         if (kmsClient == null) {
@@ -109,13 +112,16 @@ public class GcpKeyManagementClient implements 
KeyManagementClient {
           try {
             KeyManagementServiceSettings.Builder kmsBuilder =
                 KeyManagementServiceSettings.newBuilder();
+            gcpProperties.kmsEndpoint().ifPresent(kmsBuilder::setEndpoint);
             if (gcpProperties.oauth2Token().isPresent()) {
               OAuth2Credentials oAuth2Credentials =
                   
GCPAuthUtils.oauth2CredentialsFromGcpProperties(gcpProperties, closeableGroup);
               
kmsBuilder.setCredentialsProvider(FixedCredentialsProvider.create(oAuth2Credentials));
+            } else if (gcpProperties.noAuth()) {
+              
kmsBuilder.setCredentialsProvider(NoCredentialsProvider.create());
             }
 
-            // if not OAuth then defaults to 
GoogleCredentials.getApplicationDefault()
+            // if not (OAuth or no-auth) then defaults to 
GoogleCredentials.getApplicationDefault()
             this.kmsClient = 
KeyManagementServiceClient.create(kmsBuilder.build());
             closeableGroup.addCloseable(kmsClient);
 
diff --git a/gcp/src/test/java/org/apache/iceberg/gcp/TestGCPProperties.java 
b/gcp/src/test/java/org/apache/iceberg/gcp/TestGCPProperties.java
index d0fb1979ca..e4dfedd72a 100644
--- a/gcp/src/test/java/org/apache/iceberg/gcp/TestGCPProperties.java
+++ b/gcp/src/test/java/org/apache/iceberg/gcp/TestGCPProperties.java
@@ -19,6 +19,7 @@
 package org.apache.iceberg.gcp;
 
 import static org.apache.iceberg.gcp.GCPProperties.GCS_ENCRYPTION_KEY;
+import static org.apache.iceberg.gcp.GCPProperties.GCS_KMS_ENDPOINT;
 import static org.apache.iceberg.gcp.GCPProperties.GCS_KMS_KEY_NAME;
 import static org.apache.iceberg.gcp.GCPProperties.GCS_NO_AUTH;
 import static 
org.apache.iceberg.gcp.GCPProperties.GCS_OAUTH2_REFRESH_CREDENTIALS_ENABLED;
@@ -106,4 +107,11 @@ public class TestGCPProperties {
         .get()
         .isEqualTo("/v1/credentials");
   }
+
+  @Test
+  void kmsEndpoint() {
+    GCPProperties gcpProperties =
+        new GCPProperties(ImmutableMap.of(GCS_NO_AUTH, "true", 
GCS_KMS_ENDPOINT, "example.com"));
+    assertThat(gcpProperties.kmsEndpoint()).hasValue("example.com");
+  }
 }
diff --git 
a/gcp/src/test/java/org/apache/iceberg/gcp/TestGcpKeyManagementClient.java 
b/gcp/src/test/java/org/apache/iceberg/gcp/TestGcpKeyManagementClient.java
new file mode 100644
index 0000000000..5df4237ef4
--- /dev/null
+++ b/gcp/src/test/java/org/apache/iceberg/gcp/TestGcpKeyManagementClient.java
@@ -0,0 +1,50 @@
+/*
+ * 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.gcp;
+
+import static org.apache.iceberg.gcp.GCPProperties.GCS_KMS_ENDPOINT;
+import static org.apache.iceberg.gcp.GCPProperties.GCS_NO_AUTH;
+import static org.assertj.core.api.Assertions.assertThat;
+import static org.assertj.core.api.Assertions.assertThatThrownBy;
+
+import java.util.Map;
+import org.junit.jupiter.api.Test;
+
+class TestGcpKeyManagementClient {
+  @Test
+  void kmsEndpoint() {
+    try (GcpKeyManagementClient client = new GcpKeyManagementClient()) {
+      String endpoint = "example.com:443";
+      client.initialize(Map.of(GCS_NO_AUTH, "true", GCS_KMS_ENDPOINT, 
endpoint));
+
+      
assertThat(client.kmsClient().getSettings().getEndpoint()).isEqualTo(endpoint);
+    }
+  }
+
+  @Test
+  void invalidKmsEndpoint() {
+    try (GcpKeyManagementClient client = new GcpKeyManagementClient()) {
+      client.initialize(Map.of(GCS_NO_AUTH, "true", GCS_KMS_ENDPOINT, 
"example.com"));
+
+      assertThatThrownBy(client::kmsClient)
+          .isInstanceOf(IllegalArgumentException.class)
+          .hasMessageContaining("invalid endpoint, expecting 
\"<host>:<port>\"");
+    }
+  }
+}

Reply via email to