in transit (moving over the network), and proper authentication can be used to protect data in use (being used by an application), but data at rest (sitting on a file system) has been an area of risk in MySQL/MariaDB.
rest, a bad actor with access to the file system supporting the database can view data even without proper database-level permissions. Having root access to the file system is very common!
names, drivers license, financial data, social security number HIPAA: medical, health insurance data See: https://en.wikipedia.org/wiki/California_S.B._1386
108 drwx------. 2 mysql mysql 45 Oct 19 15:09 . drwxr-xr-x. 6 mysql mysql 4096 Oct 19 15:07 .. -rw-rw----. 1 mysql mysql 65 Oct 19 15:07 db.opt -rw-rw----. 1 mysql mysql 932 Oct 19 15:09 t1.frm -rw-rw----. 1 mysql mysql 98304 Oct 19 15:09 t1.ibd [root@encr_maria ~]# strings /var/lib/mysql/ allthingsopen/t1.ibd ... mysecret123-45-6789
encrypt table data in MariaDB 10.1: • innodb_encrypt_tables in the my.cnf will encrypt all tables (unless specified as “encrypted=no”). • innodb_encrypt_tables=FORCE in the my.cnf will encrypt all new tables created, and will prevent table creation with “encrypted=no.” • If the configuration innodb_encrypt_tables is not in the my.cnf, but the plugin is present, you can explicitly encrypt a table by including “encrypted=yes” in the table creation statement. (If innodb_encryption_threads is set higher than 0, then existing tables will be encrypted in the background.)
name from information_schema.innodb_tablespaces_encryption where encryption_scheme=1; Empty set (0.00 sec) MariaDB [(none)]> select name from information_schema.innodb_tablespaces_encryption where encryption_scheme=1; +--------------------------+ | name | +--------------------------+ ... | allthingsopen/t1 | +--------------------------+ 5 rows in set (0.00 sec)
encr_maria-bin.000015 ... # at 249 # Encryption scheme: 1, key_version: 1, nonce: e7f7531d547cc3ee52111b95 # The rest of the binlog is encrypted! ERROR: Error in Log_event::read_log_event(): 'Found invalid event in binary log', data_len: 39, event_type: 187 DELIMITER ; # End of log file ROLLBACK /* added by mysqlbinlog */; /*!50003 SET COMPLETION_TYPE=@OLD_COMPLETION_TYPE*/; /*!50530 SET @@SESSION.PSEUDO_SLAVE_MODE=0*/;
global log_warnings=2; MariaDB [(none)]> insert into allthingsopen.t2 (select * from allthingsopen.t1 where charcol3 like '123-45-6789' limit 1); Query OK, 0 rows affected, 1 warning (0.00 sec) Records: 0 Duplicates: 0 Warnings: 1 [root@encr_maria ~]# less /var/lib/mysql/encr_maria.err ... 2016-10-19 20:58:53 140158235900672 [Warning] Unsafe statement written to the binary log using statement format since BINLOG_FORMAT = STATEMENT. The statement is unsafe because it uses a LIMIT clause. This is unsafe because the set of rows included cannot be predicted. Statement: insert into allthingsopen.t2 (select * from allthingsopen.t1 where charcol3 like '123-45-6789' limit 1)
MariaDB [(none)]> select name from information_schema.innodb_tablespaces_encryption where encryption_scheme=1; | test/sbtest1 | MariaDB [allthingsopen]> alter table t2 encrypted=‘no'; MariaDB [allthingsopen]> select name from information_schema.innodb_tablespaces_encryption where encryption_scheme=1; Empty set (0.00 sec) # remove encryption configs from configurationn files [root@centosbase ~]# sudo systemctl restart mariadb
keyring_file_data=/var/lib/mysql/mysql-keyring/keyring [root@encr_percona ~]# service mysql start mysql> SELECT PLUGIN_NAME, PLUGIN_STATUS FROM INFORMATION_SCHEMA.PLUGINS WHERE PLUGIN_NAME LIKE 'keyring%'; +--------------+---------------+ | PLUGIN_NAME | PLUGIN_STATUS | +--------------+---------------+ | keyring_file | ACTIVE | +--------------+---------------+ mysql> show global variables like '%keyring%'; +-------------------+--------------------------------------+ | Variable_name | Value | +-------------------+--------------------------------------+ | keyring_file_data | /var/lib/mysql/mysql-keyring/keyring | +-------------------+--------------------------------------+ Store your key outside the data directory.
ls -l /var/lib/mysql/mysql- keyring/ total 0 -rw-r-----. 1 mysql mysql 0 Oct 19 16:18 keyring mysql> select * from t2; ERROR 3185 (HY000): Can't find master key from keyring, please check keyring plugin is loaded. Special note for Xtrabackup later.
-al /var/lib/mysql/mysql- keyring/keyring -rw-r-----. 1 mysql mysql 795 Oct 19 20:31 /var/ lib/mysql/mysql-keyring/keyring [root@encr_percona ~]# mysql -e'alter instance rotate innodb master key’; [root@encr_percona ~]# ls -al /var/lib/mysql/mysql- keyring/keyring -rw-r-----. 1 mysql mysql 923 Oct 19 20:58 /var/ lib/mysql/mysql-keyring/keyring
-al /var/lib/mysql/ allthingsopen/t2.ibd -rw-r-----. 1 mysql mysql 98304 Oct 19 21:08 /var/ lib/mysql/allthingsopen/t2.ibd [root@encr_percona ~]# mysql -e'alter instance rotate innodb master key’; [root@encr_percona ~]# ls -al /var/lib/mysql/ allthingsopen/t2.ibd -rw-r-----. 1 mysql mysql 98304 Oct 19 21:09 /var/ lib/mysql/allthingsopen/t2.ibd Try at home: look at the header contents of the .ibd file.
global innodb_encryption_threads=0; MariaDB [(none)]> select name from information_schema.innodb_tablespaces_encryption where encryption_scheme=1; | test/sbtest1 | MariaDB [allthingsopen]> alter table t2 encrypted=‘no'; MariaDB [allthingsopen]> select name from information_schema.innodb_tablespaces_encryption where encryption_scheme=1; Empty set (0.00 sec)
-md sha1 -k mypassword -in /var/lib/mysql/keys.txt -out / var/lib/mysql/keys.enc [root@maria101 mysql]# cat /etc/my.cnf | grep key- management file-key-management-filename = /var/lib/mysql/keys.enc file-key-management-filekey = mypassword …but of course, the password is exposed in the my.cnf on disk
/ backup/ xtrabackup: Generating a list of tablespaces InnoDB: Allocated tablespace ID 4 for allthingsopen/t2, old maximum was 0 161023 10:06:19 [01] Copying ./ibdata1 to /backup/ 2016-10-23_10-06-19/ibdata1 [01] xtrabackup: Database page corruption detected at page 1, retrying... File ./ibdata1 seems to be corrupted. [01] xtrabackup: Error: xtrabackup_copy_datafile() failed. [01] xtrabackup: Error: failed to copy datafile. See: https://mariadb.com/kb/en/mariadb/plans-for-10x/