| 1 |
# ==== Purpose ==== |
| 2 |
# |
| 3 |
# The purpose of this test script is to ensure that privilege checks are |
| 4 |
# enforced within the applier thread context and regarding the setting of the |
| 5 |
# `sql_require_primary_key` session variable. |
| 6 |
# |
| 7 |
# ==== Requirements ==== |
| 8 |
# |
| 9 |
# R1. In order to set `sql_require_primary_key` the applier security context |
| 10 |
# must have, at least, `SESSION_VARIABLES_ADMIN`. |
| 11 |
# R2. If the applier security context doesn't include, at least, |
| 12 |
# `SESSION_VARIABLES_ADMIN`, the applier thread must stop with an error. |
| 13 |
# |
| 14 |
# ==== Implementation ==== |
| 15 |
# |
| 16 |
# TC1. Run slave without `SESSION_VARIABLES_ADMIN` privilege |
| 17 |
# ---------------------------------------------------------- |
| 18 |
# 1) Setup `PRIVILEGE_CHECKS_USER` on slave. |
| 19 |
# 2) Ensure `sql_require_primary_key` is set on the master. |
| 20 |
# 3) Create a table on the master |
| 21 |
# 4) Wait for slave to catch-up and expect error. |
| 22 |
# |
| 23 |
# TC2. Run slave with `SESSION_VARIABLES_ADMIN` privilege |
| 24 |
# ------------------------------------------------------- |
| 25 |
# 1) Grant `SESSION_VARIABLES_ADMIN` to the applier security context. |
| 26 |
# 2) Wait for slave to catch-up and expect success. |
| 27 |
# |
| 28 |
# ==== References ==== |
| 29 |
# |
| 30 |
# WL#12966 Replication with Restricted Privileges |
| 31 |
# BUG#30254917 PRIVILEGE FOR `SQL_REQUIRE_PRIMARY_KEY` ARENT ENFORCED WITHIN |
| 32 |
# APPLIER CONTEXT |
| 33 |
# |
| 34 |
|
| 35 |
--source include/have_binlog_format_row.inc |
| 36 |
|
| 37 |
--echo # |
| 38 |
--echo # TC1. Run slave without `SESSION_VARIABLES_ADMIN` privilege |
| 39 |
--echo # ---------------------------------------------------------- |
| 40 |
|
| 41 |
# |
| 42 |
# 1) Setup `PRIVILEGE_CHECKS_USER` on slave. |
| 43 |
# |
| 44 |
--let $applier_user = 'u'@'localhost' |
| 45 |
--let $rpl_privilege_checks_user = *:$applier_user |
| 46 |
--let $rpl_skip_grant_privilege_checks_user_roles = 1 |
| 47 |
--let $rpl_skip_start_slave = 1 |
| 48 |
--source include/master-slave.inc |
| 49 |
|
| 50 |
--source include/rpl_connection_slave.inc |
| 51 |
--eval GRANT REPLICATION_APPLIER,CREATE,DROP ON *.* TO $applier_user |
| 52 |
CALL mtr.add_suppression(".*Access denied; you need .at least one of. the SUPER, SYSTEM_VARIABLES_ADMIN or SESSION_VARIABLES_ADMIN privilege.*"); |
| 53 |
CALL mtr.add_suppression(".*The replica coordinator and worker threads are stopped, possibly leaving data in inconsistent state.*"); |
| 54 |
|
| 55 |
# |
| 56 |
# 2) Ensure `sql_require_primary_key` is set on the master. |
| 57 |
# |
| 58 |
--source include/rpl_connection_master.inc |
| 59 |
--let $sql_require_primary_key = `SELECT @@global.sql_require_primary_key` |
| 60 |
SET @@global.sql_require_primary_key = 1; |
| 61 |
|
| 62 |
# |
| 63 |
# 3) Create a table on the master |
| 64 |
# |
| 65 |
CREATE TABLE t1 (c1 INT PRIMARY KEY); |
| 66 |
|
| 67 |
# |
| 68 |
# 4) Wait for slave to catch-up and expect error. |
| 69 |
# |
| 70 |
--source include/rpl_connection_slave.inc |
| 71 |
START SLAVE; |
| 72 |
|
| 73 |
--let $slave_sql_errno = convert_error(ER_SPECIFIC_ACCESS_DENIED_ERROR) |
| 74 |
--source include/wait_for_slave_sql_error.inc |
| 75 |
|
| 76 |
--echo # |
| 77 |
--echo # TC2. Run slave with `SESSION_VARIABLES_ADMIN` privilege |
| 78 |
--echo # ------------------------------------------------------- |
| 79 |
|
| 80 |
# |
| 81 |
# 1) Grant `SESSION_VARIABLES_ADMIN` to the applier security context. |
| 82 |
# |
| 83 |
STOP SLAVE; |
| 84 |
--eval GRANT SESSION_VARIABLES_ADMIN ON *.* TO $applier_user |
| 85 |
START SLAVE; |
| 86 |
|
| 87 |
# |
| 88 |
# 2) Wait for slave to catch-up and expect success. |
| 89 |
# |
| 90 |
--source include/rpl_connection_master.inc |
| 91 |
--source include/sync_slave_sql_with_master.inc |
| 92 |
|
| 93 |
# Clean up |
| 94 |
--source include/rpl_connection_master.inc |
| 95 |
--replace_result $sql_require_primary_key SQL_REQUIRE_PRIMARY_KEY |
| 96 |
--eval SET @@global.sql_require_primary_key = $sql_require_primary_key |
| 97 |
DROP TABLE t1; |
| 98 |
--source include/rpl_end.inc |