Skip to content

Commit

Permalink
Merge pull request #3993 from georgelorchpercona/ps-5.7-7238
Browse files Browse the repository at this point in the history
PS-7238 - Backport Data Masking plugin to 5.7
  • Loading branch information
georgelorchpercona authored Sep 4, 2020
2 parents 35567b5 + e60308f commit e9542d4
Show file tree
Hide file tree
Showing 57 changed files with 2,325 additions and 2 deletions.
3 changes: 2 additions & 1 deletion mysql-test/include/plugin.defs
Original file line number Diff line number Diff line change
Expand Up @@ -48,6 +48,7 @@ mypluglib plugin/fulltext SIMPLE_PARSER
libpluginmecab plugin/fulltext MECAB
keyring_file plugin/keyring KEYRING_PLUGIN keyring_file
keyring_udf plugin/keyring_udf KEYRING_UDF keyring_udf
data_masking plugin/data_masking DATA_MASKING_PLUGIN data_masking
adt_null plugin/audit_null AUDIT_NULL
test_security_context plugin/audit_null TEST_SECURITY_CONTEXT test_security_context
libdaemon_example plugin/daemon_example DAEMONEXAMPLE
Expand Down Expand Up @@ -95,4 +96,4 @@ ha_tokudb storage/tokudb TOKUDB tokudb,tokudb_tr
tokudb_backup plugin/tokudb-backup-plugin TOKUDB_BACKUP tokudb_backup
ha_rocksdb storage/rocksdb ROCKSDB rocksdb,rocksdb_cfstats,rocksdb_dbstats,rocksdb_perf_context,rocksdb_perf_context_global,rocksdb_cf_options,rocksdb_compaction_stats,rocksdb_global_info,rocksdb_ddl,rocksdb_index_file_map,rocksdb_locks,rocksdb_trx,rocksdb_deadlock,rocksdb_sst_props
auth_pam plugin/percona-pam-for-mysql AUTH_PAM
auth_pam_compat plugin/percona-pam-for-mysql AUTH_PAM_COMPAT
auth_pam_compat plugin/percona-pam-for-mysql AUTH_PAM_COMPAT
3 changes: 2 additions & 1 deletion mysql-test/mysql-test-run.pl
Original file line number Diff line number Diff line change
Expand Up @@ -204,7 +204,8 @@ sub set_term_args {
."tokudb.add_index,tokudb.alter_table,tokudb,tokudb.bugs,tokudb.parts,"
."tokudb.rpl,tokudb.perfschema,"
."rocksdb,rocksdb_rpl,rocksdb_sys_vars,"
."keyring_vault,audit_null,percona-pam-for-mysql";
."keyring_vault,audit_null,percona-pam-for-mysql,data_masking";

my $opt_suites;

our $opt_verbose= 0; # Verbose output, enable with --verbose
Expand Down
3 changes: 3 additions & 0 deletions mysql-test/std_data/data_masking/de_cities.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
Berlin
Munich
Bremen
4 changes: 4 additions & 0 deletions mysql-test/std_data/data_masking/us_cities.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
Houston
Phoenix
El Paso
Detroit
24 changes: 24 additions & 0 deletions mysql-test/suite/data_masking/r/gen_blacklist.result
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
#
# Plugin Data Masking: gen_blacklist
#
CREATE FUNCTION gen_blacklist RETURNS STRING SONAME 'data_masking.so';
CREATE FUNCTION gen_dictionary_drop RETURNS STRING SONAME 'data_masking.so';
CREATE FUNCTION gen_dictionary_load RETURNS STRING SONAME 'data_masking.so';
SELECT gen_dictionary_load('../../std_data/data_masking/de_cities.txt', 'de_cities');
gen_dictionary_load('../../std_data/data_masking/de_cities.txt', 'de_cities')
Dictionary load success
SELECT gen_dictionary_load('../../std_data/data_masking/us_cities.txt', 'us_cities');
gen_dictionary_load('../../std_data/data_masking/us_cities.txt', 'us_cities')
Dictionary load success
SELECT gen_blacklist('Moscow', 'DE_Cities', 'US_Cities');
gen_blacklist('Moscow', 'DE_Cities', 'US_Cities')
Moscow
SELECT gen_dictionary_drop('de_cities');
gen_dictionary_drop('de_cities')
Dictionary removed
SELECT gen_dictionary_drop('us_cities');
gen_dictionary_drop('us_cities')
Dictionary removed
DROP FUNCTION gen_dictionary_load;
DROP FUNCTION gen_dictionary_drop;
DROP FUNCTION gen_blacklist;
19 changes: 19 additions & 0 deletions mysql-test/suite/data_masking/r/gen_dictionary_drop.result
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
#
# Plugin Data Masking: gen_dictionary_drop
#
CREATE FUNCTION gen_dictionary_drop RETURNS STRING SONAME 'data_masking.so';
CREATE FUNCTION gen_dictionary_load RETURNS STRING SONAME 'data_masking.so';
SELECT gen_dictionary_drop('de_cities');
gen_dictionary_drop('de_cities')
Dictionary removal error: dictionary not present in global list
SELECT gen_dictionary_load('../../std_data/data_masking/de_cities.txt', 'de_cities');
gen_dictionary_load('../../std_data/data_masking/de_cities.txt', 'de_cities')
Dictionary load success
SELECT gen_dictionary_drop('de_cities');
gen_dictionary_drop('de_cities')
Dictionary removed
SELECT gen_dictionary_drop('de_cities');
gen_dictionary_drop('de_cities')
Dictionary removal error: dictionary not present in global list
DROP FUNCTION gen_dictionary_load;
DROP FUNCTION gen_dictionary_drop;
14 changes: 14 additions & 0 deletions mysql-test/suite/data_masking/r/gen_dictionary_load.result
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
#
# Plugin Data Masking: gen_dictionary_load
#
CREATE FUNCTION gen_dictionary_load RETURNS STRING SONAME 'data_masking.so';
SELECT gen_dictionary_load('de_cities.txt', 'de_cities');
gen_dictionary_load('de_cities.txt', 'de_cities')
Dictionary load error: dictionary file not readable
SELECT gen_dictionary_load('../../std_data/data_masking/de_cities.txt', 'de_cities');
gen_dictionary_load('../../std_data/data_masking/de_cities.txt', 'de_cities')
Dictionary load success
SELECT gen_dictionary_load('../../std_data/data_masking/de_cities.txt', 'de_cities');
gen_dictionary_load('../../std_data/data_masking/de_cities.txt', 'de_cities')
Dictionary load error: a dictionary with that name already exists
DROP FUNCTION gen_dictionary_load;
32 changes: 32 additions & 0 deletions mysql-test/suite/data_masking/r/mask_inner.result
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
#
# Plugin Data Masking: mask_inner
#
CREATE FUNCTION mask_inner RETURNS STRING SONAME 'data_masking.so';
SELECT mask_inner('This is a string', 5, 1);
mask_inner('This is a string', 5, 1)
This XXXXXXXXXXg
SELECT mask_inner('This is a string', 1, 5);
mask_inner('This is a string', 1, 5)
TXXXXXXXXXXtring
SELECT mask_inner('This is a string', 5, 1, '#');
mask_inner('This is a string', 5, 1, '#')
This ##########g
SELECT mask_inner(NULL, 1, 2);
mask_inner(NULL, 1, 2)
NULL
SELECT mask_inner(NULL, 1, 2, '#');
mask_inner(NULL, 1, 2, '#')
NULL
SELECT mask_inner('This is a string', -1, 5);
mask_inner('This is a string', -1, 5)
NULL
SELECT mask_inner('This is a string', 1, -5);
mask_inner('This is a string', 1, -5)
NULL
SELECT mask_inner('This is a string', 1, 25);
mask_inner('This is a string', 1, 25)
This is a string
SELECT mask_inner('This is a string', 100, 500);
mask_inner('This is a string', 100, 500)
This is a string
DROP FUNCTION mask_inner;
32 changes: 32 additions & 0 deletions mysql-test/suite/data_masking/r/mask_outer.result
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
#
# Plugin Data Masking: mask_outer
#
CREATE FUNCTION mask_outer RETURNS STRING SONAME 'data_masking.so';
SELECT mask_outer('This is a string', 5, 1);
mask_outer('This is a string', 5, 1)
XXXXXis a strinX
SELECT mask_outer('This is a string', 1, 5);
mask_outer('This is a string', 1, 5)
Xhis is a sXXXXX
SELECT mask_outer('This is a string', 5, 1, '#');
mask_outer('This is a string', 5, 1, '#')
#####is a strin#
SELECT mask_outer(NULL, 5, 1);
mask_outer(NULL, 5, 1)
NULL
SELECT mask_outer(NULL, 5, 1, '#');
mask_outer(NULL, 5, 1, '#')
NULL
SELECT mask_outer('This is a string', -1, 5);
mask_outer('This is a string', -1, 5)
NULL
SELECT mask_outer('This is a string', 1, -5);
mask_outer('This is a string', 1, -5)
NULL
SELECT mask_outer('This is a string', 1, 25);
mask_outer('This is a string', 1, 25)
Xhis is a string
SELECT mask_outer('This is a string', 100, 500);
mask_outer('This is a string', 100, 500)
XXXXXXXXXXXXXXXX
DROP FUNCTION mask_outer;
23 changes: 23 additions & 0 deletions mysql-test/suite/data_masking/r/mask_pan.result
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
#
# Plugin Data Masking: mask_pan
#
CREATE FUNCTION mask_pan RETURNS STRING SONAME 'data_masking.so';
SELECT mask_pan("1234567890122461");
mask_pan("1234567890122461")
XXXXXXXXXXXX2461
SELECT mask_pan("123456789012246");
mask_pan("123456789012246")
XXXXXXXXXXX2246
SELECT mask_pan(NULL);
mask_pan(NULL)
NULL
SELECT mask_pan("");
mask_pan("")
NULL
SELECT mask_pan("123496798465498779");
mask_pan("123496798465498779")
123496798465498779
SELECT mask_pan("this is not a pan");
mask_pan("this is not a pan")
this is not a pan
DROP FUNCTION mask_pan;
23 changes: 23 additions & 0 deletions mysql-test/suite/data_masking/r/mask_pan_relaxed.result
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
#
# Plugin Data Masking: mask_pan_relaxed
#
CREATE FUNCTION mask_pan_relaxed RETURNS STRING SONAME 'data_masking.so';
SELECT mask_pan_relaxed("1234567890122461");
mask_pan_relaxed("1234567890122461")
123456XXXXXX2461
SELECT mask_pan_relaxed("123456789012246");
mask_pan_relaxed("123456789012246")
123456XXXXX2246
SELECT mask_pan_relaxed(NULL);
mask_pan_relaxed(NULL)
NULL
SELECT mask_pan_relaxed("");
mask_pan_relaxed("")

SELECT mask_pan_relaxed("123496798465498779");
mask_pan_relaxed("123496798465498779")
123496798465498779
SELECT mask_pan_relaxed("this is not a pan");
mask_pan_relaxed("this is not a pan")
this is not a pan
DROP FUNCTION mask_pan_relaxed;
20 changes: 20 additions & 0 deletions mysql-test/suite/data_masking/r/mask_ssn.result
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
#
# Plugin Data Masking: mask_ssn
#
CREATE FUNCTION mask_ssn RETURNS STRING SONAME 'data_masking.so';
SELECT mask_ssn("123-45-6789");
mask_ssn("123-45-6789")
XXX-XX-6789
SELECT mask_ssn(NULL);
mask_ssn(NULL)
NULL
SELECT mask_ssn("");
mask_ssn("")
NULL
SELECT mask_ssn("123496798465498779");
mask_ssn("123496798465498779")
NULL
SELECT mask_ssn("this is not an ssn");
mask_ssn("this is not an ssn")
NULL
DROP FUNCTION mask_ssn;
13 changes: 13 additions & 0 deletions mysql-test/suite/data_masking/r/view.result
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
#
# Plugin Data Masking: view
#
CREATE FUNCTION mask_ssn RETURNS STRING SONAME 'data_masking.so';
CREATE TABLE customer (id BIGINT UNSIGNED AUTO_INCREMENT NOT NULL PRIMARY KEY, ssn VARCHAR(11), first_name VARCHAR(100), last_name VARCHAR(100));
INSERT INTO customer (ssn, first_name, last_name) VALUES ('123-45-0007', 'Joanna', 'Bond');
CREATE VIEW masked_customer AS SELECT id, first_name, last_name, mask_ssn(CONVERT(ssn USING binary)) AS ssn FROM customer;
SELECT id, ssn FROM masked_customer WHERE first_name = 'Joanna' AND last_name = 'Bond';
id ssn
1 XXX-XX-0007
DROP VIEW masked_customer;
DROP TABLE customer;
DROP FUNCTION mask_ssn;
1 change: 1 addition & 0 deletions mysql-test/suite/data_masking/t/gen_blacklist-master.opt
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
$DATA_MASKING_PLUGIN_OPT $DATA_MASKING_PLUGIN_LOAD
16 changes: 16 additions & 0 deletions mysql-test/suite/data_masking/t/gen_blacklist.test
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
--echo #
--echo # Plugin Data Masking: gen_blacklist
--echo #
CREATE FUNCTION gen_blacklist RETURNS STRING SONAME 'data_masking.so';
CREATE FUNCTION gen_dictionary_drop RETURNS STRING SONAME 'data_masking.so';
CREATE FUNCTION gen_dictionary_load RETURNS STRING SONAME 'data_masking.so';

SELECT gen_dictionary_load('../../std_data/data_masking/de_cities.txt', 'de_cities');
SELECT gen_dictionary_load('../../std_data/data_masking/us_cities.txt', 'us_cities');
SELECT gen_blacklist('Moscow', 'DE_Cities', 'US_Cities');
SELECT gen_dictionary_drop('de_cities');
SELECT gen_dictionary_drop('us_cities');

DROP FUNCTION gen_dictionary_load;
DROP FUNCTION gen_dictionary_drop;
DROP FUNCTION gen_blacklist;
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
$DATA_MASKING_PLUGIN_OPT $DATA_MASKING_PLUGIN_LOAD
13 changes: 13 additions & 0 deletions mysql-test/suite/data_masking/t/gen_dictionary_drop.test
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
--echo #
--echo # Plugin Data Masking: gen_dictionary_drop
--echo #
CREATE FUNCTION gen_dictionary_drop RETURNS STRING SONAME 'data_masking.so';
CREATE FUNCTION gen_dictionary_load RETURNS STRING SONAME 'data_masking.so';

SELECT gen_dictionary_drop('de_cities');
SELECT gen_dictionary_load('../../std_data/data_masking/de_cities.txt', 'de_cities');
SELECT gen_dictionary_drop('de_cities');
SELECT gen_dictionary_drop('de_cities');

DROP FUNCTION gen_dictionary_load;
DROP FUNCTION gen_dictionary_drop;
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
$DATA_MASKING_PLUGIN_OPT $DATA_MASKING_PLUGIN_LOAD
10 changes: 10 additions & 0 deletions mysql-test/suite/data_masking/t/gen_dictionary_load.test
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
--echo #
--echo # Plugin Data Masking: gen_dictionary_load
--echo #
CREATE FUNCTION gen_dictionary_load RETURNS STRING SONAME 'data_masking.so';

SELECT gen_dictionary_load('de_cities.txt', 'de_cities');
SELECT gen_dictionary_load('../../std_data/data_masking/de_cities.txt', 'de_cities');
SELECT gen_dictionary_load('../../std_data/data_masking/de_cities.txt', 'de_cities');

DROP FUNCTION gen_dictionary_load;
1 change: 1 addition & 0 deletions mysql-test/suite/data_masking/t/mask_inner-master.opt
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
$DATA_MASKING_PLUGIN_OPT $DATA_MASKING_PLUGIN_LOAD
16 changes: 16 additions & 0 deletions mysql-test/suite/data_masking/t/mask_inner.test
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
--echo #
--echo # Plugin Data Masking: mask_inner
--echo #
CREATE FUNCTION mask_inner RETURNS STRING SONAME 'data_masking.so';

SELECT mask_inner('This is a string', 5, 1);
SELECT mask_inner('This is a string', 1, 5);
SELECT mask_inner('This is a string', 5, 1, '#');
SELECT mask_inner(NULL, 1, 2);
SELECT mask_inner(NULL, 1, 2, '#');
SELECT mask_inner('This is a string', -1, 5);
SELECT mask_inner('This is a string', 1, -5);
SELECT mask_inner('This is a string', 1, 25);
SELECT mask_inner('This is a string', 100, 500);

DROP FUNCTION mask_inner;
1 change: 1 addition & 0 deletions mysql-test/suite/data_masking/t/mask_outer-master.opt
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
$DATA_MASKING_PLUGIN_OPT $DATA_MASKING_PLUGIN_LOAD
16 changes: 16 additions & 0 deletions mysql-test/suite/data_masking/t/mask_outer.test
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
--echo #
--echo # Plugin Data Masking: mask_outer
--echo #
CREATE FUNCTION mask_outer RETURNS STRING SONAME 'data_masking.so';

SELECT mask_outer('This is a string', 5, 1);
SELECT mask_outer('This is a string', 1, 5);
SELECT mask_outer('This is a string', 5, 1, '#');
SELECT mask_outer(NULL, 5, 1);
SELECT mask_outer(NULL, 5, 1, '#');
SELECT mask_outer('This is a string', -1, 5);
SELECT mask_outer('This is a string', 1, -5);
SELECT mask_outer('This is a string', 1, 25);
SELECT mask_outer('This is a string', 100, 500);

DROP FUNCTION mask_outer;
1 change: 1 addition & 0 deletions mysql-test/suite/data_masking/t/mask_pan-master.opt
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
$DATA_MASKING_PLUGIN_OPT $DATA_MASKING_PLUGIN_LOAD
13 changes: 13 additions & 0 deletions mysql-test/suite/data_masking/t/mask_pan.test
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
--echo #
--echo # Plugin Data Masking: mask_pan
--echo #
CREATE FUNCTION mask_pan RETURNS STRING SONAME 'data_masking.so';

SELECT mask_pan("1234567890122461");
SELECT mask_pan("123456789012246");
SELECT mask_pan(NULL);
SELECT mask_pan("");
SELECT mask_pan("123496798465498779");
SELECT mask_pan("this is not a pan");

DROP FUNCTION mask_pan;
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
$DATA_MASKING_PLUGIN_OPT $DATA_MASKING_PLUGIN_LOAD
13 changes: 13 additions & 0 deletions mysql-test/suite/data_masking/t/mask_pan_relaxed.test
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
--echo #
--echo # Plugin Data Masking: mask_pan_relaxed
--echo #
CREATE FUNCTION mask_pan_relaxed RETURNS STRING SONAME 'data_masking.so';

SELECT mask_pan_relaxed("1234567890122461");
SELECT mask_pan_relaxed("123456789012246");
SELECT mask_pan_relaxed(NULL);
SELECT mask_pan_relaxed("");
SELECT mask_pan_relaxed("123496798465498779");
SELECT mask_pan_relaxed("this is not a pan");

DROP FUNCTION mask_pan_relaxed;
1 change: 1 addition & 0 deletions mysql-test/suite/data_masking/t/mask_ssn-master.opt
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
$DATA_MASKING_PLUGIN_OPT $DATA_MASKING_PLUGIN_LOAD
12 changes: 12 additions & 0 deletions mysql-test/suite/data_masking/t/mask_ssn.test
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
--echo #
--echo # Plugin Data Masking: mask_ssn
--echo #
CREATE FUNCTION mask_ssn RETURNS STRING SONAME 'data_masking.so';

SELECT mask_ssn("123-45-6789");
SELECT mask_ssn(NULL);
SELECT mask_ssn("");
SELECT mask_ssn("123496798465498779");
SELECT mask_ssn("this is not an ssn");

DROP FUNCTION mask_ssn;
1 change: 1 addition & 0 deletions mysql-test/suite/data_masking/t/view-master.opt
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
$DATA_MASKING_PLUGIN_OPT $DATA_MASKING_PLUGIN_LOAD
13 changes: 13 additions & 0 deletions mysql-test/suite/data_masking/t/view.test
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
--echo #
--echo # Plugin Data Masking: view
--echo #
CREATE FUNCTION mask_ssn RETURNS STRING SONAME 'data_masking.so';

CREATE TABLE customer (id BIGINT UNSIGNED AUTO_INCREMENT NOT NULL PRIMARY KEY, ssn VARCHAR(11), first_name VARCHAR(100), last_name VARCHAR(100));
INSERT INTO customer (ssn, first_name, last_name) VALUES ('123-45-0007', 'Joanna', 'Bond');
CREATE VIEW masked_customer AS SELECT id, first_name, last_name, mask_ssn(CONVERT(ssn USING binary)) AS ssn FROM customer;
SELECT id, ssn FROM masked_customer WHERE first_name = 'Joanna' AND last_name = 'Bond';
DROP VIEW masked_customer;
DROP TABLE customer;

DROP FUNCTION mask_ssn;
2 changes: 2 additions & 0 deletions plugin/data_masking/AUTHORS
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
Oracle and/or its affiliates
Francisco Miguel Biete Banon
Loading

0 comments on commit e9542d4

Please sign in to comment.