MariaDB : SSL/TLS の設定2019/04/26 |
MariaDB で SSL/TLS による暗号化通信の設定を有効にします。
|
|
[1] | |
[2] | 作成した証明書をコピーして SSL/TLS の設定をします。 |
# 取得した証明書をコピーして証明書キーのフォーマット変換 root@www:~# mkdir /var/lib/mysql/pki root@www:~# cp /etc/letsencrypt/live/www.srv.world/* /var/lib/mysql/pki/ root@www:~# openssl rsa -in /var/lib/mysql/pki/privkey.pem -out /var/lib/mysql/pki/priv.key
root@www:~#
chown -R mysql. /var/lib/mysql/pki
root@www:~#
vi /etc/mysql/mariadb.conf.d/50-server.cnf # 97行目:追記
ssl-ca=/var/lib/mysql/pki/chain.pem
ssl-cert=/var/lib/mysql/pki/cert.pem ssl-key=/var/lib/mysql/pki/priv.key
root@www:~#
systemctl restart mariadb
# 設定確認 root@www:~# mysql -u root -p Enter password: Welcome to the MariaDB monitor. Commands end with ; or \g. Your MariaDB connection id is 11 Server version: 10.3.13-MariaDB-2 Ubuntu 19.04 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 MariaDB [(none)]> show variables like '%ssl%'; +---------------------+------------------------------+ | Variable_name | Value | +---------------------+------------------------------+ | have_openssl | NO | | have_ssl | YES | | ssl_ca | /var/lib/mysql/pki/chain.pem | | ssl_capath | | | ssl_cert | /var/lib/mysql/pki/cert.pem | | ssl_cipher | | | ssl_crl | | | ssl_crlpath | | | ssl_key | /var/lib/mysql/pki/priv.key | | version_ssl_library | YaSSL 2.4.4 | +---------------------+------------------------------+ 10 rows in set (0.002 sec) |
[3] | ローカルホストで SSL/TLS 接続する場合は証明書を指定して接続します。 |
root@www:~#
vi /etc/mysql/mariadb.conf.d/50-mysql-clients.cnf
[mysql]
root@www:~# # [mysql] セクション内に追記
ssl-cert=/var/lib/mysql/pki/cert.pem
ssl-key=/var/lib/mysql/pki/priv.key mysql -u root -p Enter password: Welcome to the MariaDB monitor. Commands end with ; or \g. Your MariaDB connection id is 12 Server version: 10.3.13-MariaDB-2 Ubuntu 19.04 Copyright (c) 2000, 2018, Oracle, MariaDB Corporation Ab and others. Type 'help;' or '\h' for help. Type '\c' to clear the current input statement. # 接続状況確認 MariaDB [(none)]> show status like 'ssl_cipher'; +---------------+--------------------+ | Variable_name | Value | +---------------+--------------------+ | Ssl_cipher | DHE-RSA-AES256-SHA | +---------------+--------------------+ 1 row in set (0.002 sec) MariaDB [(none)]> exit Bye # 非暗号化通信の場合 root@www:~# mysql -u root -p --ssl=false Enter password: Welcome to the MariaDB monitor. Commands end with ; or \g. Your MariaDB connection id is 13 Server version: 10.3.13-MariaDB-2 Ubuntu 19.04 Copyright (c) 2000, 2018, Oracle, MariaDB Corporation Ab and others. Type 'help;' or '\h' for help. Type '\c' to clear the current input statement. # 値はブランク MariaDB [(none)]> show status like 'ssl_cipher'; +---------------+-------+ | Variable_name | Value | +---------------+-------+ | Ssl_cipher | | +---------------+-------+ 1 row in set (0.01 sec) |
[4] | ユーザーに対して SSL/TLS アクセスを必須にする場合は、以下のように設定します。 |
root@www:~# mysql -u root -p Enter password: Welcome to the MariaDB monitor. Commands end with ; or \g. Your MariaDB connection id is 13 Server version: 10.3.13-MariaDB-2 Ubuntu 19.04 Copyright (c) 2000, 2018, Oracle, MariaDB Corporation Ab and others. Type 'help;' or '\h' for help. Type '\c' to clear the current input statement. # ユーザーを新規作成 MariaDB [(none)]> create user ubuntu identified by 'password'; Query OK, 0 rows affected (0.00 sec) # ユーザーを SSL/TLS 必須にする MariaDB [(none)]> grant usage on *.* to 'ubuntu'@'%' require ssl; Query OK, 0 rows affected (0.00 sec) # SSL/TLS 必須ユーザーは ssl_type が ANY MariaDB [(none)]> select user,host,ssl_type from mysql.user; +--------+-----------+----------+ | user | host | ssl_type | +--------+-----------+----------+ | root | localhost | | | disco | % | | | ubuntu | % | ANY | +--------+-----------+----------+ 3 rows in set (0.00 sec) |
[5] | 他ホストから SSL/TLS アクセスする場合は、アクセス元のホストに証明書/キーをコピーして設定すれば OK です。 |
root@node01:~#
root@node01:~# apt -y install mariadb-client scp ubuntu@www.srv.world:/var/lib/mysql/pki/cert.pem /etc/mysql/ root@node01:~# scp ubuntu@www.srv.world:/var/lib/mysql/pki/priv.key /etc/mysql/
root@node01:~#
vi /etc/mysql/mariadb.conf.d/50-mysql-clients.cnf
[mysql]
root@node01:~# # [mysql] セクション内に追記
ssl-cert=/etc/mysql/cert.pem
ssl-key=/etc/mysql/priv.key mysql -h www.srv.world -u ubuntu -p Enter password:
Welcome to the MariaDB monitor. Commands end with ; or \g.
Your MariaDB connection id is 13
Server version: 10.3.13-MariaDB-2 Ubuntu 19.04
Copyright (c) 2000, 2018, Oracle, MariaDB Corporation Ab and others.
Type 'help;' or '\h' for help. Type '\c' to clear the current input statement.
MariaDB [(none)]> show status like 'ssl_cipher';
+---------------+--------------------+
| Variable_name | Value |
+---------------+--------------------+
| Ssl_cipher | DHE-RSA-AES256-SHA |
+---------------+--------------------+
1 row in set (0.00 sec)
|
Sponsored Link |