55.4. 使用 Ansible 使 IdM 用户能够通过外部 IdP 进行身份验证
您可以使用 user
ansible-freeipa
模块使身份管理(IdM)用户能够通过外部身份提供者(IdP)进行身份验证。为此,将您之前创建的外部 IdP 引用与 IdM 用户帐户相关联。完成此流程,以使用 Ansible 将名为 github_idp 的外部 IdP 引用与名为 idm-user-with-external-idp 的 IdM 用户相关联。因此,用户能够使用 my_github_account_name github 身份,以 idm-user-with-external-idp 向 IdM 进行身份验证。
先决条件
- 您的 IdM 客户端和服务器使用 RHEL 9.1 或更高版本。
- 您的 IdM 客户端和服务器使用 SSSD 2.7.0 或更高版本。
- 您已在 IdM 中创建了一个对外部 IdP 的引用。请参阅 使用 Ansible 创建一个到外部身份提供者的引用。
您已配置了 Ansible 控制节点以满足以下要求:
- 您使用 Ansible 版本 2.15 或更高版本。
-
您已在 Ansible 控制器上安装了
ansible-freeipa
软件包。 - 您正在使用 RHEL 9.4 或更高版本。
- 示例假定在 ~/MyPlaybooks/ 目录中,您已创建了一个带有 IdM 服务器的完全限定域名(FQDN)的 Ansible 清单文件。
-
示例假定 secret.yml Ansible vault 存储了
ipaadmin_password
。
流程
在 Ansible 控制节点上,创建一个 enable-user-to-authenticate-via-external-idp.yml playbook:
--- - name: Ensure an IdM user uses an external IdP to authenticate to IdM hosts: ipaserver become: false gather_facts: false tasks: - name: Retrieve Github user ID ansible.builtin.uri: url: “https://api.github.com/users/my_github_account_name” method: GET headers: Accept: “application/vnd.github.v3+json” register: user_data - name: Ensure IdM user exists with an external IdP authentication ipauser: ipaadmin_password: "{{ ipaadmin_password }}" name: idm-user-with-external-idp first: Example last: User userauthtype: idp idp: github_idp idp_user_id: my_github_account_name
- 保存该文件。
运行 Ansible playbook。指定 playbook 文件、存储保护 secret.yml 文件的密码,以及清单文件:
$ ansible-playbook --vault-password-file=password_file -v -i inventory enable-user-to-authenticate-via-external-idp.yml
验证
登录到 IdM 客户端,并验证对 idm-user-with-external-idp 用户的
ipa user-show
命令的输出是否显示到 IdP 的引用:$ ipa user-show idm-user-with-external-idp User login: idm-user-with-external-idp First name: Example Last name: User Home directory: /home/idm-user-with-external-idp Login shell: /bin/sh Principal name: idm-user-with-external-idp@idm.example.com Principal alias: idm-user-with-external-idp@idm.example.com Email address: idm-user-with-external-idp@idm.example.com ID: 35000003 GID: 35000003 User authentication types: idp External IdP configuration: github External IdP user identifier: idm-user-with-external-idp@idm.example.com Account disabled: False Password: False Member of groups: ipausers Kerberos keys available: False
其他资源
-
idp
ansible-freeipa
上游文档