| 1 |
# |
| 2 |
# The test starts with unencrypted master. |
| 3 |
# It stops replication, generates a few statement and row events |
| 4 |
# on the master, then restarts the server with encrypted binlog, |
| 5 |
# generates some more events and restarts it back without encryption |
| 6 |
# (no encryption plugin). |
| 7 |
# Then it resumes replication and should error with |
| 8 |
# ER_MASTER_FATAL_ERROR_READING_BINLOG because the encrypted binlog is |
| 9 |
# sent and unable to be decrypted. |
| 10 |
# |
| 11 |
# Note this variation of encrypted_master_switch_to_unencrypted tests |
| 12 |
# using MASTER_USE_GTID=NO. In contrast to the GTID variant of this |
| 13 |
# test, at part 3 (the error case), the master will scan binlogs |
| 14 |
# starting from the first one (which is unencrypted initially, so |
| 15 |
# replication is okay) and continue until the slave encounters the |
| 16 |
# first encrypted event, which causes the slave to error. |
| 17 |
# |
| 18 |
|
| 19 |
--source include/have_binlog_format_mixed.inc |
| 20 |
|
| 21 |
--echo ################# |
| 22 |
--echo # Initialization |
| 23 |
--echo ################# |
| 24 |
|
| 25 |
--let $rpl_topology= 1->2 |
| 26 |
--source include/rpl_init.inc |
| 27 |
|
| 28 |
--connection server_2 |
| 29 |
--source include/stop_slave.inc |
| 30 |
CHANGE MASTER TO MASTER_USE_GTID=NO; |
| 31 |
--source include/start_slave.inc |
| 32 |
|
| 33 |
--connection server_1 |
| 34 |
|
| 35 |
--enable_connect_log |
| 36 |
|
| 37 |
# We stop replication because we want it to happen after the switch |
| 38 |
|
| 39 |
--connection server_2 |
| 40 |
--disable_connect_log |
| 41 |
--source include/stop_slave.inc |
| 42 |
CHANGE MASTER TO MASTER_USE_GTID=NO; |
| 43 |
--enable_connect_log |
| 44 |
|
| 45 |
--echo ##################################################### |
| 46 |
--echo # Part 1: unencrypted master |
| 47 |
--echo ##################################################### |
| 48 |
|
| 49 |
--connection server_1 |
| 50 |
|
| 51 |
call mtr.add_suppression("Got fatal error 1236 from master when reading data from binary log: 'Could not decrypt binlog: encryption key error;"); |
| 52 |
|
| 53 |
CREATE TABLE table1_no_encryption ( |
| 54 |
pk INT AUTO_INCREMENT PRIMARY KEY, |
| 55 |
ts TIMESTAMP NULL, |
| 56 |
b BLOB |
| 57 |
) ENGINE=MyISAM; |
| 58 |
|
| 59 |
INSERT INTO table1_no_encryption VALUES (NULL,NOW(),'data_no_encryption'); |
| 60 |
INSERT INTO table1_no_encryption SELECT NULL,NOW(),b FROM table1_no_encryption; |
| 61 |
FLUSH BINARY LOGS; |
| 62 |
SET binlog_format=ROW; |
| 63 |
INSERT INTO table1_no_encryption SELECT NULL,NOW(),b FROM table1_no_encryption; |
| 64 |
INSERT INTO table1_no_encryption SELECT NULL,NOW(),b FROM table1_no_encryption; |
| 65 |
|
| 66 |
# Make sure that binary logs are not encrypted |
| 67 |
|
| 68 |
--let SEARCH_RANGE = 500000 |
| 69 |
--let SEARCH_FILE= master-bin.0* |
| 70 |
--let SEARCH_PATTERN= table1_no_encryption |
| 71 |
--source include/search_pattern_in_file.inc |
| 72 |
|
| 73 |
# We are storing the position now, because up to this point the slave |
| 74 |
# should be able to synchronize with master |
| 75 |
--save_master_pos |
| 76 |
|
| 77 |
--echo ##################################################### |
| 78 |
--echo # Part 2: restart master, now with binlog encryption |
| 79 |
--echo ##################################################### |
| 80 |
|
| 81 |
--let $rpl_server_parameters= --encrypt-binlog=1 --plugin-load-add=file_key_management --file-key-management --loose-file-key-management-filename=$MYSQL_TEST_DIR/std_data/keys.txt |
| 82 |
|
| 83 |
--let $rpl_server_number= 1 |
| 84 |
--source restart_server.inc |
| 85 |
|
| 86 |
CREATE TABLE table2_to_encrypt ( |
| 87 |
pk INT AUTO_INCREMENT PRIMARY KEY, |
| 88 |
ts TIMESTAMP NULL, |
| 89 |
b BLOB |
| 90 |
) ENGINE=MyISAM; |
| 91 |
|
| 92 |
INSERT INTO table2_to_encrypt VALUES (NULL,NOW(),'data_to_encrypt'); |
| 93 |
INSERT INTO table2_to_encrypt SELECT NULL,NOW(),b FROM table2_to_encrypt; |
| 94 |
FLUSH BINARY LOGS; |
| 95 |
SET binlog_format=ROW; |
| 96 |
INSERT INTO table2_to_encrypt SELECT NULL,NOW(),b FROM table2_to_encrypt; |
| 97 |
INSERT INTO table2_to_encrypt SELECT NULL,NOW(),b FROM table2_to_encrypt; |
| 98 |
|
| 99 |
# Make sure that binary logs are encrypted |
| 100 |
|
| 101 |
--let SEARCH_FILE= master-bin.0* |
| 102 |
--let SEARCH_PATTERN= table2_to_encrypt |
| 103 |
--source include/search_pattern_in_file.inc |
| 104 |
|
| 105 |
--echo ##################################################### |
| 106 |
--echo # Part 3: restart master again without encryption |
| 107 |
--echo ##################################################### |
| 108 |
|
| 109 |
--let $rpl_server_parameters= --encrypt-binlog=0 |
| 110 |
--let $rpl_server_number= 1 |
| 111 |
--source restart_server.inc |
| 112 |
|
| 113 |
CREATE TABLE table3_no_encryption ( |
| 114 |
pk INT AUTO_INCREMENT PRIMARY KEY, |
| 115 |
ts TIMESTAMP NULL, |
| 116 |
b BLOB |
| 117 |
) ENGINE=MyISAM; |
| 118 |
|
| 119 |
INSERT INTO table3_no_encryption VALUES (NULL,NOW(),'data_no_encryption'); |
| 120 |
INSERT INTO table3_no_encryption SELECT NULL,NOW(),b FROM table3_no_encryption; |
| 121 |
INSERT INTO table3_no_encryption SELECT NULL,NOW(),b FROM table3_no_encryption; |
| 122 |
|
| 123 |
--echo ##################################################### |
| 124 |
--echo # Check: resume replication and check how it goes |
| 125 |
--echo ##################################################### |
| 126 |
|
| 127 |
--connection server_2 |
| 128 |
start slave; |
| 129 |
# The slave should be able to synchronize with master up to |
| 130 |
# the previously saved position (when the log was still unencrypted) |
| 131 |
--sync_with_master |
| 132 |
|
| 133 |
--connection server_1 |
| 134 |
# Now save the current position and make slave to try to syncrhonize. |
| 135 |
# It shouldn't work, the slave IO thread is expected to abort with an error |
| 136 |
--save_master_pos |
| 137 |
|
| 138 |
--connection server_2 |
| 139 |
--let slave_io_errno=1236 |
| 140 |
--source include/wait_for_slave_io_error.inc |
| 141 |
|
| 142 |
--sorted_result |
| 143 |
SHOW TABLES; |
| 144 |
|
| 145 |
--disable_connect_log |
| 146 |
# IO thread is stopped, stop SQL thread only |
| 147 |
--source include/stop_slave_sql.inc |
| 148 |
--enable_connect_log |
| 149 |
--let $master_use_gtid_option= No |
| 150 |
--source include/reset_slave.inc |
| 151 |
|
| 152 |
--echo ########## |
| 153 |
--echo # Cleanup |
| 154 |
--echo ########## |
| 155 |
|
| 156 |
--connection server_1 |
| 157 |
reset master; |
| 158 |
|
| 159 |
SELECT COUNT(*) FROM table1_no_encryption; |
| 160 |
SELECT COUNT(*) FROM table2_to_encrypt; |
| 161 |
SELECT COUNT(*) FROM table3_no_encryption; |
| 162 |
DROP TABLE table1_no_encryption, table2_to_encrypt, table3_no_encryption; |
| 163 |
|
| 164 |
--connection server_2 |
| 165 |
--disable_connect_log |
| 166 |
--source include/start_slave.inc |
| 167 |
--source include/rpl_end.inc |