Enhancing MySQL Security

本文从很多方面介绍了关于增强MySQL安全。

展开查看详情

1. Enhancing MySQL Security Vinicius M. Grippa Senior Support Engineer for MySQL/MongoDB vinicius.grippa@percona.com 1 © 2019 Percona

2.About Me ▪ Support Engineer at Percona since 2017 ▪ Working with MySQL for over six years ▪ Working with databases for over nine years ▪ Speaker at PL 2018 and meetups about MySQL/MongoDB 2 © 2019 Percona

3.Basic Principles • Minimum access • Isolate • Audit • Avoid spying • Default firewall 3 © 2019 Percona

4.Agenda ▪ SO/Cloud security ▪ SSL ▪ Password management ▪ Audit plugin ▪ Percona Server encryption features ▪ MySQL 8 features (undo, redo encryption) ▪ TDE ▪ New caching_sha2_password ▪ FIPS mode 4 ▪ Roles © 2019 Percona

5. OS/Cloud Security 5 © 2019 Percona

6.OS/Cloud Security • Uninstall services that are not used • Do not run compilers • Firewalls • Block internet access • Disable remote root login • Use of SSH Key 6 © 2019 Percona

7.OS/Cloud Security • Use of Amazon Virtual Private Cloud (VPC) • Use AWS Identity and Access Management (IAM) policies • Use security groups 7 © 2019 Percona

8.OS/Cloud Security 8 © 2019 Percona

9.OS/Cloud Security 9 © 2019 Percona

10.OS/Cloud Security 10 © 2019 Percona

11. SSL 11 © 2019 Percona

12.SSL • Move information over a network in a secure fashion • SSL provides an way to cryptograph the data • Default for MySQL 5.7 or higher • Certificates ▪ MySQL 5.7 • mysql_ssl_rsa_setup ▪ MySQL 5.6 • openssl 12 © 2019 Percona

13.SSL mysql > show global variables like '%ssl%'; +---------------+-----------------+ | Variable_name | Value | +---------------+-----------------+ | have_openssl | YES | | have_ssl | YES | | ssl_ca | ca.pem | | ssl_capath | | | ssl_cert | server-cert.pem | | ssl_cipher | | | ssl_crl | | | ssl_crlpath | | | ssl_key | server-key.pem | +---------------+-----------------+ 9 rows in set (0.03 sec) 13 © 2019 Percona

14.SSL mysql: root@localhost ((none)) GRANT ALL PRIVILEGES ON *.* TO 'ssluser'@'%' IDENTIFIED BY 'sekret' REQUIRE SSL; Query OK, 0 rows affected, 1 warning (0.00 sec) Query OK, 0 rows affected (0.01 sec) [root@node1 ~]# mysql -ussluser -psekret --ssl-cert=/var/lib/mysql/client-cert.pem --ssl-key=/var/lib/mysql/client-key.pem --ssl-ca=/var/lib/mysql/ca.pem -h 127.0.0.1 -P 3306 -e "\s"| grep SSL mysql: [Warning] Using a password on the command line interface can be insecure. SSL: Cipher in use is ECDHE-RSA-AES128-GCM-SHA256 14 © 2019 Percona

15.SSL It is also possible to set ssl-mode to ensure that all connections use SSL. This option is available only for client programs, not the server. [client] ssl-mode=required 15 © 2019 Percona

16.SSL 16 © 2019 Percona

17. Password Management 17 © 2019 Percona

18.Password Management • Password expiration • validate_password plugin 18 © 2019 Percona

19.Password Expiration • MySQL enables database administrators to expire account passwords manually, and to establish a policy for automatic password expiration. Expiration policy can be established globally, and individual accounts can be set to either defer to the global policy or override the global policy with specific per-account behavior. 19 © 2019 Percona

20.Password Expiration Individual Accounts mysql> create user test_expired_user@localhost identified by 'Sekr$K1et' PASSWORD EXPIRE INTERVAL 1 day; Query OK, 0 rows affected (0.01 sec) Globally mysql> SET GLOBAL default_password_lifetime = 1; 20 © 2019 Percona

21.Password Expiration mysql: test_expired_user@localhost ((none)) > show databases; ERROR 1820 (HY000): You must reset your password using ALTER USER statement before executing this statement. 21 © 2019 Percona

22.validate_plugin Its main purpose is to test passwords and improve security. It is possible to ensure the strength, length and required characters of the password. 22 © 2019 Percona

23.validate_plugin - Installing # Runtime mysql: root@localhost ((none)) > INSTALL PLUGIN validate_password SONAME 'validate_password.so'; Query OK, 0 rows affected (0.07 sec) # my.cnf [mysqld] plugin-load-add=validate_password.so 23 © 2019 Percona

24.validate_plugin - Validate mysql: root@localhost ((none)) > show global variables like '%plugin%'; +-------------------------------+--------------------------+ | Variable_name | Value | +-------------------------------+--------------------------+ | default_authentication_plugin | mysql_native_password | | plugin_dir | /usr/lib64/mysql/plugin/ | +-------------------------------+--------------------------+ 2 rows in set (0.00 sec) mysql: root@localhost ((none)) > SELECT PLUGIN_NAME, PLUGIN_STATUS FROM INFORMATION_SCHEMA.PLUGINS WHERE PLUGIN_NAME LIKE 'validate%'; +-------------------+---------------+ | PLUGIN_NAME | PLUGIN_STATUS | +-------------------+---------------+ | validate_password | ACTIVE | +-------------------+---------------+ 1 row in set (0.00 sec) 24 © 2019 Percona

25.validate_plugin - Example mysql: root@localhost ((none)) > set global validate_password_length = 6; Query OK, 0 rows affected (0.00 sec) mysql: root@localhost ((none)) > set global validate_password_policy=2; Query OK, 0 rows affected (0.00 sec) 25 © 2019 Percona

26.validate_plugin - Example mysql: root@localhost ((none)) > create user test_password@localhost identified by 'PasSw0Rd'; ERROR 1819 (HY000): Your password does not satisfy the current policy requirements mysql: root@localhost ((none)) > create user test_password@localhost identified by 'PasSw0Rd12@'; Query OK, 0 rows affected (0.00 sec) 26 © 2019 Percona

27. Audit Plugin 27 © 2019 Percona

28.Audit Plugin ▪ MySQL Enterprise – Paid ▪ Percona Server (works with community version) – Free ▪ It is different from general log ▪ Filter by command / user / database 28 © 2019 Percona

29.Audit Plugin - Installing mysql > INSTALL PLUGIN audit_log SONAME 'audit_log.so'; Query OK, 0 rows affected (0.05 sec) mysql > SELECT PLUGIN_NAME, PLUGIN_STATUS FROM INFORMATION_SCHEMA.PLUGINS WHERE PLUGIN_NAME LIKE 'audit%'; +-------------+---------------+ | PLUGIN_NAME | PLUGIN_STATUS | +-------------+---------------+ | audit_log | ACTIVE | 29 © 2019 Percona +-------------+---------------+