Gabriel39 commented on code in PR #71205: URL: https://github.com/apache/doris/pull/71205#discussion_r4785460201
########## fe/fe-filesystem/fe-filesystem-api/src/main/java/org/apache/doris/filesystem/properties/OssEndpointProperties.java: ########## @@ -0,0 +1,198 @@ +// 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 org.apache.doris.foundation.property.ConnectorPropertiesUtils; + +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.regex.Matcher; +import java.util.regex.Pattern; + +/** Pure OSS routing rules shared by property binding, provider selection and endpoint admission. */ +public final class OssEndpointProperties { + private static final List<String> ENDPOINT_ALIASES = List.of("oss.endpoint", "s3.endpoint", "AWS_ENDPOINT", + "endpoint", "ENDPOINT", "dlf.endpoint", "dlf.catalog.endpoint", "fs.oss.endpoint", "OSS_ENDPOINT"); + private static final List<String> REGION_ALIASES = List.of("oss.region", "s3.region", "AWS_REGION", "region", + "REGION", "dlf.region", "dlf.catalog.region", "iceberg.rest.signing-region", "OSS_REGION"); + private static final List<String> HDFS_ENDPOINT_ALIASES = List.of("oss.hdfs.endpoint", "oss.endpoint", + "dlf.endpoint", "dlf.catalog.endpoint", "fs.oss.endpoint"); + private static final Pattern OSS_ENDPOINT = + Pattern.compile("^(?:https?://)?(?:s3\\.)?oss-([a-z0-9-]+?)(?:-internal)?\\.aliyuncs\\.com$"); + private static final Pattern DLF_ENDPOINT = + Pattern.compile("^(?:https?://)?dlf(?:-vpc)?\\.([a-z0-9-]+)\\.aliyuncs\\.com(?:/.*)?$"); + + private OssEndpointProperties() { + } + + public static boolean isDlfEndpoint(String endpoint) { + return endpoint != null && DLF_ENDPOINT.matcher(endpoint.toLowerCase(Locale.ROOT)).matches(); + } + + public static Optional<String> regionFromEndpoint(String endpoint) { + if (endpoint == null) { + return Optional.empty(); + } + String lower = endpoint.toLowerCase(Locale.ROOT); + for (Pattern pattern : List.of(OSS_ENDPOINT, DLF_ENDPOINT)) { + Matcher matcher = pattern.matcher(lower); + if (matcher.matches()) { + return Optional.of(matcher.group(1)); + } + } + return Optional.empty(); + } + + /** Inputs are bound String fields; standard-endpoint matching deliberately retains its case semantics. */ + public static String normalizeNativeEndpoint(String endpoint, String region, boolean publicAccess) { + if (region == null || region.isBlank()) { + return endpoint; + } + if (endpoint == null || endpoint.isBlank() || !OSS_ENDPOINT.matcher(endpoint).matches()) { + // A configured region rewrites every nonstandard endpoint, including custom DLF service URLs. + return "oss-" + region + (publicAccess ? "" : "-internal") + ".aliyuncs.com"; + } + return endpoint; + } + + public static boolean matchesNativeGuess(Map<String, String> properties) { + // Guessing uses the first non-null alias, whereas field binding uses the first nonblank alias. + for (String key : List.of("oss.endpoint", "s3.endpoint", "AWS_ENDPOINT", "endpoint", "ENDPOINT", + "dlf.endpoint", "dlf.catalog.endpoint", "fs.oss.endpoint", "fs.oss.accessKeyId")) { + String value = properties.get(key); + if (value != null) { + if (!value.isBlank()) { + return !value.contains("oss-dls.aliyuncs") && value.contains("aliyuncs.com"); + } + break; + } + } + String region = properties.get("oss.region"); + if (region != null && !region.isBlank()) { + return true; + } + for (String key : List.of("hive.metastore.type", "iceberg.catalog.type", "paimon.catalog.type")) { + if ("dlf".equalsIgnoreCase(properties.get(key))) { + return true; + } + } + for (Map.Entry<String, String> entry : properties.entrySet()) { + String value = entry.getValue(); + if (("uri".equalsIgnoreCase(entry.getKey()) || "warehouse".equalsIgnoreCase(entry.getKey())) + && value != null && !value.contains("oss-dls.aliyuncs") + && (value.startsWith("oss://") + || (value.contains("aliyuncs.com") && (value.contains("oss-") || value.contains("s3."))))) { + return true; + } + } + return false; + } + + public static boolean matchesHdfsGuess(Map<String, String> properties) { + if (properties.entrySet().stream().anyMatch(entry -> "oss.hdfs.".equalsIgnoreCase(entry.getKey()) + && Boolean.parseBoolean(entry.getValue()))) { + return true; + } + // These are the legacy guess aliases; fs.oss.endpoint remains a binding alias after explicit selection. + return List.of("oss.hdfs.endpoint", "oss.endpoint", "dlf.endpoint", "dlf.catalog.endpoint").stream() + .map(properties::get).anyMatch(value -> value != null && !value.isBlank() + && value.endsWith(".oss-dls.aliyuncs.com")); + } + + static Map<String, List<String>> derivedEndpointValues(Map<String, String> properties) { + boolean guess = !hasExplicitFilesystem(properties); + boolean hdfs = Boolean.parseBoolean(properties.get("fs.oss-hdfs.support")) + || Boolean.parseBoolean(properties.get("oss.hdfs.enabled")) + || (guess && matchesHdfsGuess(properties)); + if (hdfs) { + String key = firstNonblankKey(properties, HDFS_ENDPOINT_ALIASES); + if (key != null && isDlfEndpoint(properties.get(key).trim())) { + // Jindo receives a bare rewritten OSS-DLS host; do not invent its unmodeled transport port. + throw new IllegalArgumentException( + "DLF-derived OSS-HDFS routing requires an explicit storage endpoint"); + } + return Map.of(); + } + // Raw catalog binding skips native OSS after an OSS-HDFS match. + // Any explicit filesystem flag also disables heuristic provider selection. + if (!Boolean.parseBoolean(properties.get("fs.oss.support")) && !(guess && matchesNativeGuess(properties))) { + return Map.of(); + } + String endpointKey = firstNonblankKey(properties, ENDPOINT_ALIASES); + Map<String, String> candidates = new LinkedHashMap<>(); + if (endpointKey != null) { + candidates.put(endpointKey, properties.get(endpointKey).trim()); + } else { + String pathKey = firstNonblankKey(properties, List.of("use_path_style", "s3.path-style-access")); Review Comment: Addressed in f28602a481e. Native OSS admission and binding now share legacy-URI endpoint derivation with provider-prefixed option precedence, including oss.use_path_style and oss.force_parsing_by_standard_uri. Tests retain independent blocked-peer assertions for both options; the SQL case distinguishes the region-rewritten native peer. Validation: 140 selected test classes / 2502 tests passed; FE Checkstyle and packaging checks passed. The SQL suite passed 386 expected policy refusals with positive CREATE/ALTER controls. ########## fe/fe-filesystem/fe-filesystem-api/src/main/java/org/apache/doris/filesystem/properties/OssEndpointProperties.java: ########## @@ -0,0 +1,198 @@ +// 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 org.apache.doris.foundation.property.ConnectorPropertiesUtils; + +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.regex.Matcher; +import java.util.regex.Pattern; + +/** Pure OSS routing rules shared by property binding, provider selection and endpoint admission. */ +public final class OssEndpointProperties { + private static final List<String> ENDPOINT_ALIASES = List.of("oss.endpoint", "s3.endpoint", "AWS_ENDPOINT", + "endpoint", "ENDPOINT", "dlf.endpoint", "dlf.catalog.endpoint", "fs.oss.endpoint", "OSS_ENDPOINT"); + private static final List<String> REGION_ALIASES = List.of("oss.region", "s3.region", "AWS_REGION", "region", + "REGION", "dlf.region", "dlf.catalog.region", "iceberg.rest.signing-region", "OSS_REGION"); + private static final List<String> HDFS_ENDPOINT_ALIASES = List.of("oss.hdfs.endpoint", "oss.endpoint", + "dlf.endpoint", "dlf.catalog.endpoint", "fs.oss.endpoint"); + private static final Pattern OSS_ENDPOINT = + Pattern.compile("^(?:https?://)?(?:s3\\.)?oss-([a-z0-9-]+?)(?:-internal)?\\.aliyuncs\\.com$"); + private static final Pattern DLF_ENDPOINT = + Pattern.compile("^(?:https?://)?dlf(?:-vpc)?\\.([a-z0-9-]+)\\.aliyuncs\\.com(?:/.*)?$"); + + private OssEndpointProperties() { + } + + public static boolean isDlfEndpoint(String endpoint) { + return endpoint != null && DLF_ENDPOINT.matcher(endpoint.toLowerCase(Locale.ROOT)).matches(); + } + + public static Optional<String> regionFromEndpoint(String endpoint) { + if (endpoint == null) { + return Optional.empty(); + } + String lower = endpoint.toLowerCase(Locale.ROOT); + for (Pattern pattern : List.of(OSS_ENDPOINT, DLF_ENDPOINT)) { + Matcher matcher = pattern.matcher(lower); + if (matcher.matches()) { + return Optional.of(matcher.group(1)); + } + } + return Optional.empty(); + } + + /** Inputs are bound String fields; standard-endpoint matching deliberately retains its case semantics. */ + public static String normalizeNativeEndpoint(String endpoint, String region, boolean publicAccess) { + if (region == null || region.isBlank()) { + return endpoint; + } + if (endpoint == null || endpoint.isBlank() || !OSS_ENDPOINT.matcher(endpoint).matches()) { + // A configured region rewrites every nonstandard endpoint, including custom DLF service URLs. + return "oss-" + region + (publicAccess ? "" : "-internal") + ".aliyuncs.com"; + } + return endpoint; + } + + public static boolean matchesNativeGuess(Map<String, String> properties) { + // Guessing uses the first non-null alias, whereas field binding uses the first nonblank alias. + for (String key : List.of("oss.endpoint", "s3.endpoint", "AWS_ENDPOINT", "endpoint", "ENDPOINT", + "dlf.endpoint", "dlf.catalog.endpoint", "fs.oss.endpoint", "fs.oss.accessKeyId")) { + String value = properties.get(key); + if (value != null) { + if (!value.isBlank()) { + return !value.contains("oss-dls.aliyuncs") && value.contains("aliyuncs.com"); + } + break; + } + } + String region = properties.get("oss.region"); + if (region != null && !region.isBlank()) { + return true; + } + for (String key : List.of("hive.metastore.type", "iceberg.catalog.type", "paimon.catalog.type")) { + if ("dlf".equalsIgnoreCase(properties.get(key))) { + return true; + } + } + for (Map.Entry<String, String> entry : properties.entrySet()) { + String value = entry.getValue(); + if (("uri".equalsIgnoreCase(entry.getKey()) || "warehouse".equalsIgnoreCase(entry.getKey())) + && value != null && !value.contains("oss-dls.aliyuncs") + && (value.startsWith("oss://") + || (value.contains("aliyuncs.com") && (value.contains("oss-") || value.contains("s3."))))) { + return true; + } + } + return false; + } + + public static boolean matchesHdfsGuess(Map<String, String> properties) { + if (properties.entrySet().stream().anyMatch(entry -> "oss.hdfs.".equalsIgnoreCase(entry.getKey()) + && Boolean.parseBoolean(entry.getValue()))) { + return true; + } + // These are the legacy guess aliases; fs.oss.endpoint remains a binding alias after explicit selection. + return List.of("oss.hdfs.endpoint", "oss.endpoint", "dlf.endpoint", "dlf.catalog.endpoint").stream() + .map(properties::get).anyMatch(value -> value != null && !value.isBlank() + && value.endsWith(".oss-dls.aliyuncs.com")); + } + + static Map<String, List<String>> derivedEndpointValues(Map<String, String> properties) { + boolean guess = !hasExplicitFilesystem(properties); + boolean hdfs = Boolean.parseBoolean(properties.get("fs.oss-hdfs.support")) + || Boolean.parseBoolean(properties.get("oss.hdfs.enabled")) + || (guess && matchesHdfsGuess(properties)); + if (hdfs) { + String key = firstNonblankKey(properties, HDFS_ENDPOINT_ALIASES); + if (key != null && isDlfEndpoint(properties.get(key).trim())) { + // Jindo receives a bare rewritten OSS-DLS host; do not invent its unmodeled transport port. + throw new IllegalArgumentException( + "DLF-derived OSS-HDFS routing requires an explicit storage endpoint"); + } + return Map.of(); + } + // Raw catalog binding skips native OSS after an OSS-HDFS match. + // Any explicit filesystem flag also disables heuristic provider selection. + if (!Boolean.parseBoolean(properties.get("fs.oss.support")) && !(guess && matchesNativeGuess(properties))) { + return Map.of(); + } + String endpointKey = firstNonblankKey(properties, ENDPOINT_ALIASES); + Map<String, String> candidates = new LinkedHashMap<>(); + if (endpointKey != null) { + candidates.put(endpointKey, properties.get(endpointKey).trim()); + } else { + String pathKey = firstNonblankKey(properties, List.of("use_path_style", "s3.path-style-access")); + String forceKey = firstNonblankKey(properties, List.of("force_parsing_by_standard_uri")); + Map<String, String> raw = new HashMap<>(properties); + String uriKey = raw.keySet().stream().filter(key -> key.equalsIgnoreCase("uri")).findFirst().orElse(null); + String derived = LegacyS3Uri.deriveEndpointQuietly(raw, + pathKey == null ? "false" : properties.get(pathKey).trim(), + forceKey == null ? "false" : properties.get(forceKey).trim()); + if (derived != null && !derived.isBlank()) { + candidates.put(uriKey, derived); + } + } + String regionKey = firstNonblankKey(properties, REGION_ALIASES); + if (candidates.isEmpty() && regionKey != null) { + candidates.put(regionKey, ""); + } + Map<String, List<String>> result = new LinkedHashMap<>(); + String publicKey = firstNonblankKey(properties, List.of("dlf.access.public", "dlf.catalog.accessPublic")); + boolean publicAccess = publicKey != null && ConnectorPropertiesUtils.parseBooleanProperty( + properties.get(publicKey).trim(), "dlf.access.public"); + for (Map.Entry<String, String> entry : candidates.entrySet()) { + String region = regionKey == null ? regionFromEndpoint(entry.getValue()).orElse("") + : properties.get(regionKey).trim(); + if (region.isEmpty()) { + continue; + } + if (!region.matches("[A-Za-z0-9-]+")) { + throw new IllegalArgumentException("OSS region must be a literal hostname component"); + } + String endpoint = normalizeNativeEndpoint(entry.getValue(), region, publicAccess); + // aliyun-sdk-oss 3.15.0 defaults bare endpoint authorities to HTTP, even for HTTPS resource URIs. + String peer = endpoint.contains("://") ? endpoint : "http://" + endpoint; + result.put(entry.getKey(), endpointKey == null ? List.of(peer) + : List.of(properties.get(endpointKey), peer)); Review Comment: Addressed in f28602a481e. The native OSS storage projection now admits only its effective normalized socket peer, including HTTP port 80 for a bare endpoint. Independently declared metadata destinations retain their separate interpretation. Both allowed and denied bare-endpoint controls are covered, together with an exact-port SQL refusal. Validation: 140 selected test classes / 2502 tests passed; FE Checkstyle and packaging checks passed. The SQL suite passed 386 expected policy refusals with positive CREATE/ALTER controls. ########## fe/fe-filesystem/fe-filesystem-api/src/main/java/org/apache/doris/filesystem/properties/StorageEndpointProperties.java: ########## @@ -0,0 +1,252 @@ +// 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 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)); Review Comment: Addressed in f28602a481e. The filesystem registry and admission now share the explicit-selection predicate. An explicit non-S3 selection suppresses the inactive regional AWS S3 default while preserving the selected OSS peer. The inverse-selection recording control and an enabled fail-only SQL positive case cover this behavior. Validation: 140 selected test classes / 2502 tests passed; FE Checkstyle and packaging checks passed. The SQL suite passed 386 expected policy refusals with positive CREATE/ALTER controls. ########## fe/fe-filesystem/fe-filesystem-api/src/main/java/org/apache/doris/filesystem/properties/HdfsEndpointProperties.java: ########## @@ -0,0 +1,88 @@ +// 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.net.URI; +import java.util.Arrays; +import java.util.LinkedHashSet; +import java.util.List; +import java.util.Map; +import java.util.Set; +import java.util.stream.Collectors; + +/** Resolves inline HDFS storage authorities without depending on a filesystem implementation. */ +public final class HdfsEndpointProperties { + private HdfsEndpointProperties() { + } + + /** Logical and inherited authorities are checked through their separately selected physical properties. */ + public static List<String> authorities(String value, Map<String, String> properties) { + URI uri = URI.create(value.regionMatches(true, 0, "hdfs:", 0, 5) ? value : "hdfs://" + value); + String authority = uri.getRawAuthority(); + if (authority == null || authority.isEmpty()) { + // Hadoop inherits the default authority even for hdfs:/path and hdfs:///path. + // The default's own property enters admission separately; never invent localhost here. + for (String key : List.of("fs.defaultFS", "fs.default.name", "oss.hdfs.fs.defaultFS")) { Review Comment: Addressed in f28602a481e. HDFS binding and admission now share legacy URI selection. With no canonical fs.defaultFS, an authorityless warehouse may inherit the physical HDFS uri/URI default; that physical peer remains independently checked at 8020. Recording controls cover both aliases, and SQL covers allowed inheritance and rejected CREATE/ALTER with a same-policy accepted follow-up. Validation: 140 selected test classes / 2502 tests passed; FE Checkstyle and packaging checks passed. The SQL suite passed 386 expected policy refusals with positive CREATE/ALTER controls. -- 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]
