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


##########
fe/fe-core/src/main/java/org/apache/doris/common/util/DatasourcePropertyRedactor.java:
##########
@@ -0,0 +1,208 @@
+// 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.common.util;
+
+import org.apache.doris.common.Config;
+
+import java.net.URI;
+import java.net.URISyntaxException;
+import java.net.URLDecoder;
+import java.nio.charset.StandardCharsets;
+import java.util.ArrayList;
+import java.util.List;
+import java.util.Locale;
+import java.util.Set;
+import java.util.regex.Pattern;
+
+/** Value-aware masking shared by catalog display, audit property rendering, 
and lineage metadata. */
+final class DatasourcePropertyRedactor {
+    private static final String MASK = DatasourcePrintableMap.PASSWORD_MASK;
+    // The bare URI alias is shared with REST catalogs, so its 
connection-string status depends on the value.
+    private static final Pattern CONNECTION_KEY = Pattern.compile(
+            
"(?i)(?:connection[._-]?string|(?:^|[._-])jdbc[._-]?(?:url|uri))$");
+    private static final Pattern NATIVE_CREDENTIAL = 
Pattern.compile("(?i)(?:^|[._-])(?:token|credentials?)$");
+    private static final Pattern HADOOP_CREDENTIAL = 
Pattern.compile("(?i)(?:^|\\.)fs\\.(?:"
+            + 
"s3a?\\.(?:bucket\\..+\\.)?(?:access\\.key|secret\\.key|session\\.token|"
+            + "(?:server-side-)?encryption\\.key|proxy\\.password)|"
+            + "azure\\.(?:account\\.key|sas(?:\\.fixed\\.token)?|"
+            + "account\\.oauth2\\.(?:client\\.secret|refresh\\.token)|"
+            + 
"encryption\\.encoded\\.client-provided\\.key)(?:\\..*)?|adl\\.oauth2\\.(?:credential|refresh\\.token)|"
+            + 
"oss\\.(?:accessKeyId|accessKeySecret|securityToken)|cosn\\.(?:userInfo\\.)?(?:secretId|secretKey)|"
+            + 
"obs\\.(?:access\\.key|secret\\.key|(?:session|security)\\.token))$");
+    private static final Pattern ADDRESS_KEY = Pattern.compile(
+            
"(?i)(?:^|[._-])(?:uris?|urls?|hosts?|endpoints?|addresses|address)$");
+    private static final Pattern URL_VALUE = 
Pattern.compile("^[a-zA-Z][a-zA-Z0-9+.-]*://");
+    private static final String HOST = "(?:[a-zA-Z0-9_][a-zA-Z0-9._-]*|"
+            + "\\[[a-fA-F0-9:.]+(?:%[a-zA-Z0-9_.~-]+)?\\])(?::[0-9]+)?";
+    private static final Pattern HOST_PATTERN = Pattern.compile(HOST);
+    private static final Set<String> URI_SCHEMES = Set.of("http", "https", 
"thrift", "hdfs", "s3", "s3a", "s3n",
+            "oss", "cos", "cosn", "obs", "gs", "abfs", "abfss", "wasb", 
"wasbs");
+    private static final Set<String> AZURE_STORAGE_SCHEMES = Set.of("abfs", 
"abfss", "wasb", "wasbs");
+    // Match AzureUri's container grammar, including its single-character 
compatibility form.
+    private static final Pattern AZURE_CONTAINER_NAME = 
Pattern.compile("[a-z0-9](?:[a-z0-9-]{1,61}[a-z0-9])?");
+    private static final Pattern QUERY_NAME = 
Pattern.compile("[a-zA-Z0-9_.~-]+");
+    private static final Pattern QUERY_CREDENTIAL = Pattern.compile(
+            
"(?i)password|passwd|pwd|secret|token|credential|access[._-]?key|api[._-]?key|"
+                    + "account[._-]?key|private[._-]?key|auth[._-]?key|"
+                    + "app(?:lication)?[._-]?key|authorization|^auth$|^key$");
+    private static final Pattern SIGNATURE = 
Pattern.compile("(?i)signature|(?:^|[._-])(?:sig|sas)(?:$|[._-])");
+    private static final Pattern ENCODED_ESCAPE = 
Pattern.compile("%[a-fA-F0-9]{2}");
+    private static volatile NamePattern namePattern = new 
NamePattern(Config.datasource_sensitive_property_pattern);
+
+    private DatasourcePropertyRedactor() {
+    }
+
+    static boolean isSensitiveName(String key) {
+        return CONNECTION_KEY.matcher(key).find()
+                || NATIVE_CREDENTIAL.matcher(key).find()
+                || HADOOP_CREDENTIAL.matcher(key).find() || 
configuredNamePattern().matcher(key).find();
+    }
+
+    private static Pattern configuredNamePattern() {
+        String configured = Config.datasource_sensitive_property_pattern;
+        NamePattern snapshot = namePattern;
+        if (!snapshot.source.equals(configured)) {
+            // Publish source and compiled pattern together; a concurrent 
update cannot pair different versions.
+            snapshot = new NamePattern(configured);
+            namePattern = snapshot;
+        }
+        return snapshot.pattern;
+    }
+
+    static String redact(Object key, Object value) {
+        if (DatasourcePrintableMap.isSensitiveKey(key)) {
+            return MASK;
+        }
+        String text = String.valueOf(value);
+        String address = text.trim();
+        // JDBC drivers accept incompatible credential syntaxes, including 
forms with no URI authority.
+        if (address.regionMatches(true, 0, "jdbc:", 0, 5)) {
+            return MASK;
+        }
+        if ((key instanceof String && ADDRESS_KEY.matcher((String) key).find())
+                || URL_VALUE.matcher(address).find()) {
+            return redactAddress(address);
+        }
+        return text;
+    }
+
+    private static String redactAddress(String address) {
+        if (address.isEmpty()) {
+            return address;
+        }
+        try {
+            if (!address.contains("://") && isPlainHosts(address)) {
+                return address;
+            }
+            // URI accepts a later URL as path text after the first host; SDKs 
may instead split the list.
+            if (address.indexOf(',') >= 0) {

Review Comment:
   Fixed in 48dfec45cdacaa7d3d0ec34f043b93b00f228819. The task now snapshots 
its selected singleton paths and sanitizes them independently before assembling 
the existing escaped batch syntax at final audit emission. Final success, 
failure and notification audit events retain the resolved files; one-file and 
multi-file cases are covered, including literal commas, braces, brackets, 
backslashes and spaces. Other TVF credentials and the current dynamic name 
policy still apply. Signed, unknown or nested connection values mask the entire 
batch; ordinary catalog/SQL URI lists receive no exemption. Execution inputs 
are unchanged.
   
   I also replaced the earlier incomplete test expectation that accepted hidden 
final URIs. The final local FE run passes all 553 tests in 47 classes, 
including actual audit-event publication and offset/event provider tests. FE 
Checkstyle and the full PR-range Gitleaks scan pass.



##########
fe/fe-core/src/main/java/org/apache/doris/common/util/DatasourcePropertyRedactor.java:
##########
@@ -0,0 +1,208 @@
+// 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.common.util;
+
+import org.apache.doris.common.Config;
+
+import java.net.URI;
+import java.net.URISyntaxException;
+import java.net.URLDecoder;
+import java.nio.charset.StandardCharsets;
+import java.util.ArrayList;
+import java.util.List;
+import java.util.Locale;
+import java.util.Set;
+import java.util.regex.Pattern;
+
+/** Value-aware masking shared by catalog display, audit property rendering, 
and lineage metadata. */
+final class DatasourcePropertyRedactor {
+    private static final String MASK = DatasourcePrintableMap.PASSWORD_MASK;
+    // The bare URI alias is shared with REST catalogs, so its 
connection-string status depends on the value.
+    private static final Pattern CONNECTION_KEY = Pattern.compile(
+            
"(?i)(?:connection[._-]?string|(?:^|[._-])jdbc[._-]?(?:url|uri))$");
+    private static final Pattern NATIVE_CREDENTIAL = 
Pattern.compile("(?i)(?:^|[._-])(?:token|credentials?)$");
+    private static final Pattern HADOOP_CREDENTIAL = 
Pattern.compile("(?i)(?:^|\\.)fs\\.(?:"
+            + 
"s3a?\\.(?:bucket\\..+\\.)?(?:access\\.key|secret\\.key|session\\.token|"
+            + "(?:server-side-)?encryption\\.key|proxy\\.password)|"
+            + "azure\\.(?:account\\.key|sas(?:\\.fixed\\.token)?|"
+            + "account\\.oauth2\\.(?:client\\.secret|refresh\\.token)|"
+            + 
"encryption\\.encoded\\.client-provided\\.key)(?:\\..*)?|adl\\.oauth2\\.(?:credential|refresh\\.token)|"
+            + 
"oss\\.(?:accessKeyId|accessKeySecret|securityToken)|cosn\\.(?:userInfo\\.)?(?:secretId|secretKey)|"
+            + 
"obs\\.(?:access\\.key|secret\\.key|(?:session|security)\\.token))$");
+    private static final Pattern ADDRESS_KEY = Pattern.compile(
+            
"(?i)(?:^|[._-])(?:uris?|urls?|hosts?|endpoints?|addresses|address)$");
+    private static final Pattern URL_VALUE = 
Pattern.compile("^[a-zA-Z][a-zA-Z0-9+.-]*://");
+    private static final String HOST = "(?:[a-zA-Z0-9_][a-zA-Z0-9._-]*|"
+            + "\\[[a-fA-F0-9:.]+(?:%[a-zA-Z0-9_.~-]+)?\\])(?::[0-9]+)?";
+    private static final Pattern HOST_PATTERN = Pattern.compile(HOST);
+    private static final Set<String> URI_SCHEMES = Set.of("http", "https", 
"thrift", "hdfs", "s3", "s3a", "s3n",
+            "oss", "cos", "cosn", "obs", "gs", "abfs", "abfss", "wasb", 
"wasbs");
+    private static final Set<String> AZURE_STORAGE_SCHEMES = Set.of("abfs", 
"abfss", "wasb", "wasbs");
+    // Match AzureUri's container grammar, including its single-character 
compatibility form.
+    private static final Pattern AZURE_CONTAINER_NAME = 
Pattern.compile("[a-z0-9](?:[a-z0-9-]{1,61}[a-z0-9])?");
+    private static final Pattern QUERY_NAME = 
Pattern.compile("[a-zA-Z0-9_.~-]+");
+    private static final Pattern QUERY_CREDENTIAL = Pattern.compile(
+            
"(?i)password|passwd|pwd|secret|token|credential|access[._-]?key|api[._-]?key|"
+                    + "account[._-]?key|private[._-]?key|auth[._-]?key|"
+                    + "app(?:lication)?[._-]?key|authorization|^auth$|^key$");
+    private static final Pattern SIGNATURE = 
Pattern.compile("(?i)signature|(?:^|[._-])(?:sig|sas)(?:$|[._-])");
+    private static final Pattern ENCODED_ESCAPE = 
Pattern.compile("%[a-fA-F0-9]{2}");
+    private static volatile NamePattern namePattern = new 
NamePattern(Config.datasource_sensitive_property_pattern);
+
+    private DatasourcePropertyRedactor() {
+    }
+
+    static boolean isSensitiveName(String key) {
+        return CONNECTION_KEY.matcher(key).find()
+                || NATIVE_CREDENTIAL.matcher(key).find()
+                || HADOOP_CREDENTIAL.matcher(key).find() || 
configuredNamePattern().matcher(key).find();
+    }
+
+    private static Pattern configuredNamePattern() {
+        String configured = Config.datasource_sensitive_property_pattern;
+        NamePattern snapshot = namePattern;
+        if (!snapshot.source.equals(configured)) {
+            // Publish source and compiled pattern together; a concurrent 
update cannot pair different versions.
+            snapshot = new NamePattern(configured);
+            namePattern = snapshot;
+        }
+        return snapshot.pattern;
+    }
+
+    static String redact(Object key, Object value) {
+        if (DatasourcePrintableMap.isSensitiveKey(key)) {
+            return MASK;
+        }
+        String text = String.valueOf(value);
+        String address = text.trim();
+        // JDBC drivers accept incompatible credential syntaxes, including 
forms with no URI authority.
+        if (address.regionMatches(true, 0, "jdbc:", 0, 5)) {
+            return MASK;
+        }
+        if ((key instanceof String && ADDRESS_KEY.matcher((String) key).find())

Review Comment:
   Fixed in 48dfec45cdacaa7d3d0ec34f043b93b00f228819. Recognized driver_url 
properties now retain unambiguous absolute local paths, and hierarchical 
file:/absolute/path and file:///absolute/path URIs are handled without 
requiring a host. Local file URIs require no authority and still use the shared 
query/signature/fragment rules. Sensitive-name and JDBC rules take precedence; 
ambiguous local connection syntax remains masked.
   
   Added positive and credential-bearing negative cases in property rendering, 
lineage and the SQL audit suite. The final FE run passes all 553 tests in 47 
classes, including existing ADBC property/resolver tests; FE Checkstyle passes. 
The cluster-backed SQL/ADBC regression suites were not executed locally.



##########
fe/fe-core/src/main/java/org/apache/doris/common/util/DatasourcePropertyRedactor.java:
##########
@@ -0,0 +1,208 @@
+// 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.common.util;
+
+import org.apache.doris.common.Config;
+
+import java.net.URI;
+import java.net.URISyntaxException;
+import java.net.URLDecoder;
+import java.nio.charset.StandardCharsets;
+import java.util.ArrayList;
+import java.util.List;
+import java.util.Locale;
+import java.util.Set;
+import java.util.regex.Pattern;
+
+/** Value-aware masking shared by catalog display, audit property rendering, 
and lineage metadata. */
+final class DatasourcePropertyRedactor {
+    private static final String MASK = DatasourcePrintableMap.PASSWORD_MASK;
+    // The bare URI alias is shared with REST catalogs, so its 
connection-string status depends on the value.
+    private static final Pattern CONNECTION_KEY = Pattern.compile(
+            
"(?i)(?:connection[._-]?string|(?:^|[._-])jdbc[._-]?(?:url|uri))$");
+    private static final Pattern NATIVE_CREDENTIAL = 
Pattern.compile("(?i)(?:^|[._-])(?:token|credentials?)$");
+    private static final Pattern HADOOP_CREDENTIAL = 
Pattern.compile("(?i)(?:^|\\.)fs\\.(?:"
+            + 
"s3a?\\.(?:bucket\\..+\\.)?(?:access\\.key|secret\\.key|session\\.token|"
+            + "(?:server-side-)?encryption\\.key|proxy\\.password)|"
+            + "azure\\.(?:account\\.key|sas(?:\\.fixed\\.token)?|"
+            + "account\\.oauth2\\.(?:client\\.secret|refresh\\.token)|"
+            + 
"encryption\\.encoded\\.client-provided\\.key)(?:\\..*)?|adl\\.oauth2\\.(?:credential|refresh\\.token)|"
+            + 
"oss\\.(?:accessKeyId|accessKeySecret|securityToken)|cosn\\.(?:userInfo\\.)?(?:secretId|secretKey)|"
+            + 
"obs\\.(?:access\\.key|secret\\.key|(?:session|security)\\.token))$");
+    private static final Pattern ADDRESS_KEY = Pattern.compile(
+            
"(?i)(?:^|[._-])(?:uris?|urls?|hosts?|endpoints?|addresses|address)$");
+    private static final Pattern URL_VALUE = 
Pattern.compile("^[a-zA-Z][a-zA-Z0-9+.-]*://");
+    private static final String HOST = "(?:[a-zA-Z0-9_][a-zA-Z0-9._-]*|"
+            + "\\[[a-fA-F0-9:.]+(?:%[a-zA-Z0-9_.~-]+)?\\])(?::[0-9]+)?";
+    private static final Pattern HOST_PATTERN = Pattern.compile(HOST);
+    private static final Set<String> URI_SCHEMES = Set.of("http", "https", 
"thrift", "hdfs", "s3", "s3a", "s3n",

Review Comment:
   Fixed in 48dfec45cdacaa7d3d0ec34f043b93b00f228819. ViewFS is now recognized 
under the HDFS address policy, preserving normal mount-table locations such as 
viewfs://example-cluster and their paths. Userinfo is removed, credential query 
parameters are masked, and signed or unreliable locations remain fully masked.
   
   Property and lineage tests cover safe locations and credential/signature 
boundaries; SHOW, catalogs() and persisted-audit assertions were added to the 
SQL suite. The final FE run passes all 553 tests in 47 classes and FE 
Checkstyle passes. The cluster-backed Hive/ViewFS SQL suite was not executed 
locally.



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