Red Hat Training

A Red Hat training course is available for RHEL 8

55.2. 使用 Ansible playbook 确保在 IdM 中存在 HBAC 规则

按照以下流程,使用 Ansible playbook 确保基于主机的访问控制(HBAC)规则在身份管理(IdM)中存在。

先决条件

流程

  1. 创建一个清单文件,如 inventory.file,并在该文件中定义 ipaserver

    [ipaserver]
    server.idm.example.com
  2. 创建 Ansible playbook 文件,该文件定义您要确保其存在的 HBAC 策略。要简化此步骤,您可以复制并修改 /usr/share/doc/ansible-freeipa/playbooks/hbacrule/ensure-hbacrule-allhosts-present.yml 文件中的示例:

    ---
    - name: Playbook to handle hbacrules
      hosts: ipaserver
    
      vars_files:
      - /home/user_name/MyPlaybooks/secret.yml
      tasks:
      # Ensure idm_user can access client.idm.example.com via the sshd service
      - ipahbacrule:
          ipaadmin_password: "{{ ipaadmin_password }}"
          name: login
          user: idm_user
          host: client.idm.example.com
          hbacsvc:
          - sshd
          state: present
  3. 运行 playbook:

    $ ansible-playbook --vault-password-file=password_file -v -i path_to_inventory_directory/inventory.file path_to_playbooks_directory/ensure-new-hbacrule-present.yml

验证步骤

  1. 以管理员身份登录到 IdM Web UI。
  2. 导航到 PolicyHost-Based-Access-ControlHBAC Test
  3. Who 选项卡中,选择 idm_user。
  4. Accessing 选项卡中,选择 client.idm.example.com
  5. Via service 选项卡中,选择 sshd
  6. Rules 选项卡中,选择 login
  7. Run test 选项卡中,单击 Run test 按钮。如果您看到 ACCESS GRANTED,则 HBAC 规则成功实现。

其它资源

  • 请参阅 /usr/share/doc/ansible-freeipa 目录中的 README-hbacsvc.md , README-hbacsvcgroup.mdREADME-hbacrule.md 文件。
  • 请参阅 /usr/share/doc/ansible-freeipa/playbooks 目录的子目录中的 playbook。