hello-stephen commented on code in PR #71205:
URL: https://github.com/apache/doris/pull/71205#discussion_r4774764791
##########
fe/fe-connector/fe-connector-fluss/src/main/java/org/apache/doris/connector/fluss/FlussConnectorProvider.java:
##########
@@ -58,9 +63,56 @@ public Connector create(Map<String, String> properties,
ConnectorContext context
*/
@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")
+ .withSsrfEndpoints(FlussCatalogProperties.BOOTSTRAP_SERVERS)
+ .withSsrfEndpoints(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);
+ context.putAll(lake);
+ 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(lake, key ->
+ base.sensitiveKeyPrefixes().stream().anyMatch(prefix ->
+
prefix.covers(FlussCatalogProperties.LAKE_OPTION_PREFIX + key)));
+ for (Map.Entry<String, Integer> entry : endpoints.entrySet()) {
+ String key = entry.getKey();
+ String propertyKey = FlussCatalogProperties.LAKE_OPTION_PREFIX
+ key;
+ String value = lake.get(key);
+ List<String> values = entry.getValue() == 8020
+ ? HdfsEndpointProperties.authorities(value.trim(),
context).stream()
+ .map(authority -> "hdfs://" +
authority).collect(Collectors.toList())
+ : List.of(value);
+ if (entry.getValue() > 0) {
+ surface = surface.withSsrfEndpoints(entry.getValue(),
propertyKey);
+ }
+ surface = surface.withSsrfEndpointValues(propertyKey,
values.toArray(new String[0]));
+ }
+ lake.keySet().stream().filter(key ->
LakeStorageOptions.isStorageOption(key)
+ || endpoints.containsKey(key) ||
key.endsWith(".proxy.username"))
+ .forEach(key ->
inferredProperties.remove(FlussCatalogProperties.LAKE_OPTION_PREFIX + key));
+ } catch (IllegalArgumentException e) {
+ // Surface lookup also runs without a checker; let only enabled
admission reject unknown routes.
+ return
surface.withSsrfEndpointValues(FlussCatalogProperties.LAKE_OPTION_PREFIX +
"warehouse",
+ "unmodeled-lake-route:0");
+ }
+ // Do not rediscover opaque storage values or logical HA URIs through
the raw namespace rule.
+ ConnectorSecuritySurface inferred =
surface.withSsrfEndpointPrefixes(FlussCatalogProperties.LAKE_OPTION_PREFIX);
Review Comment:
[P2] Include direct gateway Paimon endpoints in Fluss admission
This inference considers only `fluss.lake.paimon.*`, but
`PaimonSiblingProperties.copyGatewayRestOptions` also accepts direct
`paimon.rest.*` settings;
`restOptionPrecedenceIsClusterThenGatewayThenCatalogOverride` explicitly tests
that path. A Fluss REST-lake catalog with an allowed bootstrap can therefore
ALTER direct `paimon.rest.uri` to `http://127.0.0.1:9000` successfully. Shared
storage inference does not select this key either. After publication/reset, the
next lake access copies the persisted URI into the Paimon sibling and fails its
endpoint check. CREATE with `test_connection=false` has the same omission.
Include effective direct gateway endpoints alongside the nested projection and
cover rejecting CREATE/ALTER cases. This is delayed validation, distinct from
the fixed nested-HDFS case; no runtime bypass is claimed.
##########
fe/fe-core/src/main/java/org/apache/doris/connector/CatalogEndpointSecurity.java:
##########
@@ -0,0 +1,306 @@
+// 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:oceanbase:")) {
+ return JdbcEndpointParser.oceanbase(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:")) {
+ normalized = normalized.substring(5);
+ }
+ for (String endpoint :
normalized.split(",(?=\\s*[A-Za-z][A-Za-z0-9+.-]*://)", -1)) {
+ parseSingle(endpoint.trim(), defaultPort, result);
Review Comment:
[P2] Check SAP HANA proxy routes before generic JDBC admission
With enforcement enabled,
`jdbc:sap://allowed.example.com:443/?proxyHTTP=true&proxyHostName=127.0.0.1&proxyPort=9000`
falls through here and probes only `allowed.example.com:443`. Doris explicitly
supports SAP HANA, `JdbcUrlNormalizer` preserves these parameters, and [SAP
documents this tuple as selecting the HTTP
proxy](https://help.sap.com/docs/r/f1b440ded6144a54ada97ff95dac7adf/2.24/en-US/12b563c177574742bcad6dfbff315364.html).
With a valid operator-installed driver, CREATE with `test_connection=false`
and ALTER therefore admit an independent literal peer without applying the
endpoint policy to it. Later sanitizer/runtime hooks are separate. Check the
effective HANA proxy destination or reject active unmodeled proxy routing under
enforcement, and add rejecting CREATE/ALTER cases with an allowed database
authority.
--
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]