9.2. 自定义强化的可引导镜像


您可以使用 oscap-im 工具将自定义配置集应用到可引导镜像。您可以通过更改某些规则中的参数(如最小密码长度、删除以不同方式涵盖的规则以及选择附加规则)来自定义安全配置文件,以实施内部策略。您不能通过自定义配置文件来定义新规则。

先决条件

流程

  1. 创建 Containerfile

    FROM registry.redhat.io/rhel10/rhel-bootc:latest
    
    # Copy a tailoring file into the Containerfile
    COPY tailoring.xml /usr/share/
    
    # Install OpenSCAP scanner and security content to the image
    RUN dnf install -y openscap-utils scap-security-guide && dnf clean all
    
    
    # Add sudo user 'admin' with password 'admin123'.
    # The user can be used with profiles that prevent
    # ssh root logins.
    RUN useradd -G wheel -p "\$6\$Ga6Zn
    IlytrWpuCzO\$q0LqT1USHpahzUafQM9jyHCY9BiE5/ahXLNWUMiVQnFGblu0WWGZ1e6icTaCGO4GNgZNtspp1Let/qpM7FMVB0" admin
    
    # Run scan and hardening including the tailoring file
    RUN oscap-im --tailoring-file /usr/share/tailoring.xml --profile stig_customized /usr/share/xml/scap/ssg/content/ssg-rhel10-ds.xml
    Copy to Clipboard Toggle word wrap

这个 Containerfile 执行以下任务:

  • 将定制文件注入到您的镜像。
  • 安装提供 oscap-im 工具和 scap-security-guide 软件包的 openscap-utils 软件包,该软件包为数据流提供安全内容自动化协议(SCAP)内容。
  • 为阻止 SSH root 登录的配置文件添加具有 sudoer 特权的用户。
  • 扫描并修复镜像以遵守所选配置集。

    1. 使用当前目录中的 Containerfile 构建镜像:

      $ podman build -t quay.io/<namespace>/<image>:<tag> .
      Copy to Clipboard Toggle word wrap

验证

  • 列出所有镜像:

    $ podman images
    REPOSITORY                                  TAG      IMAGE ID       CREATED              SIZE
    quay.io/<namespace>/<image>                 <tag>   b28cd00741b3   About a minute ago   2.1 GB
    Copy to Clipboard Toggle word wrap

后续步骤

  • 您可以使用任何普通可引导镜像部署方法部署强化的可引导镜像。如需更多信息,请参阅部署 RHEL bootc 镜像

    但是,部署方法可能会影响目标系统的合规性状态。

    注意

    在部署期间执行的一些自定义(在 bootc-image-builder 蓝图中为 bootc-image-builder 或 Kickstart for Anaconda 中)可能会影响容器镜像中存在的配置。不要使用与安全策略要求冲突的自定义。

  • 您可以使用与软件包模式 RHEL 相同的语法和用法相同的 oscap 工具来验证在 Image Mode RHEL 中运行的系统的合规性。如需更多信息,请参阅配置合规性扫描
返回顶部
Red Hat logoGithubredditYoutubeTwitter

学习

尝试、购买和销售

社区

关于红帽文档

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

让开源更具包容性

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

關於紅帽

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

Theme

© 2025 Red Hat