MariaDB : SSL/TLS Setting2019/05/13 |
Configure SSL/TLS Setting on MariaDB.
|
|
[1] | |
[2] | Configure MariaDB. |
# copy certificates got in [1] [root@www ~]# mkdir /var/lib/mysql/pki [root@www ~]# cp /etc/letsencrypt/live/www.srv.world/* /var/lib/mysql/pki/
[root@www ~]#
chown -R mysql. /var/lib/mysql/pki
[root@www ~]#
vi /etc/my.cnf.d/mariadb-server.cnf # add into [mysqld] section [mysqld]
ssl-ca=/var/lib/mysql/pki/chain.pem
ssl-cert=/var/lib/mysql/pki/cert.pem ssl-key=/var/lib/mysql/pki/privkey.pem
[root@www ~]#
systemctl restart mariadb
# verify settings [root@www ~]# mysql -u root -p Enter password: Welcome to the MariaDB monitor. Commands end with ; or \g. Your MariaDB connection id is 8 Server version: 10.3.12-MariaDB MariaDB Server 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 if status is like follows MariaDB [(none)]> show variables like '%ssl%'; +---------------------+----------------------------------+ | Variable_name | Value | +---------------------+----------------------------------+ | have_openssl | YES | | 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/privkey.pem | | version_ssl_library | OpenSSL 1.1.1b FIPS 26 Feb 2019 | +---------------------+----------------------------------+ 10 rows in set (0.002 sec) |
[3] | To connect with SSL/TLS from Clients, connect with specifying Cert. |
[root@www ~]# mysql -u root -p --ssl-ca=/var/lib/mysql/pki/cert.pem Enter password: Welcome to the MariaDB monitor. Commands end with ; or \g. Your MariaDB connection id is 9 Server version: 10.3.12-MariaDB MariaDB Server Copyright (c) 2000, 2018, Oracle, MariaDB Corporation Ab and others. Type 'help;' or '\h' for help. Type '\c' to clear the current input statement. # show status MariaDB [(none)]> show status like 'ssl_cipher'; +---------------+------------------------+ | Variable_name | Value | +---------------+------------------------+ | Ssl_cipher | TLS_AES_256_GCM_SHA384 | +---------------+------------------------+ 1 row in set (0.002 sec) MariaDB [(none)]> exit Bye # for no SSL/TLS connection [root@www ~]# mysql -u root -p Enter password: Welcome to the MariaDB monitor. Commands end with ; or \g. Your MariaDB connection id is 10 Server version: 10.3.12-MariaDB MariaDB Server Copyright (c) 2000, 2018, Oracle, MariaDB Corporation Ab and others. Type 'help;' or '\h' for help. Type '\c' to clear the current input statement. # value is empty MariaDB [(none)]> show status like 'ssl_cipher'; +---------------+-------+ | Variable_name | Value | +---------------+-------+ | Ssl_cipher | | +---------------+-------+ 1 row in set (0.002 sec) |
[4] | To force require users to connect with SSL/TLS, set like follows. |
[root@www ~]# mysql -u root -p Enter password: Welcome to the MariaDB monitor. Commands end with ; or \g. Your MariaDB connection id is 10 Server version: 10.3.12-MariaDB MariaDB Server Copyright (c) 2000, 2018, Oracle, MariaDB Corporation Ab and others. Type 'help;' or '\h' for help. Type '\c' to clear the current input statement. # create a user who is required SSL/TLS MariaDB [(none)]> create user redhat identified by 'password' require ssl; Query OK, 0 rows affected (0.00 sec) # show status SSL/TLS required users set [ssl_type] [ANY] MariaDB [(none)]> select user,host,ssl_type from mysql.user; +--------+-----------+----------+ | user | host | ssl_type | +--------+-----------+----------+ | root | localhost | | | root | 127.0.0.1 | | | root | ::1 | | | redhat | % | ANY | | fedora | % | | +--------+-----------+----------+ 5 rows in set (0.00 sec) # set SSL/TLS required to an existing user MariaDB [(none)]> grant usage on *.* to 'fedora'@'%' require ssl; Query OK, 0 rows affected (0.00 sec) MariaDB [(none)]> select user,host,ssl_type from mysql.user; +--------+-----------+----------+ | user | host | ssl_type | +--------+-----------+----------+ | root | localhost | | | root | 127.0.0.1 | | | root | ::1 | | | redhat | % | ANY | | fedora | % | ANY | +--------+-----------+----------+ 5 rows in set (0.00 sec) |
[5] | To connect from other Hosts, copy cert on them and specify it to connect. |
[root@node01 ~]# mysql -h www.srv.world -u fedora -p --ssl-ca=/root/cert.pem Enter password:
Welcome to the MariaDB monitor. Commands end with ; or \g.
Your MariaDB connection id is 10
Server version: 10.3.12-MariaDB MariaDB Server
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 | TLS_AES_256_GCM_SHA384 |
+---------------+------------------------+
1 row in set (0.002 sec)
|
Sponsored Link |