Skip to content

Commit e6cf9d1

Browse files
authored
refactor: only set global settings need to check super privilege (#17255)
query setting, session setting, set variable will not check privileges
1 parent 00f4bd2 commit e6cf9d1

File tree

3 files changed

+41
-1
lines changed

3 files changed

+41
-1
lines changed

src/query/service/src/interpreters/access/privilege_access.rs

Lines changed: 15 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1151,7 +1151,21 @@ impl AccessChecker for PrivilegeAccess {
11511151
self.validate_access(&GrantObject::Global, UserPrivilegeType::Grant,false, false)
11521152
.await?;
11531153
}
1154-
Plan::Set(_) | Plan::Unset(_) | Plan::Kill(_) | Plan::SetPriority(_) | Plan::System(_) => {
1154+
Plan::Set(plan) => {
1155+
use databend_common_ast::ast::SetType;
1156+
if let SetType::SettingsGlobal = plan.set_type {
1157+
self.validate_access(&GrantObject::Global, UserPrivilegeType::Super, false, false)
1158+
.await?;
1159+
}
1160+
}
1161+
Plan::Unset(plan) => {
1162+
use databend_common_ast::ast::SetType;
1163+
if let SetType::SettingsGlobal = plan.unset_type {
1164+
self.validate_access(&GrantObject::Global, UserPrivilegeType::Super, false, false)
1165+
.await?;
1166+
}
1167+
}
1168+
Plan::Kill(_) | Plan::SetPriority(_) | Plan::System(_) => {
11551169
self.validate_access(&GrantObject::Global, UserPrivilegeType::Super, false, false)
11561170
.await?;
11571171
}

tests/suites/0_stateless/18_rbac/18_0007_privilege_access.result

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -142,3 +142,9 @@ OWNERSHIP default.default.t2 USER b GRANT OWNERSHIP ON 'default'.'default'.'t2'
142142
1
143143
2
144144
3
145+
=== set privilege check ===
146+
100
147+
100
148+
1
149+
1
150+
=== set privilege check succ ===

tests/suites/0_stateless/18_rbac/18_0007_privilege_access.sh

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -302,3 +302,23 @@ echo "drop table if exists t1" | $BENDSQL_CLIENT_CONNECT
302302
echo "drop table if exists t2" | $BENDSQL_CLIENT_CONNECT
303303
echo "drop stage if exists s3;" | $BENDSQL_CLIENT_CONNECT
304304
echo "drop database if exists db01" | $BENDSQL_CLIENT_CONNECT
305+
306+
echo "=== set privilege check ==="
307+
echo "drop user if exists c" | $BENDSQL_CLIENT_CONNECT
308+
echo "create user c identified by '123'" | $BENDSQL_CLIENT_CONNECT
309+
export USER_C_CONNECT="bendsql --user=c --password=123 --host=${QUERY_MYSQL_HANDLER_HOST} --port ${QUERY_HTTP_HANDLER_PORT}"
310+
echo "set session max_threads=1000" | $BENDSQL_CLIENT_CONNECT
311+
echo "unset session max_threads" | $BENDSQL_CLIENT_CONNECT
312+
echo "settings (ddl_column_type_nullable=0) select 100" | $BENDSQL_CLIENT_CONNECT
313+
echo "SET variable a = 'a';" | $BENDSQL_CLIENT_CONNECT
314+
echo "set global max_threads=1000" | $BENDSQL_CLIENT_CONNECT
315+
echo "unset global max_threads" | $BENDSQL_CLIENT_CONNECT
316+
317+
echo "set session max_threads=1000" | $USER_C_CONNECT
318+
echo "unset session max_threads" | $USER_C_CONNECT
319+
echo "settings (ddl_column_type_nullable=0) select 100" | $USER_C_CONNECT
320+
echo "SET variable a = 'a';" | $USER_C_CONNECT
321+
echo "set global max_threads=1000;" | $USER_C_CONNECT 2>&1 | grep "Super" | wc -l
322+
echo "unset global max_threads;" | $USER_C_CONNECT 2>&1 | grep "Super" | wc -l
323+
echo "drop user if exists c" | $BENDSQL_CLIENT_CONNECT
324+
echo "=== set privilege check succ ==="

0 commit comments

Comments
 (0)