时间:2021-07-01 10:21:17 帮助过:6人阅读
Password Validation插件和组件
在MySQL 8.0之前,MySQL使用的是validate_password插件(plugin)检测、验证账号密码强度,保障账号的安全性,而到了MySQL 8.0,引入了服务器组件(Components)这个特性,validate_password插件已用服务器组件重新实现。下面是官方文档的介绍:
Note
In MySQL 8.0, the validate_password plugin was reimplemented as the validate_password component. (For general information about server components, see Section 5.5, “MySQL Server Components”.) The following instructions describe how to use the component, not the plugin. For instructions on using the plugin form of validate_password, see The Password Validation Plugin in MySQL 5.7 Reference Manual.
The plugin form of validate_password is still available but is deprecated and will be removed in a future version of MySQL. MySQL installations that use the plugin should make the transition to using the component instead. See Section 6.4.3.3, “Transitioning to the Password Validation Component”.
这篇文章会介绍validate_password插件和validate_password组件,测试环境为MySQL 8.0.18,如果有其它版本的测试,会在文中进行标明、注释。
Password Validation安装插件
检查是否安装了插件/组件
插件:
mysql> SELECT PLUGIN_NAME, PLUGIN_LIBRARY, PLUGIN_STATUS, LOAD_OPTION
-> FROM INFORMATION_SCHEMA.PLUGINS
-> WHERE PLUGIN_NAME = ‘validate_password‘;
Empty set (0.01 sec)
如果已经安装了MySQL密码强度审计插件:validate_password的话,可以跳过后面的安装步骤。
组件:
mysql> SELECT * FROM mysql.component;
安装/启用插件
方法1:在参数文件my.cnf中添加参数。
[mysqld]
plugin-load-add=validate_password.so
#ON/OFF/FORCE/FORCE_PLUS_PERMANENT: 是否使用该插件(及强制/永久强制使用)
validate-password=FORCE_PLUS_PERMANENT
注释:插件库(plugin library)中的validate_password文件名的后缀名根据平台不同有所差异。 对于Unix和Unix-like系统而言,它的文件后缀名是.so,对于Windows系统而言,它的文件后缀名是.dll。
注意:参数FORCE_PLUS_PERMANENT是为了防止插件在MySQL运行时的时候被卸载,如下所示,当你卸载插件时就会报错:
mysql> SELECT PLUGIN_NAME, PLUGIN_LIBRARY, PLUGIN_STATUS, LOAD_OPTION
-> FROM INFORMATION_SCHEMA.PLUGINS
-> WHERE PLUGIN_NAME = ‘validate_password‘;
+-------------------+----------------------+---------------+----------------------+
| PLUGIN_NAME | PLUGIN_LIBRARY | PLUGIN_STATUS | LOAD_OPTION |
+-------------------+----------------------+---------------+----------------------+
| validate_password | validate_password.so | ACTIVE | FORCE_PLUS_PERMANENT |
+-------------------+----------------------+---------------+----------------------+
1 row in set (0.00 sec)
mysql> UNINSTALL PLUGIN validate_password;
ERROR 1702 (HY000): Plugin ‘validate_password‘ is force_plus_permanent and can not be unloaded
mysql>
另外,修改参数后必须重启MySQL服务才能生效。
方法2:运行时命令安装
mysql> INSTALL PLUGIN validate_password SONAME ‘validate_password.so‘;
Query OK, 0 rows affected, 1 warning (0.11 sec)
注意:此方法也会注册到元数据,也就是mysql.plugin表中,所以不用担心MySQL重启后插件会失效。
注意:MySQL支持在服务器启动和运行时加载插件。还可以在启动时控制加载插件的激活状态,并在运行时卸载它们。在加载插件时,可以从INFORMATION_SCHEMA获得关于插件的信息。
方法3:命令启动时,使用参数。这个其实和方法并无什么差异。
# /usr/sbin/mysqld start --plugin-load=‘validate_password.so‘
安装组件
INSTALL COMPONENT ‘file://component_validate_password‘;
检查确认
插件:
mysql> SELECT PLUGIN_NAME, PLUGIN_LIBRARY, PLUGIN_STATUS, LOAD_OPTION
-> FROM INFORMATION_SCHEMA.PLUGINS
-> WHERE PLUGIN_NAME = ‘validate_password‘;
+-------------------+----------------------+---------------+-------------+
| PLUGIN_NAME | PLUGIN_LIBRARY | PLUGIN_STATUS | LOAD_OPTION |
+-------------------+----------------------+---------------+-------------+
| validate_password | validate_password.so | ACTIVE | ON |
+-------------------+----------------------+---------------+-------------+
1 row in set (0.00 sec)
mysql>
mysql> select * from mysql.plugin;
+-------------------+----------------------+
| name | dl |
+-------------------+----------------------+
| CLONE | mysql_clone.so |
| validate_password | validate_password.so |
+-------------------+----------------------+
组件:
mysql> SELECT * FROM mysql.component;
+--------------+--------------------+------------------------------------+
| component_id | component_group_id | component_urn |
+--------------+--------------------+------------------------------------+
| 1 | 1 | file://component_validate_password |
+--------------+--------------------+------------------------------------+
1 row in set (0.00 sec)
如果只安装了插件,查看插件相关的系统变量,如下所示:
mysql> show variables like ‘validate_password%‘;
+--------------------------------------+--------+
| Variable_name | Value |
+--------------------------------------+--------+
| validate_password_check_user_name | ON |
| validate_password_dictionary_file | |
| validate_password_length | 8 |
| validate_password_mixed_case_count | 1 |
| validate_password_number_count | 1 |
| validate_password_policy | MEDIUM |
| validate_password_special_char_count | 1 |
+--------------------------------------+--------+
7 rows in set (0.00 sec)
mysql>
MySQL 8.0.18上可以同时安装validate_password插件和validate_password组件,此时查看系统变量时,就会出现这种情形(相信有些不知情同学的看到这种情况的时候,会有点懵逼),其实对于MySQL 8,我们只需安装validate_password组件即可。
关于插件和组件对应的系统变量说明: