35.4. 使用 Ansible 启用 IdM 用户通过外部 IdP 进行身份验证

您可以使用 用户 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 客户端和服务器使用 RHEL 9.1 或更高版本。
  • 您的 IdM 客户端和服务器使用 SSSD 2.7.0 或更高版本。
  • 您已在 IdM 中创建了对外部 IdP 的引用。请参阅使用 Ansible 创建对外部身份提供程序的引用
  • 您已配置了 Ansible 控制节点以满足以下要求:

    • 您使用 Ansible 版本 2.14 或更高版本。
    • 您已在 Ansible 控制器上安装了 ansible-freeipa 软件包。
    • 您使用 RHEL 9.4 或更高版本。
    • 示例假定在 ~/MyPlaybooks/ 目录中,您已创建了带有 IdM 服务器的完全限定域名(FQDN)的 Ansible 清单文件
    • 示例假定 secret.yml Ansible vault 存储了 ipaadmin_password

流程

  1. 在 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
  2. 保存这个文件。
  3. 运行 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 上游文档