Skip to content

Commit 0ffc433

Browse files
committed
BUG##30787535 : FULLTEXT INDEX TABLES CREATED IN ENCRYPTED SCHEMA ARE NOT
ENCRYPTED Issue: When in an encrypted table, an FTS index is created, there are some aux tables (thus tablespaces with ibd files) are created for FTS. If the table is encrypted, then the FTS tablespaces are supposed to be encrypted too, which were not. Cause: When FTS aux tables are created, for those tables, flags are borrowed from main table. While copying those flags, encryption flag was not copied, thus aux tables were always created as not encrypted. Fix: Made sure that when the table flags are being copied for aux tables for FTS, encryption flag is also copied. RB : 23906 Reviewed-by : Rahul Agarkar <[email protected]>
1 parent cae4d41 commit 0ffc433

File tree

3 files changed

+127
-1
lines changed

3 files changed

+127
-1
lines changed
Lines changed: 45 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,45 @@
1+
#
2+
# Bug#30787535 : FULLTEXT INDEX TABLES CREATED IN ENCRYPTED SCHEMA ARE NOT ENCRYPTED
3+
#
4+
#########
5+
# SETUP #
6+
#########
7+
8+
#########################################################################
9+
# RESTART 1 : WITH KEYRING PLUGIN
10+
#########################################################################
11+
# Create a new 'unencrypted' table
12+
CREATE TABLE t1 (id INT UNSIGNED AUTO_INCREMENT NOT NULL PRIMARY KEY,
13+
C1 TEXT(500),
14+
C2 VARCHAR(200),
15+
C3 VARCHAR(200)) ENCRYPTION='N' ENGINE=InnoDB;
16+
set global innodb_buf_flush_list_now = 1;
17+
# ---------------------------------------------------------------
18+
# Test 1 : t1 un-encrypted, FTS tables should also be unencrypted
19+
# ---------------------------------------------------------------
20+
# Check that tablespace file is not encrypted
21+
# Print result
22+
table space is Unencrypted.
23+
CREATE FULLTEXT INDEX idx ON t1(C1);
24+
Warnings:
25+
Warning 124 InnoDB rebuilding table to add column FTS_DOC_ID
26+
set global innodb_buf_flush_list_now = 1;
27+
# Check that FTS tablespaces file is not encrypted
28+
# Print result
29+
table space is Unencrypted.
30+
# ---------------------------------------------------------------
31+
# Test 1 : t1 encrypted, FTS tables should also be unencrypted
32+
# ---------------------------------------------------------------
33+
ALTER TABLE t1 ENCRYPTION='Y';
34+
# Check that tablespace file is encrypted now
35+
# Print result
36+
table space is Encrypted.
37+
# Check that FTS tablespace file is encrypted now
38+
# Print result
39+
table space is Encrypted.
40+
###########
41+
# CLEANUP #
42+
###########
43+
DROP TABLE test.t1;
44+
# Restarting server without keyring to restore server state
45+
# restart:
Lines changed: 80 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,80 @@
1+
--echo #
2+
--echo # Bug#30787535 : FULLTEXT INDEX TABLES CREATED IN ENCRYPTED SCHEMA ARE NOT ENCRYPTED
3+
--echo #
4+
5+
################################################################################
6+
# For an encrypted table, this test case checks physical ibd file for :
7+
# - table
8+
# - fts table created for an FTS index on table
9+
# - Other aux tables created for FTS index
10+
# to see if they are encrypted.
11+
################################################################################
12+
# Disable in valgrind because of timeout, cf. Bug#22760145
13+
--source include/not_valgrind.inc
14+
# Waiting time when (re)starting the server
15+
--let $explicit_default_wait_counter=10000;
16+
17+
--echo #########
18+
--echo # SETUP #
19+
--echo #########
20+
--echo
21+
let datadir=`SELECT @@datadir`;
22+
let search_pattern=supremum;
23+
24+
--echo #########################################################################
25+
--echo # RESTART 1 : WITH KEYRING PLUGIN
26+
--echo #########################################################################
27+
let $restart_parameters = restart: --early-plugin-load=keyring_file=$KEYRING_PLUGIN --loose-keyring_file_data=$MYSQL_TMP_DIR/mysecret_keyring $KEYRING_PLUGIN_OPT;
28+
--source include/restart_mysqld_no_echo.inc
29+
30+
--echo # Create a new 'unencrypted' table
31+
CREATE TABLE t1 (id INT UNSIGNED AUTO_INCREMENT NOT NULL PRIMARY KEY,
32+
C1 TEXT(500),
33+
C2 VARCHAR(200),
34+
C3 VARCHAR(200)) ENCRYPTION='N' ENGINE=InnoDB;
35+
36+
# Make sure all pages are flushed
37+
set global innodb_buf_flush_list_now = 1;
38+
39+
--echo # ---------------------------------------------------------------
40+
--echo # Test 1 : t1 un-encrypted, FTS tables should also be unencrypted
41+
--echo # ---------------------------------------------------------------
42+
--echo # Check that tablespace file is not encrypted
43+
--let ts_name=test/t1.ibd
44+
--source include/if_encrypted.inc
45+
46+
CREATE FULLTEXT INDEX idx ON t1(C1);
47+
48+
# Make sure all pages are flushed
49+
set global innodb_buf_flush_list_now = 1;
50+
51+
--let ts_name = `select NAME from information_schema.innodb_tables where name like "%index_1%";`
52+
--let ts_name = $ts_name.ibd
53+
--echo # Check that FTS tablespaces file is not encrypted
54+
--source include/if_encrypted.inc
55+
56+
--echo # ---------------------------------------------------------------
57+
--echo # Test 1 : t1 encrypted, FTS tables should also be unencrypted
58+
--echo # ---------------------------------------------------------------
59+
# Now, change the encryption property of table
60+
ALTER TABLE t1 ENCRYPTION='Y';
61+
62+
--echo # Check that tablespace file is encrypted now
63+
--let ts_name=test/t1.ibd
64+
--source include/if_encrypted.inc
65+
66+
--let ts_name = `select NAME from information_schema.innodb_tables where name like "%index_1%";`
67+
--let ts_name = $ts_name.ibd
68+
--echo # Check that FTS tablespace file is encrypted now
69+
--source include/if_encrypted.inc
70+
71+
--echo ###########
72+
--echo # CLEANUP #
73+
--echo ###########
74+
DROP TABLE test.t1;
75+
remove_file $MYSQLTEST_VARDIR/tmpfile.txt;
76+
remove_file $MYSQL_TMP_DIR/mysecret_keyring;
77+
78+
--echo # Restarting server without keyring to restore server state
79+
let $restart_parameters = restart: ;
80+
--source include/restart_mysqld.inc

storage/innobase/fts/fts0fts.cc

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1758,9 +1758,10 @@ tables.
17581758
@param[in] flags2 Table flags2
17591759
@return extracted flags2 for FTS aux tables */
17601760
static inline uint32_t fts_get_table_flags2_for_aux_tables(uint32_t flags2) {
1761-
/* Extract the file_per_table flag & temporary file flag
1761+
/* Extract the file_per_table flag, temporary file flag and encryption flag
17621762
from the main FTS table flags2 */
17631763
return ((flags2 & DICT_TF2_USE_FILE_PER_TABLE) |
1764+
(flags2 & DICT_TF2_ENCRYPTION_FILE_PER_TABLE) |
17641765
(flags2 & DICT_TF2_TEMPORARY) | DICT_TF2_AUX);
17651766
}
17661767

0 commit comments

Comments
 (0)