17.2. 在创建帐户后自动禁用帐户一定时间

按照以下步骤,在 dc=example,dc=com 条目中配置该帐户在管理员创建之后有 60 天过期。

例如,使用帐户过期功能来确保外部 worker 的帐户在创建后锁定一定时间。

流程

  1. 启用帐户策略插件:

    # dsconf -D "cn=Directory Manager" ldap://server.example.com plugin account-policy enable
  2. 配置插件配置条目:

    # 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: 启用登录时间记录。这需要使用 Class of Service (CoS)或具有帐户策略的角色,即使它没有设置 acctPolicySubentry 属性。
    • --state-attr createTimestamp :配置 Account Policy 插件使用 createTimestamp 属性的值来计算帐户是否已过期。
    • --Alt-state-attr 1.1 :禁止使用 alternative 属性检查主属性是否不存在。
    • --spec-attr acctPolicySubentry: Configures Directory Server 将策略应用到设置了 acctPolicySubentry 属性的条目。您可以在 CoS 条目中配置此属性。
    • --limit-attr accountInactivityLimit: 配置帐户过期策略条目中的 accountInactivityLimit 属性存储最大期限。
  3. 重启实例:

    # dsctl instance_name restart
  4. 创建帐户过期策略条目:

    # 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 Policy

    accountInactivityLimit 属性中的值配置该帐户在创建后 5184000 秒(60 天)过期。

  5. 创建 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

    此模板条目引用帐户到期策略。

  6. 创建 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.

    如果 Directory Server 拒绝访问并返回这个错误,则帐户过期工作。