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

yiguolei pushed a commit to branch branch-4.2
in repository https://gitbox.apache.org/repos/asf/doris.git


The following commit(s) were added to refs/heads/branch-4.2 by this push:
     new 8975d5156b4 [fix](iceberg) Backport Google REST auth and GCS FileIO 
fixes (branch-4.2) (#70966)
8975d5156b4 is described below

commit 8975d5156b437d33929852e1734f25d0912ffeda
Author: Gabriel <[email protected]>
AuthorDate: Wed Nov 25 09:28:16 2026 +0800

    [fix](iceberg) Backport Google REST auth and GCS FileIO fixes (branch-4.2) 
(#70966)
    
    ### What problem does this PR solve?
    
    Adapted backport of apache/doris#62988. Google REST catalog
    authentication needs GoogleAuthManager, while adding iceberg-gcp must
    preserve GCS HMAC access instead of switching gs:// metadata reads to
    ADC. BE metadata scans also need the GCSFileIO and Google SDK classes
    carried by serialized system-table tasks.
    
    ### Backport adaptation
    
    - Map the Google security type, optional FileIO and billing project
    through the legacy FE property classes.
    - Share NativeGcsResolvingFileIO between FE and the BE scanner,
    preserving explicit FileIO choices and vending-aware defaults.
    - Package unshaded Google storage/auth dependencies in the scanner and
    preserve the patched Hadoop dependency order.
    - Keep Iceberg 1.11.0 and Google storage 2.67.0. Preserve this branch's
    existing native GCP and catalog authentication adapters.
    
    ### Validation
    
    - 65 related FE tests and 4 scanner tests passed with no failures or
    skips.
    - The HMAC test reads a local object through the real SDK and verifies
    the configured access-key signature. Disabling the routing fix makes
    this assertion fail.
    - Scanner tests deserialize GCSFileIO, read through a fresh vended token
    without FE authentication classes, and execute an actual serialized
    $files task.
    - The packaged scanner passed an isolated-classloader probe: GCSFileIO,
    Google storage/auth and the shared resolver all come from the shipped
    jar; a deserialized FileIO reads the expected bytes using the storage
    bearer token.
    - FE Checkstyle and git diff --check passed. Complete local self-review
    finished and identified issues were fixed before committing.
    
    ### Limitations
    
    Live GCS/Polaris integration and token expiration during a running BE
    query were not tested. Existing vended-credential behavior is preserved;
    in-query BE token renewal remains outside this backport. Deploy matching
    BE scanner and FE artifacts, with BE first; mixed-version Iceberg
    system-table scans remain unsupported.
    
    Pre-submission status: Partially verified: live GCS/Polaris integration
    was not run locally.
    
    ### Release note
    
    Support Google REST catalog authentication, preserve GCS HMAC metadata
    access, and fix missing GCS runtime classes in Iceberg system-table
    scans.
---
 .../iceberg-metadata-scanner/pom.xml               |  28 ++++
 .../apache/doris/iceberg/IcebergGcsFileIOTest.java | 165 +++++++++++++++++++
 fe/check/checkstyle/suppressions.xml               |   2 +
 fe/fe-core/pom.xml                                 |  17 ++
 .../metastore/AbstractIcebergProperties.java       |  11 +-
 .../property/metastore/IcebergRestProperties.java  |  22 ++-
 .../metastore/IcebergRestGcsFileIOTest.java        | 181 +++++++++++++++++++++
 fe/fe-iceberg-common/pom.xml                       |  44 +++++
 .../iceberg/io/NativeGcsResolvingFileIO.java       |  41 +++++
 fe/pom.xml                                         |   2 +
 10 files changed, 510 insertions(+), 3 deletions(-)

diff --git a/fe/be-java-extensions/iceberg-metadata-scanner/pom.xml 
b/fe/be-java-extensions/iceberg-metadata-scanner/pom.xml
index edfcc1f9b57..19ad244ddd7 100644
--- a/fe/be-java-extensions/iceberg-metadata-scanner/pom.xml
+++ b/fe/be-java-extensions/iceberg-metadata-scanner/pom.xml
@@ -35,6 +35,34 @@ under the License.
     </properties>
 
     <dependencies>
+        <dependency>
+            <groupId>com.google.guava</groupId>
+            <artifactId>guava</artifactId>
+        </dependency>
+        <dependency>
+            <groupId>org.apache.hadoop</groupId>
+            <artifactId>hadoop-common</artifactId>
+            <scope>provided</scope>
+        </dependency>
+        <dependency>
+            <groupId>org.apache.doris</groupId>
+            <artifactId>fe-iceberg-common</artifactId>
+            <version>${project.version}</version>
+        </dependency>
+        <!-- Iceberg loads GCSFileIO by name, including inside serialized 
metadata scan tasks. -->
+        <dependency>
+            <groupId>org.apache.iceberg</groupId>
+            <artifactId>iceberg-gcp</artifactId>
+            <version>${iceberg.version}</version>
+            <scope>runtime</scope>
+        </dependency>
+        <!-- iceberg-gcp does not declare the Google storage/auth runtime 
closure. -->
+        <dependency>
+            <groupId>com.google.cloud</groupId>
+            <artifactId>google-cloud-storage</artifactId>
+            <version>${google-cloud-storage.version}</version>
+            <scope>runtime</scope>
+        </dependency>
         <dependency>
             <groupId>org.apache.doris</groupId>
             <artifactId>java-common</artifactId>
diff --git 
a/fe/be-java-extensions/iceberg-metadata-scanner/src/test/java/org/apache/doris/iceberg/IcebergGcsFileIOTest.java
 
b/fe/be-java-extensions/iceberg-metadata-scanner/src/test/java/org/apache/doris/iceberg/IcebergGcsFileIOTest.java
new file mode 100644
index 00000000000..1c17af13a60
--- /dev/null
+++ 
b/fe/be-java-extensions/iceberg-metadata-scanner/src/test/java/org/apache/doris/iceberg/IcebergGcsFileIOTest.java
@@ -0,0 +1,165 @@
+// 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.doris.iceberg;
+
+import org.apache.doris.common.jni.utils.OffHeap;
+
+import com.google.common.collect.ImmutableMap;
+import com.sun.net.httpserver.HttpServer;
+import org.apache.hadoop.conf.Configuration;
+import org.apache.iceberg.CatalogProperties;
+import org.apache.iceberg.DataFiles;
+import org.apache.iceberg.FileScanTask;
+import org.apache.iceberg.MetadataTableType;
+import org.apache.iceberg.MetadataTableUtils;
+import org.apache.iceberg.PartitionSpec;
+import org.apache.iceberg.Schema;
+import org.apache.iceberg.Table;
+import org.apache.iceberg.catalog.TableIdentifier;
+import org.apache.iceberg.hadoop.HadoopCatalog;
+import org.apache.iceberg.io.CloseableIterable;
+import org.apache.iceberg.io.FileIO;
+import org.apache.iceberg.io.SeekableInputStream;
+import org.apache.iceberg.types.Types;
+import org.apache.iceberg.util.SerializationUtil;
+import org.junit.jupiter.api.Assertions;
+import org.junit.jupiter.api.Test;
+import org.junit.jupiter.api.io.TempDir;
+
+import java.io.DataInputStream;
+import java.net.InetSocketAddress;
+import java.nio.charset.StandardCharsets;
+import java.nio.file.Path;
+import java.util.HashMap;
+import java.util.Map;
+import java.util.concurrent.atomic.AtomicInteger;
+import java.util.concurrent.atomic.AtomicReference;
+
+class IcebergGcsFileIOTest {
+    @Test
+    void loadsGcsRuntimeDependencies() {
+        ClassLoader loader = getClass().getClassLoader();
+        Assertions.assertDoesNotThrow(() -> 
Class.forName("org.apache.iceberg.gcp.gcs.GCSFileIO", true, loader));
+        Assertions.assertDoesNotThrow(() -> 
Class.forName("com.google.cloud.storage.StorageOptions", true, loader));
+        Assertions.assertDoesNotThrow(() -> 
Class.forName("com.google.auth.oauth2.GoogleCredentials", true, loader));
+    }
+
+    @Test
+    void deserializesGcsFileIoAndCreatesStorageClient() throws Exception {
+        // A system-table split carries its FileIO; loading FE's copy alone 
cannot validate the BE closure.
+        Class<?> type = Assertions.assertDoesNotThrow(() -> 
Class.forName("org.apache.iceberg.gcp.gcs.GCSFileIO"));
+        try (FileIO original = (FileIO) type.getConstructor().newInstance()) {
+            original.initialize(ImmutableMap.of("gcs.project-id", 
"test-project", "gcs.no-auth", "true"));
+            try (FileIO restored = SerializationUtil.deserializeFromBase64(
+                    SerializationUtil.serializeToBase64(original))) {
+                Assertions.assertEquals(type, restored.getClass());
+                Assertions.assertEquals("test-project", 
restored.properties().get("gcs.project-id"));
+                Object client = type.getMethod("client").invoke(restored);
+                Assertions.assertNotNull(client);
+                ((AutoCloseable) client).close();
+            }
+        }
+    }
+
+    @Test
+    void readsWithASerializedFreshTokenWithoutLoadingFeAuthentication() throws 
Exception {
+        byte[] content = "manifest-content".getBytes(StandardCharsets.UTF_8);
+        AtomicReference<String> authorization = new AtomicReference<>();
+        AtomicInteger refreshRequests = new AtomicInteger();
+        HttpServer server = HttpServer.create(new 
InetSocketAddress("127.0.0.1", 0), 0);
+        server.createContext("/", exchange -> {
+            try {
+                
authorization.set(exchange.getRequestHeaders().getFirst("Authorization"));
+                if (exchange.getRequestURI().getPath().startsWith("/refresh")) 
{
+                    refreshRequests.incrementAndGet();
+                    exchange.sendResponseHeaders(500, -1);
+                } else {
+                    exchange.sendResponseHeaders(200, content.length);
+                    exchange.getResponseBody().write(content);
+                }
+            } finally {
+                exchange.close();
+            }
+        });
+        server.start();
+        try {
+            String endpoint = "http://127.0.0.1:"; + 
server.getAddress().getPort();
+            Map<String, String> properties = new HashMap<>();
+            properties.put("gcs.project-id", "test-project");
+            properties.put("gcs.service.host", endpoint);
+            properties.put("gcs.oauth2.token", "test-vended-token");
+            properties.put("gcs.oauth2.token-expires-at", 
String.valueOf(System.currentTimeMillis() + 3600000));
+            properties.put("gcs.oauth2.refresh-credentials-endpoint", endpoint 
+ "/refresh");
+            properties.put("uri", endpoint);
+            // Catalog authentication belongs to FE and must not be needed for 
a fresh storage-token read.
+            properties.put("rest.auth.type", "example.FeOnlyAuthManager");
+            Class<?> type = Assertions.assertDoesNotThrow(() -> 
Class.forName("org.apache.iceberg.gcp.gcs.GCSFileIO"));
+            try (FileIO original = (FileIO) 
type.getConstructor().newInstance()) {
+                original.initialize(properties);
+                try (FileIO restored = SerializationUtil.deserializeFromBase64(
+                        SerializationUtil.serializeToBase64(original));
+                        SeekableInputStream input = 
restored.newInputFile("gs://test-bucket/manifest.avro", content.length)
+                                .newStream()) {
+                    byte[] actual = new byte[content.length];
+                    new DataInputStream(input).readFully(actual);
+                    Assertions.assertArrayEquals(content, actual);
+                    Assertions.assertEquals("Bearer test-vended-token", 
authorization.get());
+                    Assertions.assertEquals(0, refreshRequests.get());
+                }
+            }
+        } finally {
+            server.stop(0);
+        }
+    }
+
+    @Test
+    void scansFilesMetadataAfterSharedFileIoSerialization(@TempDir Path 
warehouse) throws Exception {
+        OffHeap.setTesting();
+        try (HadoopCatalog catalog = new HadoopCatalog()) {
+            catalog.setConf(new Configuration());
+            catalog.initialize("test", ImmutableMap.of(
+                    CatalogProperties.WAREHOUSE_LOCATION, 
warehouse.toUri().toString(),
+                    CatalogProperties.FILE_IO_IMPL, 
"org.apache.iceberg.io.NativeGcsResolvingFileIO"));
+            Schema schema = new Schema(Types.NestedField.required(1, "id", 
Types.IntegerType.get()));
+            Table table = catalog.createTable(TableIdentifier.of("db", "t"), 
schema, PartitionSpec.unpartitioned());
+            
table.newAppend().appendFile(DataFiles.builder(PartitionSpec.unpartitioned())
+                    .withPath(warehouse.resolve("data.parquet").toString())
+                    
.withFileSizeInBytes(10).withRecordCount(1).build()).commit();
+            Table metadata = 
MetadataTableUtils.createMetadataTableInstance(table, MetadataTableType.FILES);
+            try (CloseableIterable<FileScanTask> tasks = metadata.newScan()
+                    .project(new 
Schema(metadata.schema().findField("record_count"))).planFiles()) {
+                FileScanTask task = tasks.iterator().next();
+                Map<String, String> params = ImmutableMap.of(
+                        "serialized_split", 
SerializationUtil.serializeToBase64(task),
+                        "required_fields", "record_count", "required_types", 
"bigint", "time_zone", "UTC");
+                IcebergSysTableJniScanner scanner = new 
IcebergSysTableJniScanner(16, params);
+                try {
+                    scanner.open();
+                    Assertions.assertNotEquals(0, scanner.getNextBatchMeta());
+                    Assertions.assertEquals(1, 
scanner.getTable().getNumRows());
+                    scanner.releaseTable();
+                    Assertions.assertEquals(0, scanner.getNextBatchMeta());
+                } finally {
+                    scanner.releaseTable();
+                    scanner.close();
+                }
+            }
+        }
+    }
+
+}
diff --git a/fe/check/checkstyle/suppressions.xml 
b/fe/check/checkstyle/suppressions.xml
index 3300755eba1..d14155ed207 100644
--- a/fe/check/checkstyle/suppressions.xml
+++ b/fe/check/checkstyle/suppressions.xml
@@ -77,4 +77,6 @@ under the License.
     <!-- ignore gensrc/thrift/ExternalTableSchema.thrift -->
     <suppress files=".*thrift/schema/external/.*" checks=".*"/>
     <suppress 
files="software/amazon/awssdk/core/client/builder/SdkDefaultClientBuilder.java" 
checks=".*"/>
+    <!-- ResolvingFileIO's routing hook is package-private in the Iceberg SDK. 
-->
+    <suppress files="NativeGcsResolvingFileIO\.java" checks="ImportControl"/>
 </suppressions>
diff --git a/fe/fe-core/pom.xml b/fe/fe-core/pom.xml
index 8acc7897829..1f67fd00097 100644
--- a/fe/fe-core/pom.xml
+++ b/fe/fe-core/pom.xml
@@ -99,6 +99,23 @@ under the License.
                 </exclusion>
             </exclusions>
         </dependency>
+        <dependency>
+            <groupId>org.apache.doris</groupId>
+            <artifactId>fe-iceberg-common</artifactId>
+            <version>${project.version}</version>
+        </dependency>
+        <!-- Iceberg loads GCSFileIO by name, including inside serialized 
metadata scan tasks. -->
+        <dependency>
+            <groupId>org.apache.iceberg</groupId>
+            <artifactId>iceberg-gcp</artifactId>
+            <version>${iceberg.version}</version>
+        </dependency>
+        <!-- iceberg-gcp does not declare the Google storage/auth runtime 
closure. -->
+        <dependency>
+            <groupId>com.google.cloud</groupId>
+            <artifactId>google-cloud-storage</artifactId>
+            <version>${google-cloud-storage.version}</version>
+        </dependency>
         <dependency>
             <groupId>${project.groupId}</groupId>
             <artifactId>fe-foundation</artifactId>
diff --git 
a/fe/fe-core/src/main/java/org/apache/doris/datasource/property/metastore/AbstractIcebergProperties.java
 
b/fe/fe-core/src/main/java/org/apache/doris/datasource/property/metastore/AbstractIcebergProperties.java
index 662b7f3fff7..6c9e77abde3 100644
--- 
a/fe/fe-core/src/main/java/org/apache/doris/datasource/property/metastore/AbstractIcebergProperties.java
+++ 
b/fe/fe-core/src/main/java/org/apache/doris/datasource/property/metastore/AbstractIcebergProperties.java
@@ -43,6 +43,7 @@ import org.apache.iceberg.aws.AwsClientProperties;
 import org.apache.iceberg.aws.s3.S3FileIO;
 import org.apache.iceberg.aws.s3.S3FileIOProperties;
 import org.apache.iceberg.catalog.Catalog;
+import org.apache.iceberg.io.NativeGcsResolvingFileIO;
 import software.amazon.awssdk.auth.credentials.AnonymousCredentialsProvider;
 
 import java.util.HashMap;
@@ -256,6 +257,13 @@ public abstract class AbstractIcebergProperties extends 
MetastoreProperties {
                 fileIOProperties.put(AwsClientProperties.CLIENT_REGION, 
region);
             }
         }
+        if (IcebergExternalCatalog.ICEBERG_REST.equals(getIcebergCatalogType())
+                && 
!Boolean.parseBoolean(origProps.get("iceberg.rest.vended-credentials-enabled"))
+                && (s3Target instanceof GCSProperties
+                        || origProps.keySet().stream().anyMatch(key -> 
key.startsWith("fs.gs.")))) {
+            // Adding iceberg-gcp must not route HMAC-backed gs:// files to 
GCSFileIO's ADC identity.
+            fileIOProperties.putIfAbsent(CatalogProperties.FILE_IO_IMPL, 
NativeGcsResolvingFileIO.class.getName());
+        }
     }
 
     /**
@@ -321,7 +329,8 @@ public abstract class AbstractIcebergProperties extends 
MetastoreProperties {
                         credential.getImpersonationServiceAccount());
             }
             options.put(StorageProperties.FS_PROVIDER_KEY, "GCP");
-            options.put(CatalogProperties.FILE_IO_IMPL, 
S3FileIO.class.getName());
+            // A catalog's explicit FileIO must retain its own credential 
handling.
+            options.putIfAbsent(CatalogProperties.FILE_IO_IMPL, 
S3FileIO.class.getName());
             options.put(S3FileIOProperties.CLIENT_FACTORY, 
GcpS3FileIOAwsClientFactory.class.getName());
         }
     }
diff --git 
a/fe/fe-core/src/main/java/org/apache/doris/datasource/property/metastore/IcebergRestProperties.java
 
b/fe/fe-core/src/main/java/org/apache/doris/datasource/property/metastore/IcebergRestProperties.java
index 60e3583bd6b..d6ac425f103 100644
--- 
a/fe/fe-core/src/main/java/org/apache/doris/datasource/property/metastore/IcebergRestProperties.java
+++ 
b/fe/fe-core/src/main/java/org/apache/doris/datasource/property/metastore/IcebergRestProperties.java
@@ -89,9 +89,17 @@ public class IcebergRestProperties extends 
AbstractIcebergProperties {
     @ConnectorProperty(names = {"iceberg.rest.security.type"},
             required = false,
             description = "The security type of the iceberg rest catalog 
service,"
-                    + "optional: (none, oauth2), default: none.")
+                    + "optional: (none, oauth2, google), default: none.")
     private String icebergRestSecurityType = "none";
 
+    @ConnectorProperty(names = {"iceberg.rest.io-impl"}, required = false,
+            description = "The FileIO implementation for the iceberg rest 
catalog service.")
+    private String icebergRestIoImpl;
+
+    @ConnectorProperty(names = {"iceberg.rest.google.user-project"}, required 
= false,
+            description = "The Google project billed for using the iceberg 
rest catalog service.")
+    private String icebergRestGoogleUserProject;
+
     @ConnectorProperty(names = {"iceberg.rest.session"},
             required = false,
             description = "The session type of the iceberg rest catalog 
service,"
@@ -334,7 +342,7 @@ public class IcebergRestProperties extends 
AbstractIcebergProperties {
             Security.valueOf(icebergRestSecurityType.toUpperCase());
         } catch (IllegalArgumentException e) {
             throw new IllegalArgumentException("Invalid security type: " + 
icebergRestSecurityType
-                    + ". Supported values are: none, oauth2");
+                    + ". Supported values are: none, oauth2, google");
         }
     }
 
@@ -421,6 +429,13 @@ public class IcebergRestProperties extends 
AbstractIcebergProperties {
     }
 
     private void addOptionalProperties() {
+        if (Strings.isNotBlank(icebergRestIoImpl)) {
+            icebergRestCatalogProperties.put(CatalogProperties.FILE_IO_IMPL, 
icebergRestIoImpl);
+        }
+        if (Strings.isNotBlank(icebergRestGoogleUserProject)) {
+            icebergRestCatalogProperties.put("header.x-goog-user-project", 
icebergRestGoogleUserProject);
+        }
+
         if (Strings.isNotBlank(icebergRestPrefix)) {
             icebergRestCatalogProperties.put(PREFIX_PROPERTY, 
icebergRestPrefix);
         }
@@ -450,6 +465,8 @@ public class IcebergRestProperties extends 
AbstractIcebergProperties {
         Security security = 
Security.valueOf(icebergRestSecurityType.toUpperCase());
         if (security == Security.OAUTH2) {
             addOAuth2Properties();
+        } else if (security == Security.GOOGLE) {
+            icebergRestCatalogProperties.put(AuthProperties.AUTH_TYPE, 
AuthProperties.AUTH_MANAGER_IMPL_GOOGLE);
         }
     }
 
@@ -550,6 +567,7 @@ public class IcebergRestProperties extends 
AbstractIcebergProperties {
     public enum Security {
         NONE,
         OAUTH2,
+        GOOGLE,
     }
 
     public enum Session {
diff --git 
a/fe/fe-core/src/test/java/org/apache/doris/datasource/property/metastore/IcebergRestGcsFileIOTest.java
 
b/fe/fe-core/src/test/java/org/apache/doris/datasource/property/metastore/IcebergRestGcsFileIOTest.java
new file mode 100644
index 00000000000..60d1422d6c6
--- /dev/null
+++ 
b/fe/fe-core/src/test/java/org/apache/doris/datasource/property/metastore/IcebergRestGcsFileIOTest.java
@@ -0,0 +1,181 @@
+// 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.doris.datasource.property.metastore;
+
+import org.apache.doris.datasource.property.storage.StorageProperties;
+
+import com.google.common.collect.ImmutableList;
+import com.google.common.collect.ImmutableMap;
+import com.sun.net.httpserver.HttpServer;
+import org.apache.hadoop.conf.Configuration;
+import org.apache.iceberg.CatalogProperties;
+import org.apache.iceberg.CatalogUtil;
+import org.apache.iceberg.io.FileIO;
+import org.apache.iceberg.io.SeekableInputStream;
+import org.apache.iceberg.rest.auth.AuthProperties;
+import org.junit.jupiter.api.Assertions;
+import org.junit.jupiter.api.Test;
+
+import java.io.DataInputStream;
+import java.net.InetSocketAddress;
+import java.nio.charset.StandardCharsets;
+import java.util.HashMap;
+import java.util.Map;
+import java.util.concurrent.atomic.AtomicReference;
+
+class IcebergRestGcsFileIOTest {
+    private static final String GCS_RESOLVER = 
"org.apache.iceberg.io.NativeGcsResolvingFileIO";
+
+    @Test
+    void supportsGoogleCatalogAuthentication() {
+        IcebergRestProperties properties = properties(ImmutableMap.of(
+                "iceberg.rest.security.type", "google",
+                "iceberg.rest.google.user-project", "billing-project",
+                "iceberg.rest.io-impl", 
"org.apache.iceberg.gcp.gcs.GCSFileIO"));
+        Map<String, String> options = 
properties.getIcebergRestCatalogProperties();
+        Assertions.assertEquals(AuthProperties.AUTH_MANAGER_IMPL_GOOGLE, 
options.get(AuthProperties.AUTH_TYPE));
+        Assertions.assertEquals("billing-project", 
options.get("header.x-goog-user-project"));
+        Assertions.assertEquals("org.apache.iceberg.gcp.gcs.GCSFileIO", 
options.get(CatalogProperties.FILE_IO_IMPL));
+    }
+
+    @Test
+    void keepsHmacOnHadoopFileIoWhenGcpIsAvailable() {
+        Map<String, String> raw = new HashMap<>(ImmutableMap.of(
+                "gs.endpoint", "https://storage.googleapis.com";, 
"gs.access_key", "test-access-key",
+                "gs.secret_key", "test-secret-key", 
"iceberg.rest.vended-credentials-enabled", "false"));
+        IcebergRestProperties properties = properties(raw);
+        Map<String, String> options = new 
HashMap<>(properties.getIcebergRestCatalogProperties());
+        Configuration configuration = new Configuration(false);
+        
properties.toFileIOProperties(ImmutableList.of(StorageProperties.createPrimary(raw)),
 options, configuration);
+        // The presence of iceberg-gcp must not replace an explicitly 
configured HMAC identity with ADC.
+        Assertions.assertEquals(GCS_RESOLVER, 
options.get(CatalogProperties.FILE_IO_IMPL));
+        Assertions.assertEquals("org.apache.hadoop.fs.s3a.S3AFileSystem", 
configuration.get("fs.gs.impl"));
+        Assertions.assertEquals("test-access-key", 
configuration.get("fs.s3a.access.key"));
+    }
+
+    @Test
+    void keepsRawHadoopGcsSettingsOnHadoopFileIo() {
+        IcebergRestProperties properties = 
properties(ImmutableMap.of("fs.gs.impl", "example.GcsFileSystem"));
+        Map<String, String> options = new 
HashMap<>(properties.getIcebergRestCatalogProperties());
+        properties.toFileIOProperties(ImmutableList.of(), options, new 
Configuration(false));
+        Assertions.assertEquals(GCS_RESOLVER, 
options.get(CatalogProperties.FILE_IO_IMPL));
+    }
+
+    @Test
+    void preservesExplicitFileIo() {
+        Map<String, String> raw = new HashMap<>(ImmutableMap.of("gs.endpoint", 
"https://storage.googleapis.com";,
+                "gs.access_key", "test-access-key", "gs.secret_key", 
"test-secret-key"));
+        IcebergRestProperties properties = properties(raw);
+        Map<String, String> options = new 
HashMap<>(ImmutableMap.of(CatalogProperties.FILE_IO_IMPL,
+                "org.apache.iceberg.gcp.gcs.GCSFileIO"));
+        
properties.toFileIOProperties(ImmutableList.of(StorageProperties.createPrimary(raw)),
 options, new Configuration(false));
+        Assertions.assertEquals("org.apache.iceberg.gcp.gcs.GCSFileIO", 
options.get(CatalogProperties.FILE_IO_IMPL));
+    }
+
+    @Test
+    void doesNotChangeNonGcsDefaults() {
+        IcebergRestProperties properties = properties(ImmutableMap.of());
+        Map<String, String> options = new 
HashMap<>(properties.getIcebergRestCatalogProperties());
+        properties.toFileIOProperties(ImmutableList.of(), options, new 
Configuration(false));
+        
Assertions.assertFalse(options.containsKey(CatalogProperties.FILE_IO_IMPL));
+    }
+
+    @Test
+    void readsGcsMetadataWithHmacInsteadOfAdc() throws Exception {
+        byte[] content = "metadata".getBytes(StandardCharsets.UTF_8);
+        AtomicReference<String> authorization = new AtomicReference<>();
+        HttpServer server = HttpServer.create(new 
InetSocketAddress("127.0.0.1", 0), 0);
+        server.createContext("/", exchange -> {
+            try {
+                
authorization.set(exchange.getRequestHeaders().getFirst("Authorization"));
+                exchange.getResponseHeaders().set("ETag", "\"test-etag\"");
+                exchange.getResponseHeaders().set("Last-Modified", "Tue, 01 
Jan 2019 00:00:00 GMT");
+                exchange.getResponseHeaders().set("Content-Length", 
String.valueOf(content.length));
+                if ("HEAD".equals(exchange.getRequestMethod())) {
+                    exchange.sendResponseHeaders(200, -1);
+                } else {
+                    exchange.sendResponseHeaders(200, content.length);
+                    exchange.getResponseBody().write(content);
+                }
+            } finally {
+                exchange.close();
+            }
+        });
+        server.start();
+        try {
+            Map<String, String> raw = new HashMap<>(ImmutableMap.of(
+                    "gs.endpoint", "http://127.0.0.1:"; + 
server.getAddress().getPort(),
+                    "gs.access_key", "test-access-key", "gs.secret_key", 
"test-secret-key",
+                    "use_path_style", "true", 
"iceberg.rest.vended-credentials-enabled", "false"));
+            IcebergRestProperties properties = properties(raw);
+            Map<String, String> options = new 
HashMap<>(properties.getIcebergRestCatalogProperties());
+            Configuration configuration = new Configuration(false);
+            
properties.toFileIOProperties(ImmutableList.of(StorageProperties.createPrimary(raw)),
 options, configuration);
+            // Keep even an incorrect JSON-API route on the fixture instead of 
contacting a real bucket.
+            options.put("gcs.service.host", raw.get("gs.endpoint"));
+            options.put("gcs.no-auth", "true");
+            configuration.set("fs.s3a.endpoint.region", "us-east-1");
+            configuration.setBoolean("fs.s3a.connection.ssl.enabled", false);
+            configuration.setInt("fs.s3a.retry.limit", 0);
+            configuration.setInt("fs.s3a.attempts.maximum", 1);
+            configuration.set("fs.s3a.bucket.probe", "0");
+            String ioImpl = 
options.getOrDefault(CatalogProperties.FILE_IO_IMPL,
+                    "org.apache.iceberg.io.ResolvingFileIO");
+            try (FileIO io = CatalogUtil.loadFileIO(ioImpl, options, 
configuration);
+                    SeekableInputStream input = 
io.newInputFile("gs://test-bucket/metadata.json", content.length)
+                            .newStream()) {
+                byte[] actual = new byte[content.length];
+                new DataInputStream(input).readFully(actual);
+                Assertions.assertArrayEquals(content, actual);
+                Assertions.assertNotNull(authorization.get());
+                
Assertions.assertTrue(authorization.get().contains("Credential=test-access-key/"),
 authorization.get());
+            }
+        } finally {
+            server.stop(0);
+        }
+    }
+
+    @Test
+    void vendedGcsKeepsTheTokenAwareSdkDefault() {
+        IcebergRestProperties properties = properties(ImmutableMap.of(
+                "iceberg.rest.vended-credentials-enabled", "true", 
"fs.gs.impl", "example.GcsFileSystem"));
+        Map<String, String> options = new 
HashMap<>(properties.getIcebergRestCatalogProperties());
+        properties.toFileIOProperties(ImmutableList.of(), options, new 
Configuration(false));
+        
Assertions.assertFalse(options.containsKey(CatalogProperties.FILE_IO_IMPL));
+    }
+
+    @Test
+    void preservesExplicitFileIoForNativeGcs() {
+        Map<String, String> raw = new HashMap<>(ImmutableMap.of(
+                "gs.endpoint", "https://storage.googleapis.com";, 
"gs.credential_provider_type", "DEFAULT"));
+        IcebergRestProperties properties = properties(raw);
+        Map<String, String> options = new 
HashMap<>(ImmutableMap.of(CatalogProperties.FILE_IO_IMPL,
+                "org.apache.iceberg.gcp.gcs.GCSFileIO"));
+        
properties.toFileIOProperties(ImmutableList.of(StorageProperties.createPrimary(raw)),
+                options, new Configuration(false));
+        Assertions.assertEquals("org.apache.iceberg.gcp.gcs.GCSFileIO", 
options.get(CatalogProperties.FILE_IO_IMPL));
+    }
+
+    private static IcebergRestProperties properties(Map<String, String> raw) {
+        Map<String, String> options = new HashMap<>(raw);
+        options.put("iceberg.rest.uri", "https://catalog.example.com";);
+        IcebergRestProperties properties = new IcebergRestProperties(options);
+        properties.initNormalizeAndCheckProps();
+        return properties;
+    }
+}
diff --git a/fe/fe-iceberg-common/pom.xml b/fe/fe-iceberg-common/pom.xml
new file mode 100644
index 00000000000..2415828c7e7
--- /dev/null
+++ b/fe/fe-iceberg-common/pom.xml
@@ -0,0 +1,44 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<!--
+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.
+-->
+<project xmlns="http://maven.apache.org/POM/4.0.0"; 
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance";
+         xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 
http://maven.apache.org/xsd/maven-4.0.0.xsd";>
+    <modelVersion>4.0.0</modelVersion>
+    <parent>
+        <groupId>org.apache.doris</groupId>
+        <artifactId>fe</artifactId>
+        <version>${revision}</version>
+        <relativePath>../pom.xml</relativePath>
+    </parent>
+    <artifactId>fe-iceberg-common</artifactId>
+    <name>Doris Shared Iceberg FileIO</name>
+    <dependencies>
+        <dependency>
+            <groupId>org.apache.iceberg</groupId>
+            <artifactId>iceberg-core</artifactId>
+            <version>${iceberg.version}</version>
+            <scope>provided</scope>
+        </dependency>
+        <dependency>
+            <groupId>org.apache.hadoop</groupId>
+            <artifactId>hadoop-common</artifactId>
+            <scope>provided</scope>
+        </dependency>
+    </dependencies>
+</project>
diff --git 
a/fe/fe-iceberg-common/src/main/java/org/apache/iceberg/io/NativeGcsResolvingFileIO.java
 
b/fe/fe-iceberg-common/src/main/java/org/apache/iceberg/io/NativeGcsResolvingFileIO.java
new file mode 100644
index 00000000000..30b4bdcfe3b
--- /dev/null
+++ 
b/fe/fe-iceberg-common/src/main/java/org/apache/iceberg/io/NativeGcsResolvingFileIO.java
@@ -0,0 +1,41 @@
+// 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.io;
+
+/**
+ * A {@link ResolvingFileIO} that keeps {@code gs://} locations on {@code 
HadoopFileIO}.
+ *
+ * <p>Adding iceberg-gcp makes the SDK route these locations to GCSFileIO, 
which does not read the
+ * {@code fs.s3a.*} HMAC settings Doris supplies. Both FE and the BE metadata 
scanner must load this
+ * implementation because its class name is carried inside serialized Iceberg 
scan tasks.
+ *
+ * <p>The SDK package is required because {@code implFromLocation} is 
package-private. It also keeps
+ * this class and iceberg-core in the same class loader on both sides of a 
metadata scan.
+ */
+public class NativeGcsResolvingFileIO extends ResolvingFileIO {
+    private static final long serialVersionUID = 1L;
+
+    private static final String GCS_FILE_IO_IMPL = 
"org.apache.iceberg.gcp.gcs.GCSFileIO";
+    private static final String HADOOP_FILE_IO_IMPL = 
"org.apache.iceberg.hadoop.HadoopFileIO";
+
+    @Override
+    String implFromLocation(String location) {
+        String impl = super.implFromLocation(location);
+        return GCS_FILE_IO_IMPL.equals(impl) ? HADOOP_FILE_IO_IMPL : impl;
+    }
+}
diff --git a/fe/pom.xml b/fe/pom.xml
index 570dca61f09..603f2281704 100644
--- a/fe/pom.xml
+++ b/fe/pom.xml
@@ -223,6 +223,7 @@ under the License.
     <modules>
         <module>fe-foundation</module>
         <module>fe-common</module>
+        <module>fe-iceberg-common</module>
         <module>fe-core</module>
         <module>hive-udf</module>
         <module>be-java-extensions</module>
@@ -346,6 +347,7 @@ under the License.
         <!-- Please modify iceberg.version and avro.version together,
          you can find avro version info in iceberg mvn repository -->
         <iceberg.version>1.11.0</iceberg.version>
+        <google-cloud-storage.version>2.67.0</google-cloud-storage.version>
         <lance.version>12.0.0</lance.version>
         <substrait.version>0.40.0</substrait.version>
         <!-- 0.56.1 has bug that "SplitMode" in query response may not be 
set-->


---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]

Reply via email to