一、環境說明
操作系統: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;