12.3. 使用安全引导密钥密封引导容器映像


您可以通过计算根文件系统的密码摘要并将其嵌入签名的统一内核映像 (UKI) 中来密封 RHEL 引导容器映像。密封映像在引导时提供从固件到文件系统的端到端完整性验证。

注意

对密封图像使用ext4文件系统,因为XFS不支持fsverity

先决条件

  • 该容器在 /usr/lib/modules/<kver>/ 目录中包含一个内核。
  • 容器不包括预构建的UKI,因为构建过程会生成一个UKI。

流程

  1. 创建多阶段容器文件

    # Build your rootfs with all packages and configuration
    FROM registry.redhat.io/rhel10/rhel-bootc as rootfs
    RUN dnf install_<package name>_
    
    # Install the ukify tool
    $ dnf install -y systemd-ukify sbsigntools
    
    # Generate the sealed UKI in a tools stage
    FROM registry.redhat.io/rhel10/rhel-bootc:latest as sealed-uki
    RUN --mount=type=bind,from=rootfs,src=/,target=/target \
        --mount=type=secret,id=secureboot_key \
        --mount=type=secret,id=secureboot_cert <<EORUN
    set -euo pipefail
    
    # Find the kernel version
    kver=$(ls /target/usr/lib/modules)
    
    # Create the /out directory
    $ mkdir /out
    
    # Generate and sign the UKI with the digest embedded
    bootc container ukify --rootfs /target -- \
      --signtool sbsign \
      --secureboot-private-key /run/secrets/secureboot_key \
      --secureboot-certificate /run/secrets/secureboot_cert \
      --output "/out/${kver}.efi"
    EORUN
    
    # Final image: copy the sealed UKI into place
    FROM rootfs
    COPY --from=sealed-uki /out/*.efi /boot/EFI/Linux/

    --mount=type=bindfrom=rootfs 提供对目标文件系统的只读访问,其中引导容器 compute-composefs-digest 计算文件系统的 SHA-512 哈希,引导容器 ukify 在内核命令行中使用该摘要创建 UKI (composefs=<digest>),最后阶段将签名的 UKI 复制到根文件系统中,而不修改摘要计算中使用的任何文件。

    多阶段构建方法是必要的,因为您必须计算合成摘要而不包括UKI。由于此摘要有效地将整个文件系统缩减为驻留在 UKI 内部的单个哈希,因此在计算中包括 UKI 将更改摘要。为防止这种情况,您将UKI构建在单独的层中,避免文件系统污染,然后将UKI复制到当前层的/boot目录中,在生成EROFS映像期间,它将保持屏蔽状态。

  2. 构建启用引导的compositfs容器映像:

    $ podman build --secret=id=secureboot_key,src=db.key --secret=id=secureboot_cert,src=db.crt -t composefs-bootc .
  3. 确定文件系统的组成摘要:

    $ bootc container compute-composefs-digest <path>

验证

  1. 验证该命令是否成功列出位于 /boot/efi/systemd-boot * . efi 的签名统一内核映像 (UKI) 和签名的系统引导文件:

    $ podman run --rm -ti composefs-bootc ls /usr/lib/systemd/boot/efi/systemd-boot*.efi
    注意

    由于 sbsigntools 安装在 build-uki 阶段,在运行验证步骤之前,必须检查最终构建容器映像内是否存在 systemd-boot 和 UKI。

  2. 列出签名并验证 UKI 配置:

    $ sbverify --list <path-to-uki>

    密封映像通过 fsverity 提供持续的运行时验证,从而将验证扩展到初始引导时间检查之外。与仅验证内核的标准安全引导不同,密封映像在文件被篡改时立即返回输入或输出错误,而不是提供损坏的内容。

Red Hat logoGithubredditYoutubeTwitter

学习

尝试、购买和销售

社区

關於紅帽

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

让开源更具包容性

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

关于红帽文档

Legal Notice

Theme

© 2026 Red Hat
返回顶部