2013-10-18 21:21:10 +02:00
|
|
|
create user test_user@localhost;
|
2013-10-18 18:08:42 +02:00
|
|
|
create role test_role1;
|
|
|
|
create role test_role2;
|
2013-10-18 21:21:10 +02:00
|
|
|
grant test_role1 to test_user@localhost;
|
|
|
|
grant test_role2 to test_user@localhost;
|
2013-10-18 21:34:44 +02:00
|
|
|
grant test_role2 to test_role1;
|
2013-10-18 15:40:25 +02:00
|
|
|
select user, host from mysql.user where user not like 'root';
|
2018-11-24 14:13:41 +01:00
|
|
|
User Host
|
2020-02-19 17:50:30 +01:00
|
|
|
mariadb.sys localhost
|
2013-10-18 15:40:25 +02:00
|
|
|
test_role1
|
|
|
|
test_role2
|
|
|
|
test_user localhost
|
|
|
|
select * from mysql.roles_mapping;
|
2013-10-18 21:21:10 +02:00
|
|
|
Host User Role Admin_option
|
|
|
|
test_role1 test_role2 N
|
2013-10-18 21:27:07 +02:00
|
|
|
localhost root test_role1 Y
|
|
|
|
localhost root test_role2 Y
|
2013-10-18 21:21:10 +02:00
|
|
|
localhost test_user test_role1 N
|
|
|
|
localhost test_user test_role2 N
|
2013-10-18 15:40:25 +02:00
|
|
|
select user, host from mysql.db;
|
|
|
|
user host
|
2013-10-18 18:08:42 +02:00
|
|
|
grant select on mysql.* to test_role2;
|
2013-10-18 15:40:25 +02:00
|
|
|
flush privileges;
|
2013-10-18 18:15:55 +02:00
|
|
|
select * from information_schema.applicable_roles;
|
2015-02-09 16:16:55 +01:00
|
|
|
GRANTEE ROLE_NAME IS_GRANTABLE IS_DEFAULT
|
|
|
|
root@localhost test_role1 YES NO
|
|
|
|
root@localhost test_role2 YES NO
|
|
|
|
test_role1 test_role2 NO NULL
|
2013-10-18 18:15:55 +02:00
|
|
|
select * from information_schema.applicable_roles;
|
2015-02-09 16:16:55 +01:00
|
|
|
GRANTEE ROLE_NAME IS_GRANTABLE IS_DEFAULT
|
|
|
|
test_role1 test_role2 NO NULL
|
|
|
|
test_user@localhost test_role1 NO NO
|
|
|
|
test_user@localhost test_role2 NO NO
|
2013-10-18 15:40:25 +02:00
|
|
|
show grants;
|
|
|
|
Grants for test_user@localhost
|
2019-11-06 12:35:19 +01:00
|
|
|
GRANT USAGE ON *.* TO `test_user`@`localhost`
|
|
|
|
GRANT `test_role1` TO `test_user`@`localhost`
|
|
|
|
GRANT `test_role2` TO `test_user`@`localhost`
|
2013-10-18 15:55:26 +02:00
|
|
|
select current_user(), current_role();
|
|
|
|
current_user() current_role()
|
2013-10-18 18:09:08 +02:00
|
|
|
test_user@localhost NULL
|
2013-10-18 15:40:25 +02:00
|
|
|
set role test_role1;
|
2013-10-18 18:15:46 +02:00
|
|
|
select * from information_schema.enabled_roles;
|
|
|
|
ROLE_NAME
|
|
|
|
test_role1
|
2013-10-18 18:25:42 +02:00
|
|
|
test_role2
|
2013-10-18 15:55:26 +02:00
|
|
|
select current_user(), current_role();
|
|
|
|
current_user() current_role()
|
|
|
|
test_user@localhost test_role1
|
2013-10-18 15:40:25 +02:00
|
|
|
show grants;
|
|
|
|
Grants for test_user@localhost
|
2019-11-06 12:35:19 +01:00
|
|
|
GRANT SELECT ON `mysql`.* TO `test_role2`
|
|
|
|
GRANT USAGE ON *.* TO `test_role1`
|
|
|
|
GRANT USAGE ON *.* TO `test_role2`
|
|
|
|
GRANT USAGE ON *.* TO `test_user`@`localhost`
|
|
|
|
GRANT `test_role1` TO `test_user`@`localhost`
|
|
|
|
GRANT `test_role2` TO `test_role1`
|
|
|
|
GRANT `test_role2` TO `test_user`@`localhost`
|
2013-10-18 15:40:25 +02:00
|
|
|
set role none;
|
2013-10-18 18:15:46 +02:00
|
|
|
select * from information_schema.enabled_roles;
|
|
|
|
ROLE_NAME
|
|
|
|
NULL
|
2013-10-18 15:55:26 +02:00
|
|
|
select current_user(), current_role();
|
|
|
|
current_user() current_role()
|
2013-10-18 18:09:08 +02:00
|
|
|
test_user@localhost NULL
|
2013-10-18 15:40:25 +02:00
|
|
|
show grants;
|
|
|
|
Grants for test_user@localhost
|
2019-11-06 12:35:19 +01:00
|
|
|
GRANT USAGE ON *.* TO `test_user`@`localhost`
|
|
|
|
GRANT `test_role1` TO `test_user`@`localhost`
|
|
|
|
GRANT `test_role2` TO `test_user`@`localhost`
|
2013-10-18 15:40:25 +02:00
|
|
|
show grants for test_user@localhost;
|
2013-10-18 17:10:51 +02:00
|
|
|
Grants for test_user@localhost
|
2019-11-06 12:35:19 +01:00
|
|
|
GRANT USAGE ON *.* TO `test_user`@`localhost`
|
|
|
|
GRANT `test_role1` TO `test_user`@`localhost`
|
|
|
|
GRANT `test_role2` TO `test_user`@`localhost`
|
2013-10-18 15:40:25 +02:00
|
|
|
show grants for test_role1;
|
|
|
|
ERROR 42000: Access denied for user 'test_user'@'localhost' to database 'mysql'
|
|
|
|
show grants for test_role2;
|
|
|
|
ERROR 42000: Access denied for user 'test_user'@'localhost' to database 'mysql'
|
|
|
|
show grants for CURRENT_USER;
|
|
|
|
Grants for test_user@localhost
|
2019-11-06 12:35:19 +01:00
|
|
|
GRANT USAGE ON *.* TO `test_user`@`localhost`
|
|
|
|
GRANT `test_role1` TO `test_user`@`localhost`
|
|
|
|
GRANT `test_role2` TO `test_user`@`localhost`
|
2013-10-18 15:40:25 +02:00
|
|
|
show grants for CURRENT_USER();
|
|
|
|
Grants for test_user@localhost
|
2019-11-06 12:35:19 +01:00
|
|
|
GRANT USAGE ON *.* TO `test_user`@`localhost`
|
|
|
|
GRANT `test_role1` TO `test_user`@`localhost`
|
|
|
|
GRANT `test_role2` TO `test_user`@`localhost`
|
2013-10-18 15:40:25 +02:00
|
|
|
show grants for CURRENT_ROLE;
|
|
|
|
ERROR 42000: There is no such grant defined for user 'test_user' on host 'localhost'
|
|
|
|
show grants for CURRENT_ROLE();
|
|
|
|
ERROR 42000: There is no such grant defined for user 'test_user' on host 'localhost'
|
|
|
|
set role test_role2;
|
2013-10-18 18:15:46 +02:00
|
|
|
select * from information_schema.enabled_roles;
|
|
|
|
ROLE_NAME
|
|
|
|
test_role2
|
2013-10-18 15:55:26 +02:00
|
|
|
select current_user(), current_role();
|
|
|
|
current_user() current_role()
|
|
|
|
test_user@localhost test_role2
|
2013-10-18 15:40:25 +02:00
|
|
|
show grants;
|
|
|
|
Grants for test_user@localhost
|
2019-11-06 12:35:19 +01:00
|
|
|
GRANT SELECT ON `mysql`.* TO `test_role2`
|
|
|
|
GRANT USAGE ON *.* TO `test_role2`
|
|
|
|
GRANT USAGE ON *.* TO `test_user`@`localhost`
|
|
|
|
GRANT `test_role1` TO `test_user`@`localhost`
|
|
|
|
GRANT `test_role2` TO `test_user`@`localhost`
|
2013-10-18 15:40:25 +02:00
|
|
|
show grants for test_user@localhost;
|
|
|
|
Grants for test_user@localhost
|
2019-11-06 12:35:19 +01:00
|
|
|
GRANT USAGE ON *.* TO `test_user`@`localhost`
|
|
|
|
GRANT `test_role1` TO `test_user`@`localhost`
|
|
|
|
GRANT `test_role2` TO `test_user`@`localhost`
|
2013-10-18 15:40:25 +02:00
|
|
|
show grants for test_role1;
|
|
|
|
Grants for test_role1
|
2019-11-06 12:35:19 +01:00
|
|
|
GRANT SELECT ON `mysql`.* TO `test_role2`
|
|
|
|
GRANT USAGE ON *.* TO `test_role1`
|
|
|
|
GRANT USAGE ON *.* TO `test_role2`
|
|
|
|
GRANT `test_role2` TO `test_role1`
|
2013-10-18 15:40:25 +02:00
|
|
|
show grants for test_role2;
|
|
|
|
Grants for test_role2
|
2019-11-06 12:35:19 +01:00
|
|
|
GRANT SELECT ON `mysql`.* TO `test_role2`
|
|
|
|
GRANT USAGE ON *.* TO `test_role2`
|
2013-10-18 15:40:25 +02:00
|
|
|
show grants for CURRENT_USER;
|
|
|
|
Grants for test_user@localhost
|
2019-11-06 12:35:19 +01:00
|
|
|
GRANT USAGE ON *.* TO `test_user`@`localhost`
|
|
|
|
GRANT `test_role1` TO `test_user`@`localhost`
|
|
|
|
GRANT `test_role2` TO `test_user`@`localhost`
|
2013-10-18 15:40:25 +02:00
|
|
|
show grants for CURRENT_USER();
|
|
|
|
Grants for test_user@localhost
|
2019-11-06 12:35:19 +01:00
|
|
|
GRANT USAGE ON *.* TO `test_user`@`localhost`
|
|
|
|
GRANT `test_role1` TO `test_user`@`localhost`
|
|
|
|
GRANT `test_role2` TO `test_user`@`localhost`
|
2013-10-18 15:40:25 +02:00
|
|
|
show grants for CURRENT_ROLE;
|
|
|
|
Grants for test_role2
|
2019-11-06 12:35:19 +01:00
|
|
|
GRANT SELECT ON `mysql`.* TO `test_role2`
|
|
|
|
GRANT USAGE ON *.* TO `test_role2`
|
2013-10-18 15:40:25 +02:00
|
|
|
show grants for CURRENT_ROLE();
|
|
|
|
Grants for test_role2
|
2019-11-06 12:35:19 +01:00
|
|
|
GRANT SELECT ON `mysql`.* TO `test_role2`
|
|
|
|
GRANT USAGE ON *.* TO `test_role2`
|
2013-10-18 15:40:25 +02:00
|
|
|
drop user 'test_user'@'localhost';
|
2013-10-18 18:08:42 +02:00
|
|
|
revoke select on mysql.* from test_role2;
|
|
|
|
drop role test_role1;
|
|
|
|
drop role test_role2;
|
2013-10-18 21:19:37 +02:00
|
|
|
delete from mysql.roles_mapping where Role='test_role1';
|
|
|
|
delete from mysql.roles_mapping where Role='test_role2';
|
2013-10-18 15:40:25 +02:00
|
|
|
flush privileges;
|
2020-11-26 12:43:23 +01:00
|
|
|
#
|
|
|
|
# MDEV-24289: show grants missing with grant option
|
|
|
|
#
|
|
|
|
create role anel;
|
|
|
|
GRANT SELECT, UPDATE, DELETE, ALTER ON *.* TO 'anel';
|
|
|
|
SHOW GRANTS for 'anel';
|
|
|
|
Grants for anel
|
2020-12-01 13:55:46 +01:00
|
|
|
GRANT SELECT, UPDATE, DELETE, ALTER ON *.* TO `anel`
|
2020-11-26 12:43:23 +01:00
|
|
|
create role MariaDB_admin;
|
|
|
|
GRANT SELECT, UPDATE, DELETE, ALTER ON *.* TO 'MariaDB_admin' WITH GRANT OPTION;
|
|
|
|
SHOW GRANTS for 'MariaDB_admin';
|
|
|
|
Grants for MariaDB_admin
|
2020-12-01 13:55:46 +01:00
|
|
|
GRANT SELECT, UPDATE, DELETE, ALTER ON *.* TO `MariaDB_admin` WITH GRANT OPTION
|
2020-11-26 12:43:23 +01:00
|
|
|
drop role MariaDB_admin;
|
|
|
|
drop role anel;
|