-
Notifications
You must be signed in to change notification settings - Fork 763
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
Add SHOW GRANTS [FOR xxx] statement #3366
Conversation
Thanks for the contribution! Please review the labels and make any necessary changes. |
This pull request is being automatically deployed with Vercel (learn more). 🔍 Inspect: https://vercel.com/databend/databend/HKoiinGdDE6vpyrRmWULdAhyWySH [Deployment for 8537e88 canceled] |
Codecov Report
@@ Coverage Diff @@
## main #3366 +/- ##
=====================================
- Coverage 61% 61% -1%
=====================================
Files 610 615 +5
Lines 34185 34256 +71
=====================================
+ Hits 20992 21007 +15
- Misses 13193 13249 +56
Continue to review full report at Codecov.
|
This pull request has merge conflicts that must be resolved before it can be merged. @flaneur2020 please rebase it 🙏 |
f7947d7
to
5d6ea2b
Compare
This pull request has merge conflicts that must be resolved before it can be merged. @flaneur2020 please rebase it 🙏 |
some test in mysql:
it seems mysql would not cleanup the orphan grants after deleting the database. |
fdc0e47
to
4064e77
Compare
4064e77
to
46b77dc
Compare
@@ -15,6 +15,8 @@ GRANT SELECT ON `db01`.'tb1' TO 'test-grant'@'localhost'; | |||
GRANT SELECT ON db01.tbnotexists TO 'test-grant'@'localhost'; -- {ErrorCode 25} | |||
GRANT SELECT ON dbnotexists.* TO 'test-grant'@'localhost'; -- {ErrorCode 3} | |||
|
|||
SHOW GRANTS FOR 'test-grant'@'localhost'; | |||
|
|||
REVOKE SELECT ON db01.* FROM 'test-grant'@'localhost'; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
It would be better to check the privileges again after REVOKE:
SHOW GRANTS FOR 'test-grant'@'localhost';
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
thank you, i've add two show grant statements after each revoke statement
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
After REVOKE SELECT ON db01.* FROM 'test-grant'@'localhost';
Seems like the grants result is not correct?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
after revoke SELECT ON db01.* FROM 'test-grant'@'localhost', the rest grants is
GRANT CREATE,SELECT,INSERT,SET ON 'default'.* TO 'test-grant'@'localhost'
GRANT SELECT ON 'db01'.'tb1' TO 'test-grant'@'localhost'
the privilege on 'db01'.'tb1' is not revoked by the statement REVOKE .. ON 'db01'.'*'
, the behaviour is counter-intuitive, but the same as mysql:
╰─$ mysql -uroot --port 3306 -hlocalhost --protocol=TCP
Welcome to the MySQL monitor. Commands end with ; or \g.
Your MySQL connection id is 2
Server version: 5.7.35 Homebrew
Copyright (c) 2000, 2021, Oracle and/or its affiliates.
Oracle is a registered trademark of Oracle Corporation and/or its
affiliates. Other names may be trademarks of their respective
owners.
Type 'help;' or '\h' for help. Type '\c' to clear the current input statement.
mysql> CREATE DATABASE IF NOT EXISTS `db01`;
Query OK, 1 row affected, 1 warning (0.01 sec)
mysql> CREATE TABLE IF NOT EXISTS `db01`.`tb1` (`id` NOT NULL);
Query OK, 0 rows affected, 1 warning (0.01 sec)
mysql> CREATE USER 'test-grant'@'localhost' IDENTIFIED BY 'password';
mysql> GRANT SELECT ON db01.* TO 'test-grant'@'localhost';
Query OK, 0 rows affected (0.00 sec)
mysql> GRANT SELECT ON db01.tb1 TO 'test-grant'@'localhost';
Query OK, 0 rows affected (0.00 sec)
mysql> show grants for 'test-grant'@'localhost';
+-------------------------------------------------------------+
| Grants for test-grant@localhost |
+-------------------------------------------------------------+
| GRANT USAGE ON *.* TO 'test-grant'@'localhost' |
| GRANT SELECT ON `dbnotexists`.* TO 'test-grant'@'localhost' |
| GRANT SELECT ON `db01`.* TO 'test-grant'@'localhost' |
| GRANT SELECT ON `db01`.`tb1` TO 'test-grant'@'localhost' |
+-------------------------------------------------------------+
4 rows in set (0.00 sec)
mysql> REVOKE SELECT ON db01.* FROM 'test-grant'@'localhost';
Query OK, 0 rows affected (0.00 sec)
mysql> show grants for 'test-grant'@'localhost';
+-------------------------------------------------------------+
| Grants for test-grant@localhost |
+-------------------------------------------------------------+
| GRANT USAGE ON *.* TO 'test-grant'@'localhost' |
| GRANT SELECT ON `dbnotexists`.* TO 'test-grant'@'localhost' |
| GRANT SELECT ON `db01`.`tb1` TO 'test-grant'@'localhost' |
+-------------------------------------------------------------+
3 rows in set (0.00 sec)
it seems grant & revoke statement matches the grant objects as key by key, but not taking the relationship between the grant objects into account. (db01.* does include db01.tb1, but revoking privileges on db01.* not revoking db01.tb1)
/lgtm |
I hereby agree to the terms of the CLA available at: https://databend.rs/policies/cla/
Summary
SHOW GRANTS [FOR xxx]
statementChangelog
Related Issues
Fixes #3262
Test Plan
Unit Tests
Stateless Tests