[2] MySQL – SSL/TLS
27 stycznia 2022Skonfiguruj ustawienia SSL/TLS dla bazy MySQL.
[1] Pobierz certyfikaty z Let’s Encrypt lub wygeneruj swoje własne. My wykorzystamy nasze własne wygenerowane.
[2] Skopiuj certyfikaty i skonfiguruj MySQL.
[root@vlsr01 ~]# mkdir /var/lib/mysql/pki [root@vlsr01 ~]# cp /etc/pki/tls/certs/server.{crt,key} /var/lib/mysql/pki/ [root@vlsr01 ~]# chown -R mysql. /var/lib/mysql/pki [root@vlsr01 ~]# mcedit /etc/my.cnf.d/mysql-server.cnf #dodaj w sekcji [mysqld] [mysqld] ssl-cert=/var/lib/mysql/pki/server.crt ssl-key=/var/lib/mysql/pki/server.key [root@vlsr01 ~]# systemctl restart mysqld #sprawdź ustawienia [root@vlsr01 ~]# mysql -u root -p Enter password: #wpisz hasło Welcome to the MySQL monitor. Commands end with ; or \g. Your MySQL connection id is 8 Server version: 8.0.26 Source distribution Copyright (c) 2000, 2021, Oracle and/or its affiliates. Oracle is a registered trademark of Oracle Corporation and/or its affiliates. Other names may be trademarks of their respective owners. Type 'help;' or '\h' for help. Type '\c' to clear the current input statement. mysql> show variables like '%ssl%'; +-------------------------------------+-------------------------------+ | Variable_name | Value | +-------------------------------------+-------------------------------+ | admin_ssl_ca | | | admin_ssl_capath | | | admin_ssl_cert | | | admin_ssl_cipher | | | admin_ssl_crl | | | admin_ssl_crlpath | | | admin_ssl_key | | | have_openssl | YES | | have_ssl | YES | | mysqlx_ssl_ca | | | mysqlx_ssl_capath | | | mysqlx_ssl_cert | | | mysqlx_ssl_cipher | | | mysqlx_ssl_crl | | | mysqlx_ssl_crlpath | | | mysqlx_ssl_key | | | performance_schema_show_processlist | OFF | | ssl_ca | | | ssl_capath | | | ssl_cert | /var/lib/mysql/pki/server.crt | | ssl_cipher | | | ssl_crl | | | ssl_crlpath | | | ssl_fips_mode | OFF | | ssl_key | /var/lib/mysql/pki/server.key | +-------------------------------------+-------------------------------+ 25 rows in set (0,00 sec)
[3] Aby połączyć się z bazą za pomocą SSL/TLS użyj przełącznika [–ssl-mode].
[root@vlsr01 ~]# mysql -u root -p --ssl-mode=required --protocol=tcp Enter password: #wpisz hasło Welcome to the MySQL monitor. Commands end with ; or \g. Your MySQL connection id is 9 Server version: 8.0.26 Source distribution Copyright (c) 2000, 2021, Oracle and/or its affiliates. Oracle is a registered trademark of Oracle Corporation and/or its affiliates. Other names may be trademarks of their respective owners. Type 'help;' or '\h' for help. Type '\c' to clear the current input statement. mysql> show status like 'ssl_cipher'; +---------------+------------------------+ | Variable_name | Value | +---------------+------------------------+ | Ssl_cipher | TLS_AES_256_GCM_SHA384 | +---------------+------------------------+ 1 row in set (0,01 sec) mysql> exit Bye #bez SSL/TLS [root@vlsr01 ~]# mysql -u root -p Enter password: #wpisz hasło Welcome to the MySQL monitor. Commands end with ; or \g. Your MySQL connection id is 10 Server version: 8.0.26 Source distribution Copyright (c) 2000, 2021, Oracle and/or its affiliates. Oracle is a registered trademark of Oracle Corporation and/or its affiliates. Other names may be trademarks of their respective owners. Type 'help;' or '\h' for help. Type '\c' to clear the current input statement. mysql> show status like 'ssl_cipher'; +---------------+-------+ | Variable_name | Value | +---------------+-------+ | Ssl_cipher | | +---------------+-------+ 1 row in set (0,00 sec)
[4] Aby wymusić łączenie się za pomocą SSL/TLS wykonaj.
[root@vlsr01 ~]# mysql -u root -p Enter password: #wpisz hasło Welcome to the MySQL monitor. Commands end with ; or \g. Your MySQL connection id is 11 Server version: 8.0.26 Source distribution Copyright (c) 2000, 2021, Oracle and/or its affiliates. Oracle is a registered trademark of Oracle Corporation and/or its affiliates. Other names may be trademarks of their respective owners. Type 'help;' or '\h' for help. Type '\c' to clear the current input statement. #użytkownik bez wymuszonego SSL/TLS mysql> create user nossluser identified by 'TajneHasło'; Query OK, 0 rows affected (0,00 sec) #użytkownik z wymuszonym SSL/TLS mysql> create user ssluser identified by 'TajneHasło' require ssl; Query OK, 0 rows affected (0,00 sec) #sprawdź status wymagań SSL/TLS użytkowników mysql> select user,host,ssl_type from mysql.user; +------------------+-----------+----------+ | user | host | ssl_type | +------------------+-----------+----------+ | nossluser | % | | | ssluser | % | ANY | | mysql.infoschema | localhost | | | mysql.session | localhost | | | mysql.sys | localhost | | | root | localhost | | +------------------+-----------+----------+ 6 rows in set (0,01 sec) #ustaw SSL/TLS dla istniejącego użytkownika mysql> alter user 'nossluser'@'%' require ssl; Query OK, 0 rows affected (0,00 sec) mysql> select user,host,ssl_type from mysql.user; +------------------+-----------+----------+ | user | host | ssl_type | +------------------+-----------+----------+ | nossluser | % | ANY | | ssluser | % | ANY | | mysql.infoschema | localhost | | | mysql.session | localhost | | | mysql.sys | localhost | | | root | localhost | | +------------------+-----------+----------+ 6 rows in set (0,00 sec)