Skip to content

Commit c099068

Browse files
author
Deepthi ES
committed
WL#10886 : Add/Extend mtr tests for Replication/GR for roles
This patch implements tests to: 1. Verify that ROLES are replicated successfully. 2. Verify that ROLES on replication users used in 'CHANGE MASTER TO' work as expected for RPL/GR. 3. Verify that Activating the role by 'ALTER USER' is successful on both master/slave and GR members. 4. Verify execution of GR/RPL commands is successful by the user when different privileges are granted by roles.
1 parent c055bb2 commit c099068

File tree

4 files changed

+373
-17
lines changed

4 files changed

+373
-17
lines changed

mysql-test/suite/rpl/r/rpl_roles.result

Lines changed: 45 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,7 @@ FROM_HOST FROM_USER TO_HOST TO_USER WITH_ADMIN_OPTION
1919
% r1 % r2 N
2020
% r2 localhost u1 N
2121
% r3 localhost u1 N
22+
[connection master]
2223
REVOKE r3 FROM u1@localhost;
2324
ALTER USER u1@localhost DEFAULT ROLE r1;
2425
include/sync_slave_sql_with_master.inc
@@ -29,6 +30,7 @@ SELECT * FROM mysql.role_edges;
2930
FROM_HOST FROM_USER TO_HOST TO_USER WITH_ADMIN_OPTION
3031
% r1 % r2 N
3132
% r2 localhost u1 N
33+
[connection master]
3234
ALTER USER u1@localhost DEFAULT ROLE NONE;
3335
include/sync_slave_sql_with_master.inc
3436
SELECT * FROM mysql.default_roles;
@@ -37,15 +39,52 @@ SELECT * FROM mysql.role_edges;
3739
FROM_HOST FROM_USER TO_HOST TO_USER WITH_ADMIN_OPTION
3840
% r1 % r2 N
3941
% r2 localhost u1 N
42+
[connection master]
4043
REVOKE r1 FROM r2;
4144
include/sync_slave_sql_with_master.inc
4245
SELECT * FROM mysql.default_roles;
4346
HOST USER DEFAULT_ROLE_HOST DEFAULT_ROLE_USER
4447
SELECT * FROM mysql.role_edges;
4548
FROM_HOST FROM_USER TO_HOST TO_USER WITH_ADMIN_OPTION
4649
% r2 localhost u1 N
50+
include/stop_slave.inc
51+
set sql_log_bin=0;
52+
call mtr.add_suppression(".*Slave I/O for channel '': Master command COM_REGISTER_SLAVE failed.*");
53+
call mtr.add_suppression(".*Slave I/O thread couldn't register on master");
54+
set sql_log_bin=1;
55+
[connection master]
56+
CREATE ROLE r4;
57+
GRANT REPLICATION SLAVE ON *.* TO r4;
58+
GRANT r4 to u1@localhost;
59+
SELECT * FROM mysql.default_roles;
60+
HOST USER DEFAULT_ROLE_HOST DEFAULT_ROLE_USER
61+
SELECT * FROM mysql.role_edges;
62+
FROM_HOST FROM_USER TO_HOST TO_USER WITH_ADMIN_OPTION
63+
% r2 localhost u1 N
64+
% r4 localhost u1 N
65+
[connection slave]
66+
CHANGE MASTER TO MASTER_USER='u1';
67+
Warnings:
68+
Note 1759 Sending passwords in plain text without SSL/TLS is extremely insecure.
69+
Note 1760 Storing MySQL user name or password information in the master info repository is not secure and is therefore not recommended. Please consider using the USER and PASSWORD connection options for START SLAVE; see the 'START SLAVE Syntax' in the MySQL Manual for more information.
70+
START SLAVE;
71+
include/wait_for_slave_io_error.inc [errno=1597]
72+
[connection master]
73+
ALTER USER u1@localhost DEFAULT ROLE ALL;
74+
SELECT * FROM mysql.default_roles;
75+
HOST USER DEFAULT_ROLE_HOST DEFAULT_ROLE_USER
76+
localhost u1 % r2
77+
localhost u1 % r4
78+
SELECT * FROM mysql.role_edges;
79+
FROM_HOST FROM_USER TO_HOST TO_USER WITH_ADMIN_OPTION
80+
% r2 localhost u1 N
81+
% r4 localhost u1 N
82+
[connection slave]
83+
START SLAVE IO_THREAD;
84+
include/wait_for_slave_io_to_start.inc
4785
# Cleanup Statement
48-
DROP ROLE r1, r2, r3;
86+
[connection master]
87+
DROP ROLE r1, r2, r3,r4;
4988
DROP USER u1@localhost;
5089
include/sync_slave_sql_with_master.inc
5190
SELECT * FROM mysql.default_roles;
@@ -64,6 +103,10 @@ slave-bin.000001 # Query # # use `test`; REVOKE r3 FROM u1@localhost
64103
slave-bin.000001 # Query # # use `test`; ALTER USER u1@localhost DEFAULT ROLE r1
65104
slave-bin.000001 # Query # # use `test`; ALTER USER u1@localhost DEFAULT ROLE NONE
66105
slave-bin.000001 # Query # # use `test`; REVOKE r1 FROM r2
67-
slave-bin.000001 # Query # # use `test`; DROP ROLE r1, r2, r3
106+
slave-bin.000001 # Query # # use `test`; CREATE ROLE r4
107+
slave-bin.000001 # Query # # use `test`; GRANT REPLICATION SLAVE ON *.* TO 'r4'@'%'
108+
slave-bin.000001 # Query # # use `test`; GRANT r4 to u1@localhost
109+
slave-bin.000001 # Query # # use `test`; ALTER USER u1@localhost DEFAULT ROLE ALL
110+
slave-bin.000001 # Query # # use `test`; DROP ROLE r1, r2, r3,r4
68111
slave-bin.000001 # Query # # use `test`; DROP USER u1@localhost
69112
include/rpl_end.inc

