关于权限管理中ROLE的疑问

这里有个例子,user1限定的host为10.1.48.44,它被GRANT的角色role2限定host为192.168.9.%,但是这里看role2的IP与user1不兼容,但是依然拥有了role2的权限,那么在ROLE上限定host的意义是什么?

[tidb@UAT-APP-TiDB06 ~]$ mysql -h10.1.48.42 -P4000 -uuser1 -p123456
Welcome to the MariaDB monitor. Commands end with ; or \g.
Your MySQL connection id is 27
Server version: 5.7.25-TiDB-v5.4.0 TiDB Server (Apache License 2.0) Community Edition, MySQL 5.7 compatible

Copyright © 2000, 2018, Oracle, MariaDB Corporation Ab and others.

Type ‘help;’ or ‘\h’ for help. Type ‘\c’ to clear the current input statement.

MySQL [(none)]> show grants for user1@‘10.1.48.44’;
±-----------------------------------------------------------------+
| Grants for user1@10.1.48.44 |
±-----------------------------------------------------------------+
| GRANT USAGE ON . TO ‘user1’@‘10.1.48.44’ |
| GRANT ‘role1’@’%’, ‘role2’@‘192.168.9.%’ TO ‘user1’@‘10.1.48.44’ |
±-----------------------------------------------------------------+
2 rows in set (0.00 sec)

MySQL [(none)]> select current_role();
±----------------------+
| current_role() |
±----------------------+
| role2@192.168.9.% |
±----------------------+
1 row in set (0.00 sec)

MySQL [(none)]> create database test2;
Query OK, 0 rows affected (0.14 sec)

MySQL [(none)]> set role none;
Query OK, 0 rows affected (0.00 sec)

MySQL [(none)]> create database test3;
ERROR 1044 (42000): Access denied for user ‘user1’@‘10.1.48.44’ to database ‘test3’

我有点好奇 role2 的 “host” 是如何产生的?

同问,怎么grant给role2的

CREATE ROLE role2@‘192.168.9.%’;

MySQL 也是一样的行为,但首先其实这样不是标准、正确的语法。大概率 TiDB 为了保持和 MySQL 的兼容性而类比了。追根究底还是直接去 MySQL 社区提个 issue 问问更好

1 个赞

此话题已在最后回复的 1 分钟后被自动关闭。不再允许新回复。