This is an automated email from the ASF dual-hosted git repository. yiguolei pushed a commit to branch branch-2.1 in repository https://gitbox.apache.org/repos/asf/doris.git
The following commit(s) were added to refs/heads/branch-2.1 by this push: new fd97f4096be branch-2.1: [fix](auth)fix check internal priv when drop db of external catalog (#48644) fd97f4096be is described below commit fd97f4096be1eb327c89e03c1eb8e88924d47304 Author: zhangdong <zhangd...@selectdb.com> AuthorDate: Wed Mar 12 16:26:49 2025 +0800 branch-2.1: [fix](auth)fix check internal priv when drop db of external catalog (#48644) ### 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 | 9 ++-- .../auth_p0/test_ddl_database_external_auth.groovy | 63 ++++++++++++++++++++++ 2 files changed, 67 insertions(+), 5 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 a277f3a9ce5..66639062039 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; @@ -75,12 +74,12 @@ public class DropDbStmt extends DdlStmt { 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_p0/test_ddl_database_external_auth.groovy b/regression-test/suites/auth_p0/test_ddl_database_external_auth.groovy new file mode 100644 index 00000000000..f21c48ea778 --- /dev/null +++ b/regression-test/suites/auth_p0/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: commits-unsubscr...@doris.apache.org For additional commands, e-mail: commits-h...@doris.apache.org