hello-stephen commented on code in PR #71205:
URL: https://github.com/apache/doris/pull/71205#discussion_r4791230296


##########
fe/fe-filesystem/fe-filesystem-api/src/main/java/org/apache/doris/filesystem/properties/StorageEndpointProperties.java:
##########
@@ -0,0 +1,313 @@
+// 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.filesystem.properties;
+
+import java.util.ArrayList;
+import java.util.Collections;
+import java.util.HashMap;
+import java.util.LinkedHashMap;
+import java.util.List;
+import java.util.Locale;
+import java.util.Map;
+import java.util.Optional;
+import java.util.function.Predicate;
+import java.util.regex.Matcher;
+import java.util.regex.Pattern;
+
+/** Network endpoint aliases consumed by filesystem providers and their 
authentication clients. */
+public final class StorageEndpointProperties {
+    private static final List<String> PAIMON_STORAGE_PREFIXES = List.of(
+            "paimon.s3.", "paimon.s3a.", "paimon.fs.s3.", "paimon.fs.oss.");
+    private static final List<String> S3_REGION_ALIASES = List.of("s3.region", 
"AWS_REGION", "region", "REGION",
+            "aws.region", "glue.region", "aws.glue.region", 
"iceberg.rest.signing-region", "rest.signing-region",
+            "client.region");
+    private static final List<String> S3_ENDPOINT_ALIASES = 
List.of("s3.endpoint", "AWS_ENDPOINT", "endpoint",
+            "ENDPOINT", "aws.endpoint", "glue.endpoint", "aws.glue.endpoint");
+    private static final List<String> S3_GUESS_REGION_ALIASES = 
List.of("s3.region", "glue.region",
+            "aws.glue.region", "iceberg.rest.signing-region", 
"rest.signing-region", "client.region");
+    private static final Pattern[] S3_ENDPOINT_PATTERNS = new Pattern[] {
+            Pattern.compile(
+                    "^(?:https?://)?(?:"
+                            + 
"s3(?:[-.]fips)?(?:[-.]dualstack)?[-.]([a-z0-9-]+)|"
+                            + "s3express-control\\.([a-z0-9-]+)|"
+                            + "s3express-[a-z0-9-]+\\.([a-z0-9-]+)"
+                            + ")\\.amazonaws\\.com(?:/.*)?$",
+                    Pattern.CASE_INSENSITIVE),
+            Pattern.compile(
+                    
"^(?:https?://)?glue(?:-fips)?\\.([a-z0-9-]+)\\.(amazonaws\\.com(?:\\.cn)?|api\\.aws)$",
+                    Pattern.CASE_INSENSITIVE)
+    };
+
+    private StorageEndpointProperties() {
+    }
+
+    public static Map<String, List<String>> derivedEndpointValues(Map<String, 
String> properties) {
+        Map<String, List<String>> result = new 
LinkedHashMap<>(derivedS3EndpointValues(properties));
+        OssEndpointProperties.derivedEndpointValues(properties).forEach((key, 
values) ->
+                result.merge(key, values, (existing, added) -> {
+                    List<String> combined = new ArrayList<>(existing);
+                    combined.addAll(added);
+                    return combined;
+                }));
+        return result;
+    }
+
+    public static boolean hasExplicitFilesystem(Map<String, String> 
properties) {
+        return "true".equalsIgnoreCase(properties.get("oss.hdfs.enabled"))
+                || properties.entrySet().stream().anyMatch(entry -> 
entry.getKey() != null
+                        && entry.getKey().startsWith("fs.") && 
entry.getKey().endsWith(".support")
+                        && "true".equalsIgnoreCase(entry.getValue()));
+    }
+
+    private static Map<String, List<String>> 
derivedS3EndpointValues(Map<String, String> properties) {
+        // Region binding alone does not select S3: native OSS also accepts 
legacy AWS region aliases.
+        if ((hasExplicitFilesystem(properties) && 
!Boolean.parseBoolean(properties.get("fs.s3.support")))
+                || !matchesS3Guess(properties)) {
+            return Map.of();
+        }
+        String regionKey = firstNonblankKey(properties, S3_REGION_ALIASES);
+        String endpointKey = firstNonblankKey(properties, S3_ENDPOINT_ALIASES);
+        String sourceKey = endpointKey;
+        String endpoint = endpointKey == null ? null : 
properties.get(endpointKey).trim();
+        if (regionKey == null && endpointKey == null) {
+            // The binder's legacy URI fallback runs on its HashMap snapshot, 
including URI key aliases.
+            Map<String, String> raw = new HashMap<>(properties);
+            sourceKey = raw.keySet().stream().filter(key -> 
key.equalsIgnoreCase("uri")).findFirst().orElse(null);
+            if (sourceKey == null) {
+                return Map.of();
+            }
+            String pathKey = firstNonblankKey(properties, 
List.of("use_path_style", "s3.path-style-access"));
+            String forceKey = firstNonblankKey(properties, 
List.of("force_parsing_by_standard_uri"));
+            endpoint = LegacyS3Uri.deriveEndpointQuietly(raw,
+                    pathKey == null ? "false" : properties.get(pathKey).trim(),
+                    forceKey == null ? "false" : 
properties.get(forceKey).trim());
+        }
+        if (endpointKey == null && regionKey == null && endpoint != null
+                && !endpoint.toLowerCase(Locale.ROOT).contains("glue")) {
+            // Ordinary legacy resource URIs also bind an endpoint; 
S3ObjStorage supplies HTTPS to bare authorities.
+            return s3RegionFromEndpoint(endpoint).isPresent()
+                    ? Map.of(sourceKey, List.of("https://"; + endpoint)) : 
Map.of();
+        }
+        if (endpoint != null && 
!endpoint.toLowerCase(Locale.ROOT).contains("glue")) {
+            return Map.of();
+        }
+        // Glue normalization infers a missing region before rewriting the S3 
endpoint. Reuse the
+        // storage binder's inference and retain the original peer for callers 
that also contact Glue.
+        String region = regionKey == null
+                ? (endpoint == null ? "" : 
s3RegionFromEndpoint(endpoint).orElse(""))
+                : properties.get(regionKey).trim();
+        if (region.isEmpty()) {
+            return Map.of();
+        }
+        if (!region.matches("[A-Za-z0-9-]+")) {
+            throw new IllegalArgumentException("S3 region must be a literal 
hostname component");
+        }
+        String serviceEndpoint = s3EndpointForRegion(region);
+        if (regionKey != null) {
+            return Map.of(regionKey, List.of(serviceEndpoint));
+        }
+        String source = properties.get(sourceKey);
+        String normalized = source.trim().toLowerCase(Locale.ROOT);
+        // An S3 URI is a resource locator; its rewritten endpoint is the 
socket peer. An HTTP URI
+        // can also name the catalog service, so retain that independently 
checked original peer.
+        boolean originalPeer = endpointKey != null || 
normalized.startsWith("http://";)
+                || normalized.startsWith("https://";);
+        return Map.of(sourceKey, originalPeer ? List.of(source, 
serviceEndpoint) : List.of(serviceEndpoint));
+    }
+
+    /** Raw provider guessing shared with binding; first-non-null alias and 
URI precedence are significant. */
+    public static boolean matchesS3Guess(Map<String, String> properties) {
+        if (GcsEndpointProperties.hasExplicitS3Request(properties)) {
+            return true;
+        }
+        if (GcsEndpointProperties.guessIsGcs(properties)) {
+            return false;
+        }
+        String endpoint = null;
+        for (String key : S3_ENDPOINT_ALIASES) {
+            String value = properties.get(key);
+            if (value != null) {
+                endpoint = value;
+                break;
+            }
+        }
+        if (endpoint != null && !endpoint.isBlank()) {
+            return endpoint.contains("amazonaws.com");
+        }
+        for (Map.Entry<String, String> entry : properties.entrySet()) {
+            if ("uri".equalsIgnoreCase(entry.getKey()) && entry.getValue() != 
null) {
+                return entry.getValue().contains("amazonaws.com");
+            }
+        }
+        for (String key : S3_GUESS_REGION_ALIASES) {
+            String value = properties.get(key);
+            if (value != null && !value.isBlank()) {
+                return true;
+            }
+        }
+        return false;
+    }
+
+    public static String s3EndpointForRegion(String region) {
+        return "https://s3."; + region + ".amazonaws.com";
+    }
+
+    public static Optional<String> s3RegionFromEndpoint(String endpoint) {
+        String lowerEndpoint = endpoint.toLowerCase(Locale.ROOT);
+        for (Pattern pattern : S3_ENDPOINT_PATTERNS) {
+            Matcher matcher = pattern.matcher(lowerEndpoint);
+            if (matcher.matches()) {
+                for (int i = 1; i <= matcher.groupCount(); i++) {
+                    String group = matcher.group(i);
+                    if (group != null && !group.isBlank()) {
+                        return Optional.of(group);
+                    }
+                }
+            }
+        }
+        return Optional.empty();
+    }
+
+    private static String firstNonblankKey(Map<String, String> properties, 
List<String> aliases) {
+        for (String key : aliases) {
+            String value = properties.get(key);
+            if (value != null && !value.isBlank()) {
+                return key;
+            }
+        }
+        return null;
+    }
+
+    /**
+     * Shared aliases can reach different SDKs; require an explicit scheme or 
port instead of guessing it.
+     * @throws IllegalArgumentException if a proxy route cannot be established 
from independent endpoint values
+     */
+    public static Map<String, Integer> endpoints(Map<String, String> 
properties, Predicate<String> opaqueCredential) {
+        Map<String, Integer> endpoints = new LinkedHashMap<>();
+        // OSS-HDFS prefers its specific alias over oss.endpoint before 
emitting fs.oss.endpoint.
+        for (String key : new String[] {"s3.endpoint", "AWS_ENDPOINT", 
"endpoint", "ENDPOINT", "aws.endpoint",
+                "glue.endpoint", "aws.glue.endpoint", "oss.endpoint", 
"oss.hdfs.endpoint", "OSS_ENDPOINT",
+                "fs.oss.endpoint", "cos.endpoint", "COS_ENDPOINT",
+                "obs.endpoint", "OBS_ENDPOINT", "azure.endpoint", 
"AZURE_ENDPOINT", "azure.oauth2_server_uri",
+                "azure.oauth2_account_host", "gs.endpoint", "minio.endpoint", 
"ozone.endpoint", "fs.s3a.endpoint",
+                "fs.gs.proxy.address"}) {
+            if (properties.containsKey(key)) {
+                endpoints.put(key, -1);

Review Comment:
   [P2] Use the selected storage endpoint’s HTTPS default
   
   The bare-GCS SQL control works with `gs.endpoint=storage.googleapis.com`, 
but changing only the key to `s3.endpoint` still binds the same value in 
`GcsFileSystemProperties` and now fails admission at default port `-1`, before 
the checker can decide. Explicit S3 has the same mismatch for a bare 
`s3.endpoint`. Both clients normalize these endpoints to HTTPS. Project the 
selected provider’s effective endpoint and cover an alternate GCS alias and a 
bare S3 endpoint at port 443.



##########
fe/fe-connector/fe-connector-paimon/src/main/java/org/apache/doris/connector/paimon/PaimonConnectorProvider.java:
##########
@@ -106,7 +111,107 @@ public ConnectorSecuritySurface securitySurface() {
         // The secrets are those of every metastore flavor: the engine masks 
by key name alone.
         return ConnectorSecuritySurface.ofJdbcDriverUrls(
                 "paimon.catalog.type", "paimon.jdbc.driver_url", 
"jdbc.driver_url")
-                .withSensitiveKeys(MetaStoreProviders.sensitivePropertyKeys());
+                .withSensitiveKeys(MetaStoreProviders.sensitivePropertyKeys())
+                
.withSensitiveKeys(JdbcTlsStoreUrlSecurity.sensitivePropertyKeys("jdbc."))
+                
.withSensitiveKeys(JdbcTlsStoreUrlSecurity.sensitivePropertyKeys("paimon.jdbc."))
+                // The pass-through bearer token is opaque even when its bytes 
look like an HTTP URL.
+                .withSensitiveKeys("paimon.rest.token")
+                // REST token providers also perform HTTP calls; checking only 
the catalog URI misses them.
+                .withSsrfEndpoints("paimon.rest.uri", "uri", 
"paimon.rest.dlf.token-ecs-metadata-url",

Review Comment:
   [P2] Check dedicated REST URIs only when REST is selected
   
   On Paimon filesystem, the factory pins the filesystem metastore and never 
uses `paimon.rest.uri`. This declaration still checks a saved URI during an 
unrelated ALTER or lazy initialization, so a retired service that the operator 
no longer allows can make a local catalog unusable. Iceberg’s parallel 
`iceberg.rest.uri` declaration has the same problem on Hadoop and HMS. It also 
affects the first Hive-to-Iceberg query, since the HMS sibling inherits the 
gateway’s raw properties. Project the dedicated REST keys only for the active 
REST flavor and test that switching to REST reactivates the check.



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