hello-stephen commented on code in PR #71205:
URL: https://github.com/apache/doris/pull/71205#discussion_r4791843945
##########
fe/fe-connector/fe-connector-iceberg/src/main/java/org/apache/doris/connector/iceberg/IcebergConnectorProvider.java:
##########
@@ -95,11 +102,215 @@ public ConnectorSecuritySurface securitySurface() {
// Keep secret masking and JDBC restrictions when REST decryption adds
a KMS endpoint check.
return
ConnectorSecuritySurface.ofJdbcDriverUrls("iceberg.catalog.type",
"iceberg.jdbc.driver_url")
.withSensitiveKeys(MetaStoreProviders.sensitivePropertyKeys())
+
.withSensitiveKeys(JdbcTlsStoreUrlSecurity.sensitivePropertyKeys("jdbc."))
// Protect inline SDK credentials even when the additional
name-pattern rule is disabled.
.withSensitiveKeys(List.of("gcp.auth.credentials-json",
"gcs.oauth2.token",
"gcs.encryption-key", "gcs.decryption-key"))
- // Standalone DLF proxies open HMS clients too; Hive's surface
only covers HMS catalogs.
- .withSsrfEndpoints("kms.endpoint", "hive.metastore.uris",
"uri", "metastore.thrift.uris")
+ .withSensitiveKeyPrefix("client.credentials-provider.",
+ "credential", "password", "secret", "token", "key",
"authorization", "header")
+ .withSsrfEndpoints("kms.endpoint", "iceberg.rest.uri", "uri",
+ "hive.metastore.uris", "metastore.thrift.uris",
"s3tables.endpoint", "iceberg.jdbc.uri",
+ "dynamodb.endpoint",
+ "http-client.proxy-endpoint", "signer.uri")
+ // Native GCS overrides its storage service host independently
of the catalog's REST URI.
+ .withSsrfEndpoints("gcs.service.host")
+ .withCommaSeparatedSsrfEndpoints("hive.metastore.uris",
"metastore.thrift.uris")
+ .withSsrfEndpoints("glue.endpoint", "aws.endpoint",
"aws.glue.endpoint")
Review Comment:
[P2] Keep Glue metadata checks out of stock Hadoop and HMS catalogs
The S3 binder accepts these aliases for storage and gives the selected bare
endpoint HTTPS port 443. Iceberg Hadoop and HMS do not construct a Glue
metastore, but this unconditional service declaration parses the same alias
again with no default port. It rejects a valid storage-only configuration
before the policy can check it. Project the Glue metastore endpoint when Glue
is selected and retain the independent storage check.
##########
fe/fe-connector/fe-connector-iceberg/src/main/java/org/apache/doris/connector/iceberg/IcebergConnectorProvider.java:
##########
@@ -95,11 +102,215 @@ public ConnectorSecuritySurface securitySurface() {
// Keep secret masking and JDBC restrictions when REST decryption adds
a KMS endpoint check.
return
ConnectorSecuritySurface.ofJdbcDriverUrls("iceberg.catalog.type",
"iceberg.jdbc.driver_url")
.withSensitiveKeys(MetaStoreProviders.sensitivePropertyKeys())
+
.withSensitiveKeys(JdbcTlsStoreUrlSecurity.sensitivePropertyKeys("jdbc."))
// Protect inline SDK credentials even when the additional
name-pattern rule is disabled.
.withSensitiveKeys(List.of("gcp.auth.credentials-json",
"gcs.oauth2.token",
"gcs.encryption-key", "gcs.decryption-key"))
- // Standalone DLF proxies open HMS clients too; Hive's surface
only covers HMS catalogs.
- .withSsrfEndpoints("kms.endpoint", "hive.metastore.uris",
"uri", "metastore.thrift.uris")
+ .withSensitiveKeyPrefix("client.credentials-provider.",
+ "credential", "password", "secret", "token", "key",
"authorization", "header")
+ .withSsrfEndpoints("kms.endpoint", "iceberg.rest.uri", "uri",
+ "hive.metastore.uris", "metastore.thrift.uris",
"s3tables.endpoint", "iceberg.jdbc.uri",
+ "dynamodb.endpoint",
+ "http-client.proxy-endpoint", "signer.uri")
+ // Native GCS overrides its storage service host independently
of the catalog's REST URI.
+ .withSsrfEndpoints("gcs.service.host")
+ .withCommaSeparatedSsrfEndpoints("hive.metastore.uris",
"metastore.thrift.uris")
+ .withSsrfEndpoints("glue.endpoint", "aws.endpoint",
"aws.glue.endpoint")
+ // DLF accepts bare hosts and uses HTTPS, including on its
standalone HMS proxy path.
.withSsrfEndpoints(443, "dlf.endpoint",
"dlf.catalog.endpoint");
}
+
+ @Override
+ public ConnectorSecuritySurface securitySurface(Map<String, String>
properties) {
+ // Retired aliases and inactive proxy clients must not contribute
unused metadata destinations.
+ ConnectorSecuritySurface surface = securitySurface()
+
.withSsrfEndpointValues("dlf.endpoint").withSsrfEndpointValues("dlf.catalog.endpoint");
+ String flavor =
properties.getOrDefault(IcebergCatalogProperties.ICEBERG_CATALOG_TYPE,
+ IcebergCatalogProperties.TYPE_HMS).trim();
+ if (!IcebergCatalogProperties.TYPE_REST.equalsIgnoreCase(flavor)) {
+ // HMS siblings inherit raw options; a saved REST URI becomes a
route only after selecting REST.
+ surface = surface.withSsrfEndpointValues("iceberg.rest.uri");
+ }
+ Map<String, String> endpointProperties = new HashMap<>(properties);
+ for (String key : new String[] {"signer.endpoint",
"rest.remote-signing.endpoint",
+ "client.refresh-credentials-endpoint",
"iceberg.rest.oauth2.server-uri", "oauth2-server-uri",
+ "client.credentials-provider.oauth2-server-uri",
"gcs.oauth2.refresh-credentials-endpoint"}) {
+ String value = properties.get(key);
+ if (value != null && key.equals("iceberg.rest.oauth2.server-uri"))
{
+ // The canonical holder trims Strings before emitting the SDK
OAuth option; raw aliases do not.
+ value = value.trim();
+ }
+ // Iceberg appends signer, credential-refresh and OAuth paths
(including GCS refresh) to a checked base.
+ // Only these lowercase absolute forms replace that base with an
independent destination.
+ if (value != null && (value.startsWith("http://") ||
value.startsWith("https://"))) {
Review Comment:
[P2] Check the typed OAuth endpoint only when the factory emits it
This loop declares any absolute `iceberg.rest.oauth2.server-uri`, but
`appendRestOAuth2Properties` emits that option only for REST client-credentials
OAuth. A REST catalog that has switched to a preconfigured token can still have
a saved typed endpoint, and probing it can fail an unrelated ALTER or lazy
initialization even though the SDK never receives it as its token endpoint. Use
the same factory predicate for the typed declaration and add a test that
switches between token-only and client-credentials modes.
##########
fe/fe-core/src/main/java/org/apache/doris/connector/CatalogEndpointSecurity.java:
##########
@@ -0,0 +1,420 @@
+// 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;
+
+import org.apache.doris.cloud.security.SecurityChecker;
+import org.apache.doris.common.DdlException;
+import org.apache.doris.common.util.DatasourcePrintableMap;
+import org.apache.doris.common.util.DebugPointUtil;
+import org.apache.doris.common.util.DebugPointUtil.DebugPoint;
+import org.apache.doris.connector.spi.ConnectorSecuritySurface;
+import org.apache.doris.filesystem.properties.HdfsEndpointProperties;
+import org.apache.doris.filesystem.properties.StorageEndpointProperties;
+
+import com.google.common.net.HostAndPort;
+import com.google.common.net.InetAddresses;
+import okhttp3.HttpUrl;
+
+import java.net.IDN;
+import java.net.URI;
+import java.net.URISyntaxException;
+import java.net.URLDecoder;
+import java.nio.charset.StandardCharsets;
+import java.util.ArrayList;
+import java.util.LinkedHashMap;
+import java.util.LinkedHashSet;
+import java.util.List;
+import java.util.Locale;
+import java.util.Map;
+import java.util.Set;
+
+/** Shared endpoint admission for root and indirectly created catalog
connectors. */
+public final class CatalogEndpointSecurity {
+ private static final String REJECT_HOST_POINT =
"CatalogEndpointSecurity.reject_host";
+
+ private CatalogEndpointSecurity() {
+ }
+
+ public static boolean isEnabled() {
+ // The admission decision consumes the point; callers may ask about
availability more than once.
+ return SecurityChecker.getInstance().isEnabled() ||
DebugPointUtil.isEnableWithoutCounting(REJECT_HOST_POINT);
+ }
+
+ public static void validate(String catalogName, ConnectorSecuritySurface
surface, Map<String, String> properties)
+ throws DdlException {
+ validateAndRemember(catalogName, surface, properties, null);
+ }
+
+ /** A receipt is valid only within one CREATE statement and for the same
checker instance. */
+ static final class Admission {
+ private final SecurityChecker checker;
+ private final boolean enabled;
+ private final Set<HostAndPort> destinations;
+
+ private Admission(SecurityChecker checker, Set<HostAndPort>
destinations) {
+ this.checker = checker;
+ this.enabled = checker.isEnabled();
+ this.destinations = Set.copyOf(destinations);
+ }
+ }
+
+ static Admission validateAndRemember(String catalogName,
ConnectorSecuritySurface surface,
+ Map<String, String> properties, Admission previous) throws
DdlException {
+ SecurityChecker checker = SecurityChecker.getInstance();
+ DebugPoint rejection = DebugPointUtil.getDebugPoint(REJECT_HOST_POINT);
+ if (!checker.isEnabled() && rejection == null) {
+ return null;
+ }
+ Map<String, Integer> storageEndpoints;
+ Map<String, List<String>> derivedStorageEndpoints;
+ try {
+ storageEndpoints = StorageEndpointProperties.endpoints(properties,
DatasourcePrintableMap::isSensitiveKey);
+ derivedStorageEndpoints =
StorageEndpointProperties.derivedEndpointValues(properties);
+ } catch (IllegalArgumentException e) {
+ // Storage routing can fail before URI parsing; never expose
credential-bearing option values.
+ throw new DdlException("Cannot validate shared storage routing
against the SSRF policy");
+ }
+ Map<String, List<HostAndPort>> parsedEndpoints = new LinkedHashMap<>();
+ Map<String, Integer> storageKeys = new
LinkedHashMap<>(storageEndpoints);
+ derivedStorageEndpoints.keySet().forEach(key ->
storageKeys.putIfAbsent(key, -1));
+ for (Map.Entry<String, Integer> entry : storageKeys.entrySet()) {
+ String key = entry.getKey();
+ int port = entry.getValue() < 0 ?
surface.ssrfEndpointDefaultPort(key) : entry.getValue();
+ List<String> values = derivedStorageEndpoints.getOrDefault(key,
Review Comment:
[P2] Keep the S3 endpoint when OSS rewrites a shared alias
A catalog can bind native OSS and S3 together. OSS can normalize their
shared endpoint alias to a different peer, while an ordinary explicit S3
endpoint is retained unchanged by the S3 binder and adds no derived entry here.
This lookup replaces that original value with the OSS peer. Paimon's filesystem
path merges the bound Hadoop settings with S3 last, so it still uses the S3
endpoint. Collect the effective peers from both selected providers before
deduplicating them, and cover the co-bound case with the recording checker.
##########
fe/fe-connector/fe-connector-fluss/src/main/java/org/apache/doris/connector/fluss/FlussConnectorProvider.java:
##########
@@ -51,16 +56,112 @@ public Connector create(Map<String, String> properties,
ConnectorContext context
}
/**
- * The fluss client's SASL credentials, a small and stable set of keys,
and the lake options under
- * {@link FlussCatalogProperties#LAKE_OPTION_PREFIX}: those are open-ended
(new paimon / filesystem
+ * The fluss client's SASL and direct gateway REST credentials use stable
keys. Lake options under
+ * {@link FlussCatalogProperties#LAKE_OPTION_PREFIX} are open-ended (new
paimon / filesystem
* credential names may arrive without a Doris release), so a lake option
is a secret when its name
* carries a credential-like word, and endpoints and other operational
settings stay visible.
*/
@Override
public ConnectorSecuritySurface securitySurface() {
+ return
baseSecuritySurface().withSsrfEndpointPrefixes(FlussCatalogProperties.LAKE_OPTION_PREFIX);
+ }
+
+ private static ConnectorSecuritySurface baseSecuritySurface() {
return
ConnectorSecuritySurface.ofSensitiveKeys("fluss.client.security.sasl.username",
"fluss.client.security.sasl.password",
"fluss.client.security.sasl.jaas.config")
+ // Direct gateway REST options reach the sibling through a
separate namespace on first lake access.
+ .withSsrfEndpointPrefixes("paimon.rest.")
+ .withSensitiveKeys("paimon.rest.token",
"paimon.rest.dlf.access-key-id",
+ "paimon.rest.dlf.access-key-secret")
+
.withCommaSeparatedSsrfEndpoints(FlussCatalogProperties.BOOTSTRAP_SERVERS)
+
.withCommaSeparatedSsrfEndpoints(FlussCatalogProperties.LAKE_OPTION_PREFIX +
"hive.metastore.uris",
+ FlussCatalogProperties.LAKE_OPTION_PREFIX +
"metastore.thrift.uris")
.withSensitiveKeyPrefix(FlussCatalogProperties.LAKE_OPTION_PREFIX,
"key", "secret", "password", "token", "credential");
}
+
+ @Override
+ public ConnectorSecuritySurface securitySurface(Map<String, String>
properties) {
+ ConnectorSecuritySurface base = baseSecuritySurface();
+ ConnectorSecuritySurface surface = base;
+ Map<String, String> lake =
FlussCatalogProperties.extractLakeOverrides(properties);
+ Map<String, String> context = new HashMap<>(properties);
+ // The storage sibling binds canonical names after translating Hadoop
lake aliases.
+ Map<String, String> storage =
LakeStorageOptions.toStorageProperties(lake);
+ // Connector storage is published as defaults: even a blank direct key
remains authoritative.
+ storage.forEach(context::putIfAbsent);
+ // The sibling removes storage options; restoring their aliases could
bypass a blank direct canonical key.
+ lake.forEach((key, value) -> {
+ if (!LakeStorageOptions.isStorageOption(key)) {
+ context.putIfAbsent(key, value);
+ }
+ });
+ Map<String, String> effectiveLake = new HashMap<>(lake);
+ Map<String, String> storageOrigins = new HashMap<>();
+ for (Map.Entry<String, String> entry : lake.entrySet()) {
+ LakeStorageOptions.toStorageProperties(Map.of(entry.getKey(),
entry.getValue()))
+ .forEach((canonical, ignored) -> {
+ storageOrigins.put(canonical,
FlussCatalogProperties.LAKE_OPTION_PREFIX + entry.getKey());
+ if (properties.containsKey(canonical)) {
+ effectiveLake.remove(entry.getKey());
+ } else {
+ effectiveLake.put(entry.getKey(),
context.get(canonical));
+ }
+ });
+ }
+ Map<String, String> inferredProperties = new HashMap<>(properties);
+ try {
+ // The sibling strips the lake prefix only at first access. Apply
the same storage rules
+ // at statement admission, including legacy Paimon aliases and the
complete inline HA map.
+ Map<String, Integer> endpoints =
StorageEndpointProperties.endpoints(effectiveLake, key ->
Review Comment:
[P2] Use the translated Fluss storage endpoint's default port
Fluss translates a nested `fs.s3a.endpoint` into `s3.endpoint` before
storage binding. A selected S3 client accepts a bare endpoint at HTTPS port
443, but `effectiveLake` still stores the winner under its original name, so
this call assigns it no port. The later canonical derivation adds nothing for
an ordinary explicit S3 endpoint, and CREATE or ALTER fails before the checker
sees the peer. Run storage admission against the same merged canonical
properties used by binding and map diagnostics back to the original lake option.
##########
fe/fe-connector/fe-connector-paimon/src/main/java/org/apache/doris/connector/paimon/PaimonConnectorProvider.java:
##########
@@ -106,7 +111,111 @@ 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",
+ "hive.metastore.uris", "metastore.thrift.uris",
"paimon.jdbc.uri")
+ .withSsrfEndpoints("paimon.rest.dlf.oss-endpoint")
+ .withCommaSeparatedSsrfEndpoints("hive.metastore.uris",
"metastore.thrift.uris")
+ // DLF's scheme-less metadata aliases retain the HTTPS default
of the shared HMS path.
+ .withSsrfEndpoints(443, "dlf.endpoint", "dlf.catalog.endpoint")
+ .withSsrfEndpointPrefixes("paimon.rest.");
}
+ @Override
+ public ConnectorSecuritySurface securitySurface(Map<String, String>
properties) {
+ // Retired aliases and inactive proxy clients must not contribute
unused metadata destinations.
+ ConnectorSecuritySurface surface = securitySurface()
+
.withSsrfEndpointValues("dlf.endpoint").withSsrfEndpointValues("dlf.catalog.endpoint");
+ String configuredFlavor = properties.get("paimon.catalog.type");
+ String flavor = configuredFlavor == null || configuredFlavor.isBlank()
? "filesystem" : configuredFlavor.trim();
+ if (!"rest".equalsIgnoreCase(flavor)) {
+ // Preserve dormant REST options; complete-candidate admission
rechecks them on REST activation.
+ surface = surface.withSsrfEndpointValues("paimon.rest.uri");
+ }
+ if ("dlf".equalsIgnoreCase(flavor)) {
+ // The DLF Hive client receives this derived service host even
without an explicit endpoint property.
+ for (Map.Entry<String, String> entry
+ :
AbstractDlfMetaStoreProperties.serviceEndpointValues(properties).entrySet()) {
+ surface = surface.withSsrfEndpoints(443, entry.getKey())
+ .withSsrfEndpointValues(entry.getKey(),
entry.getValue());
+ }
+ }
+ if ("hms".equalsIgnoreCase(flavor) || ("dlf".equalsIgnoreCase(flavor)
+ && AbstractDlfMetaStoreProperties.usesHmsClient(properties))) {
+ surface = surface.withCommaSeparatedSsrfEndpoints("uri");
+ }
+ String metastore = properties.get("hive.metastore.uris");
+ boolean canonicalHmsUri = !"jdbc".equalsIgnoreCase(flavor) &&
!"rest".equalsIgnoreCase(flavor)
+ && metastore != null && !metastore.isBlank();
+ // Full candidate validation reactivates stored driver options only
for the typed JDBC branch.
+ if ("jdbc".equalsIgnoreCase(flavor)) {
+ // A complete ALTER can switch either URI alias or driver and
activate stored native options.
+ String jdbcUriKey =
JdbcProxyPropertySecurity.metastoreUriKey(properties, "paimon.jdbc.uri");
+ String jdbcUri = properties.get(jdbcUriKey);
+ String commonDriverUrl = properties.get("paimon.jdbc.driver_url");
+ // The holder selects the first nonblank artifact alias; keep both
operator-policy declarations.
+ surface = surface.withSsrfEndpointValues(commonDriverUrl == null
|| commonDriverUrl.isBlank()
Review Comment:
[P2] Match the JDBC holder's driver-alias selection
`PaimonJdbcMetaStoreProperties` skips aliases that are empty after String
trimming. The raw `isBlank()` checks here and in the adjacent driver-class
selection disagree for trim-empty values, so admission can discard the fallback
driver URL or classify the TLS-store options using a driver class the holder
does not select. Reuse the holder's alias-presence rule for both fields, as the
JDBC URI projection now does, while retaining both artifact-policy declarations.
##########
fe/fe-filesystem/fe-filesystem-api/src/main/java/org/apache/doris/filesystem/properties/OssEndpointProperties.java:
##########
@@ -0,0 +1,225 @@
+// 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.net.URI;
+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"));
+ }
+
+ public static String deriveLegacyUriEndpoint(Map<String, String>
properties) {
+ String pathKey = firstNonblankKey(properties,
+ List.of("oss.use_path_style", "use_path_style",
"s3.path-style-access"));
+ String forceKey = firstNonblankKey(properties,
+ List.of("oss.force_parsing_by_standard_uri",
"force_parsing_by_standard_uri"));
+ return LegacyS3Uri.deriveEndpointQuietly(new HashMap<>(properties),
+ pathKey == null ? "false" : properties.get(pathKey).trim(),
+ forceKey == null ? "false" : properties.get(forceKey).trim());
+ }
+
+ public static String toS3CompatibleEndpoint(String endpoint, String
region) {
+ String withScheme = endpoint.contains("://") ? endpoint : "http://" +
endpoint;
+ String host = URI.create(withScheme).getHost();
+ String publicHost = "oss-" + region + ".aliyuncs.com";
+ String internalHost = "oss-" + region + "-internal.aliyuncs.com";
+ // The S3 dialect changes the socket host, not just a property name,
and must remain idempotent.
+ return publicHost.equalsIgnoreCase(host) ||
internalHost.equalsIgnoreCase(host)
+ ? withScheme.replace(host, "s3." + host) : withScheme;
+ }
+
+ static Map<String, List<String>> derivedEndpointValues(Map<String, String>
properties) {
+ return derivedEndpointValues(properties, false);
+ }
+
+ public static Map<String, List<String>>
s3CompatibleEndpointValues(Map<String, String> properties) {
+ return derivedEndpointValues(properties, true);
+ }
+
+ public static boolean usesHdfs(Map<String, String> properties) {
+ return usesHdfs(properties,
!StorageEndpointProperties.hasExplicitFilesystem(properties));
+ }
+
+ private static boolean usesHdfs(Map<String, String> properties, boolean
guess) {
+ return Boolean.parseBoolean(properties.get("fs.oss-hdfs.support"))
+ || Boolean.parseBoolean(properties.get("oss.hdfs.enabled"))
+ || (guess && matchesHdfsGuess(properties));
+ }
+
+ private static Map<String, List<String>> derivedEndpointValues(
+ Map<String, String> properties, boolean s3Compatible) {
+ boolean guess =
!StorageEndpointProperties.hasExplicitFilesystem(properties);
+ if (usesHdfs(properties, guess)) {
+ 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 {
+ Map<String, String> raw = new HashMap<>(properties);
+ String uriKey = raw.keySet().stream().filter(key ->
key.equalsIgnoreCase("uri")).findFirst().orElse(null);
+ String derived = deriveLegacyUriEndpoint(raw);
+ 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 = s3Compatible ? toS3CompatibleEndpoint(endpoint,
region)
+ : (endpoint.contains("://") ? endpoint : "http://" +
endpoint);
+ // This is the storage interpretation; independent metadata
declarations retain their own raw peer.
+ result.put(entry.getKey(), List.of(peer));
+ }
+ return result;
+ }
+
+ 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()) {
Review Comment:
[P3] Use the OSS binder's blank test for endpoint aliases
The String binder skips a value that is empty after `trim()`, but this
helper keeps some of those values. For example, a trim-empty
`dlf.access.public` is ignored by the native OSS holder, which retains its
false default, while admission tries to parse an empty boolean and rejects the
catalog. Use the binder's presence rule here, as the S3 and GCS projections do.
--
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]