37.2. 使用 Ansible 为 web 控制台中的 SSH 登录配置智能卡验证
在 RHEL web 控制台中登录到用户帐户后,您可以使用 SSH 协议连接到远程机器。您可以使用 servicedelegationrule
和 servicedelegationtarget
Ansible 模块为受限委托功能配置 Web 控制台,这将启用 SSH 连接,而无需再次进行身份验证。
在示例流程中,web 控制台会话在 myhost.idm.example.com
主机上运行,并将它配置为代表经过身份验证的用户使用 SSH 访问 remote.idm.example.com
主机。
先决条件
-
您已在
myhost.idm.example.com
上获得了 IdMadmin
ticket-granting ticket (TGT)。 -
您有访问
remote.idm.example.com
的root
权限。 - 运行 Web 控制台的主机是 IdM 域的成员。
您已配置了 Ansible 控制节点以满足以下要求:
-
您已安装
ansible-freeipa
软件包。 -
示例假设您在
~/MyPlaybooks/
目录中创建了一个具有 IdM 服务器的完全限定域名(FQDN)的 Ansible 清单文件。 -
示例假定
secret.yml
Ansible vault 存储了ipaadmin_password
。
-
您已安装
-
目标节点(即
ansible-freeipa
模块运行的节点)是 IdM 域的一部分,作为 IdM 客户端、服务器或副本。
流程
进入您的
~/MyPlaybooks/
目录:cd ~/MyPlaybooks/
$ cd ~/MyPlaybooks/
Copy to Clipboard Copied! 将敏感变量存储在加密的文件中:
创建 vault :
ansible-vault create secret.yml
$ ansible-vault create secret.yml New Vault password: <vault_password> Confirm New Vault password: <vault_password>
Copy to Clipboard Copied! 在
ansible-vault create
命令打开编辑器后,以<key>: <value>
格式输入敏感数据:ipaadmin_password: <admin_password>
ipaadmin_password: <admin_password>
Copy to Clipboard Copied! - 保存更改,并关闭编辑器。Ansible 加密 vault 中的数据。
在 Terminal 页面中,验证 web 控制台是否在用户会话中为 User to Proxy (S4U2proxy) Kerberos ticket 创建一个服务:
klist
$ klist … Valid starting Expires Service principal 05/20/25 09:19:06 05/21/25 09:19:06 HTTP/myhost.idm.example.com@IDM.EXAMPLE.COM …
Copy to Clipboard Copied! 创建包含以下内容的
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: 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
Copy to Clipboard Copied! 添加将目标主机添加到委派目标的任务:
- 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 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
Copy to Clipboard Copied! 添加一个任务来确保存在委派规则:
- name: Ensure servicedelegationrule delegation-rule is present ipaservicedelegationrule: ipaadmin_password: "{{ ipaadmin_password }}" name: web-console-delegation-rule
- name: Ensure servicedelegationrule delegation-rule is present ipaservicedelegationrule: ipaadmin_password: "{{ ipaadmin_password }}" name: web-console-delegation-rule
Copy to Clipboard Copied! 添加一项任务,该任务确保 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
- 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
Copy to Clipboard Copied! 添加一个任务,以确保 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
- 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
Copy to Clipboard Copied! 添加一个任务,该任务在
remote.idm.example.com
上启用 Kerberos 身份验证:- name: Enable Kerberos authentication hosts: remote.idm.example.com vars: sshd_config: GSSAPIAuthentication: true roles: - role: rhel-system-roles.sshd
- name: Enable Kerberos authentication hosts: remote.idm.example.com vars: sshd_config: GSSAPIAuthentication: true roles: - role: rhel-system-roles.sshd
Copy to Clipboard Copied!
- 保存该文件。
运行 Ansible playbook。指定 playbook 文件、存储保护
secret.yml
文件和清单文件的密码的文件:ansible-playbook --vault-password-file=password_file -v -i inventory web-console-smart-card-ssh.yml
$ ansible-playbook --vault-password-file=password_file -v -i inventory web-console-smart-card-ssh.yml
Copy to Clipboard Copied!