5.5. 使用 Google Cloud Platform 上的自定义 RHEL 镜像中的安全引导机制配置 RHEL 实例
以下流程通过将自定义证书包含在 SecureBoot DB 中来配置 RHEL 实例,这可让您为自定义工件签名,如第三方内核模块和 UKI 扩展。
先决条件
-
您已安装了
python3
,efivar
,keyutils
,openssl
, 和python3-virt-firmware
软件包。 -
您已安装了
google-cloud-cli
工具。请参阅在 RHEL 上安装 gcloud CLI。
流程
创建新的随机通用唯一标识符(UUID),并将其存储在生成的随机文本文件中:
$ uuidgen --random > GUID.txt
为平台密钥数据库生成一个新的 RSA 私钥
PK.key
和自签名 X.509 证书PK.cer
:$ openssl req -quiet -newkey rsa:4096 -nodes -keyout PK.key -new -x509 -sha256 -days 3650 -subj "/CN=Platform key/" -outform DER -out PK.cer
openssl
工具通过将输出格式设置为 Distinguished Encoding Rules (DNR)来为证书生成一个通用名称平台密钥
。DNR 是数据编码的标准化二进制格式。为密钥交换密钥数据库生成一个新的 RSA 私钥
KEK.key
和自签名 X.509 证书KEK.cer
:$ openssl req -quiet -newkey rsa:4096 -nodes -keyout KEK.key -new -x509 -sha256 -days 3650 -subj "/CN=Key Exchange Key/" -outform DER -out KEK.cer
生成自定义证书
custom_db.cer
:$ openssl req -quiet -newkey rsa:4096 -nodes -keyout custom_db.key -new -x509 -sha256 -days 3650 -subj "/CN=Signature Database key/" --outform DER -out custom_db.cer
下载 Microsoft 证书:
$ wget https://go.microsoft.com/fwlink/p/?linkid=321194 --user-agent="Mozilla/5.0 (Windows NT 10.0; WOW64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/51.0.2704.103 Safari/537.36" -O MicCorUEFCA2011_2011-06-27.crt
为 64 位系统下载更新的禁止签名(dbx) UEFI Revocation List 文件:
$ wget https://uefi.org/sites/default/files/resources/x64_DBXUpdate.bin
使用
google-cloud-cli
工具在磁盘分区中创建镜像并将其注册到所需的安全引导变量:$ gcloud compute images create <example-rhel-9-efi-image> --source-image projects/<example_project_id>/global/images/<example_image_name> --platform-key-file=PK.cer --key-exchange-key-file=KEK.cer --signature-database-file=custom_db.cer,MicCorUEFCA2011_2011-06-27.crt --forbidden-database-file x64_DBXUpdate.bin --guest-os-features="UEFI_COMPATIBLE"
使用 Google Cloud 控制台
打开安全引导
功能来启动example-rhel-9-efi-image
镜像的实例。
验证
检查新创建的 RHEL 实例是否启用了安全引导机制:
$ mokutil --sb-state SecureBoot enabled
使用
keyctl
工具验证自定义证书的内核密钥环:$ sudo keyctl list %:.platform ... 757453569: ---lswrv 0 0 asymmetric: Signature Database key: f064979641c24e1b935e402bdbc3d5c4672a1acc ...