MariaDB 10.11 : SSL/TLS の設定2024/02/02 |
MariaDB で SSL/TLS による暗号化通信の設定を有効にします。 |
|
[1] |
事前に SSL/TLS 証明書を取得 または
自己署名の証明書を作成しておきます。 |
[2] | 作成した証明書をコピーして SSL/TLS の設定をします。 |
# 作成した証明書をコピー root@www:~ # mkdir /var/db/mysql/pki root@www:~ # cp /usr/local/etc/ssl/server.* /var/db/mysql/pki/
root@www:~ #
chown -R mysql:mysql /var/db/mysql/pki
root@www:~ #
vi /usr/local/etc/mysql/conf.d/server.cnf # 25行目 : 作成した証明書を追記
ssl-cert = /var/db/mysql/pki/server.crt
ssl-key = /var/db/mysql/pki/server.key
root@www:~ #
service mysql-server restart
# 設定確認 root@www:~ # mysql Welcome to the MariaDB monitor. Commands end with ; or \g. Your MariaDB connection id is 3 Server version: 10.11.6-MariaDB FreeBSD Ports Copyright (c) 2000, 2018, Oracle, MariaDB Corporation Ab and others. Type 'help;' or '\h' for help. Type '\c' to clear the current input statement. # 以下のように表示されれば OK root@localhost [(none)]> show variables like '%ssl%'; +---------------------+------------------------------+ | Variable_name | Value | +---------------------+------------------------------+ | have_openssl | YES | | have_ssl | YES | | ssl_ca | | | ssl_capath | | | ssl_cert | /var/db/mysql/pki/server.crt | | ssl_cipher | | | ssl_crl | | | ssl_crlpath | | | ssl_key | /var/db/mysql/pki/server.key | | version_ssl_library | OpenSSL 3.0.12 24 Oct 2023 | +---------------------+------------------------------+ 10 rows in set (0.001 sec) |
[3] | SSL/TLS で接続する場合は [ssl] オプションを指定して接続します。 |
root@www:~ # mysql --ssl Welcome to the MariaDB monitor. Commands end with ; or \g. Your MariaDB connection id is 4 Server version: 10.11.6-MariaDB FreeBSD Ports Copyright (c) 2000, 2018, Oracle, MariaDB Corporation Ab and others. Type 'help;' or '\h' for help. Type '\c' to clear the current input statement. # 接続状況確認 root@localhost [(none)]> show status like 'ssl_cipher'; +---------------+------------------------+ | Variable_name | Value | +---------------+------------------------+ | Ssl_cipher | TLS_AES_256_GCM_SHA384 | +---------------+------------------------+ 1 row in set (0.000 sec) root@localhost [(none)]> exit Bye # 非暗号化通信の場合 root@www:~ # mysql --skip-ssl Welcome to the MariaDB monitor. Commands end with ; or \g. Your MariaDB connection id is 5 Server version: 10.11.6-MariaDB FreeBSD Ports Copyright (c) 2000, 2018, Oracle, MariaDB Corporation Ab and others. Type 'help;' or '\h' for help. Type '\c' to clear the current input statement. # 値はブランク root@localhost [(none)]> show status like 'ssl_cipher'; +---------------+-------+ | Variable_name | Value | +---------------+-------+ | Ssl_cipher | | +---------------+-------+ 1 row in set (0.000 sec) |
[4] | ユーザーに対して SSL/TLS アクセスを必須にする場合は、以下のように設定します。 |
root@www:~ # mysql Welcome to the MariaDB monitor. Commands end with ; or \g. Your MariaDB connection id is 8 Server version: 10.11.6-MariaDB FreeBSD Ports Copyright (c) 2000, 2018, Oracle, MariaDB Corporation Ab and others. Type 'help;' or '\h' for help. Type '\c' to clear the current input statement. # SSL/TLS 必須ユーザーを新規作成 root@localhost [(none)]> create user netbsd identified by 'password' require ssl; Query OK, 0 rows affected (0.00 sec) # SSL/TLS 必須ユーザーは ssl_type が ANY root@localhost [(none)]> select user,host,ssl_type from mysql.user; +-------------+-----------+----------+ | User | Host | ssl_type | +-------------+-----------+----------+ | mariadb.sys | localhost | | | root | localhost | | | mysql | localhost | | | PUBLIC | | | | freebsd | % | | | netbsd | % | ANY | +-------------+-----------+----------+ 6 rows in set (0.001 sec) # 既存ユーザーを SSL/TLS 必須にする root@localhost [(none)]> grant usage on *.* to 'freebsd'@'%' require ssl; Query OK, 0 rows affected (0.00 sec) root@localhost [(none)]> select user,host,ssl_type from mysql.user; +-------------+-----------+----------+ | User | Host | ssl_type | +-------------+-----------+----------+ | mariadb.sys | localhost | | | root | localhost | | | mysql | localhost | | | PUBLIC | | | | freebsd | % | ANY | | netbsd | % | ANY | +-------------+-----------+----------+ 6 rows in set (0.001 sec) |
Sponsored Link |