| 1 |
# ==== Purpose ==== |
| 2 |
# |
| 3 |
# This scripts verifies that when the replication applier has SET_USER_ID but no |
| 4 |
# SYSTEM_USER privileges it fails to SUID to a system user. |
| 5 |
# |
| 6 |
# ==== Requirements ==== |
| 7 |
# |
| 8 |
# R1. An account with no `SUPER` or `SYSTEM_USER` MUST NOT have the capability |
| 9 |
# of SUID to a `SYSTEM_USER` privileged account. |
| 10 |
# |
| 11 |
# ==== Implementation ==== |
| 12 |
# |
| 13 |
# 1) Setup up slave to use an applier security context and grant privilege |
| 14 |
# `SET_USER_ID`. |
| 15 |
# 2) On the master, create a user with privileges to create a procedure, named |
| 16 |
# 'u2'@'localhost'. |
| 17 |
# 3) On the slave, create a user with the same name - 'u2'@'localhost' - with no |
| 18 |
# system user privileges. |
| 19 |
# 4) On the master, create a procedure using 'u2'@'localhost'. |
| 20 |
# 5) Synchronize the slave with the master and expect success. |
| 21 |
# 6) Ensure the procedure exists on the slave. |
| 22 |
# 7) On the slave, grant `SYSTEM_USER` to 'u2'@'localhost'. |
| 23 |
# 8) On the master, create another procedure using 'u2'@'localhost'. |
| 24 |
# 9) Wait for slave to error out, without privileges. |
| 25 |
# |
| 26 |
# ==== References ==== |
| 27 |
# |
| 28 |
# BUG#30032129 ADD TEST THAT ERRORS IF APPLIER USER TRIES TO `SUID` TO A SYSTEM |
| 29 |
# USER ACCOUNT |
| 30 |
# |
| 31 |
--source include/have_binlog_format_row.inc |
| 32 |
--source include/skip_config_privilege_checks_user.inc |
| 33 |
|
| 34 |
--let $applier_user = 'u1'@'localhost' |
| 35 |
--let $system_user = 'u2'@'localhost' |
| 36 |
|
| 37 |
# |
| 38 |
# 1) Setup up slave to use an applier security context and grant privilege |
| 39 |
# `SET_USER_ID`. |
| 40 |
# |
| 41 |
--let $rpl_privilege_checks_user = *:$applier_user |
| 42 |
# Since $rpl_privilege_checks_user is instantiated the replication applier has |
| 43 |
# no privileges on the test database |
| 44 |
--let $RPL_PRIV_DB = test |
| 45 |
--let $rpl_privilege_checks_user_additional_grants = SET_USER_ID, CREATE ROUTINE, CREATE USER, ALTER ROUTINE |
| 46 |
--source include/master-slave.inc |
| 47 |
|
| 48 |
CALL mtr.add_suppression(".*Access denied. you need .at least one of. the SYSTEM_USER.*"); |
| 49 |
CALL mtr.add_suppression(".*The replica coordinator and worker threads are stopped.*"); |
| 50 |
|
| 51 |
# |
| 52 |
# 2) On the master, create a user with privileges to create a procedure, named |
| 53 |
# 'u2'@'localhost'. |
| 54 |
# |
| 55 |
SET sql_log_bin = 0; |
| 56 |
--eval CREATE USER $system_user |
| 57 |
--eval GRANT CREATE ROUTINE ON *.* TO $system_user |
| 58 |
SET sql_log_bin = 1; |
| 59 |
|
| 60 |
# |
| 61 |
# 3) On the slave, create a user with the same name - 'u2'@'localhost' - with no |
| 62 |
# outstanding privileges. |
| 63 |
# |
| 64 |
--source include/rpl_connection_slave.inc |
| 65 |
--eval CREATE USER $system_user |
| 66 |
|
| 67 |
# |
| 68 |
# 4) On the master, create a procedure using 'u2'@'localhost'. |
| 69 |
# |
| 70 |
--replace_result $MASTER_MYPORT MASTER_PORT |
| 71 |
--connect(sys_user_conn, localhost, u2,, $RPL_PRIV_DB, $MASTER_MYPORT) |
| 72 |
--connection sys_user_conn |
| 73 |
--delimiter @ |
| 74 |
CREATE PROCEDURE simpleproc1 (OUT param1 INT) |
| 75 |
BEGIN |
| 76 |
SELECT COUNT(*) INTO param1 FROM t; |
| 77 |
END@ |
| 78 |
--delimiter ; |
| 79 |
--source include/rpl_connection_master.inc |
| 80 |
|
| 81 |
# |
| 82 |
# 5) Synchronize the slave with the master and expect success. |
| 83 |
# |
| 84 |
--source include/sync_slave_sql_with_master.inc |
| 85 |
|
| 86 |
# |
| 87 |
# 6) Ensure the procedure exists on the slave. |
| 88 |
# |
| 89 |
--let $count = `SELECT COUNT(*) FROM information_schema.routines WHERE routine_name = "simpleproc1"` |
| 90 |
--let $assert_text = Procedure simpleproc1 does exist |
| 91 |
--let $assert_cond = $count = 1 |
| 92 |
--source include/assert.inc |
| 93 |
|
| 94 |
# |
| 95 |
# 7) On the slave, grant `SYSTEM_USER` to 'u2'@'localhost'. |
| 96 |
# |
| 97 |
--eval GRANT SYSTEM_USER ON *.* TO $system_user |
| 98 |
|
| 99 |
# |
| 100 |
# 8) On the master, create another procedure using 'u2'@'localhost'. |
| 101 |
# |
| 102 |
--connection sys_user_conn |
| 103 |
--delimiter @ |
| 104 |
CREATE PROCEDURE simpleproc2 (OUT param1 INT) |
| 105 |
BEGIN |
| 106 |
SELECT COUNT(*) INTO param1 FROM t; |
| 107 |
END@ |
| 108 |
--delimiter ; |
| 109 |
--disconnect sys_user_conn |
| 110 |
|
| 111 |
# |
| 112 |
# 9) Wait for slave to error out, without privileges. |
| 113 |
# |
| 114 |
--source include/rpl_connection_slave.inc |
| 115 |
--let $slave_sql_errno = convert_error(ER_SPECIFIC_ACCESS_DENIED_ERROR) |
| 116 |
--source include/wait_for_slave_sql_error.inc |
| 117 |
|
| 118 |
# Clean up |
| 119 |
--eval GRANT SYSTEM_USER ON *.* TO $applier_user |
| 120 |
--source include/start_slave.inc |
| 121 |
--source include/rpl_connection_master.inc |
| 122 |
DROP PROCEDURE simpleproc1; |
| 123 |
DROP PROCEDURE simpleproc2; |
| 124 |
--eval DROP USER $system_user |
| 125 |
--source include/rpl_end.inc |