| 1 |
# |
| 2 |
# Verifies that wsrep_sst_rsync.sh rejects a joiner-supplied certificate |
| 3 |
# whose CN contains shell-unsafe characters. |
| 4 |
# |
| 5 |
# Brings up a 2-node cluster with rsync SST and ssl-mode=VERIFY_CA, then |
| 6 |
# forces a fresh SST on node_2 using std_data/server-new-cert.pem -- a |
| 7 |
# cert whose CN intentionally contains shell metacharacters. Confirms |
| 8 |
# that the donor (node_1) logs |
| 9 |
# "Invalid value for WSREP_SST_OPT_REMOTE_USER" |
| 10 |
# i.e. the rsync SST script refuses the value rather than interpolating |
| 11 |
# it into stunnel.conf or the rsync magic file. |
| 12 |
# |
| 13 |
|
| 14 |
--source include/galera_cluster.inc |
| 15 |
--source include/have_innodb.inc |
| 16 |
|
| 17 |
SELECT 1; |
| 18 |
|
| 19 |
--connection node_2 |
| 20 |
--let $wait_condition = SELECT VARIABLE_VALUE = 'Synced' FROM INFORMATION_SCHEMA.GLOBAL_STATUS WHERE VARIABLE_NAME = 'WSREP_LOCAL_STATE_COMMENT' |
| 21 |
--source include/wait_condition.inc |
| 22 |
|
| 23 |
# Confirm the initial SST went via rsync + stunnel (sanity check for the |
| 24 |
# test configuration). |
| 25 |
--let SEARCH_FILE = $MYSQLTEST_VARDIR/log/mysqld.1.err |
| 26 |
--let SEARCH_PATTERN = wsrep_sst_rsync |
| 27 |
--source include/search_pattern_in_file.inc |
| 28 |
|
| 29 |
|
| 30 |
# Reject shell-unsafe joiner-supplied auth (rsync) |
| 31 |
|
| 32 |
# Suppressions are per-server. node_1 will log the donor-side rejection |
| 33 |
# ("Invalid value for WSREP_SST_OPT_REMOTE_USER"); node_2 will log the |
| 34 |
# joiner-side "Will never receive state" abort. Add to both. |
| 35 |
--connection node_1 |
| 36 |
call mtr.add_suppression('Invalid value for WSREP_SST_OPT_REMOTE_USER'); |
| 37 |
call mtr.add_suppression('Failed to read from: wsrep_sst_rsync'); |
| 38 |
call mtr.add_suppression('Process completed with error: wsrep_sst_rsync'); |
| 39 |
call mtr.add_suppression('Command did not run: wsrep_sst_rsync'); |
| 40 |
call mtr.add_suppression('State transfer to .* failed'); |
| 41 |
call mtr.add_suppression('Will never receive state. Need to abort'); |
| 42 |
call mtr.add_suppression('Error while getting data from donor node'); |
| 43 |
call mtr.add_suppression('Cleanup after exit with status'); |
| 44 |
call mtr.add_suppression('Removing .*/sst_in_progress'); |
| 45 |
call mtr.add_suppression('Parent mysqld process .* terminated unexpectedly'); |
| 46 |
|
| 47 |
--connection node_2 |
| 48 |
--source include/shutdown_mysqld.inc |
| 49 |
|
| 50 |
# force SST again |
| 51 |
--remove_file $MYSQLTEST_VARDIR/mysqld.2/data/grastate.dat |
| 52 |
# using a cert with shell-unsafe CN |
| 53 |
--exec echo '[mysqld.2]' >> $MYSQLTEST_VARDIR/my.cnf |
| 54 |
--exec echo ssl-cert=$MYSQL_TEST_DIR/std_data/server-new-cert.pem >> $MYSQLTEST_VARDIR/my.cnf |
| 55 |
--exec echo ssl-key=$MYSQL_TEST_DIR/std_data/server-new-key.pem >> $MYSQLTEST_VARDIR/my.cnf |
| 56 |
|
| 57 |
# start the server |
| 58 |
# Joiner mariadbd exits when SST is aborted; the exit code varies by |
| 59 |
# platform (clean 0 on some systems, signalled 134 / 1 on others). |
| 60 |
--error 0,1,134 |
| 61 |
--exec $MYSQLD_LAST_CMD |
| 62 |
# the donor refused the SST request |
| 63 |
|
| 64 |
--connection node_1 |
| 65 |
# safe() in wsrep_sst_common.sh logs this when it rejects the joiner CN; |
| 66 |
# wsrep_sst_rsync.sh wraps the joiner-supplied REMOTE_USER with $(safe ..) |
| 67 |
# at line 249 so the value never reaches the stunnel.conf heredoc. |
| 68 |
--let SEARCH_PATTERN = Invalid value for WSREP_SST_OPT_REMOTE_USER |
| 69 |
--source include/search_pattern_in_file.inc |
| 70 |
|
| 71 |
# cleanup |
| 72 |
# Kill joiner's stunnel / rsync that may linger after the aborted SST. |
| 73 |
# Use a perl block because --exec with pkill -f matches the mtr cmdline |
| 74 |
# itself (which contains the pattern) and tears down the wrong process. |
| 75 |
perl; |
| 76 |
open(my $fh, '-|', 'ps', '-eo', 'pid,args') or die "ps: $!"; |
| 77 |
while (<$fh>) { |
| 78 |
next unless /server-new-cert/; |
| 79 |
next unless /^\s*(\d+)\s+(?:.*\/)?(stunnel|socat|rsync)\b/; |
| 80 |
kill 'TERM', $1; |
| 81 |
} |
| 82 |
close $fh; |
| 83 |
EOF |
| 84 |
--exec echo ssl-cert=$MYSQL_TEST_DIR/std_data/server-cert.pem >> $MYSQLTEST_VARDIR/my.cnf |
| 85 |
--exec echo ssl-key=$MYSQL_TEST_DIR/std_data/server-key.pem >> $MYSQLTEST_VARDIR/my.cnf |
| 86 |
|
| 87 |
# Switch back to node_2 before restarting it; the connection associates |
| 88 |
# with the soon-to-be-restarted server so mtr auto-reconnects and the |
| 89 |
# wait_condition + late suppressions land on the new instance. |
| 90 |
--connection node_2 |
| 91 |
--source $MYSQL_TEST_DIR/include/start_mysqld.inc |
| 92 |
|
| 93 |
--let $wait_condition = SELECT VARIABLE_VALUE = 2 FROM INFORMATION_SCHEMA.GLOBAL_STATUS WHERE VARIABLE_NAME = 'wsrep_cluster_size' |
| 94 |
--source include/wait_condition.inc |
| 95 |
|
| 96 |
call mtr.add_suppression('Will never receive state. Need to abort'); |
| 97 |
call mtr.add_suppression('Parent mysqld process .* terminated unexpectedly'); |
| 98 |
call mtr.add_suppression('Cleanup after exit with status'); |
| 99 |
call mtr.add_suppression('State transfer to .* failed'); |