12.3. 使用安全引导密钥密封引导容器映像
您可以通过计算根文件系统的密码摘要并将其嵌入签名的统一内核映像 (UKI) 中来密封 RHEL 引导容器映像。密封映像在引导时提供从固件到文件系统的端到端完整性验证。
对密封图像使用ext4文件系统,因为XFS不支持fsverity。
先决条件
-
该容器在
/usr/lib/modules/<kver>/目录中包含一个内核。 - 容器不包括预构建的UKI,因为构建过程会生成一个UKI。
流程
创建多阶段
容器文件:# 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=bind和from=rootfs提供对目标文件系统的只读访问,其中引导容器compute-composefs-digest计算根文件系统的 SHA-512 哈希,引导容器 ukify在内核命令行中使用该摘要创建 UKI (composefs=<digest>),最后阶段将签名的 UKI 复制到根文件系统中,而不修改摘要计算中使用的任何文件。多阶段构建方法是必要的,因为您必须计算
合成摘要而不包括UKI。由于此摘要有效地将整个文件系统缩减为驻留在 UKI 内部的单个哈希,因此在计算中包括 UKI 将更改摘要。为防止这种情况,您将UKI构建在单独的层中,避免文件系统污染,然后将UKI复制到当前层的/boot目录中,在生成EROFS映像期间,它将保持屏蔽状态。构建启用
引导的compositfs容器映像:$ podman build --secret=id=secureboot_key,src=db.key --secret=id=secureboot_cert,src=db.crt -t composefs-bootc .确定文件系统的
组成摘要:$ bootc container compute-composefs-digest <path>
验证
验证该命令是否成功列出位于
/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。列出签名并验证 UKI 配置:
$ sbverify --list <path-to-uki>密封映像通过
fsverity提供持续的运行时验证,从而将验证扩展到初始引导时间检查之外。与仅验证内核的标准安全引导不同,密封映像在文件被篡改时立即返回输入或输出错误,而不是提供损坏的内容。