Gabriel39 commented on code in PR #71205:
URL: https://github.com/apache/doris/pull/71205#discussion_r4785464718


##########
fe/fe-connector/fe-connector-es/src/main/java/org/apache/doris/connector/es/EsConnectorProvider.java:
##########
@@ -61,6 +61,15 @@ public Connector create(Map<String, String> properties, 
ConnectorContext context
     /** The engine masks the sensitive properties (the password) wherever it 
shows catalog properties. */
     @Override
     public ConnectorSecuritySurface securitySurface() {
-        return 
ConnectorSecuritySurface.EMPTY.withSensitiveKeys(EsCatalogProperties.sensitiveKeys());
+        return 
ConnectorSecuritySurface.EMPTY.withSensitiveKeys(EsCatalogProperties.sensitiveKeys())
+                .withSsrfEndpoints(80, "hosts", "elasticsearch.hosts")
+                // ES splits every comma, including a bare node following a 
URI with a path.
+                .withCommaSeparatedSsrfEndpoints("hosts", 
"elasticsearch.hosts");
+    }
+
+    @Override
+    public ConnectorSecuritySurface securitySurface(Map<String, String> 
properties) {
+        return 
securitySurface().withSsrfEndpoints(EsCatalogProperties.of(properties).isHttpSslEnabled()
 ? 443 : 80,
+                "hosts", "elasticsearch.hosts");

Review Comment:
   Addressed in f28602a481e. The property-aware ES surface now uses the 
holder-selected canonical hosts list and clears only the retired alias 
projection. Comma splitting and effective SSL defaults remain explicit. 
Recording tests cover both default transports; SQL covers accepted 
CREATE/replacement and rejection of a forbidden canonical replacement.
   
   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-connector/fe-connector-iceberg/src/main/java/org/apache/doris/connector/iceberg/IcebergConnectorProvider.java:
##########
@@ -95,11 +99,149 @@ 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",

Review Comment:
   Addressed in f28602a481e. Iceberg and Paimon now select the first nonblank 
uri before their connector-specific JDBC alias before projecting database 
endpoints, supplied ports and TLS-store grammar. The inactive service alias is 
cleared without erasing its independent storage interpretation. Tests cover 
permitted selected URLs alongside forbidden retired URLs and retired 
MariaDB-only store grammar.
   
   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-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() {
+        return SecurityChecker.getInstance().isEnabled() || 
DebugPointUtil.isEnable(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,
+                    properties.get(key) == null ? List.of() : 
List.of(properties.get(key)));
+            appendEndpoints(catalogName, key, values, port, entry.getValue() 
== 8020, properties, parsedEndpoints);
+        }
+        Map<String, Integer> serviceKeys = new LinkedHashMap<>();
+        for (String key : surface.ssrfEndpointKeys(properties)) {
+            serviceKeys.put(key, surface.ssrfEndpointDefaultPort(key));
+        }
+        // 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://";)) {
+                    serviceKeys.put(key, -1);

Review Comment:
   Addressed in f28602a481e. Standalone JDBC now clears the inactive 
driver-download SSRF projection using its existing canonical-key presence rule, 
while preserving both driver artifact-policy declarations. A recording control 
covers an allowed local selected artifact and a forbidden retired remote alias. 
The analogous Paimon first-nonblank common/raw artifact alias case was also 
fixed and tested.
   
   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]

Reply via email to