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

starocean999 pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/doris.git


The following commit(s) were added to refs/heads/master by this push:
     new 112a299e881 [fix](auth)Fixed an issue where the wrong catalog was used 
when checking permissions with use cluster  (#58084)
112a299e881 is described below

commit 112a299e881ad8de90b5a0c6b9c953e0b7dbcff7
Author: zhangdong <[email protected]>
AuthorDate: Thu Nov 20 18:22:20 2025 +0800

    [fix](auth)Fixed an issue where the wrong catalog was used when checking 
permissions with use cluster  (#58084)
    
    
    
    when
    
    switch catalog1;
    
    use `db1`@`group1`;
    
    check priv of internal.db1
    
    should check priv of catalog1.db1
---
 .../plans/commands/use/UseCloudClusterCommand.java | 12 +++---
 .../plans/commands/UseCloudClusterCommandTest.java | 43 ++++++++++++++++++++++
 2 files changed, 49 insertions(+), 6 deletions(-)

diff --git 
a/fe/fe-core/src/main/java/org/apache/doris/nereids/trees/plans/commands/use/UseCloudClusterCommand.java
 
b/fe/fe-core/src/main/java/org/apache/doris/nereids/trees/plans/commands/use/UseCloudClusterCommand.java
index 1ada7cbd007..c44e05c0f6d 100644
--- 
a/fe/fe-core/src/main/java/org/apache/doris/nereids/trees/plans/commands/use/UseCloudClusterCommand.java
+++ 
b/fe/fe-core/src/main/java/org/apache/doris/nereids/trees/plans/commands/use/UseCloudClusterCommand.java
@@ -28,7 +28,6 @@ import org.apache.doris.common.DdlException;
 import org.apache.doris.common.ErrorCode;
 import org.apache.doris.common.ErrorReport;
 import org.apache.doris.common.UserException;
-import org.apache.doris.datasource.InternalCatalog;
 import org.apache.doris.mysql.privilege.PrivPredicate;
 import org.apache.doris.nereids.trees.plans.PlanType;
 import org.apache.doris.nereids.trees.plans.commands.Command;
@@ -38,7 +37,6 @@ import org.apache.doris.qe.ConnectContext;
 import org.apache.doris.qe.StmtExecutor;
 
 import com.google.common.base.Strings;
-import org.apache.commons.lang3.StringUtils;
 
 /**
  * Representation of a use cluster statement.
@@ -107,15 +105,17 @@ public class UseCloudClusterCommand extends Command 
implements NoForward {
             return;
         }
         if (!Env.getCurrentEnv().getAccessManager()
-                .checkDbPriv(ConnectContext.get(),
-                StringUtils.isEmpty(catalogName) ? 
InternalCatalog.INTERNAL_CATALOG_NAME : catalogName,
-                database,
-                PrivPredicate.SHOW)) {
+                .checkDbPriv(ConnectContext.get(), getAuthCatalogName(), 
database,
+                        PrivPredicate.SHOW)) {
             
ErrorReport.reportAnalysisException(ErrorCode.ERR_DBACCESS_DENIED_ERROR,
                     ctx.getQualifiedUser(), database);
         }
     }
 
+    public String getAuthCatalogName() {
+        return catalogName == null ? ConnectContext.get().getDefaultCatalog() 
: catalogName;
+    }
+
     private void handleUseCloudClusterCommand(ConnectContext context) throws 
AnalysisException {
         if (!Config.isCloudMode()) {
             ErrorReport.reportAnalysisException(ErrorCode.ERR_NOT_CLOUD_MODE);
diff --git 
a/fe/fe-core/src/test/java/org/apache/doris/nereids/trees/plans/commands/UseCloudClusterCommandTest.java
 
b/fe/fe-core/src/test/java/org/apache/doris/nereids/trees/plans/commands/UseCloudClusterCommandTest.java
new file mode 100644
index 00000000000..15eb05bb6fc
--- /dev/null
+++ 
b/fe/fe-core/src/test/java/org/apache/doris/nereids/trees/plans/commands/UseCloudClusterCommandTest.java
@@ -0,0 +1,43 @@
+// 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.nereids.trees.plans.commands;
+
+import 
org.apache.doris.nereids.trees.plans.commands.use.UseCloudClusterCommand;
+import org.apache.doris.utframe.TestWithFeService;
+
+import org.junit.jupiter.api.Assertions;
+import org.junit.jupiter.api.Test;
+
+public class UseCloudClusterCommandTest extends TestWithFeService {
+    @Override
+    protected void runBeforeAll() throws Exception {
+        connectContext.changeDefaultCatalog("dummycatalog");
+    }
+
+    @Test
+    public void testNotSpecifyCatalog() {
+        UseCloudClusterCommand command = new UseCloudClusterCommand("c1", 
"db1");
+        Assertions.assertEquals("dummycatalog", command.getAuthCatalogName());
+    }
+
+    @Test
+    public void testSpecifyCatalog() {
+        UseCloudClusterCommand command = new UseCloudClusterCommand("c1", 
"db1", "ctl1");
+        Assertions.assertEquals("ctl1", command.getAuthCatalogName());
+    }
+}


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

Reply via email to