Gabriel39 commented on code in PR #71414: URL: https://github.com/apache/doris/pull/71414#discussion_r4795753490
########## fe/fe-core/src/main/java/org/apache/doris/connector/CatalogEndpointSecurity.java: ########## @@ -0,0 +1,123 @@ +// 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)); + 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 = surface.isCommaSeparatedSsrfEndpoint(key) + ? value.split(",", -1) : new String[] {value}; + for (String endpoint : endpoints) { + try { + destinations.add(parseEndpoint(endpoint.trim(), + surface.ssrfEndpointDefaultPorts().getOrDefault(key, -1))); + } catch (IllegalArgumentException e) { + // Authorities and queries may contain credentials; do not retain the parser's cause. + throw new DdlException("Cannot validate endpoint property '" + key + "' of catalog '" + + catalogName + "' against the SSRF policy: use an explicit URI or host:port"); + } + } + } + } + // Resolve the complete declaration before probing, so malformed later values cannot be skipped. + for (HostAndPort destination : destinations) { + checker.checkEndpointForSsrf(destination.getHost(), destination.getPort()); + } + } + + private static HostAndPort parseEndpoint(String value, int defaultPort) { + try { + String host; + int port; + if (value.regionMatches(true, 0, "http://", 0, 7) + || value.regionMatches(true, 0, "https://", 0, 8)) { + HttpUrl target = HttpUrl.parse(value); + if (target == null) { + throw new IllegalArgumentException("Invalid HTTP destination"); + } + host = target.host(); + port = target.port(); + } else if (value.matches("[A-Za-z][A-Za-z0-9+.-]*://.*")) { + URI target = new URI(value); + host = target.getHost(); + port = target.getPort(); + } else if (defaultPort >= 0) { + URL raw = new URL("https://" + value); + HttpUrl target = HttpUrl.get(raw); + if (target == null) { + throw new IllegalArgumentException("Invalid destination authority"); + } + host = target.host(); + port = raw.getPort() < 0 ? defaultPort : raw.getPort(); + } else { + int slash = value.indexOf('/'); + HostAndPort target = HostAndPort.fromString(slash < 0 ? value : value.substring(0, slash)); Review Comment: Fixed in 8e588408ad4. Bare host:port values now pass strict local URI authority validation before any policy probe, and embedded userinfo, query, and fragment delimiters are rejected. Added six malformed-authority cases asserting zero probes and zero hook starts; localhost, IPv4, IPv6, and trailing-dot hosts remain covered. ########## fe/fe-core/src/main/java/org/apache/doris/connector/CatalogEndpointSecurity.java: ########## @@ -0,0 +1,123 @@ +// 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)); + 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 = surface.isCommaSeparatedSsrfEndpoint(key) Review Comment: Fixed in 8e588408ad4. The immutable surface now exposes whether a value is projected, and comma splitting applies only to raw list properties. Tests cover both builder orders, multiple projected URLs with commas, dormant projections, and rejection of empty raw list items. All 342 targeted FE and complete SPI cases pass, along with strict FE Checkstyle and the FE build. -- 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]
