Skip to content

Commit 4040bf1

Browse files
author
Jan Lindström
committed
MDEV-7593: Default encryption key does not work correctly for page
encrypted tables Introduced a new innodb_default_page_encryption_key configuration variable to allow user to set the default key identifier.
1 parent 11536f9 commit 4040bf1

File tree

13 files changed

+249
-21
lines changed

13 files changed

+249
-21
lines changed

mysql-test/suite/innodb/r/innodb-page_encryption.result

Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,14 @@ create table innodb_compact(c1 bigint not null, b char(200)) engine=innodb row_f
55
create table innodb_compressed(c1 bigint not null, b char(200)) engine=innodb row_format=compressed page_encryption=1 page_encryption_key=2;
66
create table innodb_dynamic(c1 bigint not null, b char(200)) engine=innodb row_format=dynamic page_encryption=1 page_encryption_key=3;
77
create table innodb_redundant(c1 bigint not null, b char(200)) engine=innodb row_format=redundant page_encryption=1 page_encryption_key=4;
8+
SET GLOBAL innodb_default_page_encryption_key = 5;
9+
create table innodb_defkey(c1 bigint not null, b char(200)) engine=innodb page_encryption=1;
10+
show create table innodb_defkey;
11+
Table Create Table
12+
innodb_defkey CREATE TABLE `innodb_defkey` (
13+
`c1` bigint(20) NOT NULL,
14+
`b` char(200) DEFAULT NULL
15+
) ENGINE=InnoDB DEFAULT CHARSET=latin1 `page_encryption`=1
816
show create table innodb_compact;
917
Table Create Table
1018
innodb_compact CREATE TABLE `innodb_compact` (
@@ -47,11 +55,13 @@ insert into innodb_compact select * from innodb_normal;
4755
insert into innodb_compressed select * from innodb_normal;
4856
insert into innodb_dynamic select * from innodb_normal;
4957
insert into innodb_redundant select * from innodb_normal;
58+
insert into innodb_defkey select * from innodb_normal;
5059
update innodb_normal set c1 = c1 +1;
5160
update innodb_compact set c1 = c1 + 1;
5261
update innodb_compressed set c1 = c1 + 1;
5362
update innodb_dynamic set c1 = c1 + 1;
5463
update innodb_redundant set c1 = c1 + 1;
64+
update innodb_defkey set c1 = c1 + 1;
5565
select count(*) from innodb_compact where c1 < 1500000;
5666
count(*)
5767
2000
@@ -64,6 +74,9 @@ count(*)
6474
select count(*) from innodb_redundant where c1 < 1500000;
6575
count(*)
6676
2000
77+
select count(*) from innodb_defkey where c1 < 1500000;
78+
count(*)
79+
2000
6780
select count(*) from innodb_compact t1, innodb_normal t2 where
6881
t1.c1 = t2.c1 and t1.b = t2.b;
6982
count(*)
@@ -80,6 +93,10 @@ select count(*) from innodb_redundant t1, innodb_normal t2 where
8093
t1.c1 = t2.c1 and t1.b = t2.b;
8194
count(*)
8295
2000
96+
select count(*) from innodb_defkey t1, innodb_normal t2 where
97+
t1.c1 = t2.c1 and t1.b = t2.b;
98+
count(*)
99+
2000
83100
SELECT variable_value >= 0 FROM information_schema.global_status WHERE LOWER(variable_name) = 'innodb_num_pages_page_encrypted';
84101
variable_value >= 0
85102
1
@@ -96,6 +113,7 @@ update innodb_compact set c1 = c1 + 1;
96113
update innodb_compressed set c1 = c1 + 1;
97114
update innodb_dynamic set c1 = c1 + 1;
98115
update innodb_redundant set c1 = c1 + 1;
116+
update innodb_defkey set c1 = c1 + 1;
99117
select count(*) from innodb_compact where c1 < 1500000;
100118
count(*)
101119
2000
@@ -108,6 +126,9 @@ count(*)
108126
select count(*) from innodb_redundant where c1 < 1500000;
109127
count(*)
110128
2000
129+
select count(*) from innodb_defkey where c1 < 1500000;
130+
count(*)
131+
2000
111132
select count(*) from innodb_compact t1, innodb_normal t2 where
112133
t1.c1 = t2.c1 and t1.b = t2.b;
113134
count(*)
@@ -124,6 +145,10 @@ select count(*) from innodb_redundant t1, innodb_normal t2 where
124145
t1.c1 = t2.c1 and t1.b = t2.b;
125146
count(*)
126147
2000
148+
select count(*) from innodb_defkey t1, innodb_normal t2 where
149+
t1.c1 = t2.c1 and t1.b = t2.b;
150+
count(*)
151+
2000
127152
SELECT variable_value >= 0 FROM information_schema.global_status WHERE LOWER(variable_name) = 'innodb_num_pages_page_encrypted';
128153
variable_value >= 0
129154
1
@@ -187,6 +212,12 @@ innodb_redundant CREATE TABLE `innodb_redundant` (
187212
`c1` bigint(20) NOT NULL,
188213
`b` char(200) DEFAULT NULL
189214
) ENGINE=InnoDB DEFAULT CHARSET=latin1 ROW_FORMAT=REDUNDANT
215+
show create table innodb_defkey;
216+
Table Create Table
217+
innodb_defkey CREATE TABLE `innodb_defkey` (
218+
`c1` bigint(20) NOT NULL,
219+
`b` char(200) DEFAULT NULL
220+
) ENGINE=InnoDB DEFAULT CHARSET=latin1 `page_encryption`=1
190221
update innodb_normal set c1 = c1 +1;
191222
update innodb_compact set c1 = c1 + 1;
192223
update innodb_compressed set c1 = c1 + 1;
@@ -235,3 +266,4 @@ drop table innodb_compact;
235266
drop table innodb_compressed;
236267
drop table innodb_dynamic;
237268
drop table innodb_redundant;
269+
drop table innodb_defkey;

mysql-test/suite/innodb/t/innodb-page_encryption.test

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@
44
--disable_query_log
55
let $innodb_file_format_orig = `SELECT @@innodb_file_format`;
66
let $innodb_file_per_table_orig = `SELECT @@innodb_file_per_table`;
7+
let $default_page_encryption_key = `SELECT @@innodb_default_page_encryption_key`;
78
--enable_query_log
89

910
SET GLOBAL innodb_file_format = `Barracuda`;
@@ -15,6 +16,10 @@ create table innodb_compressed(c1 bigint not null, b char(200)) engine=innodb ro
1516
create table innodb_dynamic(c1 bigint not null, b char(200)) engine=innodb row_format=dynamic page_encryption=1 page_encryption_key=3;
1617
create table innodb_redundant(c1 bigint not null, b char(200)) engine=innodb row_format=redundant page_encryption=1 page_encryption_key=4;
1718

19+
SET GLOBAL innodb_default_page_encryption_key = 5;
20+
create table innodb_defkey(c1 bigint not null, b char(200)) engine=innodb page_encryption=1;
21+
show create table innodb_defkey;
22+
1823
show create table innodb_compact;
1924
show create table innodb_compressed;
2025
show create table innodb_dynamic;
@@ -42,16 +47,20 @@ insert into innodb_compact select * from innodb_normal;
4247
insert into innodb_compressed select * from innodb_normal;
4348
insert into innodb_dynamic select * from innodb_normal;
4449
insert into innodb_redundant select * from innodb_normal;
50+
insert into innodb_defkey select * from innodb_normal;
4551

4652
update innodb_normal set c1 = c1 +1;
4753
update innodb_compact set c1 = c1 + 1;
4854
update innodb_compressed set c1 = c1 + 1;
4955
update innodb_dynamic set c1 = c1 + 1;
5056
update innodb_redundant set c1 = c1 + 1;
57+
update innodb_defkey set c1 = c1 + 1;
58+
5159
select count(*) from innodb_compact where c1 < 1500000;
5260
select count(*) from innodb_compressed where c1 < 1500000;
5361
select count(*) from innodb_dynamic where c1 < 1500000;
5462
select count(*) from innodb_redundant where c1 < 1500000;
63+
select count(*) from innodb_defkey where c1 < 1500000;
5564
select count(*) from innodb_compact t1, innodb_normal t2 where
5665
t1.c1 = t2.c1 and t1.b = t2.b;
5766
select count(*) from innodb_dynamic t1, innodb_normal t2 where
@@ -60,6 +69,8 @@ select count(*) from innodb_compressed t1, innodb_normal t2 where
6069
t1.c1 = t2.c1 and t1.b = t2.b;
6170
select count(*) from innodb_redundant t1, innodb_normal t2 where
6271
t1.c1 = t2.c1 and t1.b = t2.b;
72+
select count(*) from innodb_defkey t1, innodb_normal t2 where
73+
t1.c1 = t2.c1 and t1.b = t2.b;
6374

6475
# Note there that these variables are updated only when real I/O is done, thus they are not reliable
6576
SELECT variable_value >= 0 FROM information_schema.global_status WHERE LOWER(variable_name) = 'innodb_num_pages_page_encrypted';
@@ -76,10 +87,12 @@ update innodb_compact set c1 = c1 + 1;
7687
update innodb_compressed set c1 = c1 + 1;
7788
update innodb_dynamic set c1 = c1 + 1;
7889
update innodb_redundant set c1 = c1 + 1;
90+
update innodb_defkey set c1 = c1 + 1;
7991
select count(*) from innodb_compact where c1 < 1500000;
8092
select count(*) from innodb_compressed where c1 < 1500000;
8193
select count(*) from innodb_dynamic where c1 < 1500000;
8294
select count(*) from innodb_redundant where c1 < 1500000;
95+
select count(*) from innodb_defkey where c1 < 1500000;
8396
select count(*) from innodb_compact t1, innodb_normal t2 where
8497
t1.c1 = t2.c1 and t1.b = t2.b;
8598
select count(*) from innodb_dynamic t1, innodb_normal t2 where
@@ -88,6 +101,8 @@ select count(*) from innodb_compressed t1, innodb_normal t2 where
88101
t1.c1 = t2.c1 and t1.b = t2.b;
89102
select count(*) from innodb_redundant t1, innodb_normal t2 where
90103
t1.c1 = t2.c1 and t1.b = t2.b;
104+
select count(*) from innodb_defkey t1, innodb_normal t2 where
105+
t1.c1 = t2.c1 and t1.b = t2.b;
91106

92107
SELECT variable_value >= 0 FROM information_schema.global_status WHERE LOWER(variable_name) = 'innodb_num_pages_page_encrypted';
93108
SELECT variable_value >= 0 FROM information_schema.global_status WHERE LOWER(variable_name) = 'innodb_num_pages_page_decrypted';
@@ -111,6 +126,7 @@ show create table innodb_compact;
111126
show create table innodb_compressed;
112127
show create table innodb_dynamic;
113128
show create table innodb_redundant;
129+
show create table innodb_defkey;
114130

115131
update innodb_normal set c1 = c1 +1;
116132
update innodb_compact set c1 = c1 + 1;
@@ -141,9 +157,11 @@ drop table innodb_compact;
141157
drop table innodb_compressed;
142158
drop table innodb_dynamic;
143159
drop table innodb_redundant;
160+
drop table innodb_defkey;
144161

145162
# reset system
146163
--disable_query_log
147164
EVAL SET GLOBAL innodb_file_per_table = $innodb_file_per_table_orig;
148165
EVAL SET GLOBAL innodb_file_format = $innodb_file_format_orig;
166+
EVAL SET GLOBAL innodb_default_page_encryption_key = $default_page_encryption_key;
149167
--enable_query_log
Lines changed: 71 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,71 @@
1+
SET @start_global_value = @@global.innodb_default_page_encryption_key;
2+
SELECT @start_global_value;
3+
@start_global_value
4+
1
5+
Valid value 0-9
6+
select @@global.innodb_default_page_encryption_key <= 9;
7+
@@global.innodb_default_page_encryption_key <= 9
8+
1
9+
select @@global.innodb_default_page_encryption_key;
10+
@@global.innodb_default_page_encryption_key
11+
1
12+
select @@session.innodb_default_page_encryption_key;
13+
ERROR HY000: Variable 'innodb_default_page_encryption_key' is a GLOBAL variable
14+
show global variables like 'innodb_default_page_encryption_key';
15+
Variable_name Value
16+
innodb_default_page_encryption_key 1
17+
show session variables like 'innodb_default_page_encryption_key';
18+
Variable_name Value
19+
innodb_default_page_encryption_key 1
20+
select * from information_schema.global_variables where variable_name='innodb_default_page_encryption_key';
21+
VARIABLE_NAME VARIABLE_VALUE
22+
INNODB_DEFAULT_PAGE_ENCRYPTION_KEY 1
23+
select * from information_schema.session_variables where variable_name='innodb_default_page_encryption_key';
24+
VARIABLE_NAME VARIABLE_VALUE
25+
INNODB_DEFAULT_PAGE_ENCRYPTION_KEY 1
26+
set global innodb_default_page_encryption_key=2;
27+
select @@global.innodb_default_page_encryption_key;
28+
@@global.innodb_default_page_encryption_key
29+
2
30+
select * from information_schema.global_variables where variable_name='innodb_default_page_encryption_key';
31+
VARIABLE_NAME VARIABLE_VALUE
32+
INNODB_DEFAULT_PAGE_ENCRYPTION_KEY 2
33+
select * from information_schema.session_variables where variable_name='innodb_default_page_encryption_key';
34+
VARIABLE_NAME VARIABLE_VALUE
35+
INNODB_DEFAULT_PAGE_ENCRYPTION_KEY 2
36+
set session innodb_default_page_encryption_key=4;
37+
ERROR HY000: Variable 'innodb_default_page_encryption_key' is a GLOBAL variable and should be set with SET GLOBAL
38+
set global innodb_default_page_encryption_key=1.1;
39+
ERROR 42000: Incorrect argument type to variable 'innodb_default_page_encryption_key'
40+
set global innodb_default_page_encryption_key=1e1;
41+
ERROR 42000: Incorrect argument type to variable 'innodb_default_page_encryption_key'
42+
set global innodb_default_page_encryption_key="foo";
43+
ERROR 42000: Incorrect argument type to variable 'innodb_default_page_encryption_key'
44+
set global innodb_default_page_encryption_key=10;
45+
select @@global.innodb_default_page_encryption_key;
46+
@@global.innodb_default_page_encryption_key
47+
10
48+
select * from information_schema.global_variables where variable_name='innodb_default_page_encryption_key';
49+
VARIABLE_NAME VARIABLE_VALUE
50+
INNODB_DEFAULT_PAGE_ENCRYPTION_KEY 10
51+
set global innodb_default_page_encryption_key=-7;
52+
Warnings:
53+
Warning 1292 Truncated incorrect innodb_default_page_encryption_k value: '-7'
54+
select @@global.innodb_default_page_encryption_key;
55+
@@global.innodb_default_page_encryption_key
56+
1
57+
select * from information_schema.global_variables where variable_name='innodb_default_page_encryption_key';
58+
VARIABLE_NAME VARIABLE_VALUE
59+
INNODB_DEFAULT_PAGE_ENCRYPTION_KEY 1
60+
set global innodb_default_page_encryption_key=1;
61+
select @@global.innodb_default_page_encryption_key;
62+
@@global.innodb_default_page_encryption_key
63+
1
64+
set global innodb_default_page_encryption_key=255;
65+
select @@global.innodb_default_page_encryption_key;
66+
@@global.innodb_default_page_encryption_key
67+
255
68+
SET @@global.innodb_default_page_encryption_key = @start_global_value;
69+
SELECT @@global.innodb_default_page_encryption_key;
70+
@@global.innodb_default_page_encryption_key
71+
1

mysql-test/suite/sys_vars/r/sysvars_innodb.result

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -565,6 +565,20 @@ NUMERIC_BLOCK_SIZE NULL
565565
ENUM_VALUE_LIST NULL
566566
READ_ONLY YES
567567
COMMAND_LINE_ARGUMENT REQUIRED
568+
VARIABLE_NAME INNODB_DEFAULT_PAGE_ENCRYPTION_KEY
569+
SESSION_VALUE NULL
570+
GLOBAL_VALUE 1
571+
GLOBAL_VALUE_ORIGIN COMPILE-TIME
572+
DEFAULT_VALUE 1
573+
VARIABLE_SCOPE GLOBAL
574+
VARIABLE_TYPE INT UNSIGNED
575+
VARIABLE_COMMENT Encryption key used for page encryption.
576+
NUMERIC_MIN_VALUE 1
577+
NUMERIC_MAX_VALUE 255
578+
NUMERIC_BLOCK_SIZE 0
579+
ENUM_VALUE_LIST NULL
580+
READ_ONLY NO
581+
COMMAND_LINE_ARGUMENT REQUIRED
568582
VARIABLE_NAME INNODB_DEFRAGMENT
569583
SESSION_VALUE NULL
570584
GLOBAL_VALUE OFF
Lines changed: 60 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,60 @@
1+
2+
--source include/have_innodb.inc
3+
4+
SET @start_global_value = @@global.innodb_default_page_encryption_key;
5+
SELECT @start_global_value;
6+
7+
#
8+
# exists as global only
9+
#
10+
--echo Valid value 0-9
11+
select @@global.innodb_default_page_encryption_key <= 9;
12+
select @@global.innodb_default_page_encryption_key;
13+
--error ER_INCORRECT_GLOBAL_LOCAL_VAR
14+
select @@session.innodb_default_page_encryption_key;
15+
show global variables like 'innodb_default_page_encryption_key';
16+
show session variables like 'innodb_default_page_encryption_key';
17+
select * from information_schema.global_variables where variable_name='innodb_default_page_encryption_key';
18+
select * from information_schema.session_variables where variable_name='innodb_default_page_encryption_key';
19+
20+
#
21+
# show that it's writable
22+
#
23+
set global innodb_default_page_encryption_key=2;
24+
select @@global.innodb_default_page_encryption_key;
25+
select * from information_schema.global_variables where variable_name='innodb_default_page_encryption_key';
26+
select * from information_schema.session_variables where variable_name='innodb_default_page_encryption_key';
27+
--error ER_GLOBAL_VARIABLE
28+
set session innodb_default_page_encryption_key=4;
29+
30+
#
31+
# incorrect types
32+
#
33+
--error ER_WRONG_TYPE_FOR_VAR
34+
set global innodb_default_page_encryption_key=1.1;
35+
--error ER_WRONG_TYPE_FOR_VAR
36+
set global innodb_default_page_encryption_key=1e1;
37+
--error ER_WRONG_TYPE_FOR_VAR
38+
set global innodb_default_page_encryption_key="foo";
39+
40+
set global innodb_default_page_encryption_key=10;
41+
select @@global.innodb_default_page_encryption_key;
42+
select * from information_schema.global_variables where variable_name='innodb_default_page_encryption_key';
43+
set global innodb_default_page_encryption_key=-7;
44+
select @@global.innodb_default_page_encryption_key;
45+
select * from information_schema.global_variables where variable_name='innodb_default_page_encryption_key';
46+
47+
#
48+
# min/max values
49+
#
50+
set global innodb_default_page_encryption_key=1;
51+
select @@global.innodb_default_page_encryption_key;
52+
set global innodb_default_page_encryption_key=255;
53+
select @@global.innodb_default_page_encryption_key;
54+
55+
#
56+
# cleanup
57+
#
58+
59+
SET @@global.innodb_default_page_encryption_key = @start_global_value;
60+
SELECT @@global.innodb_default_page_encryption_key;

0 commit comments

Comments
 (0)