Skip to content

Commit 5f555f1

Browse files
authored
fix(rbac): drop non-existent table (#34614)
1 parent 21bdfaf commit 5f555f1

File tree

2 files changed

+46
-1
lines changed

2 files changed

+46
-1
lines changed

source/libs/catalog/src/ctgUtil.c

Lines changed: 14 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2612,7 +2612,20 @@ int32_t ctgChkSetBasicAuthRes(SCatalog* pCtg, SCtgAuthReq* req, SCtgAuthRsp* res
26122612
case PRIV_CM_SHOW_CREATE: {
26132613
if (pReq->objType == PRIV_OBJ_TBL) {
26142614
// don't support tag condition
2615-
CTG_ERR_RET(ctgChkSetTbAuthRsp(pCtg, req, res));
2615+
code = ctgChkSetTbAuthRsp(pCtg, req, res);
2616+
if ((pReq->privType == PRIV_CM_DROP) && !pRes->pass[AUTH_RES_BASIC]) {
2617+
if (pReq->dbOwner) {
2618+
pRes->pass[AUTH_RES_BASIC] = true;
2619+
res->metaNotExists = false; // rewrite metaNotExists since drop tb privilege exists
2620+
return TSDB_CODE_SUCCESS;
2621+
}
2622+
CTG_ERR_RET(ctgChkSetCommonAuthRsp(pCtg, req, res));
2623+
if (pRes->pass[AUTH_RES_BASIC]) {
2624+
res->metaNotExists = false; // rewrite metaNotExists since drop tb privilege exists
2625+
return TSDB_CODE_SUCCESS;
2626+
}
2627+
}
2628+
CTG_ERR_RET(code);
26162629
} else {
26172630
if (pReq->dbOwner) {
26182631
pRes->pass[AUTH_RES_BASIC] = true;

test/cases/25-Privileges/test_priv_rbac.py

Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -79,6 +79,37 @@ def do_check_role_privileges(self):
7979
tdSql.execute(f"grant role `SYSINFO_1` to ur1")
8080
tdSql.execute(f"show users")
8181

82+
def do_check_6841225129(self):
83+
""" Test for drop not exist table """
84+
85+
tdSql.execute("drop database if exists d1")
86+
tdSql.execute("create database d1")
87+
tdSql.execute("use d1")
88+
tdSql.execute(f"create user u3 pass '{self.test_pass}'")
89+
tdSql.execute("drop table if exists d1.not_exist_table")
90+
tdSql.error("drop table d1.not_exist_table", expectErrInfo="Table does not exist", fullMatched=False)
91+
tdSql.connect("u3", self.test_pass)
92+
tdSql.error("drop table if exists d1.not_exist_table", expectErrInfo="Permission denied to use database", fullMatched=False)
93+
tdSql.error("drop table d1.not_exist_table", expectErrInfo="Permission denied to use database", fullMatched=False)
94+
tdSql.connect("root", "taosdata")
95+
tdSql.execute("grant use on database d1 to u3")
96+
tdSql.execute("grant drop on table d1.* to u3")
97+
tdSql.connect("u3", self.test_pass)
98+
tdSql.execute("drop table if exists d1.not_exist_table")
99+
tdSql.error("drop table d1.not_exist_table", expectErrInfo="Table does not exist", fullMatched=False)
100+
tdSql.connect("root", "taosdata")
101+
tdSql.execute("revoke drop on table d1.* from u3")
102+
tdSql.connect("u3", self.test_pass)
103+
time.sleep(5) # wait for privileges to take effect
104+
tdSql.error("drop table if exists d1.not_exist_table", expectErrInfo="Permission denied or target object not exist", fullMatched=False)
105+
tdSql.error("drop table d1.not_exist_table", expectErrInfo="Permission denied or target object not exist", fullMatched=False)
106+
tdSql.connect("root", "taosdata")
107+
tdSql.execute("grant create database to u3")
108+
tdSql.connect("u3", self.test_pass)
109+
tdSql.execute("create database d2")
110+
tdSql.execute("drop table if exists d2.not_exist_table")
111+
tdSql.error("drop table d2.not_exist_table", expectErrInfo="Table does not exist", fullMatched=False)
112+
82113
#
83114
# ------------------- main ----------------
84115
#
@@ -122,5 +153,6 @@ def test_priv_basic(self):
122153
# self.do_check_user_privileges()
123154
self.do_check_role_privileges()
124155
# self.do_check_variable_privileges()
156+
self.do_check_6841225129()
125157

126158
tdLog.debug("finish executing %s" % __file__)

0 commit comments

Comments
 (0)