branch-2.1: [enhance](auth)When authorization includes create, not check if resources exist #45125 (#45166)

Cherry-picked from #45125

Co-authored-by: zhangdong <zhangdong@selectdb.com>
This commit is contained in:
github-actions[bot]
2024-12-11 14:57:46 +08:00
committed by GitHub
parent f83d98bb2e
commit e68460a730
2 changed files with 9 additions and 3 deletions

View File

@ -598,7 +598,7 @@ public class Auth implements Writable {
writeLock();
try {
if (!isReplay) {
checkTablePatternExist(tblPattern);
checkTablePatternExist(tblPattern, privs);
}
if (role == null) {
if (!doesUserExist(userIdent)) {
@ -618,8 +618,12 @@ public class Auth implements Writable {
}
}
private void checkTablePatternExist(TablePattern tablePattern) throws DdlException {
private void checkTablePatternExist(TablePattern tablePattern, PrivBitSet privs) throws DdlException {
Objects.requireNonNull(tablePattern, "tablePattern can not be null");
Objects.requireNonNull(privs, "privs can not be null");
if (privs.containsPrivs(Privilege.CREATE_PRIV)) {
return;
}
PrivLevel privLevel = tablePattern.getPrivLevel();
if (privLevel == PrivLevel.GLOBAL) {
return;

View File

@ -39,7 +39,9 @@ suite("test_grant_nonexist_table","p0,auth") {
sql """grant select_priv on internal.${dbName}.non_exist_table to ${user}"""
exception "table"
}
// contain create_triv should not check name, Same behavior as MySQL
sql """grant create_priv on internal.${dbName}.non_exist_table to ${user}"""
sql """grant create_priv,select_priv on internal.${dbName}.non_exist_table to ${user}"""
try_sql("DROP USER ${user}")
}