19.8. 使用 Ansible playbook 将额外的密码策略选项应用到 IdM 组
您可以使用 Ansible playbook 应用额外的密码策略选项,来为特定的 IdM 组增强密码策略要求。为此,您可以使用 maxrepeat、maxsequence、dictcheck 和 usercheck 密码策略选项。这个示例描述了如何为 managers 组设置以下要求:
- 用户新密码不包含对应用户名的用户。
- 密码连续不包含两个以上相同字符。
- 密码中的任何单调字符序列都不能超过 3 个字符。这意味着系统不接受如 1234 或 abcd 这样序列的密码。
先决条件
您已配置了 Ansible 控制节点以满足以下要求:
- 您使用 Ansible 版本 2.13 或更高版本。
-
您已在 Ansible 控制器上安装了
ansible-freeipa软件包。 - 您已在 ~/MyPlaybooks/ 目录中创建了一个带有 IdM 服务器的完全限定域名(FQDN)的 Ansible 清单文件。
-
您已将
ipaadmin_password存储在 secret.yml Ansible vault 中。
- 正在确保 IdM 中存在密码策略的组。
流程
创建 Ansible playbook 文件 manager_pwpolicy_present.yml,其定义了您要确保其存在的密码策略。要简化此步骤,请复制并修改以下示例:
--- - name: Tests hosts: ipaserver vars_files: - /home/user_name/MyPlaybooks/secret.yml tasks: - name: Ensure presence of usercheck and maxrepeat pwpolicy for group managers ipapwpolicy: ipaadmin_password: "{{ ipaadmin_password }}" name: managers usercheck: True maxrepeat: 2 maxsequence: 3运行 playbook:
$ ansible-playbook --vault-password-file=password_file -v -i path_to_inventory_directory/inventory.file path_to_playbooks_directory_/manager_pwpolicy_present.yml
验证
添加名为 test_user 的测试用户:
$ ipa user-add test_user First name: test Last name: user ---------------------------- Added user "test_user" ----------------------------将 test 用户添加到 managers 组:
- 在 IdM Web UI 中,点 Identity>Groups>User Groups。
- 点 managers。
- 点击 Add。
- 在 Add users into user group 'managers' 页面上,检查 test_user。
- 点击 > 箭头将用户移到 Prospect ive 列中。
- 点击 Add。
重置测试用户的密码:
- 前往 Identity>Users。
- 单击 test_user。
- 在 Actions 菜单中,单击 Reset Password。
- 输入用户的临时密码。
尝试获取 test_user 的 Kerberos 票据授予票据(TGT):
在命令行中输入以下命令:
$ kinit test_user- 输入临时密码。
系统会通知您必须更改密码。输入包含用户名 test_user 的密码:
Password expired. You must change it now. Enter new password: Enter it again: Password change rejected: Password not changed. Unspecified password quality failure while trying to change password. Please try again.系统通知您输入的密码被拒绝。输入包含连续三个或多个相同字符的密码:
Password change rejected: Password not changed. Unspecified password quality failure while trying to change password. Please try again. Enter new password: Enter it again:系统通知您输入的密码被拒绝。输入一个包含 3 个以上字符的单调字符序列的密码。此类序列的示例包括 1234 和 fedc :
Password change rejected: Password not changed. Unspecified password quality failure while trying to change password. Please try again. Enter new password: Enter it again:系统通知您输入的密码被拒绝。输入满足 managers 密码策略条件的密码:
Password change rejected: Password not changed. Unspecified password quality failure while trying to change password. Please try again. Enter new password: Enter it again:
验证您是否已获得 TGT,这只有在输入了有效密码后才有可能:
$ klist Ticket cache: KCM:0:33945 Default principal: test_user@IDM.EXAMPLE.COM Valid starting Expires Service principal 07/07/2021 12:44:44 07/08/2021 12:44:44 krbtgt@IDM.EXAMPLE.COM@IDM.EXAMPLE.COM