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


内部 RHEL 镜像构建器支持 OpenSCAP 集成。这个集成启用了预强化的 RHEL 镜像的生产。通过设置蓝图,您可以执行以下操作:

  • 使用一组预定义的安全配置文件对其进行自定义
  • 添加一组软件包或附加文件
  • 构建一个更适合您的环境、准备部署到所选平台上的自定义 RHEL 镜像

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

8.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 10 中支持的 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-rhel10-ds.xml"
profile_id = "xccdf_org.ssgproject.content_profile_cis"
Copy to Clipboard Toggle word wrap

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

# oscap info /usr/share/xml/scap/ssg/content/ssg-rhel10-ds.xml
Copy to Clipboard Toggle word wrap

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

例如,命令:

# oscap xccdf generate fix --profile=cis --fix-type=blueprint /usr/share/xml/scap/ssg/content/ssg-rhel10-ds.xml
Copy to Clipboard Toggle word wrap

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

# Blueprint for CIS Red Hat Enterprise Linux 10.0 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 10 Benchmark™, v3.0.0, released 2023-10-30.
# This profile includes Center for Internet Security®
# Red Hat Enterprise Linux 10.0 CIS Benchmarks™ content.
#
# Profile ID:  xccdf_org.ssgproject.content_profile_cis
# Benchmark ID:  xccdf_org.ssgproject.content_benchmark_RHEL-10.0
# Benchmark Version:  0.1.74
# XCCDF Version:  1.2

name = "hardened_xccdf_org.ssgproject.content_profile_cis"
description = "CIS Red Hat Enterprise Linux 10.0 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"]
Copy to Clipboard Toggle word wrap
注意

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

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

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

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

    注意

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

返回顶部
Red Hat logoGithubredditYoutubeTwitter

学习

尝试、购买和销售

社区

关于红帽文档

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

让开源更具包容性

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

關於紅帽

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

Theme

© 2025 Red Hat