你当前正在访问 Microsoft Azure Global Edition 技术文档网站。 如果需要访问由世纪互联运营的 Microsoft Azure 中国技术文档网站,请访问 https://docs.azure.cn

将密钥保管库 VM 扩展应用到 Azure 云服务(外延支持)

本文提供有关适用于 Windows 的 Azure Key Vault VM 扩展的基本信息,并演示如何在 Azure 云服务中启用它。

什么是 Key Vault VM 扩展?

密钥保管库 VM 扩展可自动刷新 Azure 密钥保管库中存储的证书。 具体而言,该扩展会监视在密钥保管库中存储的观察到的证书列表。 扩展检测到更改时,它会检索并安装相应的证书。 有关详细信息,请参阅适用于 Windows 的 Key Vault VM 扩展

Key Vault VM 扩展中有哪些新增功能?

现在,密钥保管库 VM 扩展在 Azure 云服务(外延支持)平台上受支持,可启用端到端的证书管理。 该扩展现在可以按预定义的轮询间隔从配置的密钥保管库拉取证书,并安装这些证书以供服务使用。

如何使用 Key Vault VM 扩展?

以下过程将演示如何通过在保管库中创建启动证书来从 Microsoft Entra ID 获取令牌,在 Azure 云服务 上安装密钥库 VM 扩展。 该令牌将有助于使用保管库对扩展进行身份验证。 设置身份验证过程并安装扩展后,将按定期的轮询间隔自动拉取所有最新证书。

注意

Key Vault VM 扩展将 Windows 证书存储中的所有证书下载到 VM 扩展设置中 certificateStoreLocation 属性提供的位置。 目前,Key Vault VM 扩展仅向本地系统管理员帐户授予对证书私钥的访问权限。

先决条件

若要使用 Azure 密钥库 VM 扩展,需要有 Microsoft Entra 租户。 有关详细信息,请参阅快速入门:设置租户

启用 Azure 密钥保管库 VM 扩展

  1. 在保管库中生成证书,并下载该证书的 .cer 文件。

  2. Azure 门户中,转到“应用注册”。

    Screenshot of resources available in the Azure portal, including app registrations.

  3. 在“应用注册”页面,选择“新增注册”。

    Screenshot that shows the page for app registrations in the Azure portal.

  4. 在下一页上,填写表单并完成应用创建。

  5. 将证书的 .cer 文件上传到 Microsoft Entra 应用门户。

    或者,可以使用 Key Vault 的 Azure 事件网格通知功能上传证书。

  6. 在 密钥库 中授予 Microsoft Entra 应用机密权限:

    • 如果使用基于角色的访问控制(RBAC)预览版,请搜索你创建的 Microsoft Entra 应用的名称,并将其分配给密钥库机密用户(预览版)角色。
    • 如果使用保管库访问策略,请将 Secret-Get 权限分配给所创建的 Microsoft Entra 应用。 有关详细信息,请参阅分配访问策略
  7. 使用 cloudService 资源的 Azure 资源管理器模板片段安装 Key Vault VM 扩展:

    {
        "osProfile":
        {
            "secrets":
            [
                {
                    "sourceVault":
                    {
                        "id": "[parameters('sourceVaultValue')]"
                    },
                    "vaultCertificates":
                    [
                        {
                            "certificateUrl": "[parameters('bootstrpCertificateUrlValue')]"
                        }
                    ]
                }
            ]
        },
        "extensionProfile":
        {
            "extensions":
            [
                {
                    "name": "KVVMExtensionForPaaS",
                    "properties":
                    {
                        "type": "KeyVaultForPaaS",
                        "autoUpgradeMinorVersion": true,
                        "typeHandlerVersion": "1.0",
                        "publisher": "Microsoft.Azure.KeyVault",
                        "settings":
                        {
                            "secretsManagementSettings":
                            {
                                "pollingIntervalInS": "3600",
                                "certificateStoreName": "My",
                                "certificateStoreLocation": "LocalMachine",
                                "linkOnRenewal": false,
                                "requireInitialSync": false,
                                "observedCertificates": "[parameters('keyVaultObservedCertificates']"
                            },
                            "authenticationSettings":
                            {
                                "clientId": "Your AAD app ID",
                                "clientCertificateSubjectName": "Your boot strap certificate subject name [Do not include the 'CN=' in the subject name]"
                            }
                        }
                    }
                }
            ]
        }
    }
    

    可能需要在 ServiceDefinition.csdef 中指定启动证书的证书存储:

        <Certificates>
                 <Certificate name="bootstrapcert" storeLocation="LocalMachine" storeName="My" />
        </Certificates> 
    

后续步骤

通过在 Azure 云服务(外延支持)中启用监视来进一步改善部署。