5.2. 使用安全引导在 Azure 上配置 RHEL 虚拟机
要确保 Azure 云平台上的 Red Hat Enterprise Linux 实例有一个安全的操作系统引导过程,请使用安全引导(Secure Boot)。当注册自定义 RHEL Azure 镜像时,镜像由安全引导的预存储统一固件接口(UEFI)变量组成。这可让从 RHEL 镜像启动的所有实例都使用带有第一次引导时所需的变量的安全引导机制。
Microsoft Azure 支持使用受信任的启动虚拟机的安全引导。这些虚拟机提供安全机制来保护对 rootkits 和 bootkits 的影响,同时提供了其他功能,如 Virtual Trusted Platform Manager (vTPM)。使用 GUI 创建实例时,您可以在 Configure security features 设置中找到 Enable secure 引导选项。
先决条件
已安装这些软件包:
-
python3 -
openssl -
efivar -
keyutils -
python3-virt-firmware
-
-
已安装
azure-cli工具。详情请参阅在 Linux 上安装 Azure CLI。
流程
使用
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-state SecureBoot enabled使用
keyctl工具验证自定义证书的内核密钥环:$ sudo keyctl list %:.platform keys in keyring: ... 586621657: ---lswrv 0 0 asymmetric: Signature Database key: f064979641c24e1b935e402bdbc3d5c4672a1acc ...