Skip to content

Commit

Permalink
[enhance](auth)When authorization includes create, not check if resou…
Browse files Browse the repository at this point in the history
…rces exist (#45125)

### What problem does this PR solve?

Issue Number: close #xxx

Related PR: #39597 

Problem Summary:
When authorization includes create, not check if resources exist
  • Loading branch information
zddr committed Dec 19, 2024
1 parent 28f7573 commit a7a783f
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 3 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -583,7 +583,7 @@ private void grantInternal(UserIdentity userIdent, String role, TablePattern tbl
writeLock();
try {
if (!isReplay) {
checkTablePatternExist(tblPattern);
checkTablePatternExist(tblPattern, privs);
}
if (role == null) {
if (!doesUserExist(userIdent)) {
Expand All @@ -603,8 +603,12 @@ private void grantInternal(UserIdentity userIdent, String role, TablePattern tbl
}
}

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;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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}")
}

0 comments on commit a7a783f

Please sign in to comment.