第 7 章 使用 RHEL 镜像构建器 OpenSCAP 集成创建预先强化的镜像


使用 RHEL 镜像构建器对 OpenSCAP 集成的内部支持,您可以创建具有特定的安全配置文件的自定义蓝图,并使用蓝图构建预先强化的镜像。通过它,您可以使用此预先强化的镜像来部署需要符合特定配置文件的系统。您可以添加一组软件包或附加文件来自定义蓝图。通过它,您可以构建预先强化的自定义 RHEL 镜像来部署合规的系统。

在镜像构建过程中,OSBuild oscap.remediation 阶段在文件系统树上的 chroot 环境中运行 OpenSCAP 工具。OpenSCAP 工具为您选择的配置文件运行标准的评估,并将补救应用到镜像。通过它,您可以构建可根据安全配置文件要求配置的镜像,即使在其首次引导之前也是如此。

红帽提供了在构建系统时可以选择的安全强化配置文件的定期的更新版本,以便您能够满足当前部署指南。

7.1. OpenSCAP 蓝图自定义

有了对蓝图自定义的 OpenSCAP 支持,您可以从 'scap-security-guide' 内容中为特定安全配置文件生成蓝图,然后使用蓝图构建自己的预先强化的镜像。

使用 OpenSCAP 创建自定义蓝图涉及以下高级别步骤:

  • 修改挂载点,并根据具体要求配置文件系统布局。
  • 在蓝图中,选择 OpenSCAP 配置文件。这会根据所选的配置文件集,在镜像构建过程中触发补救。另外,在镜像构建过程中,OpenSCAP 应用了首次启动前的补救。

要在镜像蓝图中使用 OpenSCAP 蓝图自定义,您需要提供以下信息:

  • datastream 修复指令的数据流路径。scap-security-guide 软件包中的数据流文件位于 /usr/share/xml/scap/ssg/content/ 目录中。
  • 所需的安全配置集的 profile_idprofile_id 字段的值接受长和短形式,例如以下是可接受的形式:cisxccdf_org.ssgproject.content_profile_cis。如需了解更多详细信息,请参阅 RHEL 9 支持的 SCAP 安全指南配置集

以下示例是 OpenSCAP 补救阶段的一个片断:

[customizations.openscap]
# If you want to use the data stream from the 'scap-security-guide' package
# the 'datastream' key could be omitted.
# datastream = "/usr/share/xml/scap/ssg/content/ssg-rhel9-ds.xml"
profile_id = "xccdf_org.ssgproject.content_profile_cis"

您可以使用以下命令,从 scap-security-guide 软件包中找到有关 SCAP 源数据流的更多详细信息,包括它提供的安全配置文件的列表:

# oscap info /usr/share/xml/scap/ssg/content/ssg-rhel9-ds.xml

为方便起见,OpenSCAP 工具可以为 scap-security-guide 数据流中的任何配置文件生成强化蓝图。

例如,命令:

# oscap xccdf generate fix --profile=cis --fix-type=blueprint /usr/share/xml/scap/ssg/content/ssg-rhel9-ds.xml

为 CIS 配置集生成一个蓝图,类似如下:

# Blueprint for CIS Red Hat Enterprise Linux 9 Benchmark for Level 2 - Server
#
# Profile Description:
# This profile defines a baseline that aligns to the "Level 2 - Server"
# configuration from the Center for Internet Security® Red Hat Enterprise
# Linux 9 Benchmark™, v3.0.0, released 2023-10-30.
# This profile includes Center for Internet Security®
# Red Hat Enterprise Linux 9 CIS Benchmarks™ content.
#
# Profile ID:  xccdf_org.ssgproject.content_profile_cis
# Benchmark ID:  xccdf_org.ssgproject.content_benchmark_RHEL-9
# Benchmark Version:  0.1.74
# XCCDF Version:  1.2

name = "hardened_xccdf_org.ssgproject.content_profile_cis"
description = "CIS Red Hat Enterprise Linux 9 Benchmark for Level 2 - Server"
version = "0.1.74"

[customizations.openscap]
profile_id = "xccdf_org.ssgproject.content_profile_cis"
# If your hardening data stream is not part of the 'scap-security-guide' package
# provide the absolute path to it (from the root of the image filesystem).
# datastream = "/usr/share/xml/scap/ssg/content/ssg-xxxxx-ds.xml"

[[customizations.filesystem]]
mountpoint = "/home"
size = 1073741824

[[customizations.filesystem]]
mountpoint = "/tmp"
size = 1073741824

[[customizations.filesystem]]
mountpoint = "/var"
size = 3221225472

[[customizations.filesystem]]
mountpoint = "/var/tmp"
size = 1073741824

[[packages]]
name = "aide"
version = "*"

[[packages]]
name = "libselinux"
version = "*"

[[packages]]
name = "audit"
version = "*"

[customizations.kernel]
append = "audit_backlog_limit=8192 audit=1"

[customizations.services]
enabled = ["auditd","crond","firewalld","systemd-journald","rsyslog"]
disabled = []
masked = ["nfs-server","rpcbind","autofs","bluetooth","nftables"]
注意

不要将此精确的蓝图片断用于镜像强化。它没有反映一个完整的配置文件。由于红帽不断为 scap-security-guide 软件包中的每个配置文件更新并提炼安全要求,因此始终使用为您的系统提供的最新的数据流版本来重新生成初始模板是有意义的。

现在,您可以自定义蓝图,或者按原样使用它来构建镜像。

RHEL 镜像构建器根据您的蓝图自定义为 osbuild 阶段生成所需的配置。另外,RHEL 镜像构建器向镜像中添加两个软件包:

  • openscap-scanner - OpenSCAP 工具。
  • scap-security-guide - 包含修复和评估指令的软件包。

    注意

    补救阶段将 scap-security-guide 软件包用于 datastream,因为这个软件包默认安装在镜像中。如果要使用不同的数据流,将必要的软件包添加到蓝图中,并在 oscap 配置中指定到 datastream 的路径。

Red Hat logoGithubRedditYoutubeTwitter

学习

尝试、购买和销售

社区

关于红帽文档

通过我们的产品和服务,以及可以信赖的内容,帮助红帽用户创新并实现他们的目标。

让开源更具包容性

红帽致力于替换我们的代码、文档和 Web 属性中存在问题的语言。欲了解更多详情,请参阅红帽博客.

關於紅帽

我们提供强化的解决方案,使企业能够更轻松地跨平台和环境(从核心数据中心到网络边缘)工作。

© 2024 Red Hat, Inc.