核心内容摘要
黑苹果配置系统指南:使用OpenCore工具从零开始的高效实践
文章目录环境文档用途详细信息环境系统平台Linux x
Red Hat Enterprise Linux 7版本
4.
2文档用途通过调用函数的方式增强用户密码的安全性详细信息一般来说数据库密码安全管理要考虑以下几个方面 :密码过期策略, 决定密码的有效期, 多长时间过期.密码复用策略, 密码修改时需要对比以前的密码, 多少次以后才可以复用, 或者永不能使用与以前密码相同的密码.密码长度策略, 密码的最小长度, 太短的话很容易被穷举法破解, 一般至少使用8位以上长度的密码.密码复杂度策略, 密码包含的字符复杂度, 一般要求包含数字字母大小写以及特殊字符. 另外不要使用与数据库名, 用户名相似或一致的密码.密码字典过滤, 过滤掉一些用户常用的或者有意义的字符, 也是为了避免密码很容易被穷举破解.密码存储策略, 使用加密存储, 不要使用明文存储.加密存储在创建用户时使用encrypted password即可.如果设置了password_encryptionoff, 同时创建用户时不加encrypted, 那么密码将以明文存储.加密存储方法 :highgo# create role u1 login encrypted password highgo;CREATEROLE highgo# select * from pg_shadow where usenameu1;usename|usesysid|usecreatedb|usesuper|userepl|usebypassrls|passwd|v aluntil|useconfig---------------------------------------------------------------------------------------------------------------------------u1|131294|f|f|f|f|md50a0a7a2ef5607a4424f00e4903877f2e||(1row)密码锁策略, 密码输入错误多少次后锁用户, 多长时间解锁.HighgoDB不支持密码锁策略.密码保护策略, 密码输入错误多少次后延迟认证. 可用来防止暴力破解.目前HighgoDB在密码管理这块做得较弱, 以下举例通过函数来实现其中的部分安全策略 :创建一个字典表, 用于存放已经使用过的密码的md5值, 以及用来进行暴力破解的密码字典的md5值.highgo# create table pwd_dictionary(pwd text unique);CREATETABLE创建一个记录用户最后一次修改密码时间的表. 用于实施密码过期提醒策略.highgo# create table user_pwd(rolename name not null unique, pwd_modify_time timestamp not null);CREATETABLE创建用户的函数 :highgo# create or replace function create_role(i_rolename name, i_pwd text) returns void as $$declarev_lengthint:8;begin-- 密码长度策略iflength(i_pwd)v_lengththenraise noticepassword too short, please use password long than %.,v_length;return;endif;-- 密码复杂度策略, 包含数字, 字母大小写.ifnot(i_pwd~[a-z]andi_pwd~[A-Z]andi_pwd~[
])thenraise noticepassword too simple, please ensure password contain a-z,A-Z and 0-
;return;endif;-- 密码复用策略, 不允许重复使用已经存在的密码.-- 密码字典策略, 不允许使用密码字典中的密码.insertintopwd_dictionary(pwd)values(md5(i_pwd));-- 插入用户表, 记录用户最后一次修改密码的时间, 用于密码过期策略insertintouser_pwd(rolename,pwd_modify_time)values(i_rolename,now());-- 创建用户executecreate role ||i_rolename|| encrypted password ||quote_literal(i_pwd);raise noticecreate role % successed.,i_rolename;return;end;$$languageplpgsql strict;CREATEFUNCTION创建用户密码过短,不允许创建.highgo# select * from create_role(u4,pwd);NOTICE: password too short,pleaseusepassword long than
create_role-------------(1row)创建用户密码过于简单, 不允许创建.highgo# select * from create_role(u4,abcdefee);NOTICE: password toosimple,please ensure password contain a-z,A-Zand0-
create_role-------------(1row)创建用户正常.highgo# select * from create_role(u4,aA0ffffffff);NOTICE:createrole u4 successed.create_role-------------(1row)创建用户密码与现有密码重复, 不允许创建.highgo# select * from create_role(new,aA0ffffffff);ERROR:duplicatekeyvalueviolatesuniqueconstraintpwd_dictionary_pwd_keyDETAIL:Key(pwd)(2b9aa88182d13d35930180b4cc791beb)alreadyexists.CONTEXT:SQLstatementinsert into pwd_dictionary(pwd) values (md5(i_pwd))PL/pgSQLfunctioncreate_role(name,text)line17atSQLstatement修改用户密码的函数 :highgo# create or replace function alter_role_pwd(i_rolename name, i_pwd text) returns void as $$declarev_lengthint:8;begin-- 密码长度策略iflength(i_pwd)v_lengththenraise noticepassword too short, please use password long than %.,v_length;return;endif;-- 密码复杂度策略, 包含数字, 字母大小写.ifnot(i_pwd~[a-z]andi_pwd~[A-Z]andi_pwd~[
])thenraise noticepassword too simple, please ensure password contain a-z,A-Z and 0-
;return;endif;-- 密码复用策略, 不允许重复使用已经存在的密码.-- 密码字典策略, 不允许使用密码字典中的密码.insertintopwd_dictionary(pwd)values(md5(i_pwd));-- 更新用户表, 记录用户最后一次修改密码的时间, 用于密码过期策略updateuser_pwdsetpwd_modify_timenow()whererolenamei_rolename;-- 修改用户密码executealter role ||i_rolename|| encrypted password ||quote_literal(i_pwd);raise noticemodify role % password successed.,i_rolename;return;end;$$languageplpgsql strict;CREATEFUNCTION使用该函数修改用户密码 highgo# select * from alter_role_pwd(u4,new);NOTICE: password too short,pleaseusepassword long than
alter_role_pwd----------------(1row)highgo# select * from alter_role_pwd(u4,new
;NOTICE: password toosimple,please ensure password contain a-z,A-Zand0-
alter_role_pwd----------------(1row)highgo# select * from alter_role_pwd(u4,new2222222z
;NOTICE: password toosimple,please ensure password contain a-z,A-Zand0-
alter_role_pwd----------------(1row)highgo# select * from alter_role_pwd(u4,new2222222z2A);NOTICE:modifyrole u4 password successed.alter_role_pwd----------------(1row)highgo# select * from alter_role_pwd(u4,new2222222z2A);ERROR:duplicatekeyvalueviolatesuniqueconstraintpwd_dictionary_pwd_keyDETAIL:Key(pwd)(9a5c46207db775d4d98e64d427481cbc)alreadyexists.CONTEXT:SQLstatementinsert into pwd_dictionary(pwd) values (md5(i_pwd))PL/pgSQLfunctionalter_role_pwd(name,text)line17atSQLstatement密码过期提醒 :因为密码最后一次修改时间已经更新到user_pwd表, 所以结合这个可以在系统crontab中或者nagios监控软件中实施密码过期提醒.highgo# select * from user_pwd ;rolename|pwd_modify_time--------------------------------------u4|
:21:
5