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


##########
fe/fe-core/src/main/java/org/apache/doris/connector/CatalogEndpointSecurity.java:
##########
@@ -0,0 +1,211 @@
+// 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.DebugPointUtil;
+import org.apache.doris.common.util.DebugPointUtil.DebugPoint;
+import org.apache.doris.connector.spi.ConnectorSecuritySurface;
+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.util.ArrayList;
+import java.util.LinkedHashMap;
+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> endpoints = new 
LinkedHashMap<>(StorageEndpointProperties.endpoints(properties));
+        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);
+            if (value == null || value.trim().isEmpty()) {
+                continue;
+            }
+            if (value.contains("${")) {
+                throw new DdlException("Endpoint property '" + key + "' must 
be literal under the SSRF policy; "
+                        + "a placeholder can change its destination after 
validation");
+            }
+            List<HostAndPort> destinations;
+            try {
+                destinations = parseEndpoints(value.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) {
+        List<HostAndPort> result = new ArrayList<>();
+        String normalized = value.trim();
+        if (normalized.startsWith("jdbc:")) {

Review Comment:
   [P2] Parse the supported JDBC URL grammars before admission
   
   With the checker enabled, supported URLs such as 
`jdbc:sqlserver://allowed.example.com:1433;databaseName=db` and 
`jdbc:oracle:thin:@allowed.example.com:1521:ORCL` now fail admission even when 
their destinations are allowed. Removing `jdbc:` does not make them ordinary 
network URIs: the SQL Server parameters become part of the parsed port, and the 
Oracle thin form has no URI authority. Existing JDBC client tests and catalog 
regression suites use both formats. This blocks CREATE, lazy reconstruction, 
and unrelated ALTERs that revalidate the stored URL. Extract destinations using 
the supported JDBC grammars and add enabled-policy tests for these valid forms.



##########
fe/fe-connector/fe-connector-jdbc/src/main/java/org/apache/doris/connector/jdbc/JdbcConnectorProvider.java:
##########
@@ -56,6 +56,7 @@ public ConnectorSecuritySurface securitySurface() {
         // the engine's operator gate applies jdbc_driver_secure_path / the 
mandatory rule on CREATE + ALTER.
         // The engine masks passwords and complete JDBC connection URLs 
wherever it shows catalog properties.
         return ConnectorSecuritySurface.ofJdbcDriverUrls(null, "driver_url", 
"jdbc.driver_url")
-                .withSensitiveKeys(JdbcCatalogProperties.sensitiveKeys());
+                .withSensitiveKeys(JdbcCatalogProperties.sensitiveKeys())
+                .withSsrfEndpoints(JdbcCatalogProperties.JDBC_URL);

Review Comment:
   [P2] Declare the prefixed JDBC URL alias for admission
   
   `JdbcCatalogProperties.stripJdbcPrefix` accepts `jdbc.jdbc_url` as the same 
connection property as `jdbc_url`, but admission examines the raw map and this 
declaration includes only the latter. A prefixed-only CREATE or ALTER therefore 
never parses or probes the database destination, bypassing the new 
statement-time endpoint policy. The existing runtime JDBC URL sanitizer still 
runs; this finding concerns the missing admission check. Declare 
`jdbc.jdbc_url` too, or consistently canonicalize properties before admission, 
and test prefixed-only properties with a rejecting checker.



##########
fe/fe-core/src/main/java/org/apache/doris/connector/CatalogEndpointSecurity.java:
##########
@@ -0,0 +1,211 @@
+// 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.DebugPointUtil;
+import org.apache.doris.common.util.DebugPointUtil.DebugPoint;
+import org.apache.doris.connector.spi.ConnectorSecuritySurface;
+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.util.ArrayList;
+import java.util.LinkedHashMap;
+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> endpoints = new 
LinkedHashMap<>(StorageEndpointProperties.endpoints(properties));
+        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);
+            if (value == null || value.trim().isEmpty()) {
+                continue;
+            }
+            if (value.contains("${")) {
+                throw new DdlException("Endpoint property '" + key + "' must 
be literal under the SSRF policy; "
+                        + "a placeholder can change its destination after 
validation");
+            }
+            List<HostAndPort> destinations;
+            try {
+                destinations = parseEndpoints(value.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) {
+        List<HostAndPort> result = new ArrayList<>();
+        String normalized = value.trim();
+        if (normalized.startsWith("jdbc:")) {
+            normalized = normalized.substring(5);
+        }
+        for (String endpoint : 
normalized.split(",(?=\\s*[A-Za-z][A-Za-z0-9+.-]*://)", -1)) {

Review Comment:
   [P2] Parse Elasticsearch host lists using their consumer semantics
   
   For `hosts=https://allowed.example.com:9200/,127.0.0.1:9200`, this regex 
does not split before the bare second node. `parseSingle` sees only the first 
URI authority and treats the second destination as path text, so admission 
probes only `allowed.example.com`. `EsCatalogProperties` instead splits every 
comma, supplies both nodes to the REST client, and its retry loop can select 
the second one. With `test_connection=false`, CREATE can thus accept a 
destination that admission should reject; ALTER has the same gap. Runtime 
request hooks remain. Preserve the provider-specific list semantics without 
weakening path-comma handling for ordinary URLs.



##########
fe/fe-filesystem/fe-filesystem-api/src/main/java/org/apache/doris/filesystem/properties/StorageEndpointProperties.java:
##########
@@ -0,0 +1,61 @@
+// 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.Locale;
+import java.util.Map;
+
+/** Network endpoint aliases consumed by filesystem providers and their 
authentication clients. */
+public final class StorageEndpointProperties {
+    private StorageEndpointProperties() {
+    }
+
+    /** Shared aliases can reach different SDKs; require an explicit scheme or 
port instead of guessing it. */
+    public static Map<String, Integer> endpoints(Map<String, String> 
properties) {
+        Map<String, Integer> endpoints = new LinkedHashMap<>();
+        for (String key : new String[] {"s3.endpoint", "AWS_ENDPOINT", 
"endpoint", "ENDPOINT", "aws.endpoint",
+                "glue.endpoint", "aws.glue.endpoint", "oss.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"}) {

Review Comment:
   [P2] Preserve the host-only Azure OAuth account property
   
   `azure.oauth2_account_host` is a bare hostname, for example 
`myaccount.dfs.core.windows.net`, as used by `AzureFileSystemPropertiesTest`. 
Registering it with default port `-1` makes `parseAuthority` reject that valid 
value whenever the checker is enabled, blocking Azure OAuth catalogs and their 
reconstruction. The suggested scheme/port workaround is incompatible with the 
consumer: `AzureFileSystemProperties.toHadoopConfigurationMap` appends the raw 
value to account-specific Hadoop configuration keys. Derive its actual network 
endpoint/default without changing the stored hostname, and cover a valid Azure 
OAuth configuration in admission tests.



##########
fe/fe-connector/fe-connector-spi/src/main/java/org/apache/doris/connector/spi/ConnectorSecuritySurface.java:
##########
@@ -146,15 +159,65 @@ public ConnectorSecuritySurface 
withSensitiveKeyPrefix(String prefix, String...
         merged.add(new SensitiveKeyPrefix(prefix,
                 Collections.unmodifiableList(new 
ArrayList<>(Arrays.asList(markers)))));
         return new ConnectorSecuritySurface(ssrfEndpointKeys, 
jdbcDriverUrlKeys, jdbcDriverUrlFlavorKey,
-                sensitiveKeys, Collections.unmodifiableList(merged));
+                sensitiveKeys, Collections.unmodifiableList(merged), 
ssrfDefaultPorts, ssrfEndpointPrefixes);
     }
 
     /** Adds endpoint checks without dropping existing driver-url or 
secret-masking declarations. */
     public ConnectorSecuritySurface withSsrfEndpoints(String... keys) {
         Set<String> endpoints = new LinkedHashSet<>(ssrfEndpointKeys);
         endpoints.addAll(Arrays.asList(keys));
         return new ConnectorSecuritySurface(Collections.unmodifiableList(new 
ArrayList<>(endpoints)),
-                jdbcDriverUrlKeys, jdbcDriverUrlFlavorKey, sensitiveKeys, 
sensitiveKeyPrefixes);
+                jdbcDriverUrlKeys, jdbcDriverUrlFlavorKey, sensitiveKeys, 
sensitiveKeyPrefixes,
+                ssrfDefaultPorts, ssrfEndpointPrefixes);
+    }
+
+    /** Declares the port used by the client when these endpoint properties 
omit their scheme and port. */
+    public ConnectorSecuritySurface withSsrfEndpoints(int defaultPort, 
String... keys) {
+        if (defaultPort < 1 || defaultPort > 65535) {
+            throw new IllegalArgumentException("Invalid endpoint default 
port");
+        }
+        ConnectorSecuritySurface extended = withSsrfEndpoints(keys);
+        Map<String, Integer> ports = new LinkedHashMap<>(ssrfDefaultPorts);
+        for (String key : keys) {
+            ports.put(key, defaultPort);
+        }
+        return new ConnectorSecuritySurface(extended.ssrfEndpointKeys, 
jdbcDriverUrlKeys, jdbcDriverUrlFlavorKey,
+                sensitiveKeys, sensitiveKeyPrefixes, 
Collections.unmodifiableMap(ports), ssrfEndpointPrefixes);
+    }
+
+    /**
+     * Declares HTTP(S) URLs and endpoint-named options in an SDK's open-ended 
property namespace.
+     * An unknown scheme-less endpoint requires an explicit port rather than 
guessing the SDK's default;
+     * credentials and ordinary filesystem paths are not interpreted as hosts.
+     */
+    public ConnectorSecuritySurface withSsrfEndpointPrefixes(String... 
prefixes) {
+        Set<String> merged = new LinkedHashSet<>(ssrfEndpointPrefixes);
+        merged.addAll(Arrays.asList(prefixes));
+        return new ConnectorSecuritySurface(ssrfEndpointKeys, 
jdbcDriverUrlKeys, jdbcDriverUrlFlavorKey,
+                sensitiveKeys, sensitiveKeyPrefixes, ssrfDefaultPorts,
+                Collections.unmodifiableList(new ArrayList<>(merged)));
+    }
+
+    /** Includes URL-valued and endpoint-named SDK options whose names can 
evolve independently of Doris. */
+    public List<String> ssrfEndpointKeys(Map<String, String> properties) {
+        Set<String> keys = new LinkedHashSet<>(ssrfEndpointKeys);
+        properties.forEach((key, value) -> {
+            String normalized = value == null ? "" : 
value.trim().toLowerCase(Locale.ROOT);
+            String lowerKey = key.toLowerCase(Locale.ROOT);
+            boolean endpointName = lowerKey.endsWith(".uri") || 
lowerKey.endsWith(".url")
+                    || lowerKey.endsWith(".endpoint") || 
lowerKey.endsWith("-uri")
+                    || lowerKey.endsWith("-url") || 
lowerKey.endsWith("-endpoint");
+            if ((normalized.startsWith("http://";) || 
normalized.startsWith("https://";) || endpointName)

Review Comment:
   [P2] Exclude opaque credentials from inferred endpoint values
   
   This content heuristic also selects known passwords under the declared SDK 
prefix. For example, `trino.connection-password="https://"` is an opaque 
password passed unchanged by `TrinoCatalogProperties.deriveTrinoProperties`, 
but it now becomes an endpoint and fails URI parsing before any policy probe. 
Thus otherwise valid catalogs are rejected when the checker is enabled, even if 
every real destination is allowed. Preserve explicitly declared endpoint keys, 
including sensitive URLs, while excluding known opaque credential properties 
from fallback inference. Add a URL-shaped password case; the current 
`sdk.password=secret` test does not exercise it.



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