Gabriel39 commented on code in PR #71031:
URL: https://github.com/apache/doris/pull/71031#discussion_r4717372530


##########
fe/fe-iceberg-common/src/main/java/org/apache/iceberg/io/NativeGcsResolvingFileIO.java:
##########
@@ -39,9 +45,31 @@ public class NativeGcsResolvingFileIO extends 
ResolvingFileIO {
     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";
 
+    public static boolean hasSdkGcsProperties(Map<String, String> properties) {
+        return properties.keySet().stream().anyMatch(key -> key != null && 
key.startsWith("gcs."));
+    }
+
     @Override
     String implFromLocation(String location) {
         String impl = super.implFromLocation(location);
-        return GCS_FILE_IO_IMPL.equals(impl) ? HADOOP_FILE_IO_IMPL : impl;
+        if (!GCS_FILE_IO_IMPL.equals(impl)) {
+            return impl;
+        }
+        StorageCredential matching = null;
+        for (StorageCredential credential : credentials()) {
+            if (location.startsWith(credential.prefix())
+                    && (matching == null || credential.prefix().length() >= 
matching.prefix().length())) {
+                matching = credential;
+            }
+        }
+        // Validate the effective scope before choosing an identity: a present 
null token is not an absent token.
+        GcsOAuthTokenValidator.validate(properties(), matching == null ? 
Collections.emptyMap() : matching.config());
+        // REST/table configuration and matching storage credentials can 
arrive after FE selected this class.
+        // HadoopFileIO ignores SDK encryption, billing and token options, so 
those retain the native path.
+        if (hasSdkGcsProperties(properties())) {

Review Comment:
   Confirmed and fixed in fdd96ce0825abef4bb3c82c6582e0efd0f2f3375. Project ID 
no longer replaces configured Hadoop/HMAC identity. SDK-only options without a 
supported SDK identity report a field-specific configuration error. The SDK/ADC 
default is retained when Hadoop identity is absent. HTTP tests check the actual 
HMAC authorization header; unit and SQL regression cover the default and both 
generic aliases.



##########
fe/fe-connector/fe-connector-iceberg/src/main/java/org/apache/doris/connector/iceberg/IcebergCatalogFactory.java:
##########
@@ -513,6 +516,29 @@ public static Map<String, String> 
buildCatalogProperties(IcebergCatalogPropertie
         return opts;
     }
 
+    static void preserveHadoopGcsFileIO(IcebergCatalogProperties catalogProps,
+            Map<String, String> options, Configuration conf) {
+        boolean rest = 
IcebergCatalogProperties.TYPE_REST.equals(catalogProps.getFlavor());
+        String ioImpl = options.get(CatalogProperties.FILE_IO_IMPL);
+        if (!ResolvingFileIO.class.getName().equals(ioImpl) && !(rest && 
ioImpl == null)) {
+            return;
+        }
+        if (rest && 
IcebergRestMetaStoreProperties.of(catalogProps.getRaw()).isVendedCredentialsEnabled())
 {
+            return;
+        }
+        if (NativeGcsResolvingFileIO.hasSdkGcsProperties(options)) {

Review Comment:
   Confirmed and fixed in fdd96ce0825abef4bb3c82c6582e0efd0f2f3375. Default and 
explicitly configured REST generic resolvers now use the same effective-token 
validation after table load. SQL covers six malformed values through all three 
choices (18 expected failures), asserting zero fallback reads and zero rejected 
storage requests. Explicit concrete/custom FileIO choices remain unchanged.



##########
fe/fe-iceberg-common/src/main/java/org/apache/iceberg/io/NativeGcsResolvingFileIO.java:
##########
@@ -39,9 +45,31 @@ public class NativeGcsResolvingFileIO extends 
ResolvingFileIO {
     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";
 
+    public static boolean hasSdkGcsProperties(Map<String, String> properties) {
+        return properties.keySet().stream().anyMatch(key -> key != null && 
key.startsWith("gcs."));
+    }
+
     @Override
     String implFromLocation(String location) {
         String impl = super.implFromLocation(location);
-        return GCS_FILE_IO_IMPL.equals(impl) ? HADOOP_FILE_IO_IMPL : impl;
+        if (!GCS_FILE_IO_IMPL.equals(impl)) {
+            return impl;
+        }
+        StorageCredential matching = null;
+        for (StorageCredential credential : credentials()) {
+            if (location.startsWith(credential.prefix())
+                    && (matching == null || credential.prefix().length() >= 
matching.prefix().length())) {
+                matching = credential;
+            }
+        }
+        // Validate the effective scope before choosing an identity: a present 
null token is not an absent token.
+        GcsOAuthTokenValidator.validate(properties(), matching == null ? 
Collections.emptyMap() : matching.config());

Review Comment:
   Confirmed against the packaged SDK and fixed in 
fdd96ce0825abef4bb3c82c6582e0efd0f2f3375. Each delegate receives the effective 
global/matching map and only the selected longest/last credential scope. Caches 
are bounded by prefix, released on replacement/reinitialization/close, and 
recreated after serialization. Actual newInputFile HTTP reads cover unrelated 
invalid expiry and overridden invalid global expiry, plus credential 
replacement and serialization after opening. Both SQL expiry scenarios pass.



##########
fe/fe-connector/fe-connector-iceberg/src/main/java/org/apache/doris/connector/iceberg/IcebergGoogleCredentialValidator.java:
##########
@@ -0,0 +1,60 @@
+// 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.connector.iceberg;
+
+import com.google.api.client.json.GenericJson;
+import com.google.api.client.json.JsonObjectParser;
+import com.google.api.client.json.gson.GsonFactory;
+
+import java.io.IOException;
+import java.io.StringReader;
+import java.util.Map;
+
+/** Checks the JSON fields the Google SDK consumes without resolving 
credential sources. */
+final class IcebergGoogleCredentialValidator {
+    private IcebergGoogleCredentialValidator() {
+    }
+
+    static void validate(Map<String, String> properties) {
+        String json = properties.get("gcp.auth.credentials-json");
+        // The SDK treats empty JSON as unset; ALTER uses it to fall back to a 
credential path or ADC.
+        if (json == null || json.isEmpty()) {
+            return;
+        }
+        GenericJson credential;
+        try {
+            // Use the SDK parser so duplicate fields have the same final type 
at validation and consumption.
+            credential = new JsonObjectParser(GsonFactory.getDefaultInstance())
+                    .parseAndClose(new StringReader(json), GenericJson.class);
+        } catch (IOException | RuntimeException failure) {
+            // Parser messages and causes may contain private keys; expose 
only the fixed property name.
+            throw new IllegalArgumentException("Invalid 
gcp.auth.credentials-json");
+        }
+        if (credential == null || !(credential.get("type") instanceof String)) 
{
+            throw new IllegalArgumentException("gcp.auth.credentials-json type 
must contain a string");
+        }
+        // The SDK casts these fields to String; its JSON-null sentinel is 
also a non-String value.
+        // Keep credential type, file and endpoint selection with the SDK, as 
existing catalogs require.
+        for (String field : new String[] {"client_id", "client_email", 
"private_key", "private_key_id", "project_id",

Review Comment:
   Confirmed and fixed in fdd96ce0825abef4bb3c82c6582e0efd0f2f3375. The 
validator checks refresh_token and client_secret for supported user credential 
types, plus account for authorized_user. Errors expose only the field name, 
without values or parser causes. Parameterized CREATE/ALTER/runtime tests cover 
null, numeric, boolean, array and object values; SQL adds 30 CREATE/ALTER 
rejection checks with a valid control. Existing credential types and 
empty-inline fallback remain supported.



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