| 1 |
# ==== Purpose ==== |
| 2 |
# |
| 3 |
# To verify that rotating master key are recovered correctly after crashes at |
| 4 |
# different points when executing the command 'ALTER INSTANCE ROTATE BINLOG |
| 5 |
# MASTER KEY' on enabling binlog_encryption. |
| 6 |
# |
| 7 |
# ==== Implementation ==== |
| 8 |
# |
| 9 |
# 1. Set a debug point. |
| 10 |
# 2. Verify that an expected crash happened at the debug point when executing |
| 11 |
# the command 'ALTER INSTANCE ROTATE BINLOG MASTER KEY'. |
| 12 |
# 3. Recover the server with disabling the binlog_encryption. |
| 13 |
# 4. Verify that 'binlog_encryption' is off after above crash recovery |
| 14 |
# 5. Verify that an error is emitted to the client side if needed when |
| 15 |
# executing the command 'SET @@GLOBAL.binlog_encryption=ON' if there |
| 16 |
# is an error. |
| 17 |
# 6. Verify that 'binlog_encryption' can be enabled and rotating master key |
| 18 |
# is recovered after above crash recovery on enabling binlog_encryption. |
| 19 |
# 7. Verify that 'ALTER INSTANCE ROTATE BINLOG MASTER KEY' works after |
| 20 |
# above crash recovery. |
| 21 |
# |
| 22 |
# ==== References ==== |
| 23 |
# |
| 24 |
# Wl#12080 Add support to binary log encryption key rotation and cleanup |
| 25 |
|
| 26 |
--source include/have_binlog_format_row.inc |
| 27 |
--source include/not_valgrind.inc |
| 28 |
--source include/have_log_bin.inc |
| 29 |
--source include/have_debug.inc |
| 30 |
--source include/have_debug_sync.inc |
| 31 |
|
| 32 |
--let $MASTER_DATADIR= `select @@datadir` |
| 33 |
--let $default_binlog_encryption = `SELECT @@GLOBAL.binlog_encryption` |
| 34 |
|
| 35 |
SET @@GLOBAL.binlog_encryption=ON; |
| 36 |
|
| 37 |
--let $first_encrypted_binary_log=query_get_value(SHOW MASTER STATUS, File, 1) |
| 38 |
--let $rpl_log_file=$MASTER_DATADIR$first_encrypted_binary_log |
| 39 |
--source include/rpl_get_log_encryption_key_id.inc |
| 40 |
--let $assert_text=the first encrypted binary log is encrypted using first master key |
| 41 |
--let $assert_cond= RIGHT("$rpl_encryption_key_id", 2) = "_1" |
| 42 |
--source include/assert.inc |
| 43 |
|
| 44 |
CREATE TABLE t1 (a INT) ENGINE=InnoDB; |
| 45 |
INSERT INTO t1 VALUES(1); |
| 46 |
|
| 47 |
ALTER INSTANCE ROTATE BINLOG MASTER KEY; |
| 48 |
INSERT INTO t1 VALUES(2); |
| 49 |
|
| 50 |
|
| 51 |
--echo # Part 1: crash_before_set_old_master_key_seqno_on_keyring |
| 52 |
--let $debug_point=crash_before_set_old_master_key_seqno_on_keyring |
| 53 |
--let $statement=ALTER INSTANCE ROTATE BINLOG MASTER KEY |
| 54 |
--source suite/binlog/include/binlog_server_crash_recovery.inc |
| 55 |
|
| 56 |
--let $assert_text= 'binlog_encryption' is off after above crash recovery. |
| 57 |
--let $assert_cond= "[SELECT @@GLOBAL.binlog_encryption]" = "0" |
| 58 |
--source include/assert.inc |
| 59 |
|
| 60 |
--echo # |
| 61 |
--echo # Verify that an error 'ER_RPL_ENCRYPTION_MASTER_KEY_RECOVERY_FAILED' |
| 62 |
--echo # is emitted to the client side when executing the command |
| 63 |
--echo # 'SET @@GLOBAL.binlog_encryption=ON' if there is an error |
| 64 |
--echo # when fetching master key seqno from keyring. |
| 65 |
--echo # |
| 66 |
--let $debug_point=fail_to_fetch_master_key_seqno_from_keyring |
| 67 |
--source include/add_debug_point.inc |
| 68 |
--error ER_RPL_ENCRYPTION_MASTER_KEY_RECOVERY_FAILED |
| 69 |
SET @@GLOBAL.binlog_encryption=ON; |
| 70 |
--source include/remove_debug_point.inc |
| 71 |
|
| 72 |
--echo # |
| 73 |
--echo # Verify that an error 'ER_RPL_ENCRYPTION_MASTER_KEY_RECOVERY_FAILED' |
| 74 |
--echo # is emitted to the client side when executing the command |
| 75 |
--echo # 'SET @@GLOBAL.binlog_encryption=ON' if there is an error |
| 76 |
--echo # when fetching old master key seqno from keyring. |
| 77 |
--echo # |
| 78 |
--let $debug_point=fail_to_fetch_old_master_key_seqno_from_keyring |
| 79 |
--source include/add_debug_point.inc |
| 80 |
--error ER_RPL_ENCRYPTION_MASTER_KEY_RECOVERY_FAILED |
| 81 |
SET @@GLOBAL.binlog_encryption=ON; |
| 82 |
--source include/remove_debug_point.inc |
| 83 |
|
| 84 |
SET @@GLOBAL.binlog_encryption=ON; |
| 85 |
--let $assert_text= Verify that 'binlog_encryption' can be enabled after above crash recovery. |
| 86 |
--let $assert_cond= "[SELECT @@GLOBAL.binlog_encryption]" = "1" |
| 87 |
--source include/assert.inc |
| 88 |
|
| 89 |
--let $current_master_key_id=2 |
| 90 |
--let $current_comparison_digit=2 |
| 91 |
--let $rotated_master_key_id=3 |
| 92 |
--let $rotated_comparison_digit=2 |
| 93 |
--source suite/binlog/include/binlog_rotate_binlog_master_key_work.inc |
| 94 |
|
| 95 |
--echo # Part 2: crash_after_set_old_master_key_seqno_on_keyring |
| 96 |
--let $debug_point=crash_after_set_old_master_key_seqno_on_keyring |
| 97 |
--let $statement=ALTER INSTANCE ROTATE BINLOG MASTER KEY |
| 98 |
--source suite/binlog/include/binlog_server_crash_recovery.inc |
| 99 |
|
| 100 |
--let $assert_text= 'binlog_encryption' is off after above crash recovery. |
| 101 |
--let $assert_cond= "[SELECT @@GLOBAL.binlog_encryption]" = "0" |
| 102 |
--source include/assert.inc |
| 103 |
|
| 104 |
--echo # |
| 105 |
--echo # Verify that an error 'ER_binlog_MASTER_KEY_RECOVERY_OUT_OF_COMBINATION' |
| 106 |
--echo # is emitted to the client side when executing the command |
| 107 |
--echo # 'SET @@GLOBAL.binlog_encryption=ON' if the combination of |
| 108 |
--echo # values of new_master_key_seqno, master_key_seqno and |
| 109 |
--echo # old_master_key_seqno are wrong when recovering binlog master key. |
| 110 |
--echo # |
| 111 |
--let $debug_point=simulate_master_key_recovery_out_of_combination |
| 112 |
--source include/add_debug_point.inc |
| 113 |
--error ER_BINLOG_MASTER_KEY_RECOVERY_OUT_OF_COMBINATION |
| 114 |
SET @@GLOBAL.binlog_encryption=ON; |
| 115 |
--source include/remove_debug_point.inc |
| 116 |
|
| 117 |
SET @@GLOBAL.binlog_encryption=ON; |
| 118 |
--let $assert_text= Verify that 'binlog_encryption' can be enabled after above crash recovery. |
| 119 |
--let $assert_cond= "[SELECT @@GLOBAL.binlog_encryption]" = "1" |
| 120 |
--source include/assert.inc |
| 121 |
|
| 122 |
--let $current_master_key_id=4 |
| 123 |
--let $rotated_master_key_id=5 |
| 124 |
--source suite/binlog/include/binlog_rotate_binlog_master_key_work.inc |
| 125 |
|
| 126 |
--echo # Part 3: crash_after_set_new_master_key_seqno_on_keyring |
| 127 |
--let $debug_point=crash_after_set_new_master_key_seqno_on_keyring |
| 128 |
--let $statement=ALTER INSTANCE ROTATE BINLOG MASTER KEY |
| 129 |
--source suite/binlog/include/binlog_server_crash_recovery.inc |
| 130 |
|
| 131 |
--let $assert_text= 'binlog_encryption' is off after above crash recovery. |
| 132 |
--let $assert_cond= "[SELECT @@GLOBAL.binlog_encryption]" = "0" |
| 133 |
--source include/assert.inc |
| 134 |
|
| 135 |
--echo # |
| 136 |
--echo # Verify that an error 'ER_RPL_ENCRYPTION_MASTER_KEY_RECOVERY_FAILED' |
| 137 |
--echo # is emitted to the client side when executing the command |
| 138 |
--echo # 'SET @@GLOBAL.binlog_encryption=ON' if there is an error |
| 139 |
--echo # when fetching new master key from keyring. |
| 140 |
--echo # |
| 141 |
--let $debug_point=fail_to_fetch_new_master_key_from_keyring |
| 142 |
--source include/add_debug_point.inc |
| 143 |
--error ER_RPL_ENCRYPTION_MASTER_KEY_RECOVERY_FAILED |
| 144 |
SET @@GLOBAL.binlog_encryption=ON; |
| 145 |
--source include/remove_debug_point.inc |
| 146 |
|
| 147 |
SET @@GLOBAL.binlog_encryption=ON; |
| 148 |
--let $assert_text= Verify that 'binlog_encryption' can be enabled after above crash recovery. |
| 149 |
--let $assert_cond= "[SELECT @@GLOBAL.binlog_encryption]" = "1" |
| 150 |
--source include/assert.inc |
| 151 |
|
| 152 |
--let $current_master_key_id=6 |
| 153 |
--let $rotated_master_key_id=7 |
| 154 |
--source suite/binlog/include/binlog_rotate_binlog_master_key_work.inc |
| 155 |
|
| 156 |
--echo # Part 4: crash_after_generate_new_master_key_on_keyring |
| 157 |
--let $debug_point=crash_after_generate_new_master_key_on_keyring |
| 158 |
--let $statement=ALTER INSTANCE ROTATE BINLOG MASTER KEY |
| 159 |
--source suite/binlog/include/binlog_server_crash_recovery.inc |
| 160 |
|
| 161 |
--let $assert_text= 'binlog_encryption' is off after above crash recovery. |
| 162 |
--let $assert_cond= "[SELECT @@GLOBAL.binlog_encryption]" = "0" |
| 163 |
--source include/assert.inc |
| 164 |
|
| 165 |
--echo # |
| 166 |
--echo # Verify that an error 'ER_RPL_ENCRYPTION_MASTER_KEY_RECOVERY_FAILED' |
| 167 |
--echo # is emitted to the client side when executing the command |
| 168 |
--echo # 'SET @@GLOBAL.binlog_encryption=ON' if there is an error |
| 169 |
--echo # when fetching new master key seqno from keyring. |
| 170 |
--echo # |
| 171 |
--let $debug_point=fail_to_fetch_new_master_key_seqno_from_keyring |
| 172 |
--source include/add_debug_point.inc |
| 173 |
--error ER_RPL_ENCRYPTION_MASTER_KEY_RECOVERY_FAILED |
| 174 |
SET @@GLOBAL.binlog_encryption=ON; |
| 175 |
--source include/remove_debug_point.inc |
| 176 |
|
| 177 |
SET @@GLOBAL.binlog_encryption=ON; |
| 178 |
--let $assert_text= Verify that 'binlog_encryption' can be enabled after above crash recovery. |
| 179 |
--let $assert_cond= "[SELECT @@GLOBAL.binlog_encryption]" = "1" |
| 180 |
--source include/assert.inc |
| 181 |
|
| 182 |
--let $current_master_key_id=8 |
| 183 |
--let $rotated_master_key_id=9 |
| 184 |
--source suite/binlog/include/binlog_rotate_binlog_master_key_work.inc |
| 185 |
|
| 186 |
--echo # Part 5: crash_after_remove_master_key_seqno_from_keyring |
| 187 |
--let $debug_point=crash_after_remove_master_key_seqno_from_keyring |
| 188 |
--let $statement=ALTER INSTANCE ROTATE BINLOG MASTER KEY |
| 189 |
--source suite/binlog/include/binlog_server_crash_recovery.inc |
| 190 |
|
| 191 |
--let $assert_text= 'binlog_encryption' is off after above crash recovery. |
| 192 |
--let $assert_cond= "[SELECT @@GLOBAL.binlog_encryption]" = "0" |
| 193 |
--source include/assert.inc |
| 194 |
|
| 195 |
SET @@GLOBAL.binlog_encryption=ON; |
| 196 |
--let $assert_text= Verify that 'binlog_encryption' can be enabled after above crash recovery. |
| 197 |
--let $assert_cond= "[SELECT @@GLOBAL.binlog_encryption]" = "1" |
| 198 |
--source include/assert.inc |
| 199 |
|
| 200 |
--let $current_master_key_id=10 |
| 201 |
--let $current_comparison_digit=3 |
| 202 |
--let $rotated_master_key_id=11 |
| 203 |
--let $rotated_comparison_digit=3 |
| 204 |
--source suite/binlog/include/binlog_rotate_binlog_master_key_work.inc |
| 205 |
|
| 206 |
--echo # Part 6: crash_after_set_master_key_seqno_on_keyring |
| 207 |
--let $debug_point=crash_after_set_master_key_seqno_on_keyring |
| 208 |
--let $statement=ALTER INSTANCE ROTATE BINLOG MASTER KEY |
| 209 |
--source suite/binlog/include/binlog_server_crash_recovery.inc |
| 210 |
|
| 211 |
--let $assert_text= 'binlog_encryption' is off after above crash recovery. |
| 212 |
--let $assert_cond= "[SELECT @@GLOBAL.binlog_encryption]" = "0" |
| 213 |
--source include/assert.inc |
| 214 |
|
| 215 |
SET @@GLOBAL.binlog_encryption=ON; |
| 216 |
--let $assert_text= Verify that 'binlog_encryption' can be enabled after above crash recovery. |
| 217 |
--let $assert_cond= "[SELECT @@GLOBAL.binlog_encryption]" = "1" |
| 218 |
--source include/assert.inc |
| 219 |
|
| 220 |
--let $current_master_key_id=12 |
| 221 |
--let $rotated_master_key_id=13 |
| 222 |
--source suite/binlog/include/binlog_rotate_binlog_master_key_work.inc |
| 223 |
|
| 224 |
--echo # Part 7: crash_after_remove_old_master_key_seqno_from_keyring |
| 225 |
--let $debug_point=crash_after_remove_old_master_key_seqno_from_keyring |
| 226 |
--let $statement=ALTER INSTANCE ROTATE BINLOG MASTER KEY |
| 227 |
--source suite/binlog/include/binlog_server_crash_recovery.inc |
| 228 |
|
| 229 |
--let $assert_text= 'binlog_encryption' is off after above crash recovery. |
| 230 |
--let $assert_cond= "[SELECT @@GLOBAL.binlog_encryption]" = "0" |
| 231 |
--source include/assert.inc |
| 232 |
|
| 233 |
SET @@GLOBAL.binlog_encryption=ON; |
| 234 |
--let $assert_text= Verify that 'binlog_encryption' can be enabled after above crash recovery. |
| 235 |
--let $assert_cond= "[SELECT @@GLOBAL.binlog_encryption]" = "1" |
| 236 |
--source include/assert.inc |
| 237 |
|
| 238 |
--let $current_master_key_id=14 |
| 239 |
--let $rotated_master_key_id=15 |
| 240 |
--source suite/binlog/include/binlog_rotate_binlog_master_key_work.inc |
| 241 |
|
| 242 |
--echo # Part 8: crash_after_remove_new_master_key_seqno_from_keyring |
| 243 |
--let $debug_point=crash_after_remove_new_master_key_seqno_from_keyring |
| 244 |
--let $statement=ALTER INSTANCE ROTATE BINLOG MASTER KEY |
| 245 |
--source suite/binlog/include/binlog_server_crash_recovery.inc |
| 246 |
|
| 247 |
--let $assert_text= 'binlog_encryption' is off after above crash recovery. |
| 248 |
--let $assert_cond= "[SELECT @@GLOBAL.binlog_encryption]" = "0" |
| 249 |
--source include/assert.inc |
| 250 |
|
| 251 |
SET @@GLOBAL.binlog_encryption=ON; |
| 252 |
--let $assert_text= Verify that 'binlog_encryption' can be enabled after above crash recovery. |
| 253 |
--let $assert_cond= "[SELECT @@GLOBAL.binlog_encryption]" = "1" |
| 254 |
--source include/assert.inc |
| 255 |
|
| 256 |
--let $current_master_key_id=16 |
| 257 |
--let $rotated_master_key_id=17 |
| 258 |
--source suite/binlog/include/binlog_rotate_binlog_master_key_work.inc |
| 259 |
|
| 260 |
--echo # Part 9: crash_after_set_old_master_key_seqno_on_keyring |
| 261 |
--let $debug_point=crash_after_set_old_master_key_seqno_on_keyring |
| 262 |
--let $statement=ALTER INSTANCE ROTATE BINLOG MASTER KEY |
| 263 |
--source suite/binlog/include/binlog_server_crash_recovery.inc |
| 264 |
|
| 265 |
--let $assert_text= 'binlog_encryption' is off after above crash recovery. |
| 266 |
--let $assert_cond= "[SELECT @@GLOBAL.binlog_encryption]" = "0" |
| 267 |
--source include/assert.inc |
| 268 |
|
| 269 |
--echo # |
| 270 |
--echo # Verify that an error 'ER_RPL_ENCRYPTION_FAILED_TO_STORE_KEY' |
| 271 |
--echo # is emitted to the client side when executing the command |
| 272 |
--echo # 'SET @@GLOBAL.binlog_encryption=ON' if there is an error |
| 273 |
--echo # on setting new master key seqno on keyring when recovering |
| 274 |
--echo # binlog master key. |
| 275 |
--echo # |
| 276 |
--let $debug_point=fail_to_set_new_master_key_seqno_on_keyring |
| 277 |
--source include/add_debug_point.inc |
| 278 |
--error ER_RPL_ENCRYPTION_FAILED_TO_STORE_KEY |
| 279 |
SET @@GLOBAL.binlog_encryption=ON; |
| 280 |
--source include/remove_debug_point.inc |
| 281 |
|
| 282 |
SET @@GLOBAL.binlog_encryption=ON; |
| 283 |
--let $assert_text= Verify that 'binlog_encryption' can be enabled after above crash recovery. |
| 284 |
--let $assert_cond= "[SELECT @@GLOBAL.binlog_encryption]" = "1" |
| 285 |
--source include/assert.inc |
| 286 |
|
| 287 |
--let $current_master_key_id=18 |
| 288 |
--let $rotated_master_key_id=19 |
| 289 |
--source suite/binlog/include/binlog_rotate_binlog_master_key_work.inc |
| 290 |
|
| 291 |
# Cleanup |
| 292 |
DROP TABLE t1; |
| 293 |
--replace_result $default_binlog_encryption DEFAULT_BINLOG_ENCRYPTION |
| 294 |
--eval SET @@GLOBAL.binlog_encryption=$default_binlog_encryption |
| 295 |
|