Skip to content

REVOKE ALL fails on current user #23850

@morgo

Description

@morgo

Bug Report

This was discovered by running mysql-test against TiDB. A user should have permission to revoke privileges from themselves as long as they have CREATE USER granted.

This fails in TiDB because ALL is expanded into the all privileges mask + Grant priv.

It also fails in the case that the privilege check is met (u4).

1. Minimal reproduce step (Required)

CREATE USER u1;
GRANT ALL ON *.* TO u1;
CREATE USER u2;
GRANT SELECT ON *.* to u2;
CREATE USER u3;
GRANT SELECT, CREATE USER ON *.* to u3;
CREATE USER u4;
GRANT ALL ON *.* TO u4 WITH GRANT OPTION;

$ mysql -u u1 # should work

SHOW GRANTS;
REVOKE ALL ON *.* FROM CURRENT_USER();

$ mysql -u u2 # should fail

SHOW GRANTS;
REVOKE ALL ON *.* FROM CURRENT_USER();

$ mysql -u u3 # should work

SHOW GRANTS;
REVOKE ALL ON *.* FROM CURRENT_USER();

$ mysql -u u4 # should work

SHOW GRANTS;
REVOKE ALL ON *.* FROM CURRENT_USER();

2. What did you expect to see? (Required)

mysql [localhost:8022] {u1} ((none)) > REVOKE ALL ON *.* FROM CURRENT_USER();
Query OK, 0 rows affected (0.00 sec)
..
mysql [localhost:8022] {u2} ((none)) > REVOKE ALL ON *.* FROM u2;
ERROR 1227 (42000): Access denied; you need (at least one of) the CREATE USER privilege(s) for this operation
..
mysql [localhost:8022] {u3} ((none)) > REVOKE ALL ON *.* FROM CURRENT_USER();
Query OK, 0 rows affected (0.00 sec)
..
mysql [localhost:8022] {u4} ((none)) > REVOKE ALL ON *.* FROM CURRENT_USER();
Query OK, 0 rows affected (0.00 sec)

3. What did you see instead (Required)

mysql> revoke all on *.* from current_user();
ERROR 8121 (HY000): privilege check fail

mysql> revoke all on *.* from current_user();
ERROR 8121 (HY000): privilege check fail

mysql> revoke all on *.* from current_user();
ERROR 8121 (HY000): privilege check fail

mysql> revoke all on *.* from current_user();
ERROR 1105 (HY000): Unknown user: @

4. What is your TiDB version? (Required)

mysql> SELECT tidb_version()\G
*************************** 1. row ***************************
tidb_version(): Release Version: v4.0.0-beta.2-2561-g9c75cfa4e
Edition: Community
Git Commit Hash: 9c75cfa4e2bbb854ab90562ecec0409f84a989b0
Git Branch: master
UTC Build Time: 2021-04-02 18:50:29
GoVersion: go1.13
Race Enabled: false
TiKV Min Version: v3.0.0-60965b006877ca7234adaced7890d7b029ed1306
Check Table Before Drop: false
1 row in set (0.00 sec)

Metadata

Metadata

Assignees

Type

No type

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions