mariadb密码审计

一、环境说明

      操作系统:CentOS Linux release 7.6.1810 (Core)

      数据库版本:mariadb-10.6.4-rhel-7-x86_64

      要求:

           1、密码有效周期审计(需要10.4开始支持)

           2、密码复杂度审计

二、开启审计

          1、密码复杂度审计

                简单密码检查插件首次在mariadb 10.1.2发布。 simple_password_check是密码验证插件。

                可以检查密码是否包含特定类型的至少一定数量的字符。

                首次安装时,密码要求至少为八个字符,并且需要至少一个数字、一个上壳字符、一个小写字符和一个既不是数字也不是字母的字符。

                启动命令:INSTALL SONAME 'simple_password_check'; 

                

 

                show variables like '%password%';

 

                

 

 

                simple_password_check_minimal_length:密码长度,默认8位

                simple_password_check_other_characters:特殊符号,1代表至少1位

                simple_password_check_letters_same_case:字母数,1代表至少1位

                simple_password_check_digits:数字数,1代表至少1位

                也可以直接在/etc/my.cnf里边添加:

                simple_password_check_minimal_length=N

                simple_password_check_other_characters=N

                simple_password_check_letters_same_case=N

                simple_password_check_digits=N

           2、密码有效期,10.4以上直接可以配置,以上因为开启了密码审计,所以执行如下SQL来创建用户:

                create user 'laiyifa'@'localhosts' identified by '123QWe!@#'  password expire interval 30 day;  #30天过期

                create user 'laiyifa'@'localhost' password expire never;  #永不过期

                alter user 'laiyifa'@'localhost' password expire interval 120 DAY; #修改为120天过期

                alter user 'laiyifa'@'localhost' password expire never; #修改为永不过期

           3、查看账号状态,SQL如下:

WITH password_expiration_info AS (
  SELECT User, Host,
  IF(
   IFNULL(JSON_EXTRACT(Priv, '$.password_lifetime'), -1) = -1,
   @@global.default_password_lifetime,
   JSON_EXTRACT(Priv, '$.password_lifetime')
  ) AS password_lifetime,
  JSON_EXTRACT(Priv, '$.password_last_changed') AS password_last_changed
  FROM mysql.global_priv
)
SELECT pei.User, pei.Host,
  pei.password_lifetime,
  FROM_UNIXTIME(pei.password_last_changed) AS password_last_changed_datetime,
  FROM_UNIXTIME(
   pei.password_last_changed +
   (pei.password_lifetime * 60 * 60 * 24)
  ) AS password_expiration_datetime
  FROM password_expiration_info pei
  WHERE pei.password_lifetime != 0
   AND pei.password_last_changed IS NOT NULL
UNION
SELECT pei.User, pei.Host,
  pei.password_lifetime,
  FROM_UNIXTIME(pei.password_last_changed) AS password_last_changed_datetime,
  0 AS password_expiration_datetime
  FROM password_expiration_info pei
  WHERE pei.password_lifetime = 0
   OR pei.password_last_changed IS NULL;

 

posted on 2021-08-19 16:41  明.Sir  阅读(786)  评论(0编辑  收藏  举报

导航