1.Base基础/3.Icon图标/操作/search备份
1.Base基础/3.Icon图标/操作/search备份
EN
文档
关于AntDB
部署与升级
快速入门
使用教程
运维
调优
工具和插件
高级服务
数据安全
参考
  • 文档首页 /
  • 工具和插件 /
  • 集中式 /
  • credcheck

credcheck

更新时间:2024-07-01 14:39:41

credcheck 插件描述

credcheck 是一个 AntDB 扩展。提供了一些通用的凭据检查,这些检查将在用户创建、密码更改和用户重命名期间进行评估。通过使用此扩展,我们可以定义一组规则:

  • 允许一组特定的凭据

  • 拒绝特定类型的凭据

  • 拒绝容易破解的密码

  • 强制使用密码最短为天的过期日期

  • 定义密码重用策略

  • 定义禁止用户之前允许的身份验证失败次数

此扩展将所有检查作为可配置参数提供。默认配置设置不会强制执行任何复杂的检查,并将尝试允许大多数凭据。通过使用如下命令,强制执行凭据检查的新设置。设置只能由超级用户更改。

SET credcheck<check-name> TO <some value>;

使用准备

  • 修改配置文件后重启数据库
# 修改postgresql.conf文件
shared_preload_libraries = 'credcheck'
  • 登陆数据库,执行 SQL 命令,创建扩展
CREATE EXTENSION credcheck;

检查列表

下面是常规检查列表,我们可以对凭据强制执行这些检查。

检查类型Description设置的值认可的不认可的
username_min_lengthusername用户名的最小长度4✓ abcd✘ abc
username_min_specialusername最小特殊字符数1✓ a@bc✘ abcd
username_min_digitusername最小位数1✓ a1bc✘ abcd
username_min_upperusername大写字母的最小数目2✓ aBC✘ aBc
username_min_lowerusername小写字母的最小数目1✓ aBC✘ ABC
username_min_repeatusername字符应重复的最大次数2✓ aaBCa✘ aaaBCa
username_contain_passwordusername用户名不应包含密码on✓ username - password✘ username + password
username_containusername用户名应包含以下字符之一a,b,c✓ ade✘ efg
username_not_containusername用户名不应包含以下字符之一x,y,z✓ ade✘ axf
username_ignore_caseusername执行上述检查时忽略 caseon✓ Ade✘ aXf
password_min_lengthpassword密码的最小长度4✓ abcd✘ abc
password_min_specialpassword最小特殊字符数1✓ a@bc✘ abc
password_min_digitpassword密码中的最小位数1✓ a1bc✘ abc
password_min_upperpassword最小大写字符数1✓ Abc✘ abc
password_min_lowerpassword最小小写字符数1✓ aBC✘ ABC
password_min_repeatpassword字符应重复的最大次数2✓ aab✘ aaab
password_contain_usernamepassword密码不应包含密码on✓ password - username✘ password + username
password_containpassword密码应包含以下字符a,b,c✓ ade✘ xfg
password_not_containpassword密码不应包含以下字符x,y,z✓ abc✘ axf
password_ignore_casepassword执行上述检查时忽略 caseon✓ Abc✘ aXf
password_valid_untilpassword强制使用CREATE ROLE 语句中的 VALID UNTIL子句的最少天数60✓ CREATE ROLE abcd VALID UNTIL (now()+'3 months'::interval)::date✘ CREATE ROLE abcd LOGIN;
password_valid_maxpassword强制使用CREATE ROLE语句中的 VALID UNTIL子句的最大天数365✓ CREATE ROLE abcd VALID UNTIL (now()+'6 months'::interval)::date✘ CREATE ROLE abcd VALID UNTIL (now()+'2 years'::interval)::date;

使用范例:

#查询credcheck的配置参数名
antdb=# SELECT name,setting FROM pg_settings WHERE name LIKE '%credcheck%';
                name                 | setting
-------------------------------------+---------
 credcheck.auth_failure_cache_size   | 1024
 credcheck.history_max_size          | 65535
 credcheck.max_auth_failure          | 0
 credcheck.no_password_logging       | on
 credcheck.password_contain          |
 credcheck.password_contain_username | on
 credcheck.password_ignore_case      | off
 credcheck.password_min_digit        | 0
 credcheck.password_min_length       | 1
 credcheck.password_min_lower        | 0
 credcheck.password_min_repeat       | 0
 credcheck.password_min_special      | 0
 credcheck.password_min_upper        | 0
 credcheck.password_not_contain      |
 credcheck.password_reuse_history    | 0
 credcheck.password_reuse_interval   | 0
 credcheck.password_valid_max        | 0
 credcheck.password_valid_until      | 0
 credcheck.reset_superuser           | off
 credcheck.username_contain          |
 credcheck.username_contain_password | on
 credcheck.username_ignore_case      | off
 credcheck.username_min_digit        | 0
 credcheck.username_min_length       | 4
 credcheck.username_min_lower        | 0
 credcheck.username_min_repeat       | 0
 credcheck.username_min_special      | 0
 credcheck.username_min_upper        | 0
 credcheck.username_not_contain      |
(29 rows)

1. 测试 credcheck.username_min_length
# 查看credcheck.username_min_length的值
antdb=# SHOW credcheck.username_min_length;
  credcheck.username_min_length
-------------------------------
 1
(1 row)

# 设置credcheck.username_min_length的值
antdb=# SET credcheck.username_min_length TO 4;
SET

# 创建满足credcheck.username_min_length的值设置的用户才会成功
antdb=# CREATE USER abc WITH PASSWORD 'pass';
ERROR:  username length should match the configured credcheck.username_min_length
antdb=# CREATE USER abcd WITH PASSWORD 'pass';
CREATE ROLE


2. 设置 credcheck.password_ignore_case,忽略大小写
antdb=# SET credcheck.password_ignore_case=on;
SET
antdb=# SHOW credcheck.password_ignore_case;
 credcheck.password_ignore_case 
--------------------------------
 on
(1 row)
antdb=# CREATE USER user6 WITH PASSWORD 'user6@123';
ERROR:  password should not contain username
antdb=# CREATE USER user6 WITH PASSWORD 'USER6@123';   --忽略大小写后,跟'user6@123'一样
ERROR:  password should not contain username
antdb=# CREATE USER user6 WITH PASSWORD 'abcd@123';  
CREATE ROLE
问题反馈