Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[fix](auth) fix use database stmt access unauthorized catalog #45720

Merged
merged 4 commits into from
Dec 26, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -80,12 +80,11 @@ public void analyze(Analyzer analyzer) throws AnalysisException, UserException {
if (Strings.isNullOrEmpty(database)) {
ErrorReport.reportAnalysisException(ErrorCode.ERR_NO_DB_ERROR);
}

String currentCatalogName = catalogName == null ? ConnectContext.get().getDefaultCatalog() : catalogName;
if (!Env.getCurrentEnv().getAccessManager()
.checkDbPriv(ConnectContext.get(), ConnectContext.get().getDefaultCatalog(), database,
PrivPredicate.SHOW)) {
ErrorReport.reportAnalysisException(ErrorCode.ERR_DBACCESS_DENIED_ERROR,
analyzer.getQualifiedUser(), database);
.checkDbPriv(ConnectContext.get(), currentCatalogName, database, PrivPredicate.SHOW)) {
ErrorReport.reportAnalysisException(ErrorCode.ERR_DBACCESS_DENIED_ERROR, analyzer.getQualifiedUser(),
database);
}
}

Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
-- This file is automatically generated. You should know what you did if you want to edit this
-- !sql --
internal

-- !sql --
internal

Original file line number Diff line number Diff line change
@@ -0,0 +1,76 @@
// 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.

suite("test_use_database_stmt", "p0,external,mysql,external_docker,external_docker_mysql") {
String enabled = context.config.otherConfigs.get("enableJdbcTest")
String externalEnvIp = context.config.otherConfigs.get("externalEnvIp")
String s3_endpoint = getS3Endpoint()
String bucket = getS3BucketName()
String driver_url = "https://${bucket}.${s3_endpoint}/regression/jdbc_driver/mysql-connector-java-8.0.25.jar"
if (enabled != null && enabled.equalsIgnoreCase("true")) {
String catalog_name = "use_db_nereids";
String internal_catalog = "internal";
String internal_db_name = "testdb";
String ex_db_name = "testdb";
String user = "kevin"
String pwd = "doris@123456"
String mysql_port = context.config.otherConfigs.get("mysql_57_port");
String[] tokens = context.config.jdbcUrl.split('/')
String url=tokens[0] + "//" + tokens[2] + "/" + "${internal_db_name}" + "?"

sql """drop catalog if exists ${catalog_name}; """
sql """drop database if exists ${internal_db_name};"""

sql """switch internal;"""
sql """create database ${internal_db_name};"""
sql """use ${internal_db_name};"""

sql """create catalog if not exists ${catalog_name} properties(
"type"="jdbc",
"user"="root",
"password"="123456",
"jdbc_url" = "jdbc:mysql://${externalEnvIp}:${mysql_port}/doris_test?useSSL=false",
"driver_url" = "${driver_url}",
"driver_class" = "com.mysql.cj.jdbc.Driver"
);"""

sql """CALL EXECUTE_STMT("${catalog_name}", "drop database if exists ${ex_db_name}");"""
sql """CALL EXECUTE_STMT("${catalog_name}", "create database if not exists ${ex_db_name}");"""
sql """switch ${internal_catalog};"""

try_sql("DROP USER ${user}")
sql """CREATE USER ${user}@'%' IDENTIFIED BY '${pwd}';"""
sql """GRANT SELECT_PRIV ON ${internal_catalog}.*.* TO '${user}'@'%';"""

connect(user, pwd, url) {
try {
sql """switch internal"""
sql """use ${internal_db_name}"""
qt_sql """select current_catalog()"""
sql """use ${catalog_name}.${ex_db_name}"""
exception"Access denied for user '${user}' to database '${ex_db_name}'";
} catch (Exception e) {
log.info(e.getMessage())
}
qt_sql """select current_catalog()"""
}
sql """switch ${internal_catalog}"""
sql """drop database if exists ${internal_db_name};"""
sql """CALL EXECUTE_STMT("${catalog_name}", "drop database if exists ${ex_db_name}");"""
sql """ drop catalog if exists ${catalog_name} ;"""
}
}
Loading