mysql-test/suite/rpl/t/rpl_roles.test

Lines changed: 47 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -6,11 +6,13 @@
66
# Creation: #
77
# 2016-08-26 prabprad Added this test as part of WL#988 Roles #
88
# #
9+
# WL#10886 : Add/Extend mtr tests for Replication/GR for roles #
10+
# This test was extended to verify starting of replication #
11+
# by using roles to grant privileges to user. #
912
######################################################################
1013

1114
--source include/master-slave.inc
1215
# Create roles, user and role hierarchy on master
13-
--connection master
1416
CREATE ROLE r1, r2, r3;
1517
CREATE USER u1@localhost;
1618
GRANT r1 TO r2;
@@ -25,40 +27,70 @@ ALTER USER u1@localhost DEFAULT ROLE ALL;
2527
# All the operations done in master will affect the
2628
# mysql.roles_edges and mysql.default_roles table only.
2729
# Hence only this table is checked on slave.
28-
--connection slave
2930
SELECT * FROM mysql.default_roles;
3031
SELECT * FROM mysql.role_edges;
31-
--connection master
32+
--source include/rpl_connection_master.inc
3233
REVOKE r3 FROM u1@localhost;
3334
ALTER USER u1@localhost DEFAULT ROLE r1;
3435
--source include/sync_slave_sql_with_master.inc
35-
--connection slave
3636
SELECT * FROM mysql.default_roles;
3737
SELECT * FROM mysql.role_edges;
38-
--connection master
38+
--source include/rpl_connection_master.inc
3939
ALTER USER u1@localhost DEFAULT ROLE NONE;
4040
--source include/sync_slave_sql_with_master.inc
41-
--connection slave
4241
SELECT * FROM mysql.default_roles;
4342
SELECT * FROM mysql.role_edges;
44-
--connection master
43+
--source include/rpl_connection_master.inc
4544
REVOKE r1 FROM r2;
4645
--source include/sync_slave_sql_with_master.inc
47-
--connection slave
4846
SELECT * FROM mysql.default_roles;
4947
SELECT * FROM mysql.role_edges;
5048

