Gabriel39 commented on code in PR #71205: URL: https://github.com/apache/doris/pull/71205#discussion_r4792367707
########## 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() { + // The admission decision consumes the point; callers may ask about availability more than once. + return SecurityChecker.getInstance().isEnabled() || DebugPointUtil.isEnableWithoutCounting(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, Review Comment: Fixed in dcd1c9c3312f9b619a2dbe84bb76b52554b80886. Shared storage projection now contributes the ordinary selected S3 and GCS endpoint before merging native OSS rewrites. Values under the same alias are combined, and the engine deduplicates only the final host/port set. Recording tests cover all four shared aliases, three endpoint forms, refusals of either client, and exactly one probe per distinct peer. SQL covers both the original S3/GCS peer and the rewritten OSS peer, with rejected ALTER retention under the same policy. The current head passed 2906 FE tests, strict FE Checkstyle, a fresh FE build, and both local SQL suites. Scope and verification limits are recorded in the PR description. ########## fe/fe-connector/fe-connector-fluss/src/main/java/org/apache/doris/connector/fluss/FlussConnectorProvider.java: ########## @@ -51,16 +56,112 @@ public Connector create(Map<String, String> properties, ConnectorContext context } /** - * The fluss client's SASL credentials, a small and stable set of keys, and the lake options under - * {@link FlussCatalogProperties#LAKE_OPTION_PREFIX}: those are open-ended (new paimon / filesystem + * The fluss client's SASL and direct gateway REST credentials use stable keys. Lake options under + * {@link FlussCatalogProperties#LAKE_OPTION_PREFIX} are open-ended (new paimon / filesystem * credential names may arrive without a Doris release), so a lake option is a secret when its name * carries a credential-like word, and endpoints and other operational settings stay visible. */ @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") + // Direct gateway REST options reach the sibling through a separate namespace on first lake access. + .withSsrfEndpointPrefixes("paimon.rest.") + .withSensitiveKeys("paimon.rest.token", "paimon.rest.dlf.access-key-id", + "paimon.rest.dlf.access-key-secret") + .withCommaSeparatedSsrfEndpoints(FlussCatalogProperties.BOOTSTRAP_SERVERS) + .withCommaSeparatedSsrfEndpoints(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); + // The storage sibling binds canonical names after translating Hadoop lake aliases. + Map<String, String> storage = LakeStorageOptions.toStorageProperties(lake); + // Connector storage is published as defaults: even a blank direct key remains authoritative. + storage.forEach(context::putIfAbsent); + // The sibling removes storage options; restoring their aliases could bypass a blank direct canonical key. + lake.forEach((key, value) -> { + if (!LakeStorageOptions.isStorageOption(key)) { + context.putIfAbsent(key, value); + } + }); + Map<String, String> effectiveLake = new HashMap<>(lake); + Map<String, String> storageOrigins = new HashMap<>(); + for (Map.Entry<String, String> entry : lake.entrySet()) { + LakeStorageOptions.toStorageProperties(Map.of(entry.getKey(), entry.getValue())) + .forEach((canonical, ignored) -> { + storageOrigins.put(canonical, FlussCatalogProperties.LAKE_OPTION_PREFIX + entry.getKey()); + if (properties.containsKey(canonical)) { + effectiveLake.remove(entry.getKey()); + } else { + effectiveLake.put(entry.getKey(), context.get(canonical)); + } + }); + } + 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(effectiveLake, key -> Review Comment: Fixed in dcd1c9c3312f9b619a2dbe84bb76b52554b80886. Fluss now obtains provider selection and default ports from the merged canonical storage map and maps the result back to the original lake option. A separate surface retains nonstorage sibling options, including an independent nested warehouse beside a direct gateway warehouse. Tests cover direct and nested S3 selection, HTTPS port 443, malformed-key diagnostics, and the independent HDFS peer. Two SQL CREATE/ALTER sequences exercise the translated bare endpoint and rejected-update retention. The current head passed 2906 FE tests, strict FE Checkstyle, a fresh FE build, and both local SQL suites. Scope and verification limits are recorded in the PR description. ########## fe/fe-connector/fe-connector-iceberg/src/main/java/org/apache/doris/connector/iceberg/IcebergConnectorProvider.java: ########## @@ -95,11 +102,215 @@ 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", + "dynamodb.endpoint", + "http-client.proxy-endpoint", "signer.uri") + // Native GCS overrides its storage service host independently of the catalog's REST URI. + .withSsrfEndpoints("gcs.service.host") + .withCommaSeparatedSsrfEndpoints("hive.metastore.uris", "metastore.thrift.uris") + .withSsrfEndpoints("glue.endpoint", "aws.endpoint", "aws.glue.endpoint") Review Comment: Fixed in dcd1c9c3312f9b619a2dbe84bb76b52554b80886. The three Glue aliases contribute metadata peers only when the Glue flavor is selected. Their storage interpretation is retained independently by shared admission, including the selected S3 HTTPS default on Hadoop/HMS. Six recording cases, two actual catalog-gate cases and six SQL CREATE/ALTER sequences cover these flavor/alias combinations. The active Glue holder and its validation are retained. The current head passed 2906 FE tests, strict FE Checkstyle, a fresh FE build, and both local SQL suites. Scope and verification limits are recorded in the PR description. ########## fe/fe-connector/fe-connector-iceberg/src/main/java/org/apache/doris/connector/iceberg/IcebergConnectorProvider.java: ########## @@ -95,11 +102,215 @@ 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", + "dynamodb.endpoint", + "http-client.proxy-endpoint", "signer.uri") + // Native GCS overrides its storage service host independently of the catalog's REST URI. + .withSsrfEndpoints("gcs.service.host") + .withCommaSeparatedSsrfEndpoints("hive.metastore.uris", "metastore.thrift.uris") + .withSsrfEndpoints("glue.endpoint", "aws.endpoint", "aws.glue.endpoint") + // DLF accepts bare hosts and uses HTTPS, including on its standalone HMS proxy path. .withSsrfEndpoints(443, "dlf.endpoint", "dlf.catalog.endpoint"); } + + @Override + public ConnectorSecuritySurface securitySurface(Map<String, String> properties) { + // Retired aliases and inactive proxy clients must not contribute unused metadata destinations. + ConnectorSecuritySurface surface = securitySurface() + .withSsrfEndpointValues("dlf.endpoint").withSsrfEndpointValues("dlf.catalog.endpoint"); + String flavor = properties.getOrDefault(IcebergCatalogProperties.ICEBERG_CATALOG_TYPE, + IcebergCatalogProperties.TYPE_HMS).trim(); + if (!IcebergCatalogProperties.TYPE_REST.equalsIgnoreCase(flavor)) { + // HMS siblings inherit raw options; a saved REST URI becomes a route only after selecting REST. + surface = surface.withSsrfEndpointValues("iceberg.rest.uri"); + } + Map<String, String> endpointProperties = new HashMap<>(properties); + for (String key : new String[] {"signer.endpoint", "rest.remote-signing.endpoint", + "client.refresh-credentials-endpoint", "iceberg.rest.oauth2.server-uri", "oauth2-server-uri", + "client.credentials-provider.oauth2-server-uri", "gcs.oauth2.refresh-credentials-endpoint"}) { + String value = properties.get(key); + if (value != null && key.equals("iceberg.rest.oauth2.server-uri")) { + // The canonical holder trims Strings before emitting the SDK OAuth option; raw aliases do not. + value = value.trim(); + } + // Iceberg appends signer, credential-refresh and OAuth paths (including GCS refresh) to a checked base. + // Only these lowercase absolute forms replace that base with an independent destination. + if (value != null && (value.startsWith("http://") || value.startsWith("https://"))) { Review Comment: Fixed in dcd1c9c3312f9b619a2dbe84bb76b52554b80886. The typed endpoint declaration and raw-SDK-alias replacement now use one eligibility result from the same factory predicate, with bound String values. Token-only and non-REST flavors keep the typed option dormant; activating client credentials checks the complete candidate. Unit tests cover ordinary and trim-empty credentials and other metastore flavors. The SQL mode cycle checks both directions and has an immediate successful benign update after each refused credential activation. Existing fixtures that intended an active typed OAuth endpoint now explicitly select client credentials; their assertions remain. The current head passed 2906 FE tests, strict FE Checkstyle, a fresh FE build, and both local SQL suites. Scope and verification limits are recorded in the PR description. -- 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]
