6.5. 使用 Ansible 配置 Web 控制台,允许用户使用智能卡通过 SSH 向远程主机进行身份验证,而无需再次进行身份验证
登录到 RHEL web 控制台中的用户帐户后,作为身份管理 (IdM) 系统管理员,您可能需要使用 SSH
协议连接到远程机器。您可以使用受限委托 功能来使用 SSH
,而无需再次进行身份验证。
按照以下流程,使用 servicedelegationrule
和 servicedelegationtarget
ansible-freeipa
模块将 Web 控制台配置为使用受限委托。在以下示例中,web 控制台会话在 myhost.idm.example.com 主机上运行,它被配置为代表经过身份验证的用户使用 SSH
访问 remote.idm.example.com 主机。
先决条件
-
IdM
admin
密码。 -
对 remote.idm.example.com 的
root
访问权限。 - Web 控制台服务存在于 IdM 中。
- remote.idm.example.com 主机存在于 IdM 中。
Web 控制台在用户会话中创建了一个
S4U2Proxy
Kerberos ticket。要验证是否是这种情况,请以 IdM 用户身份登录 Web 控制台,打开Terminal
页面,并输入:$ klist Ticket cache: FILE:/run/user/1894000001/cockpit-session-3692.ccache Default principal: user@IDM.EXAMPLE.COM Valid starting Expires Service principal 07/30/21 09:19:06 07/31/21 09:19:06 HTTP/myhost.idm.example.com@IDM.EXAMPLE.COM 07/30/21 09:19:06 07/31/21 09:19:06 krbtgt/IDM.EXAMPLE.COM@IDM.EXAMPLE.COM for client HTTP/myhost.idm.example.com@IDM.EXAMPLE.COM
您已配置了 Ansible 控制节点以满足以下要求:
- 您使用 Ansible 版本 2.14 或更高版本。
-
您已在 Ansible 控制器上安装了
ansible-freeipa
软件包。 - 示例假定在 ~/MyPlaybooks/ 目录中,您已创建了一个带有 IdM 服务器的完全限定域名(FQDN)的 Ansible 清单文件。
-
示例假定 secret.yml Ansible vault 存储了
ipaadmin_password
。
-
目标节点(这是执行
ansible-freeipa
模块的节点)是 IdM 域的一部分,来作为 IdM 客户端、服务器或副本。
流程
进入您的 ~/MyPlaybooks/ 目录:
$ cd ~/MyPlaybooks/
创建包含以下内容的
web-console-smart-card-ssh.yml
playbook:创建确保存在委派目标的任务:
--- - name: Playbook to create a constrained delegation target hosts: ipaserver vars_files: - /home/user_name/MyPlaybooks/secret.yml tasks: - name: Ensure servicedelegationtarget web-console-delegation-target is present ipaservicedelegationtarget: ipaadmin_password: "{{ ipaadmin_password }}" name: web-console-delegation-target
添加将目标主机添加到委派目标的任务:
- name: Ensure servicedelegationtarget web-console-delegation-target member principal host/remote.idm.example.com@IDM.EXAMPLE.COM is present ipaservicedelegationtarget: ipaadmin_password: "{{ ipaadmin_password }}" name: web-console-delegation-target principal: host/remote.idm.example.com@IDM.EXAMPLE.COM action: member
添加一个任务来确保存在委派规则:
- name: Ensure servicedelegationrule delegation-rule is present ipaservicedelegationrule: ipaadmin_password: "{{ ipaadmin_password }}" name: web-console-delegation-rule
添加一项任务,该任务确保 Web 控制台客户端服务的 Kerberos 主体是受限委派规则的成员:
- name: Ensure the Kerberos principal of the web console client service is added to the servicedelegationrule web-console-delegation-rule ipaservicedelegationrule: ipaadmin_password: "{{ ipaadmin_password }}" name: web-console-delegation-rule principal: HTTP/myhost.idm.example.com action: member
添加一个任务,以确保 delegation 规则与 web-console-delegation-target 委派目标关联:
- name: Ensure a constrained delegation rule is associated with a specific delegation target ipaservicedelegationrule: ipaadmin_password: "{{ ipaadmin_password }}" name: web-console-delegation-rule target: web-console-delegation-target action: member
- 保存该文件。
运行 Ansible playbook。指定 playbook 文件、存储保护 secret.yml 文件的密码,以及清单文件:
$ ansible-playbook --vault-password-file=password_file -v -i inventory web-console-smart-card-ssh.yml
在 remote.idm.example.com 上启用 Kerberos 身份验证:
-
以
root
身份通过SSH
连接到 remote.idm.example.com。 -
打开
/etc/ssh/sshd_config
文件进行编辑。 -
通过取消注释
GSSAPIAuthentication no
行,并将它替换为GSSAPIAuthentication yes
来启用GSSAPIAuthentication
。
-
以
其他资源
- 使用智能卡登录到 web 控制台
- 身份管理中的受限委托
-
/usr/share/doc/ansible-freeipa/
目录中的README-servicedelegationrule.md
和README-servicedelegationtarget.md
-
/usr/share/doc/ansible-freeipa/playbooks/servicedelegationtarget
和/usr/share/doc/ansible-freeipa/playbooks/servicedelegationrule
目录中的 playbook 示例