Skip to content

Commit f8eab69

Browse files
committed
MDEV-21858: START/STOP ALL SLAVES does not return access errors
Check the user privileges and fail the command, even if there are no slaves that need starting respectively stopping. Signed-off-by: Kristian Nielsen <[email protected]>
1 parent 867b53c commit f8eab69

File tree

3 files changed

+73
-0
lines changed

3 files changed

+73
-0
lines changed

mysql-test/suite/multi_source/simple.result

Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -520,6 +520,34 @@ Slave_received_heartbeats 0
520520
Slave_heartbeat_period 60.000
521521
Gtid_Slave_Pos
522522
stop all slaves;
523+
#
524+
# MDEV-21858: START/STOP ALL SLAVES does not return access errors
525+
#
526+
connection slave;
527+
SET SESSION sql_log_bin=0;
528+
CREATE USER 'unpriv'@'127.0.0.1';
529+
GRANT USAGE ON *.* TO 'unpriv'@'127.0.0.1';
530+
connect con1,127.0.0.1,unpriv,,,$SERVER_MYPORT_3;
531+
STOP SLAVE 'slave2';
532+
ERROR 42000: Access denied; you need (at least one of) the REPLICATION SLAVE ADMIN privilege(s) for this operation
533+
START SLAVE 'slave2';
534+
ERROR 42000: Access denied; you need (at least one of) the REPLICATION SLAVE ADMIN privilege(s) for this operation
535+
STOP ALL SLAVES;
536+
ERROR 42000: Access denied; you need (at least one of) the REPLICATION SLAVE ADMIN privilege(s) for this operation
537+
connection slave;
538+
START SLAVE 'slave2';
539+
set default_master_connection = 'slave2';
540+
include/wait_for_slave_to_start.inc
541+
connection con1;
542+
START ALL SLAVES;
543+
ERROR 42000: Access denied; you need (at least one of) the REPLICATION SLAVE ADMIN privilege(s) for this operation
544+
disconnect con1;
545+
connection slave;
546+
STOP SLAVE 'slave2';
547+
set default_master_connection = 'slave2';
548+
include/wait_for_slave_to_stop.inc
549+
DROP USER 'unpriv'@'127.0.0.1';
550+
SET SESSION sql_log_bin=1;
523551
include/reset_master_slave.inc
524552
disconnect slave;
525553
connection master1;

mysql-test/suite/multi_source/simple.test

Lines changed: 38 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -84,6 +84,44 @@ query_vertical show all slaves status;
8484
# Ensure that start all slaves doesn't do anything as all slaves are stopped
8585
stop all slaves;
8686

87+
--echo #
88+
--echo # MDEV-21858: START/STOP ALL SLAVES does not return access errors
89+
--echo #
90+
--connection slave
91+
SET SESSION sql_log_bin=0;
92+
CREATE USER 'unpriv'@'127.0.0.1';
93+
GRANT USAGE ON *.* TO 'unpriv'@'127.0.0.1';
94+
95+
connect (con1,127.0.0.1,unpriv,,,$SERVER_MYPORT_3);
96+
97+
--error ER_SPECIFIC_ACCESS_DENIED_ERROR
98+
STOP SLAVE 'slave2';
99+
--error ER_SPECIFIC_ACCESS_DENIED_ERROR
100+
START SLAVE 'slave2';
101+
102+
# Test that STOP/START ALL SLAVES checks privileges, even if there are no
103+
# slaves that need stopping or starting.
104+
--error ER_SPECIFIC_ACCESS_DENIED_ERROR
105+
STOP ALL SLAVES;
106+
107+
--connection slave
108+
START SLAVE 'slave2';
109+
set default_master_connection = 'slave2';
110+
--source include/wait_for_slave_to_start.inc
111+
112+
--connection con1
113+
--error ER_SPECIFIC_ACCESS_DENIED_ERROR
114+
START ALL SLAVES;
115+
--disconnect con1
116+
117+
--connection slave
118+
STOP SLAVE 'slave2';
119+
set default_master_connection = 'slave2';
120+
--source include/wait_for_slave_to_stop.inc
121+
122+
DROP USER 'unpriv'@'127.0.0.1';
123+
SET SESSION sql_log_bin=1;
124+
87125
#
88126
# clean up
89127
#

sql/rpl_mi.cc

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,7 @@
2121
#include "slave.h"
2222
#include "strfunc.h"
2323
#include "sql_repl.h"
24+
#include "sql_acl.h"
2425

2526
#ifdef HAVE_REPLICATION
2627

@@ -1641,6 +1642,9 @@ bool Master_info_index::start_all_slaves(THD *thd)
16411642
DBUG_ENTER("start_all_slaves");
16421643
mysql_mutex_assert_owner(&LOCK_active_mi);
16431644

1645+
if (check_global_access(thd, PRIV_STMT_START_SLAVE))
1646+
DBUG_RETURN(true);
1647+
16441648
for (uint i= 0; i< master_info_hash.records; i++)
16451649
{
16461650
Master_info *mi;
@@ -1719,6 +1723,9 @@ bool Master_info_index::stop_all_slaves(THD *thd)
17191723
mysql_mutex_assert_owner(&LOCK_active_mi);
17201724
DBUG_ASSERT(thd);
17211725

1726+
if (check_global_access(thd, PRIV_STMT_STOP_SLAVE))
1727+
DBUG_RETURN(true);
1728+
17221729
for (uint i= 0; i< master_info_hash.records; i++)
17231730
{
17241731
Master_info *mi;

0 commit comments

Comments
 (0)