-
Notifications
You must be signed in to change notification settings - Fork 5.9k
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
Role-base User Created Non-retrievable View #24414
Comments
Bug verified by @crazycs520 |
Maybe another bug when I was trying to reproduce it: ... (##login as mobius-admin
|
I guess this bug is not just related to RBAC:
(##login as test2
|
@bb7133 It is related to RBAC. The reason you are still seeing this error is because of the Here is a testcase that can be completed in one session (no need to log back in): use test;
DROP TABLE IF EXISTS table1;
DROP VIEW IF EXISTS test_view, test_view2, test_view3;
DROP USER IF EXISTS 'mobius-admin';
DROP ROLE IF EXISTS 'ACL-mobius-admin';
create table table1(
col1 int,
col2 int,
col3 int
);
insert into table1 values (1,1,1),(2,2,2);
CREATE ROLE 'ACL-mobius-admin';
CREATE USER 'mobius-admin';
CREATE USER 'mobius-admin-no-role';
GRANT Select,Insert,Update,Delete,Create,Drop,Alter,Index,Create View,Show View ON test.* TO 'ACL-mobius-admin'@'%';
GRANT Select,Insert,Update,Delete,Create,Drop,Alter,Index,Create View,Show View ON test.* TO 'mobius-admin-no-role'@'%';
GRANT 'ACL-mobius-admin'@'%' to 'mobius-admin'@'%';
SET DEFAULT ROLE ALL TO 'mobius-admin';
CREATE ALGORITHM = UNDEFINED DEFINER = 'mobius-admin'@'127.0.0.1' SQL SECURITY DEFINER VIEW test_view (col1 , col2 , col3) AS SELECT * from table1;
CREATE ALGORITHM = UNDEFINED DEFINER = 'mobius-admin-no-role'@'127.0.0.1' SQL SECURITY DEFINER VIEW test_view2 (col1 , col2 , col3) AS SELECT * from table1;
CREATE VIEW test_view3 (col1 , col2 , col3) AS SELECT * from table1;
select * from test_view; # fails
select * from test_view2; # works
select * from test_view3; # works
|
This is a bug in the privilege manager code. The SQL Security definer calls tidb/privilege/privileges/privileges.go Lines 142 to 143 in 289dcfe
I verified outside of this example that the session is expected to preload default roles, and not the privilege manager. So the default roles need to be loaded in |
Please edit this comment or add a new comment to complete the following informationBug1. Root Cause Analysis (RCA) (optional)The privilege manager code did not correctly consider default roles in the API call 2. Symptom (optional)3. All Trigger Conditions (optional)4. Workaround (optional)Do not use roles, but regular privileges. 5. Affected versions[v4.0.1:v4.0.12], [v5.0.0:v5.0.1] 6. Fixed versionsmaster |
( AffectedVersions ) fields are empty. |
1 similar comment
( AffectedVersions ) fields are empty. |
Bug Report
Please answer these questions before submitting your issue. Thanks!
1. Minimal reproduce step (Required)
create table table1(
col1
int,col2
int,col3
int);
insert into table1 values (1,1,1),(2,2,2);
CREATE ROLE 'ACL-mobius-admin';
GRANT Select,Insert,Update,Delete,Create,Drop,Alter,Index,Create View,Show View ON test.* TO 'ACL-mobius-admin'@'%';
CREATE USER 'mobius-admin';
GRANT 'ACL-mobius-admin'@'%' to 'mobius-admin'@'%';
SET DEFAULT ROLE ALL TO 'mobius-admin';
##login as mobius-admin
mysql -h 127.0.0.1 -P 4000 -u mobius-admin
mysql> show databases;
+--------------------+
| Database |
+--------------------+
| INFORMATION_SCHEMA |
| test |
+--------------------+
2 rows in set (0.01 sec)
use test;
CREATE ALGORITHM = UNDEFINED DEFINER =
mobius-admin
@127.0.0.1
SQL SECURITY DEFINER VIEWtest_view
(col1
,col2
,col3
) AS SELECT * from table1;select * from test_view;
ERROR 1356 (HY000): View 'test.test_view' references invalid table(s) or column(s) or function(s) or definer/invoker of view lack rights to use them
2. What did you expect to see? (Required)
mysql> select * from test_view;
+------+------+------+
| col1 | col2 | col3 |
+------+------+------+
| 1 | 1 | 1 |
| 2 | 2 | 2 |
+------+------+------+
3. What did you see instead (Required)
mysql> select * from test_view;
ERROR 1356 (HY000): View 'test.test_view' references invalid table(s) or column(s) or function(s) or definer/invoker of view lack rights to use them
4. What is your TiDB version? (Required)
v4.0.12
The text was updated successfully, but these errors were encountered: