5.2. 使用安全引导在 Azure 上配置 RHEL 虚拟机


要确保 Azure 云平台上的 Red Hat Enterprise Linux (RHEL)实例有一个安全引导过程,请使用安全引导机制。您可以在注册自定义 RHEL Azure 镜像的过程中配置安全引导。

先决条件

  • 在使用 GUI 创建虚拟机时,已在 Configure security features 设置下启用了 Enable secure 引导选项

    Azure 平台上的安全引导
  • 您已安装了这些软件包:

    • python3
    • openssl
    • efivar
    • keyutils
    • python3-virt-firmware
  • 您已安装了 azure-cli 工具。详情请参阅 在 Linux 上安装 Azure CLI

    注意

    此镜像由预先存储的统一可扩展固件接口(UEFI)变量组成。因此,从此镜像启动的虚拟机使用安全引导机制以及第一次引导时所需的变量。Microsoft Azure 通过可信启动的 VM 支持安全启动。这些虚拟机提供了防止 rootkits 和 bootkits 的安全机制,同时提供了其他功能,如 Virtual Trusted Platform Manager (vTPM)。

流程

  1. 使用 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
  2. 将证书转换为 base64 编码的格式:

    $ echo `base64 -w0 custom_db.cer`
    MIIFIjCCAwqgAwIBAgITNf23J4k0d8c0NR ...
  3. 创建并编辑 azure-example-template.json Azure 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>__"
                                        ]
                                    }
                                ]
                            }
                        }
                    }
                }
            }
        ]
    }
  4. 使用 azure-cli 工具注册镜像版本:

    $ az deployment group create --name <example_deployment> \
    --resource-group <example_resource_group> \
    --template-file <example_template.json>
  5. 从 Azure 门户重启实例。

验证

  1. 检查新创建的 RHEL 实例是否启用了安全引导:

    $ mokutil --sb-state
    SecureBoot enabled
  2. 使用 keyctl 工具验证自定义证书的内核 keyring :

    $ sudo keyctl list %:.platform
    keys in keyring:
    ...
    586621657: ---lswrv 0 0
    asymmetric: _Signature Database key_: f064979641c24e1b935e402bdbc3d5c4672a1acc
    ...
Red Hat logoGithubredditYoutubeTwitter

学习

尝试、购买和销售

社区

關於紅帽

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

让开源更具包容性

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

关于红帽文档

Legal Notice

Theme

© 2026 Red Hat
返回顶部