51-
--echo # Cleanup Statement
52-
--connection master
53-
DROP ROLE r1, r2, r3;
54-
DROP USER u1@localhost;
55-
--source include/sync_slave_sql_with_master.inc
49+
# Start replication by using roles to grant priviliges to user
50+
# STOP SLAVE
51+
--source include/stop_slave.inc
52+
set sql_log_bin=0;
53+
call mtr.add_suppression(".*Slave I/O for channel '': Master command COM_REGISTER_SLAVE failed.*");
54+
call mtr.add_suppression(".*Slave I/O thread couldn't register on master");
55+
set sql_log_bin=1;
56+
57+
# Create role,user on master for replication
58+
--source include/rpl_connection_master.inc
59+
CREATE ROLE r4;
60+
GRANT REPLICATION SLAVE ON *.* TO r4;
61+
GRANT r4 to u1@localhost;
5662
SELECT * FROM mysql.default_roles;
5763
SELECT * FROM mysql.role_edges;
58-
source include/show_binlog_events.inc;
59-
--source include/rpl_end.inc
6064

65+
--source include/rpl_connection_slave.inc
66+
CHANGE MASTER TO MASTER_USER='u1';
67+
START SLAVE;
68+
69+
# Wait until IO_THREAD is inactive
70+
--let $wait_condition=SELECT COUNT(*)=1 FROM performance_schema.replication_connection_status WHERE service_state='OFF'
71+
--source include/wait_condition_or_abort.inc
6172

73+
# Error ER_SLAVE_MASTER_COM_FAILURE as user 'u1' doesn't have REPLICATION SLAVE privilege
74+
--let $slave_io_errno=convert_error(ER_SLAVE_MASTER_COM_FAILURE)
75+
--source include/wait_for_slave_io_error.inc
76+
77+
# Enable role 'r4' for user 'u1'
78+
--source include/rpl_connection_master.inc
79+
ALTER USER u1@localhost DEFAULT ROLE ALL;
80+
SELECT * FROM mysql.default_roles;
81+
SELECT * FROM mysql.role_edges;
6282

83+
--source include/rpl_connection_slave.inc
84+
START SLAVE IO_THREAD;
85+
--source include/wait_for_slave_io_to_start.inc
6386

87+
--echo # Cleanup Statement
88+
--source include/rpl_connection_master.inc
89+
DROP ROLE r1, r2, r3,r4;
90+
DROP USER u1@localhost;
91+
--source include/sync_slave_sql_with_master.inc
92+
SELECT * FROM mysql.default_roles;
93+
SELECT * FROM mysql.role_edges;
94+
source include/show_binlog_events.inc;
6495

