MySQL 8.0 : SSL/TLS の設定2021/05/27 |
MySQL で SSL/TLS による暗号化通信の設定を有効にします。
|
|
[1] | |
[2] | 作成した証明書をコピーして SSL/TLS の設定をします。 |
[root@www ~]# mkdir /var/lib/mysql/pki [root@www ~]# cp /etc/pki/tls/certs/server.{crt,key} /var/lib/mysql/pki/
[root@www ~]#
chown -R mysql. /var/lib/mysql/pki
[root@www ~]#
vi /etc/my.cnf.d/mysql-server.cnf # [mysqld] セクション内に追記 [mysqld]
ssl-cert=/var/lib/mysql/pki/server.crt
ssl-key=/var/lib/mysql/pki/server.key
[root@www ~]#
systemctl restart mysqld
# 設定確認 [root@www ~]# mysql -u root -p Enter password: Welcome to the MySQL monitor. Commands end with ; or \g. Your MySQL connection id is 9 Server version: 8.0.21 Source distribution Copyright (c) 2000, 2020, Oracle and/or its affiliates. All rights reserved. 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. # 以下のように表示されれば OK 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 | | | 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 | +--------------------+-------------------------------+ 24 rows in set (0.01 sec) |
[3] | SSL/TLS で接続する場合は [--ssl-mode] を指定して接続します。 |
[root@www ~]# mysql -u root -p --ssl-mode=required --protocol=tcp Enter password: Welcome to the MySQL monitor. Commands end with ; or \g. Your MySQL connection id is 10 Server version: 8.0.21 Source distribution Copyright (c) 2000, 2020, Oracle and/or its affiliates. All rights reserved. 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.00 sec) mysql> exit Bye # 非暗号化通信の場合 [root@www ~]# mysql -u root -p Enter password: Welcome to the MySQL monitor. Commands end with ; or \g. Your MySQL connection id is 11 Server version: 8.0.21 Source distribution Copyright (c) 2000, 2020, Oracle and/or its affiliates. All rights reserved. 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] | ユーザーに対して SSL/TLS アクセスを必須にする場合は、以下のように設定します。 |
[root@www ~]# mysql -u root -p Enter password: Welcome to the MySQL monitor. Commands end with ; or \g. Your MySQL connection id is 12 Server version: 8.0.21 Source distribution Copyright (c) 2000, 2020, Oracle and/or its affiliates. All rights reserved. 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. # SSL/TLS 必須ユーザーを新規作成 mysql> create user redhat identified by 'password' require ssl; Query OK, 0 rows affected (0.12 sec) # SSL/TLS 必須ユーザーは ssl_type が ANY mysql> select user,host,ssl_type from mysql.user; +------------------+-----------+----------+ | user | host | ssl_type | +------------------+-----------+----------+ | cent | % | | | redhat | % | ANY | | mysql.infoschema | localhost | | | mysql.session | localhost | | | mysql.sys | localhost | | | root | localhost | | +------------------+-----------+----------+ 6 rows in set (0.00 sec) # 既存ユーザーを SSL/TLS 必須にする mysql> alter user 'cent'@'%' require ssl; Query OK, 0 rows affected (0.06 sec) mysql> select user,host,ssl_type from mysql.user; +------------------+-----------+----------+ | user | host | ssl_type | +------------------+-----------+----------+ | cent | % | ANY | | redhat | % | ANY | | mysql.infoschema | localhost | | | mysql.session | localhost | | | mysql.sys | localhost | | | root | localhost | | +------------------+-----------+----------+ 6 rows in set (0.00 sec) |
Sponsored Link |