5.2. 在创建帐户后自动禁用帐户一定时间
按照以下步骤配置 dc=example,dc=com 条目中的帐户在管理员创建 60 天后过期。
使用帐户到期功能,例如,确保外部 worker 的帐户在创建时间被锁定。
流程
启用帐户策略插件:
# dsconf -D "cn=Directory Manager" ldap://server.example.com plugin account-policy enable配置插件配置条目:
# dsconf -D "cn=Directory Manager" ldap://server.example.com plugin account-policy config-entry set "cn=config,cn=Account Policy Plugin,cn=plugins,cn=config" --always-record-login yes --state-attr createTimestamp --alt-state-attr 1.1 --spec-attr acctPolicySubentry --limit-attr accountInactivityLimit这个命令使用以下选项:
-
--always-record-login yes:启用登录时间的日志记录。这需要使用带帐户策略的类服务(CoS)或角色,即使它没有设置acctPolicySubentry属性。 -
--state-attr createTimestamp: Configures that the Account Policy 插件使用createTimestamp属性的值来计算帐户是否已过期。 -
--Alt-state-attr 1.1:禁用使用替代属性来检查主属性是否不存在。 -
--spec-attr acctPolicySubentry: Configures Directory Server 应用策略到设置了acctPolicySubentry属性的条目。您可以在 CoS 条目中配置此属性。 -
--limit-attr accountInactivityLimit:配置帐户到期策略条目中的accountInactivityLimit属性存储最大年龄。
-
重启实例:
# dsctl instance_name restart创建帐户过期策略条目:
# ldapadd -D "cn=Directory Manager" -W -H ldap://server.example.com -x dn: cn=Account Expiration Policy,dc=example,dc=com objectClass: top objectClass: ldapsubentry objectClass: extensibleObject objectClass: accountpolicy accountInactivityLimit: 5184000 cn: Account Expiration PolicyaccountInactivityLimit属性中的值将配置帐户在创建后5184000秒(60 天)过期。创建 CoS 模板条目:
# ldapadd -D "cn=Directory Manager" -W -H ldap://server.example.com -x dn: cn=TemplateCoS,dc=example,dc=com objectClass: top objectClass: ldapsubentry objectClass: extensibleObject objectClass: cosTemplate acctPolicySubentry: cn=Account Expiration Policy,dc=example,dc=com此模板条目引用帐户到期策略。
创建 CoS 定义条目:
# ldapadd -D "cn=Directory Manager" -W -H ldap://server.example.com -x dn: cn=DefinitionCoS,dc=example,dc=com objectClass: top objectClass: ldapsubentry objectclass: cosSuperDefinition objectclass: cosPointerDefinition cosTemplateDn: cn=TemplateCoS,dc=example,dc=com cosAttribute: acctPolicySubentry default operational-default此定义条目引用了 CoS 模板条目,并导致
acctPolicySubentry属性出现在每个用户条目中,值设为cn=Account Expiration Policy,dc=example,dc=com。
验证
尝试以存储在
dc=example,dc=com条目中的用户的身份连接到该目录,其createTimestamp属性设置为一个大于 60 天前的值:# ldapsearch -H ldap://server.example.com -x -D "uid=example,dc=example,dc=com" -W -b "dc=example,dc=com" ldap_bind: Constraint violation (19) additional info: Account inactivity limit exceeded. Contact system administrator to reset.如果目录服务器拒绝访问并返回这个错误,则帐户到期可以正常工作。