hello-stephen commented on code in PR #71414: URL: https://github.com/apache/doris/pull/71414#discussion_r4795849861
########## fe/fe-core/src/main/java/org/apache/doris/connector/CatalogEndpointSecurity.java: ########## @@ -0,0 +1,132 @@ +// 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.connector.spi.ConnectorSecuritySurface; + +import com.google.common.net.HostAndPort; +import okhttp3.HttpUrl; + +import java.net.MalformedURLException; +import java.net.URI; +import java.net.URISyntaxException; +import java.net.URL; +import java.util.LinkedHashSet; +import java.util.List; +import java.util.Map; +import java.util.Set; + +/** Standalone endpoint admission; callers supply the provider's effective, detached security surface. */ +public final class CatalogEndpointSecurity { + private CatalogEndpointSecurity() { + } + + /** + * Checks every active destination using the installed policy. This utility does not initialize a + * connector, mutate a catalog, interpret storage properties, or guard subsequent SDK requests. + */ + public static void validate(String catalogName, ConnectorSecuritySurface surface, Map<String, String> properties) + throws DdlException { + validate(catalogName, surface, properties, SecurityChecker.getInstance()); + } + + static void validate(String catalogName, ConnectorSecuritySurface surface, Map<String, String> properties, + SecurityChecker checker) throws DdlException { + if (!checker.isEnabled()) { + return; + } + Set<HostAndPort> destinations = new LinkedHashSet<>(); + for (String key : surface.ssrfEndpointKeys()) { + List<String> values = surface.ssrfEndpointValues(key, properties.get(key)); + // Projections already name individual destinations; list syntax belongs to the raw property only. + boolean splitRawValues = surface.isCommaSeparatedSsrfEndpoint(key) + && !surface.hasSsrfEndpointValueOverride(key); + for (String value : values) { + if (value.trim().isEmpty()) { + continue; + } + if (value.contains("${")) { + throw new DdlException("Endpoint property '" + key + "' must be literal under the SSRF policy"); + } + String[] endpoints = splitRawValues + ? value.split(",", -1) : new String[] {value}; + for (String endpoint : endpoints) { + try { + destinations.add(parseEndpoint(endpoint.trim(), Review Comment: [P3] Deduplicate DNS names case-insensitively If two aliases specify `catalog.example:9083` and `CATALOG.EXAMPLE:9083`, the URI parser preserves both spellings and `HostAndPort` compares the host strings case-sensitively. The same DNS destination is then probed twice in sequence, adding up to another five-second connect timeout. Normalize DNS name case in the deduplication key while preserving IPv6 scope identifiers, and cover mixed-case aliases in `duplicateDestinationsAreProbedOncePerValidation`. [Guava host equality](https://github.com/google/guava/blob/v33.2.1/guava/src/com/google/common/net/HostAndPort.java#L264-L279), [JDK hostname parsing](https://github.com/openjdk/jdk17u/blob/master/src/java.base/share/classes/java/net/URI.java#L3353-L3368). -- 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]
