This is an automated email from the ASF dual-hosted git repository.

dataroaring pushed a commit to branch branch-3.0
in repository https://gitbox.apache.org/repos/asf/doris.git


The following commit(s) were added to refs/heads/branch-3.0 by this push:
     new e73c5bde214 branch-3.0: [fix](auth)fix check internal priv when drop 
db of external catalog (#47876)
e73c5bde214 is described below

commit e73c5bde214fd3ad12c24a594e35e50c9241a793
Author: zhangdong <[email protected]>
AuthorDate: Sat Mar 15 10:09:48 2025 +0800

    branch-3.0: [fix](auth)fix check internal priv when drop db of external 
catalog (#47876)
    
    ### What problem does this PR solve?
    fix check internal priv when drop db of external catalog
    
    It was not picked from the master because the master cannot use the old
    optimizer, so it is not fixed in the master
---
 .../java/org/apache/doris/analysis/DropDbStmt.java | 10 ++--
 .../test_ddl_database_external_auth.groovy         | 63 ++++++++++++++++++++++
 2 files changed, 67 insertions(+), 6 deletions(-)

diff --git a/fe/fe-core/src/main/java/org/apache/doris/analysis/DropDbStmt.java 
b/fe/fe-core/src/main/java/org/apache/doris/analysis/DropDbStmt.java
index 47fdfdce4e2..ac8aec8b5ed 100644
--- a/fe/fe-core/src/main/java/org/apache/doris/analysis/DropDbStmt.java
+++ b/fe/fe-core/src/main/java/org/apache/doris/analysis/DropDbStmt.java
@@ -24,7 +24,6 @@ import org.apache.doris.common.ErrorCode;
 import org.apache.doris.common.ErrorReport;
 import org.apache.doris.common.UserException;
 import org.apache.doris.common.util.InternalDatabaseUtil;
-import org.apache.doris.datasource.InternalCatalog;
 import org.apache.doris.mysql.privilege.PrivPredicate;
 import org.apache.doris.qe.ConnectContext;
 
@@ -74,13 +73,12 @@ public class DropDbStmt extends DdlStmt implements 
NotFallbackInParser {
             
ErrorReport.reportAnalysisException(ErrorCode.ERR_DBACCESS_DENIED_ERROR,
                     analyzer.getQualifiedUser(), dbName);
         }
-
+        String effectiveCatalog = StringUtils.isEmpty(ctlName) ? 
ConnectContext.get().getCurrentCatalog().getName()
+                : ctlName;
         if (!Env.getCurrentEnv().getAccessManager()
-                .checkDbPriv(ConnectContext.get(),
-                        StringUtils.isEmpty(ctlName) ? 
InternalCatalog.INTERNAL_CATALOG_NAME : ctlName, dbName,
-                        PrivPredicate.DROP)) {
+                .checkDbPriv(ConnectContext.get(), effectiveCatalog, dbName, 
PrivPredicate.DROP)) {
             
ErrorReport.reportAnalysisException(ErrorCode.ERR_DBACCESS_DENIED_ERROR,
-                    ConnectContext.get().getQualifiedUser(), dbName);
+                    ConnectContext.get().getQualifiedUser(), effectiveCatalog 
+ "." + dbName);
         }
     }
 
diff --git 
a/regression-test/suites/auth_call/test_ddl_database_external_auth.groovy 
b/regression-test/suites/auth_call/test_ddl_database_external_auth.groovy
new file mode 100644
index 00000000000..f21c48ea778
--- /dev/null
+++ b/regression-test/suites/auth_call/test_ddl_database_external_auth.groovy
@@ -0,0 +1,63 @@
+// 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.
+
+import org.junit.Assert;
+
+suite("test_ddl_database_external_auth","p0,auth_call,external,hive,external_docker,external_docker_hive")
 {
+    String enabled = context.config.otherConfigs.get("enableHiveTest")
+    if (enabled == null || !enabled.equalsIgnoreCase("true")) {
+        logger.info("diable Hive test.")
+        return;
+    }
+    String suiteName = "test_ddl_database_external_auth"
+    String hivePrefix = "hive3";
+    String hms_port = context.config.otherConfigs.get(hivePrefix + "HmsPort")
+    String catalog_name = "${suiteName}_catalog"
+    String externalEnvIp = context.config.otherConfigs.get("externalEnvIp")
+
+    sql """drop catalog if exists ${catalog_name}"""
+    sql """create catalog if not exists ${catalog_name} properties (
+        "type"="hms",
+        'hive.metastore.uris' = 'thrift://${externalEnvIp}:${hms_port}'
+    );"""
+
+
+    String user = "${suiteName}_user"
+    String pwd = 'C123_567p'
+    try_sql("DROP USER ${user}")
+    sql """CREATE USER '${user}' IDENTIFIED BY '${pwd}'"""
+    sql """grant drop_priv,create_priv on ${catalog_name}.*.* to ${user}"""
+    sql """grant select_priv on regression_test to ${user}"""
+    //cloud-mode
+    if (isCloudMode()) {
+        def clusters = sql " SHOW CLUSTERS; "
+        assertTrue(!clusters.isEmpty())
+        def validCluster = clusters[0][0]
+        sql """GRANT USAGE_PRIV ON CLUSTER `${validCluster}` TO ${user}""";
+    }
+
+    String dbName = "${suiteName}_db"
+    try_sql """drop database if exists ${catalog_name}.${dbName}"""
+
+    connect(user, "${pwd}", context.config.jdbcUrl) {
+        sql """switch ${catalog_name};"""
+        sql """create database ${dbName};"""
+        sql """drop database ${dbName};"""
+    }
+    sql """drop catalog if exists ${catalog_name}"""
+    try_sql("DROP USER ${user}")
+}


---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]

Reply via email to