96+
--source include/rpl_end.inc
Lines changed: 88 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,88 @@
1+
include/group_replication.inc [rpl_server_count=2]
2+
Warnings:
3+
Note #### Sending passwords in plain text without SSL/TLS is extremely insecure.
4+
Note #### Storing MySQL user name or password information in the master info repository is not secure and is therefore not recommended. Please consider using the USER and PASSWORD connection options for START SLAVE; see the 'START SLAVE Syntax' in the MySQL Manual for more information.
5+
[connection server1]
6+
CREATE ROLE 'gr_user','gr_recovery_user';
7+
GRANT SYSTEM_VARIABLES_ADMIN ON *.* TO 'gr_user';
8+
GRANT REPLICATION SLAVE ON *.* TO 'gr_recovery_user';
9+
CREATE USER 'alpha' IDENTIFIED BY 'alpha';
10+
GRANT gr_user TO alpha;
11+
# Check that 'gr_user' role is assigned to 'alpha' user
12+
[connection alpha]
13+
ERROR 42000: Access denied; you need (at least one of) the SUPER or SYSTEM_VARIABLES_ADMIN privilege(s) for this operation
14+
SET GLOBAL group_replication_bootstrap_group= 1;
15+
ERROR 42000: Access denied; you need (at least one of) the SUPER or SYSTEM_VARIABLES_ADMIN privilege(s) for this operation
16+
START GROUP_REPLICATION;
17+
ERROR 42000: Access denied; you need (at least one of) the SUPER or GROUP_REPLICATION_ADMIN privilege(s) for this operation
18+
[connection server1]
19+
ALTER USER alpha DEFAULT ROLE 'gr_user';
20+
# Check that 'gr_user' role is enabled for 'alpha' user
21+
[connection alpha]
22+
SELECT CURRENT_ROLE();
23+
CURRENT_ROLE()
24+
`gr_user`@`%`
25+
SET GLOBAL group_replication_group_name= "GROUP_REPLICATION_GROUP_NAME";
26+
SET GLOBAL group_replication_bootstrap_group= 1;
27+
START GROUP_REPLICATION;
28+
ERROR 42000: Access denied; you need (at least one of) the SUPER or GROUP_REPLICATION_ADMIN privilege(s) for this operation
29+
[connection server1]
30+
GRANT GROUP_REPLICATION_ADMIN ON *.* TO 'gr_user';
31+
[connection alpha]
32+
START GROUP_REPLICATION;
33+
SET GLOBAL group_replication_bootstrap_group= 0;
34+
[connection server1]
35+
# Wait until server1 is ONLINE
36+
[connection server2]
37+
set sql_log_bin=0;
38+
call mtr.add_suppression(".*Slave I/O for channel 'group_replication_recovery': Master command COM_REGISTER_SLAVE failed.*");
39+
call mtr.add_suppression(".*Slave I/O thread couldn't register on master");
40+
set sql_log_bin=1;
41+
SET GLOBAL group_replication_group_name= "GROUP_REPLICATION_GROUP_NAME";
42+
CHANGE MASTER TO MASTER_USER='alpha', MASTER_PASSWORD='alpha' FOR CHANNEL 'group_replication_recovery';
43+
Warnings:
44+
Note 1759 Sending passwords in plain text without SSL/TLS is extremely insecure.
45+
Note 1760 Storing MySQL user name or password information in the master info repository is not secure and is therefore not recommended. Please consider using the USER and PASSWORD connection options for START SLAVE; see the 'START SLAVE Syntax' in the MySQL Manual for more information.
46+
START GROUP_REPLICATION;
47+
Pattern found.
48+
Pattern found.
49+
include/stop_group_replication.inc
50+
[connection server1]
51+
GRANT gr_recovery_user TO alpha;
52+
ALTER USER alpha DEFAULT ROLE ALL;
53+
# Check that all roles assigned to 'alpha' user are enabled
54+
SELECT DEFAULT_ROLE_USER FROM mysql.default_roles WHERE USER='alpha';
55+
DEFAULT_ROLE_USER
56+
gr_recovery_user
57+
gr_user
58+
SELECT FROM_USER FROM mysql.role_edges WHERE TO_USER='alpha';
59+
FROM_USER
60+
gr_recovery_user
61+
gr_user
62+
[connection alpha]
63+
SELECT CURRENT_ROLE();
64+
CURRENT_ROLE()
65+
`gr_recovery_user`@`%`,`gr_user`@`%`
66+
SHOW GRANTS;
67+
Grants for alpha@%
68+
GRANT REPLICATION SLAVE ON *.* TO `alpha`@`%`
69+
GRANT GROUP_REPLICATION_ADMIN,SYSTEM_VARIABLES_ADMIN ON *.* TO `alpha`@`%`
70+
GRANT `gr_recovery_user`@`%`,`gr_user`@`%` TO `alpha`@`%`
71+
CREATE DATABASE newtest;
72+
ERROR 42000: Access denied for user 'alpha'@'%' to database 'newtest'
73+
[connection server2]
74+
START GROUP_REPLICATION;
75+
GRANT ALL ON newtest.* TO gr_recovery_user;
76+
[connection alpha]
77+
CREATE DATABASE newtest;
78+
use newtest;
79+
CREATE TABLE t1(a INT PRIMARY KEY);
80+
INSERT INTO t1 VALUES (1),(2);
81+
UPDATE t1 SET a=4 WHERE a=1;
82+
DELETE FROM t1;
83+
[connection server2]
84+
DROP TABLE newtest.t1;
85+
DROP DATABASE newtest;
86+
DROP ROLE gr_user, gr_recovery_user;
87+
DROP USER alpha;
88+
include/group_replication_end.inc

0 commit comments

Comments
 (0)