5.2. 使用安全引导在 Azure 上配置 RHEL 虚拟机
要确保 Azure 云平台上的 Red Hat Enterprise Linux (RHEL)实例有一个安全引导过程,请使用安全引导机制。您可以在注册自定义 RHEL Azure 镜像的过程中配置安全引导。
先决条件
在使用 GUI 创建虚拟机时,已在
Configure security features设置下启用了Enable secure 引导选项。
您已安装了这些软件包:
-
python3 -
openssl -
efivar -
keyutils -
python3-virt-firmware
-
您已安装了
azure-cli工具。详情请参阅 在 Linux 上安装 Azure CLI。注意此镜像由预先存储的统一可扩展固件接口(UEFI)变量组成。因此,从此镜像启动的虚拟机使用安全引导机制以及第一次引导时所需的变量。Microsoft Azure 通过可信启动的 VM 支持安全启动。这些虚拟机提供了防止 rootkits 和 bootkits 的安全机制,同时提供了其他功能,如 Virtual Trusted Platform Manager (vTPM)。
流程
使用
openssl工具生成自定义证书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将证书转换为
base64编码的格式:$ echo `base64 -w0 custom_db.cer`MIIFIjCCAwqgAwIBAgITNf23J4k0d8c0NR ...创建并编辑
azure-example-template.jsonAzure Resource Manager (ARM)文件,以注册新的 Azure Compute Gallery 镜像版本:$ vi azure-example-template.json{ "$schema": "https://schema.management.azure.com/schemas/2019-04-01/deploymentTemplate.json#", "contentVersion": "1.0.0.0", "resources": [ { "type": "Microsoft.Compute/galleries/images/versions", "apiVersion": "2023-07-03", "name": "__<your compute gallery/your image definition/version>__", "location": "__<location of the VHD>__", "properties": { "storageProfile": { "osDiskImage": { "source": { "id": "__<your-storage-account-id>__", "uri": "__<url-with-the-vhd>__" }, "hostCaching": "ReadOnly" } }, "securityProfile": { "uefiSettings": { "signatureTemplateNames": [ "MicrosoftUefiCertificateAuthorityTemplate" ], "additionalSignatures": { "db": [ { "type": "x509", "value": [ "__<base64 of custom_db.cer>__" ] } ] } } } } } ] }使用
azure-cli工具注册镜像版本:$ az deployment group create --name <example_deployment> \ --resource-group <example_resource_group> \ --template-file <example_template.json>- 从 Azure 门户重启实例。
验证
检查新创建的 RHEL 实例是否启用了安全引导:
$ mokutil --sb-stateSecureBoot enabled使用
keyctl工具验证自定义证书的内核 keyring :$ sudo keyctl list %:.platformkeys in keyring: ... 586621657: ---lswrv 0 0 asymmetric: _Signature Database key_: f064979641c24e1b935e402bdbc3d5c4672a1acc ...