Gabriel39 commented on code in PR #71205:
URL: https://github.com/apache/doris/pull/71205#discussion_r4770483540
##########
fe/fe-connector/fe-connector-iceberg/src/main/java/org/apache/doris/connector/iceberg/IcebergConnectorProvider.java:
##########
@@ -94,6 +95,91 @@ 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())
- .withSsrfEndpoints("kms.endpoint");
+ .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")
+ .withSsrfEndpoints("glue.endpoint", "aws.endpoint",
"aws.glue.endpoint",
+ "dlf.endpoint", "dlf.catalog.endpoint");
+ }
+
+ @Override
+ public ConnectorSecuritySurface securitySurface(Map<String, String>
properties) {
+ ConnectorSecuritySurface surface = securitySurface();
+ 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"}) {
+ String value = properties.get(key);
+ // Iceberg appends signer, credential-refresh and OAuth paths to
an already 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:
Fixed in `e2ceb1005b0e`.
The canonical `iceberg.rest.oauth2.server-uri` is classified after the same
String trimming used by its typed holder, so padded absolute URLs now enter
endpoint checking. Raw/provider SDK aliases retain their untrimmed path
semantics. Padded relative canonical values keep the checked REST base. The
factory fixture verifies that the holder really emits the trimmed SDK value;
recording-policy units and CREATE/ALTER SQL cover the padded absolute case.
Final local verification passed: FE Checkstyle; 120 classes / 1705 tests
(410 endpoint cases and all 40 SPI classes / 184 tests), zero
failures/errors/skips; both API signature baselines; forced FE build with 37
API42 manifests and eight class-byte matches; standard SQL with 87 CREATE + 50
ALTER rejections, seven positive CREATE admissions and one positive ALTER. The
separate upstream Google JSON suite passed 30 expected rejections and one valid
catalog. HTTP authentication and default masking were preserved, and the owned
runtime was stopped.. The optional proprietary security SDK and full
external/native integration were unavailable; those limits remain explicit in
the PR description.
##########
fe/fe-filesystem/fe-filesystem-api/src/main/java/org/apache/doris/filesystem/properties/StorageEndpointProperties.java:
##########
@@ -0,0 +1,122 @@
+// 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.Collections;
+import java.util.LinkedHashMap;
+import java.util.List;
+import java.util.Locale;
+import java.util.Map;
+import java.util.function.Predicate;
+
+/** 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 StorageEndpointProperties() {
+ }
+
+ /**
+ * 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",
+ "dlf.endpoint", "dlf.catalog.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);
+ }
+ }
+ // ABFS OAuth always uses HTTPS; this value is a hostname also used in
Hadoop property keys.
+ if (properties.containsKey("azure.oauth2_account_host")) {
+ endpoints.put("azure.oauth2_account_host", 443);
+ }
+ // Hadoop passes through new client options. Keep URI-valued token and
service endpoints covered
+ // even when a dependency adds an option that Doris does not bind
itself yet.
+ properties.forEach((key, value) -> {
+ String trimmed = value == null ? "" : value.trim();
+ String normalized = trimmed.toLowerCase(Locale.ROOT);
+ String lowerKey = key.toLowerCase(Locale.ROOT);
+ boolean endpointName = lowerKey.endsWith(".url") ||
lowerKey.endsWith(".uri")
+ || lowerKey.endsWith(".endpoint");
+ String storageKey = hadoopStorageKey(key);
+ // Bucket options and aliases can replace a filesystem proxy tuple
after endpoint checking.
+ // Until those routes are modeled together, reject configured
proxy hosts before any probe.
+ if (!trimmed.isEmpty() && (storageKey.equals("fs.s3a.proxy.host")
|| storageKey.equals("fs.obs.proxy.host")
+ || ((storageKey.startsWith("fs.s3a.bucket.") ||
storageKey.startsWith("fs.obs.bucket."))
+ && storageKey.endsWith(".proxy.host")))) {
+ throw new IllegalArgumentException("Unsupported filesystem
proxy routing");
+ }
+ boolean storageOption = storageKey.startsWith("fs.") ||
storageKey.startsWith("dfs.")
+ || storageKey.startsWith("hadoop.");
+ boolean opaqueValue = opaqueCredential.test(storageKey)
+ || (!storageKey.equals(key) && opaqueCredential.test(key))
+ || storageKey.endsWith(".proxy.username") ||
storageKey.endsWith(".access-key")
+ || storageKey.endsWith(".secret-key") ||
storageKey.endsWith(".session-token");
+ boolean warehouse = key.equals("warehouse") ||
key.endsWith(".warehouse")
+ || key.equals("hive.metastore.warehouse.dir");
+ if ((storageOption
+ // URL-shaped passwords stay opaque; explicit aliases and
endpoint names still win.
+ && (endpointName || (!opaqueValue
+ && (normalized.startsWith("http://") ||
normalized.startsWith("https://")))))
+ || (warehouse
+ && (normalized.startsWith("http://") ||
normalized.startsWith("https://")))) {
+ endpoints.put(key, -1);
+ }
+ // Paimon HMS eagerly opens its warehouse, including an inherited
Hadoop default filesystem.
+ // Keep HDFS separate so admission can expand logical HA
nameservices to physical RPC nodes.
+ // A preferred storage alias can replace fs.defaultFS during
binding; retain every raw candidate.
+ boolean defaultFilesystem = key.equals("fs.defaultFS") ||
key.equals("fs.default.name")
+ || key.equals("oss.hdfs.fs.defaultFS");
+ // Interpolation can supply the scheme itself, so these known
storage keys must enter
+ // literal validation even when their raw value does not yet start
with a network scheme.
+ if ((warehouse || defaultFilesystem) && trimmed.contains("${")) {
+ endpoints.put(key, -1);
+ }
+ // Hadoop's lowercase "local" sentinel is special; other bare
values are HDFS hostnames.
+ if (((warehouse || defaultFilesystem || (storageOption &&
(endpointName || !opaqueValue)))
Review Comment:
Fixed in `e2ceb1005b0e`.
With enforcement enabled, warehouse/default-filesystem and forwarded
nonopaque WebHDFS/secure WebHDFS routes fail closed before any probe. Their
HTTP HA/redirect peers are not modeled by the HDFS RPC parser. A bounded audit
confirmed the same admission gap for stock ViewFS mount-table/Nfly routing, FTP
connections before login, and valid-shaped HAR paths that read delegated
metadata before archive validation fails; those routes now fail closed too.
Literal warehouse/default aliases, URI-list delegation, disabled-policy
behavior and opaque credentials are covered. Existing HDFS/HA, object-store and
local-path controls remain covered.
Final local verification passed: FE Checkstyle; 120 classes / 1705 tests
(410 endpoint cases and all 40 SPI classes / 184 tests), zero
failures/errors/skips; both API signature baselines; forced FE build with 37
API42 manifests and eight class-byte matches; standard SQL with 87 CREATE + 50
ALTER rejections, seven positive CREATE admissions and one positive ALTER. The
separate upstream Google JSON suite passed 30 expected rejections and one valid
catalog. HTTP authentication and default masking were preserved, and the owned
runtime was stopped.. SQL covers both CREATE and ALTER for direct/inherited
filesystem routes.
##########
fe/fe-core/src/main/java/org/apache/doris/connector/CatalogEndpointSecurity.java:
##########
@@ -0,0 +1,303 @@
+// 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 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;
+
+/** 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() {
+ return SecurityChecker.getInstance().isEnabled() ||
DebugPointUtil.isEnable(REJECT_HOST_POINT);
+ }
+
+ public static void validate(String catalogName, ConnectorSecuritySurface
surface, Map<String, String> properties)
+ throws DdlException {
+ SecurityChecker checker = SecurityChecker.getInstance();
+ DebugPoint rejection = DebugPointUtil.getDebugPoint(REJECT_HOST_POINT);
+ if (!checker.isEnabled() && rejection == null) {
+ return;
+ }
+ Map<String, Integer> storageEndpoints;
+ try {
+ storageEndpoints = StorageEndpointProperties.endpoints(properties,
DatasourcePrintableMap::isSensitiveKey);
+ } 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, Integer> endpoints = new LinkedHashMap<>(storageEndpoints);
+ for (String key : surface.ssrfEndpointKeys(properties)) {
+ int defaultPort = surface.ssrfEndpointDefaultPort(key);
+ endpoints.put(key, defaultPort < 0 ? endpoints.getOrDefault(key,
-1) : defaultPort);
+ }
+ // Driver downloads can connect during pre-validation, before a
connector's connectivity test.
+ String flavor = surface.jdbcDriverUrlFlavorKey();
+ String flavorValue = flavor == null ? "jdbc" :
properties.getOrDefault(flavor, "").trim();
+ if ("jdbc".equalsIgnoreCase(flavorValue)) {
+ for (String key : surface.jdbcDriverUrlKeys()) {
+ String value = properties.getOrDefault(key,
"").trim().toLowerCase(Locale.ROOT);
+ if (value.startsWith("http://") ||
value.startsWith("https://")) {
+ endpoints.put(key, -1);
+ }
+ }
+ }
+ // Validate every candidate on ALTER: a flavor/authentication change
can activate a stored address
+ // without modifying its key. Replays never enter this statement-time
path.
+ Map<String, List<HostAndPort>> parsedEndpoints = new LinkedHashMap<>();
+ for (Map.Entry<String, Integer> entry : endpoints.entrySet()) {
+ String key = entry.getKey();
+ String value = properties.get(key);
+ List<HostAndPort> destinations;
+ try {
+ destinations = new ArrayList<>();
+ for (String endpoint : surface.ssrfEndpointValues(key, value))
{
+ // A provider can derive destinations even when this raw
property is absent.
+ if (endpoint == null || endpoint.trim().isEmpty()) {
+ continue;
+ }
+ if (endpoint.contains("${")) {
+ throw new DdlException("Endpoint property '" + key +
"' must be literal under the SSRF policy; "
+ + "a placeholder can change its destination
after validation");
+ }
+ if (storageEndpoints.getOrDefault(key, -1) == 8020) {
+ for (String authority :
HdfsEndpointProperties.authorities(endpoint.trim(), properties)) {
+ destinations.add(parseAuthority(authority, 8020));
+ }
+ } else {
+ destinations.addAll(parseEndpoints(endpoint.trim(),
entry.getValue()));
+ }
+ }
+ } catch (IllegalArgumentException e) {
+ // Do not echo URLs: their authority or query can carry
credentials.
+ throw new DdlException("Cannot validate endpoint property '" +
key + "' of catalog '"
+ + catalogName + "' against the SSRF policy: use an
explicit network URI or host:port");
+ }
+ parsedEndpoints.put(key, destinations);
+ }
+ for (Map.Entry<String, List<HostAndPort>> entry :
parsedEndpoints.entrySet()) {
+ String key = entry.getKey();
+ for (HostAndPort destination : entry.getValue()) {
+ // A fail-only seam lets SQL regression tests exercise routing
without the optional SDK.
+ // It cannot bypass a real policy rejection or allow a
connection.
+ if (rejection != null &&
destination.getHost().equals(rejection.param("host", "127.0.0.1"))) {
+ throw new DdlException("Endpoint property '" + key + "' is
rejected by the SSRF policy");
+ }
+ checker.checkEndpointForSsrf(destination.getHost(),
destination.getPort());
+ }
+ }
+ }
+
+ /** Parses URI lists, multi-host authorities and scheme-less endpoints
without splitting URL path commas. */
+ public static List<HostAndPort> parseEndpoints(String value, int
defaultPort) {
+ String normalized = value.trim();
+ List<HostAndPort> result = parseUnnormalizedEndpoints(normalized,
defaultPort);
+ if (normalized.regionMatches(true, 0, "jdbc:", 0, 5) &&
normalized.contains(" ")) {
+ // Standalone JDBC strips spaces; Paimon and Iceberg pass the raw
URL to their drivers.
+ // Checking both interpretations prevents normalization from
hiding an active host override.
+ LinkedHashSet<HostAndPort> destinations = new
LinkedHashSet<>(result);
+
destinations.addAll(parseUnnormalizedEndpoints(normalized.replace(" ", ""),
defaultPort));
+ return new ArrayList<>(destinations);
+ }
+ return result;
+ }
+
+ private static List<HostAndPort> parseUnnormalizedEndpoints(String
normalized, int defaultPort) {
+ List<HostAndPort> result = new ArrayList<>();
+ // JDBC-specific parameters and Oracle descriptors are not ordinary
URI authorities.
+ if (normalized.regionMatches(true, 0, "jdbc:mysql:", 0, 11)
+ || normalized.regionMatches(true, 0, "jdbc:mysql+srv:", 0,
15)) {
+ return JdbcEndpointParser.mysql(normalized);
+ }
+ if (normalized.startsWith("jdbc:postgresql:")) {
+ return JdbcEndpointParser.postgresql(normalized);
+ }
+ if (normalized.startsWith("jdbc:sqlserver://")) {
+ return JdbcEndpointParser.sqlServer(normalized);
+ }
+ if (normalized.startsWith("jdbc:oracle:thin:")) {
+ return JdbcEndpointParser.oracle(normalized);
+ }
+ if (normalized.startsWith("jdbc:clickhouse:") ||
normalized.startsWith("jdbc:ch:")) {
+ return JdbcEndpointParser.clickhouse(normalized);
+ }
+ if (normalized.startsWith("jdbc:trino:") ||
normalized.startsWith("jdbc:presto:")) {
+ return JdbcEndpointParser.trinoOrPresto(normalized);
+ }
+ if (normalized.startsWith("jdbc:db2:") ||
normalized.startsWith("jdbc:ibmdb:")
+ || normalized.startsWith("jdbc:ids:") ||
normalized.startsWith("jdbc:informix-sqli:")
+ || normalized.startsWith("jdbc:db2os390:") ||
normalized.startsWith("jdbc:db2os390sqlj:")) {
+ return JdbcEndpointParser.db2(normalized);
+ }
+ if (normalized.startsWith("postgresql://") ||
normalized.startsWith("postgres://")) {
+ validateNativePostgresql(normalized);
+ parseSingle(normalized, defaultPort, result);
+ return result;
+ }
+ if (normalized.startsWith("jdbc:")) {
Review Comment:
Fixed in `e2ceb1005b0e`.
OceanBase URLs now enter a dedicated admission parser before generic URI
handling. Enabled enforcement rejects SOCKS, custom socket factories,
pipes/local sockets/shared memory, OB proxy transport and HA/discovery forms
instead of ignoring their independent peers. Literal authorities follow the
pinned 2.4.8 contract: default 3306, query-port replacement even for explicit
authority ports, exact case-sensitive undecoded keys, first duplicates, literal
hash and asymmetric quote boundaries. Both raw and space-stripped consumer
interpretations are checked. Tests cover an initial quote that still exposes a
later proxy, quoted password data that does not, disabled policy, multiple
peers and IPv6.
The actual published 2.4.8 property/authority components passed 46 offline
assertions and 3 exact quote contracts without connections, DNS, listeners or
new threads. Final local verification passed: FE Checkstyle; 120 classes / 1705
tests (410 endpoint cases and all 40 SPI classes / 184 tests), zero
failures/errors/skips; both API signature baselines; forced FE build with 37
API42 manifests and eight class-byte matches; standard SQL with 87 CREATE + 50
ALTER rejections, seven positive CREATE admissions and one positive ALTER. The
separate upstream Google JSON suite passed 30 expected rejections and one valid
catalog. HTTP authentication and default masking were preserved, and the owned
runtime was stopped.. CREATE/ALTER SQL includes both ordinary and initial-quote
proxy configurations.
--
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]