924060929 commented on code in PR #71031:
URL: https://github.com/apache/doris/pull/71031#discussion_r4716387655
##########
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:
**[P1] Preserve the catalog’s HMAC identity when a project ID is set**
`gcs.project-id` identifies a project, but its presence here also switches
the storage client. I tested a REST catalog with `gs.access_key` and
`gs.secret_key`. With `gcs.project-id` set, the base revision selected
`HadoopFileIO`. On this revision the same configuration selected `GCSFileIO`,
and the client picked up the test process’s Application Default Credentials. A
manifest read can therefore fail with a 403 or run under a different account.
Please choose the storage identity independently of options such as
`gcs.project-id`. Preserve HMAC when no SDK credential overrides it for the
path, and report an explicit configuration error if the requested option cannot
be honored with HMAC. A regression test should check which identity the client
uses.
##########
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:
**[P2] Apply token validation to the explicitly configured generic resolver**
On a REST catalog with HMAC and `gcs.project-id`, I had the table-load
response return a single space for `gcs.oauth2.token`. With the default
resolver, opening the manifest rejected the token. Setting only
`io-impl=org.apache.iceberg.io.ResolvingFileIO` made this early return keep the
upstream resolver, and the same blank token reached the Google client. The read
then depends on how the client or storage service handles an invalid credential.
Please make both generic resolver choices validate the effective token after
the table response and path-specific credentials are available. The same REST
table-load test should reject the blank token before a storage request in both
configurations.
##########
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:
**[P2] Validate the fields used by `authorized_user` credentials**
For `gcp.auth.credentials-json` with `type=authorized_user`, setting either
`refresh_token` or `client_secret` to a JSON number passed both the CREATE and
ALTER property validators. When the catalog initialized authentication,
`GoogleCredentials.fromStream()` called `UserCredentials.fromJson()`, which
casts both fields to `String` and threw `ClassCastException`. The user only
discovers the bad configuration when the catalog is used.
Please validate the fields consumed by each supported credential type,
including these two for `authorized_user`. Report the field name without its
value, and cover both CREATE and ALTER with otherwise valid `authorized_user`
credentials.
##########
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:
**[P2] Isolate the selected credential scope when opening the file**
With a valid token and expiry for the requested prefix, changing only
another bucket’s `gcs.oauth2.token-expires-at` to a nonnumeric value made
`newInputFile()` throw `NumberFormatException`. `ioClass()` still returned
`GCSFileIO`. This check validates the matching prefix, but Iceberg 1.12 builds
clients for all GCS prefixes and parses their expiries when opening the first
file. I saw the same failure with an invalid global expiry overridden by a
valid one for the requested prefix.
Please ensure the delegate opening the file consumes the same effective
configuration that passed validation. Add `newInputFile()` coverage for both an
unrelated invalid expiry and an overridden global expiry so a valid manifest
remains readable.
--
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]