我的 MySQL 服务器已正确配置以下参数
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)
这些文件存在于datadir
[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
然后我创建一个用户:
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)
我可以使用证书进行连接
[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>
但也没有证书
[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>
它是否正确?我可以强制用户仅使用这些证书登录吗?
指定用户
REQUIRE SSL
并不意味着该用户需要证书。SSL 用于加密传输,而证书用于身份验证。您可以创建一个用户,并
REQUIRE X509
选择强制客户端使用证书。您可以
mysqld
使用require_secure_transport进行配置加密连接的服务器端启动配置