Ubuntu 18.04
Sponsored Link

MariaDB : SSL/TLS Setting
2018/06/07
 
Enable SSL/TLS connection to MariaDB.
[1]
[2] Configure MariaDB for SSL/TLS.
# copy certificates got in [1] and convert format for certificate key

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
# line 98: add

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
# verify

root@www:~#
mysql -u root -p

Enter password:
Welcome to the MariaDB monitor.  Commands end with ; or \g.
Your MariaDB connection id is 5
Server version: 10.1.29-MariaDB-6 Ubuntu 18.04

Copyright (c) 2000, 2017, 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        | 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.00 sec)
[3] To connect with SSL/TLS from Localhost, connect with specifying Certs.
root@www:~#
vi /etc/mysql/mariadb.conf.d/50-mysql-clients.cnf
[mysql]
# add follows into [mysql] section

ssl-cert=/var/lib/mysql/pki/cert.pem
ssl-key=/var/lib/mysql/pki/priv.key
root@www:~#
mysql -u root -p

Enter password:
Welcome to the MariaDB monitor.  Commands end with ; or \g.
Your MariaDB connection id is 6
Server version: 10.1.29-MariaDB-6 Ubuntu 18.04

Copyright (c) 2000, 2017, 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    | DHE-RSA-AES256-SHA |
+---------------+--------------------+
1 row in set (0.00 sec)

MariaDB [(none)]> exit 
Bye

# for no SSL/TLS connection

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 7
Server version: 10.1.29-MariaDB-6 Ubuntu 18.04

Copyright (c) 2000, 2017, 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.01 sec)
[4] To force 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 8
Server version: 10.1.29-MariaDB-6 Ubuntu 18.04

Copyright (c) 2000, 2017, Oracle, MariaDB Corporation Ab and others.

Type 'help;' or '\h' for help. Type '\c' to clear the current input statement.

# create a user
MariaDB [(none)]> create user ubuntu identified by 'password'; 
Query OK, 0 rows affected (0.00 sec)

# set SSL/TLS required to the user
MariaDB [(none)]> grant usage on *.* to 'ubuntu'@'%' 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 |          |
| bionic | %         |          |
| ubuntu | %         | ANY      |
+--------+-----------+----------+
3 rows in set (0.00 sec)
[5] To connect from other Hosts, copy Certs on them and specify it to connect.
root@node01:~#
apt -y install mariadb-client
root@node01:~#
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]
# add follows into [mysql] section

ssl-cert=/etc/mysql/cert.pem
ssl-key=/etc/mysql/priv.key
root@node01:~#
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.1.29-MariaDB-6 Ubuntu 18.04

Copyright (c) 2000, 2017, 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)
Matched Content
 
Tweet