Meu servidor MySQL possui os seguintes parâmetros configurados corretamente
mysql> show global variables like '%have_ssl%';
+---------------+-------+
| Variable_name | Value |
+---------------+-------+
| have_ssl | YES |
+---------------+-------+
1 row in set (0.00 sec)
mysql> show global variables like 'ssl_ca';
+---------------+--------+
| Variable_name | Value |
+---------------+--------+
| ssl_ca | ca.pem |
+---------------+--------+
1 row in set (0.00 sec)
mysql> show global variables like 'ssl_cert';
+---------------+-----------------+
| Variable_name | Value |
+---------------+-----------------+
| ssl_cert | server-cert.pem |
+---------------+-----------------+
1 row in set (0.00 sec)
mysql> show global variables like 'ssl_key';
+---------------+----------------+
| Variable_name | Value |
+---------------+----------------+
| ssl_key | server-key.pem |
+---------------+----------------+
1 row in set (0.00 sec)
mysql> show global variables like 'datadir';
+---------------+---------+
| Variable_name | Value |
+---------------+---------+
| datadir | /dados/ |
+---------------+---------+
1 row in set (0.00 sec)
E esses arquivos existem emdatadir
[root@mysqlen1 dados]# ls -l ca.pem server-cert.pem server-key.pem
-rw-r--r-- 1 mysql mysql 1112 Nov 3 10:28 ca.pem
-rw-r--r-- 1 mysql mysql 1112 Nov 3 10:28 server-cert.pem
-rw------- 1 mysql mysql 1680 Nov 3 10:28 server-key.pem
Então eu crio um usuário:
mysql> create user 'teste'@'%' identified by 'teste123' require ssl;
Query OK, 0 rows affected (0.00 sec)
mysql> flush privileges;
Query OK, 0 rows affected (0.00 sec)
Posso me conectar usando os certificados
[root@TCCPUC-ENGDADOS:~]# mysql -uteste -p'teste123' -h 192.168.0.110 --ssl-ca=ca.pem --ssl-cert=client-cert.pem --ssl-key=client-key.pem
mysql: [Warning] Using a password on the command line interface can be insecure.
Welcome to the MySQL monitor. Commands end with ; or \g.
Your MySQL connection id is 30
Server version: 8.0.28 MySQL Community Server - GPL
Copyright (c) 2000, 2023, Oracle and/or its affiliates.
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>
Mas sem os certificados também
[root@TCCPUC-ENGDADOS:~]# mysql -uteste -p'teste123' -h 192.168.0.110
mysql: [Warning] Using a password on the command line interface can be insecure.
Welcome to the MySQL monitor. Commands end with ; or \g.
Your MySQL connection id is 31
Server version: 8.0.28 MySQL Community Server - GPL
Copyright (c) 2000, 2023, Oracle and/or its affiliates.
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>
Isso está correto? Posso forçar o usuário a fazer login apenas com esses certificados?
Especificar um usuário
REQUIRE SSL
não significa que o usuário exija certificados. SSL é para transporte criptografado, mas certificados são para autenticação.Você pode criar um usuário com
REQUIRE X509
a opção de forçar os clientes a usar um certificado.Você pode configurar
mysqld
usando require_secure_transportConfiguração de inicialização do lado do servidor para conexões criptografadas