| 1 |
# ==== Purpose ==== |
| 2 |
# |
| 3 |
# To Verify that Rows log event privilege check works with partial revokes. |
| 4 |
# |
| 5 |
# ==== Implementation ==== |
| 6 |
# |
| 7 |
# TC1. Execute INSERT with and without the necessary privileges by |
| 8 |
# means of partial revoke |
| 9 |
# ----------------------------------------------------------------- |
| 10 |
# 1) Create a table on master and insert a row |
| 11 |
# 2) On slave create an user 'u1' which will be used as a |
| 12 |
# PRIVILEGE_CHECKS_USER to apply events in the replication stream. |
| 13 |
# 3) Grant INSERT globally and partially revoke for current database. |
| 14 |
# 4) Start slave and expect an error as the user doesn't have INSERT privilege. |
| 15 |
# 5) Stop slave and grant INSERT privilege. |
| 16 |
# 6) Start slave again and this time there should not be any error. |
| 17 |
# 7) Revoke the privilege granted in step 4) |
| 18 |
# 8) Ensure table is the same on master and slave. |
| 19 |
# 9) Drop the table from master and slave. |
| 20 |
# |
| 21 |
# ==== References ==== |
| 22 |
# |
| 23 |
# WL#12966: Replication with Restricted Privileges |
| 24 |
# |
| 25 |
|
| 26 |
--source include/not_group_replication_plugin.inc |
| 27 |
--source include/have_binlog_format_row.inc |
| 28 |
--source include/skip_config_privilege_checks_user.inc |
| 29 |
--let $rpl_privilege_checks_user = 2:'u1'@'localhost' |
| 30 |
# Since $rpl_privilege_checks_user is instantiated the replication applier has |
| 31 |
# no privileges on the test database |
| 32 |
--let $RPL_PRIV_DB = test |
| 33 |
--let $rpl_skip_start_slave=1 |
| 34 |
--source include/master-slave.inc |
| 35 |
|
| 36 |
--echo # |
| 37 |
--echo # TC1. Execute INSERT with and without the necessary |
| 38 |
--echo # privileges |
| 39 |
--echo # -------------------------------------------------- |
| 40 |
--echo # |
| 41 |
|
| 42 |
# 1) Create a table on master and insert a row |
| 43 |
SET @@session.sql_log_bin = OFF; |
| 44 |
CREATE TABLE t(c INT); |
| 45 |
SET @@session.sql_log_bin = ON; |
| 46 |
INSERT INTO t VALUES(10); |
| 47 |
--source include/save_master_pos.inc |
| 48 |
|
| 49 |
# 2) On slave create an user 'u1' which will be used as a |
| 50 |
# PRIVILEGE_CHECKS_USER to apply events in the replication stream. |
| 51 |
--source include/rpl_connection_slave.inc |
| 52 |
--let $opt_partial_revokes = `SELECT @@partial_revokes` |
| 53 |
SET GLOBAL partial_revokes = ON; |
| 54 |
|
| 55 |
CALL mtr.add_suppression(".*command denied to user."); |
| 56 |
CALL mtr.add_suppression(".*The replica coordinator and worker threads are stopped.*"); |
| 57 |
CREATE TABLE t(c INT); |
| 58 |
|
| 59 |
# 3) Grant INSERT globally and partially revoke for current database. |
| 60 |
GRANT INSERT ON *.* TO 'u1'@'localhost'; |
| 61 |
--eval REVOKE INSERT ON $RPL_PRIV_DB.* FROM 'u1'@'localhost' |
| 62 |
SHOW GRANTS FOR 'u1'@'localhost'; |
| 63 |
|
| 64 |
# 4) Start slave and expect an error as the user doesn't have the privilege. |
| 65 |
START SLAVE; |
| 66 |
--let $slave_sql_errno= convert_error(ER_TABLEACCESS_DENIED_ERROR) |
| 67 |
--source include/wait_for_slave_sql_error.inc |
| 68 |
|
| 69 |
# 5) Stop slave and grant the privilege. |
| 70 |
STOP SLAVE; |
| 71 |
--eval GRANT INSERT ON $RPL_PRIV_DB.* TO 'u1'@'localhost' |
| 72 |
|
| 73 |
# 6) Start slave again and this time there should not be any error. |
| 74 |
START SLAVE; |
| 75 |
--source include/sync_slave_sql.inc |
| 76 |
|
| 77 |
# 7) Revoke the privilege granted in step 4) |
| 78 |
REVOKE INSERT ON *.* FROM 'u1'@'localhost'; |
| 79 |
|
| 80 |
# 8) Ensure table is the same on master and slave. |
| 81 |
--let $diff_tables = master:t, slave:t |
| 82 |
--source include/diff_tables.inc |
| 83 |
|
| 84 |
--disable_query_log |
| 85 |
--eval SET GLOBAL partial_revokes = $opt_partial_revokes |
| 86 |
--enable_query_log |
| 87 |
|
| 88 |
# 9) Drop the table from master and slave. |
| 89 |
DROP TABLE t; |
| 90 |
--source include/rpl_connection_master.inc |
| 91 |
SET @@session.sql_log_bin = OFF; |
| 92 |
DROP TABLE t; |
| 93 |
SET @@session.sql_log_bin = ON; |
| 94 |
|
| 95 |
--let $rpl_only_running_threads=1 |
| 96 |
--source include/rpl_end.inc |