| 1 |
# |
| 2 |
# The test checks effects and workarounds for the situation when |
| 3 |
# the key used to encrypt previous binary logs on master has been lost, |
| 4 |
# and master runs with a different one. |
| 5 |
# |
| 6 |
# The test starts with encrypted binlogs on master. |
| 7 |
# It stops replication, generates a few statement and row events |
| 8 |
# on the master, then restarts the server with encrypted binlog, |
| 9 |
# but with a different value for key 1. |
| 10 |
# |
| 11 |
# Then it resumes replication and checks what happens when the master |
| 12 |
# feed the encrypted logs to the slave (slave SQL thread should |
| 13 |
# produce and error). |
| 14 |
# |
| 15 |
# Then the test resets the slave, configures it to start from a "good" |
| 16 |
# master binlog log, for which the master has a key, starts replication |
| 17 |
# and checks that it works. |
| 18 |
# |
| 19 |
# Then it resets the slave again, purges binary logs on master up |
| 20 |
# to the "good" one, starts replication and checks that it works. |
| 21 |
# |
| 22 |
|
| 23 |
--source include/have_binlog_format_mixed.inc |
| 24 |
|
| 25 |
--echo ################# |
| 26 |
--echo # Initialization |
| 27 |
--echo ################# |
| 28 |
|
| 29 |
--let $rpl_topology= 1->2 |
| 30 |
--source include/rpl_init.inc |
| 31 |
|
| 32 |
--enable_connect_log |
| 33 |
|
| 34 |
# We stop replication because we want it to happen after the switch |
| 35 |
|
| 36 |
--connection server_2 |
| 37 |
--disable_connect_log |
| 38 |
--source include/stop_slave.inc |
| 39 |
--enable_connect_log |
| 40 |
|
| 41 |
--echo ##################################################### |
| 42 |
--echo # Pre-test 1: Initial key value |
| 43 |
--echo ##################################################### |
| 44 |
|
| 45 |
--connection server_1 |
| 46 |
|
| 47 |
CREATE TABLE table1_to_encrypt ( |
| 48 |
pk INT AUTO_INCREMENT PRIMARY KEY, |
| 49 |
ts TIMESTAMP NULL, |
| 50 |
b BLOB |
| 51 |
) ENGINE=MyISAM; |
| 52 |
|
| 53 |
INSERT INTO table1_to_encrypt VALUES (NULL,NOW(),'data_to_encrypt'); |
| 54 |
INSERT INTO table1_to_encrypt SELECT NULL,NOW(),b FROM table1_to_encrypt; |
| 55 |
SET binlog_format=ROW; |
| 56 |
INSERT INTO table1_to_encrypt SELECT NULL,NOW(),b FROM table1_to_encrypt; |
| 57 |
INSERT INTO table1_to_encrypt SELECT NULL,NOW(),b FROM table1_to_encrypt; |
| 58 |
|
| 59 |
# Make sure that binary logs are encrypted |
| 60 |
|
| 61 |
--let SEARCH_RANGE = 500000 |
| 62 |
--let SEARCH_FILE= master-bin.0* |
| 63 |
--let SEARCH_PATTERN= table1_to_encrypt |
| 64 |
--source include/search_pattern_in_file.inc |
| 65 |
|
| 66 |
--echo ####################################################### |
| 67 |
--echo # Pre-test 2: restart master with a different key value |
| 68 |
--echo ####################################################### |
| 69 |
|
| 70 |
--write_file $MYSQL_TMP_DIR/master_lose_key.key |
| 71 |
1;00000AAAAAAAAAAAAAAAAAAAAAA00000 |
| 72 |
EOF |
| 73 |
|
| 74 |
--let $rpl_server_parameters= --file-key-management-filename=$MYSQL_TMP_DIR/master_lose_key.key |
| 75 |
|
| 76 |
--let $rpl_server_number= 1 |
| 77 |
--source restart_server.inc |
| 78 |
|
| 79 |
CREATE TABLE table2_to_encrypt ( |
| 80 |
pk INT AUTO_INCREMENT PRIMARY KEY, |
| 81 |
ts TIMESTAMP NULL, |
| 82 |
b BLOB |
| 83 |
) ENGINE=MyISAM; |
| 84 |
|
| 85 |
INSERT INTO table2_to_encrypt VALUES (NULL,NOW(),'data_to_encrypt'); |
| 86 |
INSERT INTO table2_to_encrypt SELECT NULL,NOW(),b FROM table2_to_encrypt; |
| 87 |
SET binlog_format=ROW; |
| 88 |
INSERT INTO table2_to_encrypt SELECT NULL,NOW(),b FROM table2_to_encrypt; |
| 89 |
INSERT INTO table2_to_encrypt SELECT NULL,NOW(),b FROM table2_to_encrypt; |
| 90 |
|
| 91 |
# Make sure that binary logs are encrypted |
| 92 |
|
| 93 |
--let SEARCH_FILE= master-bin.0* |
| 94 |
--let SEARCH_PATTERN= table2_to_encrypt |
| 95 |
--source include/search_pattern_in_file.inc |
| 96 |
|
| 97 |
--echo ##################################################### |
| 98 |
--echo # Pre-test 3: restart master again with the right key |
| 99 |
--echo ##################################################### |
| 100 |
|
| 101 |
--let $rpl_server_parameters= |
| 102 |
--let $rpl_server_number= 1 |
| 103 |
--source restart_server.inc |
| 104 |
|
| 105 |
--let $good_master_binlog= query_get_value(SHOW MASTER STATUS,File,1) |
| 106 |
|
| 107 |
CREATE TABLE table3_to_encrypt ( |
| 108 |
pk INT AUTO_INCREMENT PRIMARY KEY, |
| 109 |
ts TIMESTAMP NULL, |
| 110 |
b BLOB |
| 111 |
) ENGINE=MyISAM; |
| 112 |
|
| 113 |
INSERT INTO table3_to_encrypt VALUES (NULL,NOW(),'data_to_encrypt'); |
| 114 |
INSERT INTO table3_to_encrypt SELECT NULL,NOW(),b FROM table3_to_encrypt; |
| 115 |
INSERT INTO table3_to_encrypt SELECT NULL,NOW(),b FROM table3_to_encrypt; |
| 116 |
FLUSH BINARY LOGS; |
| 117 |
INSERT INTO table3_to_encrypt SELECT NULL,NOW(),b FROM table3_to_encrypt; |
| 118 |
|
| 119 |
--save_master_pos |
| 120 |
|
| 121 |
--echo ##################################################### |
| 122 |
--echo # Test 1: Check that if master has an encrypted |
| 123 |
--echo # binary log which it cannot decrypt, it |
| 124 |
--echo # still feeds events to the slave, and SQL |
| 125 |
--echo # thread produces an expected error upon |
| 126 |
--echo # receiving these unreadable events . |
| 127 |
--echo # This behavior is confirmed in MDEV-11323 |
| 128 |
--echo ##################################################### |
| 129 |
--connection server_2 |
| 130 |
|
| 131 |
--disable_connect_log |
| 132 |
START SLAVE IO_THREAD; |
| 133 |
--source include/wait_for_slave_io_to_start.inc |
| 134 |
|
| 135 |
START SLAVE SQL_THREAD; |
| 136 |
--let $slave_sql_errno= 1594 |
| 137 |
--source include/wait_for_slave_sql_error.inc |
| 138 |
--enable_connect_log |
| 139 |
|
| 140 |
# Here we should see only table1_to_encrypt and its contents, |
| 141 |
# because it was logged with the initial key |
| 142 |
--sorted_result |
| 143 |
SHOW TABLES; |
| 144 |
SELECT COUNT(*) FROM table1_to_encrypt; |
| 145 |
|
| 146 |
--echo ##################################################### |
| 147 |
--echo # Test 2: check that replication works if it starts |
| 148 |
--echo # from a good binary log |
| 149 |
--echo ##################################################### |
| 150 |
--connection server_2 |
| 151 |
|
| 152 |
--disable_connect_log |
| 153 |
--source include/stop_slave.inc |
| 154 |
RESET SLAVE ALL; |
| 155 |
DROP DATABASE test; |
| 156 |
CREATE DATABASE test; |
| 157 |
USE test; |
| 158 |
--replace_result $SERVER_MYPORT_1 <MASTER_PORT> |
| 159 |
eval CHANGE MASTER TO MASTER_HOST='127.0.0.1', MASTER_PORT=$SERVER_MYPORT_1, MASTER_USER='root', MASTER_LOG_FILE='$good_master_binlog'; |
| 160 |
--source include/start_slave.inc |
| 161 |
--enable_connect_log |
| 162 |
--sync_with_master |
| 163 |
|
| 164 |
--sorted_result |
| 165 |
SHOW TABLES; |
| 166 |
|
| 167 |
--echo ##################################################### |
| 168 |
--echo # Test 3: check that replication works if we purge |
| 169 |
--echo # master logs up to the good one |
| 170 |
--echo ##################################################### |
| 171 |
--connection server_2 |
| 172 |
|
| 173 |
--connection server_1 |
| 174 |
eval PURGE BINARY LOGS TO '$good_master_binlog'; |
| 175 |
|
| 176 |
--connection server_2 |
| 177 |
--disable_connect_log |
| 178 |
--source include/stop_slave.inc |
| 179 |
RESET SLAVE ALL; |
| 180 |
DROP DATABASE test; |
| 181 |
CREATE DATABASE test; |
| 182 |
USE test; |
| 183 |
--replace_result $SERVER_MYPORT_1 <MASTER_PORT> |
| 184 |
eval CHANGE MASTER TO MASTER_HOST='127.0.0.1', MASTER_PORT=$SERVER_MYPORT_1, MASTER_USER='root'; |
| 185 |
--source include/start_slave.inc |
| 186 |
--enable_connect_log |
| 187 |
--sync_with_master |
| 188 |
|
| 189 |
--sorted_result |
| 190 |
SHOW TABLES; |
| 191 |
|
| 192 |
--echo ########## |
| 193 |
--echo # Cleanup |
| 194 |
--echo ########## |
| 195 |
|
| 196 |
--connection server_1 |
| 197 |
|
| 198 |
DROP TABLE table1_to_encrypt, table2_to_encrypt, table3_to_encrypt; |
| 199 |
|
| 200 |
--save_master_pos |
| 201 |
|
| 202 |
--connection server_2 |
| 203 |
--sync_with_master |
| 204 |
|
| 205 |
--disable_connect_log |
| 206 |
--source include/rpl_end.inc |