18.7. 创建修复 Ansible Playbook,使系统与特定基准保持一致
您可以创建一个 Ansible Playbook,它只包含使您的系统与特定基准保持一致所需的补救。此 playbook 更小,因为它没有涵盖已满足要求。创建 playbook 不会以任何方式修改您的系统,您只需为后续应用程序准备一个文件。
在 RHEL 8.6 中,Ansible Engine 被 ansible-core
软件包替代,该软件包只包含内置模块。请注意,很多 Ansible 补救使用社区和可端口操作系统接口(POSIX)集合中的模块,它们没有包含在内置模块中。在这种情况下,您可以使用 Bash 补救来替代 Ansible 补救。RHEL 8.6 中的 Red Hat Connector 包括修复 playbook 与 Ansible Core 正常工作所需的 Ansible 模块。
先决条件
-
scap-security-guide
软件包已安装。 -
ansible-core
软件包已安装。如需更多信息,请参阅 Ansible 安装指南。 -
rhc-worker-playbook
软件包已安装。 - 您知道要修复系统的配置文件的 ID。详情请参阅 查看配置文件以了解配置合规性。
流程
扫描系统并保存结果:
oscap xccdf eval --profile <profileID> --results <profile-results.xml> /usr/share/xml/scap/ssg/content/ssg-rhel8-ds.xml
# oscap xccdf eval --profile <profileID> --results <profile-results.xml> /usr/share/xml/scap/ssg/content/ssg-rhel8-ds.xml
Copy to Clipboard Copied! Toggle word wrap Toggle overflow 在带有结果的文件中找到结果 ID 的值:
oscap info <profile-results.xml>
# oscap info <profile-results.xml>
Copy to Clipboard Copied! Toggle word wrap Toggle overflow 根据第 1 步中生成的文件生成 Ansible Playbook:
oscap xccdf generate fix --fix-type ansible --result-id xccdf_org.open-scap_testresult_xccdf_org.ssgproject.content_profile_<profileID> --output <profile-remediations.yml> <profile-results.xml>
# oscap xccdf generate fix --fix-type ansible --result-id xccdf_org.open-scap_testresult_xccdf_org.ssgproject.content_profile_<profileID> --output <profile-remediations.yml> <profile-results.xml>
Copy to Clipboard Copied! Toggle word wrap Toggle overflow -
检查生成的 <
;profile-remediations.yml
> 文件是否包含在第 1 步中执行的扫描中失败的规则的 Ansible 修复。 使用 Ansible 修复您的系统,使其与所选配置文件一致:
ANSIBLE_COLLECTIONS_PATH=/usr/share/rhc-worker-playbook/ansible/collections/ansible_collections/ ansible-playbook -i "localhost," -c local <profile-remediations.yml>`
# ANSIBLE_COLLECTIONS_PATH=/usr/share/rhc-worker-playbook/ansible/collections/ansible_collections/ ansible-playbook -i "localhost," -c local <profile-remediations.yml>`
Copy to Clipboard Copied! Toggle word wrap Toggle overflow ANSIBLE_COLLECTIONS_PATH
环境变量是运行命令才能运行 playbook 所必需的。警告如果不小心使用,在启用了
Remediate
选项的情况下运行系统评估可能会导致系统无法正常工作。红帽不提供任何自动的方法来恢复由安全补救补救所做的更改。默认配置的 RHEL 系统支持自动安全补救功能。如果在安装后更改了您的系统,运行修复可能无法使其遵守所需的安全配置文件。
验证
使用所选配置集评估系统的合规性,并将扫描结果保存到文件中:
oscap xccdf eval --profile <profileID> --report <scan-report.html> /usr/share/xml/scap/ssg/content/ssg-rhel8-ds.xml
# oscap xccdf eval --profile <profileID> --report <scan-report.html> /usr/share/xml/scap/ssg/content/ssg-rhel8-ds.xml
Copy to Clipboard Copied! Toggle word wrap Toggle overflow 将
<scan-report.html>
替换为oscap
保存扫描结果的文件名。