Skip to content

Commit 3118a65

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 : 23923 Reviewed-by : Rahul Agarkar <[email protected]>
1 parent ffe10c0 commit 3118a65

File tree

4 files changed

+167
-2
lines changed

4 files changed

+167
-2
lines changed
Lines changed: 36 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,36 @@
1+
#################### Perl module starts ####################
2+
perl;
3+
my $d_dir = $ENV{'datadir'};
4+
my $s_pattern = $ENV{'search_pattern'};
5+
my $filename = $ENV{'ts_name'};
6+
my $ts_filename="$d_dir/$filename";
7+
open TS_FILE, "<$ts_filename" or die "$!";
8+
@lines = <TS_FILE>;
9+
close TS_FILE;
10+
11+
my $vardir = $ENV{'MYSQLTEST_VARDIR'};
12+
my $filename="$vardir/tmpfile.txt";
13+
open(OP_FILE, '>', $filename) or die "$!";
14+
15+
my $found = 0;
16+
foreach $line (@lines) {
17+
chomp( $line );
18+
print OP_FILE;
19+
if($line =~ /$s_pattern/) {
20+
$found=1;
21+
}
22+
}
23+
24+
if ($found == 1) {
25+
print OP_FILE "table space is Unencrypted.\n";
26+
} else {
27+
print OP_FILE "table space is Encrypted.\n";
28+
}
29+
30+
close OP_FILE;
31+
EOF
32+
#################### Perl module ends ####################
33+
34+
--echo # Print result
35+
cat_file $MYSQLTEST_VARDIR/tmpfile.txt;
36+
Lines changed: 46 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,46 @@
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+
# restart: --early-plugin-load=keyring_file=keyring_file.so --loose-keyring_file_data=MYSQL_TMP_DIR/mysecret_keyring --plugin-dir=KEYRING_PLUGIN_PATH
12+
# Create a new 'unencrypted' table
13+
CREATE TABLE t1 (id INT UNSIGNED AUTO_INCREMENT NOT NULL PRIMARY KEY,
14+
C1 TEXT(500),
15+
C2 VARCHAR(200),
16+
C3 VARCHAR(200)) ENCRYPTION='N' ENGINE=InnoDB;
17+
set global innodb_buf_flush_list_now = 1;
18+
# ---------------------------------------------------------------
19+
# Test 1 : t1 un-encrypted, FTS tables should also be unencrypted
20+
# ---------------------------------------------------------------
21+
# Check that tablespace file is not encrypted
22+
# Print result
23+
table space is Unencrypted.
24+
CREATE FULLTEXT INDEX idx ON t1(C1);
25+
Warnings:
26+
Warning 124 InnoDB rebuilding table to add column FTS_DOC_ID
27+
set global innodb_buf_flush_list_now = 1;
28+
# Check that FTS tablespaces file is not encrypted
29+
# Print result
30+
table space is Unencrypted.
31+
# ---------------------------------------------------------------
32+
# Test 1 : t1 encrypted, FTS tables should also be unencrypted
33+
# ---------------------------------------------------------------
34+
ALTER TABLE t1 ENCRYPTION='Y';
35+
# Check that tablespace file is encrypted now
36+
# Print result
37+
table space is Encrypted.
38+
# Check that FTS tablespace file is encrypted now
39+
# Print result
40+
table space is Encrypted.
41+
###########
42+
# CLEANUP #
43+
###########
44+
DROP TABLE test.t1;
45+
# Restarting server without keyring to restore server state
46+
# restart:
Lines changed: 82 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,82 @@
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+
--replace_result $MYSQL_TMP_DIR MYSQL_TMP_DIR $KEYRING_PLUGIN_OPT --plugin-dir=KEYRING_PLUGIN_PATH $KEYRING_PLUGIN keyring_file.so
29+
--replace_regex /\.dll/.so/
30+
--source include/restart_mysqld.inc
31+
32+
--echo # Create a new 'unencrypted' table
33+
CREATE TABLE t1 (id INT UNSIGNED AUTO_INCREMENT NOT NULL PRIMARY KEY,
34+
C1 TEXT(500),
35+
C2 VARCHAR(200),
36+
C3 VARCHAR(200)) ENCRYPTION='N' ENGINE=InnoDB;
37+
38+
# Make sure all pages are flushed
39+
set global innodb_buf_flush_list_now = 1;
40+
41+
--echo # ---------------------------------------------------------------
42+
--echo # Test 1 : t1 un-encrypted, FTS tables should also be unencrypted
43+
--echo # ---------------------------------------------------------------
44+
--echo # Check that tablespace file is not encrypted
45+
--let ts_name=test/t1.ibd
46+
--source include/if_encrypted.inc
47+
48+
CREATE FULLTEXT INDEX idx ON t1(C1);
49+
50+
# Make sure all pages are flushed
51+
set global innodb_buf_flush_list_now = 1;
52+
53+
--let ts_name = `select NAME from information_schema.innodb_sys_tables where name like "%INDEX_1%";`
54+
--let ts_name = $ts_name.ibd
55+
--echo # Check that FTS tablespaces file is not encrypted
56+
--source include/if_encrypted.inc
57+
58+
--echo # ---------------------------------------------------------------
59+
--echo # Test 1 : t1 encrypted, FTS tables should also be unencrypted
60+
--echo # ---------------------------------------------------------------
61+
# Now, change the encryption property of table
62+
ALTER TABLE t1 ENCRYPTION='Y';
63+
64+
--echo # Check that tablespace file is encrypted now
65+
--let ts_name=test/t1.ibd
66+
--source include/if_encrypted.inc
67+
68+
--let ts_name = `select NAME from information_schema.innodb_sys_tables where name like "%INDEX_1%";`
69+
--let ts_name = $ts_name.ibd
70+
--echo # Check that FTS tablespace file is encrypted now
71+
--source include/if_encrypted.inc
72+
73+
--echo ###########
74+
--echo # CLEANUP #
75+
--echo ###########
76+
DROP TABLE test.t1;
77+
remove_file $MYSQLTEST_VARDIR/tmpfile.txt;
78+
remove_file $MYSQL_TMP_DIR/mysecret_keyring;
79+
80+
--echo # Restarting server without keyring to restore server state
81+
let $restart_parameters = restart: ;
82+
--source include/restart_mysqld.inc

storage/innobase/fts/fts0fts.cc

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1782,9 +1782,10 @@ ulint
17821782
fts_get_table_flags2_for_aux_tables(
17831783
ulint flags2)
17841784
{
1785-
/* Extract the file_per_table flag & temporary file flag
1786-
from the main FTS table flags2 */
1785+
/* Extract the file_per_table flag, temporary file flag and
1786+
encryption flag from the main FTS table flags2 */
17871787
return((flags2 & DICT_TF2_USE_FILE_PER_TABLE) |
1788+
(flags2 & DICT_TF2_ENCRYPTION) |
17881789
(flags2 & DICT_TF2_TEMPORARY));
17891790
}
17901791

0 commit comments

Comments
 (0)