37.3. 使用 Ansible 配置 Web 控制台,允许用户使用智能卡进行身份验证的用户运行 sudo,而无需再次进行身份验证
登录到 RHEL web 控制台中的用户帐户后,作为 RHEL Identity Management (IdM)系统管理员,您可能需要使用超级用户权限运行命令。您可以使用 受限委托 功能在系统上运行 sudo
,而无需再次进行身份验证。
按照以下流程,使用 ipaservicedelegationrule
和 ipaservicedelegationtarget
ansible-freeipa
模块将 Web 控制台配置为使用受限的委托。在以下示例中,Web 控制台会话运行在myhost.idm.example.com主机上。
先决条件
-
您已通过使用智能卡向 web 控制台会话进行身份验证,而获得了一个 IdM
admin
票据授予票(TGT)。 - Web 控制台服务已注册到 IdM 。
- myhost.idm.example.com 主机在 IdM 中存在。
-
您已为 IdM 服务器 上的域管理员启用了
admin
sudo
访问权限。 Web 控制台在用户会话中创建了一个
S4U2Proxy
Kerberos ticket。要验证是否是这种情况,请以 IdM 用户身份登录 Web 控制台,打开Terminal
页面,并输入:klist
$ 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
Copy to Clipboard Copied! 您已配置了 Ansible 控制节点以满足以下要求:
- 您在使用 Ansible 版本 2.15 或更高版本。
-
已安装
freeipa.ansible_freeipa
集合。 - 示例假定在 ~/MyPlaybooks/ 目录中,您已创建了一个具有 IdM 服务器的完全限定域名(FQDN)的 Ansible 清单文件。
-
示例假定 secret.yml Ansible vault 存储了您的
ipaadmin_password
,并且您可以访问存储了保护 secret.yml 文件的密码的文件。
-
目标节点(这是执行
freeipa.ansible_freeipa
模块的节点)是作为 IdM 客户端、服务器或副本的 IdM 域的一部分。
流程
在 Ansible 控制节点上,导航到 ~/MyPlaybooks/ 目录:
cd ~/MyPlaybooks/
$ cd ~/MyPlaybooks/
Copy to Clipboard Copied! 使用以下内容创建
web-console-smart-card-sudo.yml
playbook:创建确保存在委派目标的任务:
--- - name: Playbook to create a constrained delegation target hosts: ipaserver vars_files: - /home/user_name/MyPlaybooks/secret.yml tasks: - name: Ensure servicedelegationtarget named sudo-web-console-delegation-target is present freeipa.ansible_freeipa.ipaservicedelegationtarget: ipaadmin_password: "{{ ipaadmin_password }}" name: sudo-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 named sudo-web-console-delegation-target is present freeipa.ansible_freeipa.ipaservicedelegationtarget: ipaadmin_password: "{{ ipaadmin_password }}" name: sudo-web-console-delegation-target
Copy to Clipboard Copied! 添加将目标主机添加到委派目标的任务:
- name: Ensure that a member principal named host/myhost.idm.example.com@IDM.EXAMPLE.COM is present in a service delegation target named sudo-web-console-delegation-target freeipa.ansible_freeipa.ipaservicedelegationtarget: ipaadmin_password: "{{ ipaadmin_password }}" name: sudo-web-console-delegation-target principal: host/myhost.idm.example.com@IDM.EXAMPLE.COM action: member
- name: Ensure that a member principal named host/myhost.idm.example.com@IDM.EXAMPLE.COM is present in a service delegation target named sudo-web-console-delegation-target freeipa.ansible_freeipa.ipaservicedelegationtarget: ipaadmin_password: "{{ ipaadmin_password }}" name: sudo-web-console-delegation-target principal: host/myhost.idm.example.com@IDM.EXAMPLE.COM action: member
Copy to Clipboard Copied! 添加一个任务来确保存在委派规则:
- name: Ensure servicedelegationrule named sudo-web-console-delegation-rule is present freeipa.ansible_freeipa.ipaservicedelegationrule: ipaadmin_password: "{{ ipaadmin_password }}" name: sudo-web-console-delegation-rule
- name: Ensure servicedelegationrule named sudo-web-console-delegation-rule is present freeipa.ansible_freeipa.ipaservicedelegationrule: ipaadmin_password: "{{ ipaadmin_password }}" name: sudo-web-console-delegation-rule
Copy to Clipboard Copied! 添加一个任务,确保 Web 控制台服务的 Kerberos 主体是约束委派规则的一个成员:
- name: Ensure the Kerberos principal of the web console service is added to the service delegation rule named sudo-web-console-delegation-rule freeipa.ansible_freeipa.ipaservicedelegationrule: ipaadmin_password: "{{ ipaadmin_password }}" name: sudo-web-console-delegation-rule principal: HTTP/myhost.idm.example.com action: member
- name: Ensure the Kerberos principal of the web console service is added to the service delegation rule named sudo-web-console-delegation-rule freeipa.ansible_freeipa.ipaservicedelegationrule: ipaadmin_password: "{{ ipaadmin_password }}" name: sudo-web-console-delegation-rule principal: HTTP/myhost.idm.example.com action: member
Copy to Clipboard Copied! 添加一个任务,确保约束委派规则与 sudo-web-console-delegation-target 委派目标关联:
- name: Ensure a constrained delegation rule is associated with a specific delegation target freeipa.ansible_freeipa.ipaservicedelegationrule: ipaadmin_password: "{{ ipaadmin_password }}" name: sudo-web-console-delegation-rule target: sudo-web-console-delegation-target action: member
- name: Ensure a constrained delegation rule is associated with a specific delegation target freeipa.ansible_freeipa.ipaservicedelegationrule: ipaadmin_password: "{{ ipaadmin_password }}" name: sudo-web-console-delegation-rule target: sudo-web-console-delegation-target action: member
Copy to Clipboard Copied!
- 保存该文件。
运行 Ansible playbook。指定 playbook 文件、存储保护 secret.yml 文件的密码,以及清单文件:
ansible-playbook --vault-password-file=password_file -v -i inventory web-console-smart-card-sudo.yml
$ ansible-playbook --vault-password-file=password_file -v -i inventory web-console-smart-card-sudo.yml
Copy to Clipboard Copied! 启用
pam_sss_gss
,用来通过通用安全服务应用程序接口(GSSAPI)与系统安全服务守护进程(SSSD)合作来验证用户的 PAM 模块:-
打开
/etc/sssd/sssd.conf
文件进行编辑。 指定
pam_sss_gss
可以为 IdM 域中的sudo
和sudo -i
命令提供身份验证:[domain/idm.example.com] pam_gssapi_services = sudo, sudo-i
[domain/idm.example.com] pam_gssapi_services = sudo, sudo-i
Copy to Clipboard Copied! - 保存并退出文件。
-
打开
/etc/pam.d/sudo
文件进行编辑。 将以下行插入到
#%PAM-1.0
列表的顶部以允许但不要求sudo
命令的 GSSAPI 身份验证:auth sufficient pam_sss_gss.so
auth sufficient pam_sss_gss.so
Copy to Clipboard Copied! - 保存并退出文件。
-
打开
重启
SSSD
服务,以便上述更改立即生效:systemctl restart sssd
$ systemctl restart sssd
Copy to Clipboard Copied!