暂无图片
暂无图片
暂无图片
暂无图片
暂无图片

Mogdb用户可用性参数VALID UNTIL,EXPIRD和password_effect_time实践参考测试

由迪 2024-03-22
209

原作者:陈坤

Mogdb 中 关于密码过期的参数有password_effect_time和password_notify_time,客户因为有审计要求,需要设置此参数,故对此参数设置后的行为进行了测试。并对用户可用性相关的设置进行了归纳总结。

1,密码有效期

参数说明:

password_effect_time:

该字段决定帐户密码的有效时间,单位天。默认值90。

password_notify_time:

该字段决定帐户密码到期前提醒的天数。默认值7。

password_effect_time过期测试

修改 password_effect_time

gs_guc set -I all -N all -c “password_effect_time=1”

gs_ctl reload

gsql -c “show password_effect_time;”

此时密码过期时间为1天,只要不是一天内修改过密码,数据库中之前的用户密码都将过期。

登录数据库,提示密码过期:

[enmo@master137 ~]$ gsql -Uck -WEnmo#2023 -r

gsql ((MogDB 5.0.1 build ae6d2ada) compiled at 2023-08-16 09:07:43 commit 0 last mr 1804 )

NOTICE : The password has been expired, please change the password.

Non-SSL connection (SSL connection is recommended when requiring high-security)

Type “help” for help.

且用omm 在服务器免密登录数据库,也会同样提示密码过期。

使用omm用户登录修改密码

gsql -r

alter user ck identified by “Enmo#2024”;

再次登录

可以正常登录,由于设置了 password_notify_time=7 即密码到期7天内,登录会打印提示:1 days left before password expired, please change the password.

[enmo@master137 ~]$ gsql -Uck -WEnmo#2024 -r

gsql ((MogDB 5.0.1 build ae6d2ada) compiled at 2023-08-16 09:07:43 commit 0 last mr 1804 )

NOTICE : 1 days left before password expired, please change the password.

Non-SSL connection (SSL connection is recommended when requiring high-security)

Type “help” for help.

修改操作系统时间,

su - root

date -s “2023-11-12 12:00:00”

然后再登录数据库,再次提示密码失效。

[enmo@master137 ~]$ gsql -Uck -WEnmo#2024 -r

gsql ((MogDB 5.0.1 build ae6d2ada) compiled at 2023-08-16 09:07:43 commit 0 last mr 1804 )

NOTICE : The password has been expired, please change the password.

Non-SSL connection (SSL connection is recommended when requiring high-security)

Type “help” for help.

提示密码过期依然可以登录,且能正常进行数据库操作。

修改过期时间

gs_guc reload -I all -N all -c “password_effect_time=10”

再次尝试登录,没有过期提示了。

[enmo@master137 ~]$ gsql -Uck -WEnmo#2024 -r

gsql ((MogDB 5.0.1 build ae6d2ada) compiled at 2023-08-16 09:07:43 commit 0 last mr 1804 )

Non-SSL connection (SSL connection is recommended when requiring high-security)

Type “help” for help.

创建用户指定用户有效期

创建用户时,可以通过VALID BEGIN,VALID UNTIL设置用户有效期。这个在有效期内,用户可正常使用,超过有效期,用户将无法登陆。

CREATE USER test1 WITH PASSWORD ‘test@123’ VALID BEGIN ‘2023-11-10 08:00:00’ VALID UNTIL ‘2023-11-14 23:00:00’;

修改时间

date -s “2023-11-13 12:00:00”

登录,提示账户不在有效期内

[enmo@master137 ~]$ gsql -Utest1 -Wtest@123

gsql: FATAL: The account is not within the period of validity.

创建过期用户

在创建用户时可指定EXPIRED参数,即创建密码失效用户,该用户不允许执行简单查询和扩展查询。只有在修改自身密码后才可正常执行语句。

MogDB=# CREATE USER test1 WITH PASSWORD ‘test@123’ expired;

NOTICE: The encrypted password contains MD5 ciphertext, which is not secure.

CREATE ROLE

MogDB=# \q

[enmo@master137 ~]$ gsql -Utest1 -Wtest@123

可以登录,但是尝试进行查询操作,提示需要修改密码之后才能进行操作:

MogDB=> select current_user;

ERROR: Please use “ALTER ROLE user_name IDENTIFIED BY ‘password’ REPLACE ‘old password’;” to modify the expired password of user test1 before operation!

总结:

这里介绍了三种限制用户行为的手段或参数:

password_effect_time只有提示作用,密码过期用户依然可正常操作数据库。

VALID BEGIN,VALID UNTIL创建的用户只能在指定时间能可用,超时后将无法登录。

创建EXPIRED用户相当于创建了一个首次操作数据库就要修改密码的用户。且普通用户修改自己的密码,需要指定旧密码。要用

ALTER ROLE user_name IDENTIFIED BY ‘password’ REPLACE ‘old password’;

语句

注意:在PG_USER_STATUS 视图中的 passwordexpired 表示的是 密码是否失效,意思是用户是否是expired 用户,即创建用户时带有expired 选项。而不是 密码设置时间 超过 password_effect_time 过期的意思。

CREATE USER test1 WITH PASSWORD ‘test@123’ expired;

select b.rolname, a.* from PG_USER_STATUS a,pg_authid b where a.roloid=b.oid;

rolname | roloid | failcount | locktime | rolstatus | permspace | tempspace | passwordexpired

---------±-------±----------±------------------------------±----------±----------±----------±----------------

susi | 16775 | 0 | 2023-10-31 14:55:40.9036+08 | 0 | 8192 | 0 | 0

ck | 16779 | 0 | 2023-10-31 14:52:37.389781+08 | 0 | 327680 | 0 | 0

test1 | 20244 | 0 | 2023-11-11 12:16:47.601055+08 | 0 | 0 | 0 | 1

(3 rows)

如果要查询用户 根据 password_effect_time计算密码是否过期,可使用这条sql:

select

​ rolname ,

​ a.passwordtime,

​ pg_catalog.current_setting(‘password_effect_time’),

​ a.passwordtime + pg_catalog.current_setting(‘password_effect_time’)::interval as 过期日期

from

​ pg_catalog.pg_roles pr

left join

(

​ select

​ roloid,

​ max(passwordtime) as passwordtime

​ from

​ pg_auth_history

​ group by

​ roloid) a on a.roloid = pr.“oid”

where rolname not like ‘gs_%’;

rolname | passwordtime | current_setting | 过期日期

---------±------------------------------±----------------±------------------------------

enmo | 2023-10-31 14:08:25.20573+08 | 1 | 2023-11-01 14:08:25.20573+08

susi | 2023-10-31 14:51:35.851861+08 | 1 | 2023-11-01 14:51:35.851861+08

ck | 2023-11-10 15:37:48.338082+08 | 1 | 2023-11-11 15:37:48.338082+08

test1 | 2023-11-12 12:04:45.88003+08 | 1 | 2023-11-13 12:04:45.88003+08

(4 rows)

「喜欢这篇文章,您的关注和赞赏是给作者最好的鼓励」
关注作者
【版权声明】本文为墨天轮用户原创内容,转载时必须标注文章的来源(墨天轮),文章链接,文章作者等基本信息,否则作者和墨天轮有权追究责任。如果您发现墨天轮中有涉嫌抄袭或者侵权的内容,欢迎发送邮件至:contact@modb.pro进行举报,并提供相关证据,一经查实,墨天轮将立刻删除相关内容。

文章被以下合辑收录

评论