排查 Azure 中 Windows VM 上的扩展证书问题

适用于:✔️ Windows VM

本文介绍如何识别和修复使用扩展的 Windows 虚拟机(VM)上涉及证书的问题。 通常,这些问题与加密操作或证书本身相关。

故障排除清单

查看来宾日志

若要获取有关错误的详细信息,请检查来宾日志。 下表显示了 Windows VM 上用于排查扩展证书错误的最有用的日志。

日志 说明
C:\WindowsAzure\Logs\WaAppAgent.log 日志文件 来宾代理日志。 描述扩展的操作(例如下载、安装、启用和禁用)及其结果。
C:\WindowsAzure\Logs\Plugins\<ExtensionName> 文件夹中的日志文件 反映特定扩展操作的各种日志。 每个扩展都有自己的功能,但大多数扩展都有一组标准日志文件,包括 CommandExecution.log、CommandExecution_Timestamp>.logCustomScriptHandler.logIaaSBcdrExtension<Number>.log。<

注意

此表仅包含最值得注意的日志文件。 这不是一个全面的列表。

或者,可以运行 CollectGuestLogs.exe 工具将所有来宾日志收集到 .zip 存档文件中。 CollectGuestLogs.exe工具位于以下目录中的 Windows VM 上:

  • C:\WindowsAzure\Packages
  • C:\WindowsAzure\GuestAgent_<VersionNumber>_<Timestamp>

现象

以下列表概述了在 Windows VM 上使用扩展时可能发生的最常见错误:

  • FailedToDecryptProtectedSettings 异常:VM 中缺少用于解密扩展受保护设置的传输证书。

    注意

    异常的FailedToDecryptProtectedSettings变体会导致在 Crypto\RSA\MachineKeys 文件夹中设置不正确的权限。 在此方案中,将显示以下错误消息之一:

    System.Security.Cryptography.CryptographicException: Keyset does not exist  
      at System.Security.Cryptography.Pkcs.EnvelopedCms.DecryptContent(RecipientInfoCollection recipientInfos, X509Certificate2Collection extraStore)  
      at Microsoft.Azure.Plugins.Diagnostics.dll.PluginConfigurationSettingsProvider.DecryptPrivateConfig(String encryptedConfig)  
    
    Failed to decode, decrypt, and deserialize the protected settings string. Error Message: Keyset does not exist"
    
    Decrypting Protected Settings - Invalid provider type specified
    
    [ERROR] Failed to get TransportCertificate. Error: Microsoft.WindowsAzure.GuestAgent.CertificateManager.CryptographyNative+PInvokeException: Self-signed Certificate Generation failed. Error Code: -2146893808.
    
  • “无法检索证书”错误消息。

  • CryptographicException VM 诊断设置中的异常,并附带消息“信封数据消息不包含指定的收件人”。以下文本描述了此异常的示例:

    DiagnosticsPluginLauncher.exe Information: 0 : [6/29/2020 1:32:20 PM] Decrypting private configuration
    
    DiagnosticsPluginLauncher.exe Warning: 0 : [6/29/2020 1:32:20 PM] No certficate with given thumbprint found in the certificate store. Thumbprint:34C8CDC747693E0E33A9648703E3990EC4F2C484
    
    DiagnosticsPluginLauncher.exe Information: 0 : [6/29/2020 1:32:20 PM] Retrying after 30 seconds. Retry attempt 1
    
    DiagnosticsPluginLauncher.exe Warning: 0 : [6/29/2020 1:32:50 PM] No certficate with given thumbprint found in the certificate store. Thumbprint:34C8CDC747693E0E33A9648703E3990EC4F2C484
    
    DiagnosticsPluginLauncher.exe Information: 0 : [6/29/2020 1:32:50 PM] Retrying after 30 seconds. Retry attempt 2
    
    DiagnosticsPluginLauncher.exe Warning: 0 : [6/29/2020 1:33:20 PM] No certficate with given thumbprint found in the certificate store. Thumbprint:34C8CDC747693E0E33A9648703E3990EC4F2C484
    
    DiagnosticsPluginLauncher.exe Information: 0 : [6/29/2020 1:33:20 PM] Retrying after 30 seconds. Retry attempt 3
    
    DiagnosticsPluginLauncher.exe Error: 0 : [6/29/2020 1:33:50 PM] System.Security.Cryptography.CryptographicException: The enveloped-data message does not contain the specified recipient.
      at System.Security.Cryptography.Pkcs.EnvelopedCms.DecryptContent(RecipientInfoCollection recipientInfos, X509Certificate2Collection extraStore)
      at Microsoft.Azure.Plugins.Diagnostics.dll.PluginConfigurationSettingsProvider.DecryptPrivateConfig(String encryptedConfig)
    
  • 推送到 VM 的新证书,但会干扰其他操作。

原因:工作流和依赖项代码更改

此问题主要是由在 2020 年 5 月左右实施的 Azure 平台的更改引起的。 更改是改进 VM 扩展的工作流,并消除其他 Azure 组件上的某些依赖项。 它要求扩展、自定义资源提供程序(CRP)和来宾代理共同工作。 次要 bug 导致扩展证书问题中反映的次要问题。

解决方案 1:更新扩展证书

请按照以下步骤更新为可与扩展一起使用的证书:

  1. 检查 Windows Azure CRP 证书生成器证书是否包含在Microsoft管理控制台的证书管理单元中。 为此,请按照 Azure IaaS VM 上的多个证书中的 说明操作,该证书使用扩展 查找 Windows VM 症状。

  2. 删除该证书。 为此,请选择 Windows Azure CRP 证书生成器证书,然后选择“删除图标。

    注意

    当需要 Windows Azure CRP 证书生成器证书时,VM 会重新创建证书(如果缺少)。

  3. 通过应用以下选项之一来触发来宾代理的新目标状态:

    • 运行以下 PowerShell 脚本,其中包含 Get-AzureRmVMUpdate-AzureRmVM 命令:

      $rg = "<name-of-the-resource-group-containing-the-virtual-machine>"
      $vmName = "<name-of-the-virtual-machine>"
      $vm = Get-AzureRmVM -ResourceGroupName $rg -Name $vmName  
      Update-AzureRmVM -ResourceGroupName $rg -VM $vm  
      
    • 按照虚拟机的“解决方法”部分中的说明,在 VM 上执行“重新应用”操作,该操作 停滞在失败状态 文章中。

  4. 重试扩展操作。

如果证书更新未解决问题,请停止或解除分配 VM,然后再次启动 VM。

解决方案 2:修复 MachineKeys 或 SystemKeys 文件夹中的访问控制列表(ACL)

Crypto\RSA\MachineKeys 文件夹中,修复访问控制列表(ACL),以便应用正确的权限。

  1. 在管理 PowerShell 控制台中,运行以下命令以获取租户证书的唯一密钥容器名称。 请确保注释掉其中一个$certName定义,具体取决于使用的是经典 RedDog 前端(RDFE)VM(证书名称为Windows Azure Service Management for Extensions)还是 Azure 资源管理器 VM(证书名称为Windows Azure CRP Certificate Generator):

    # Comment out one of the following certificate name definitions.
    $certName = "Windows Azure Service Management for Extensions"  # Classic RDFE VM
    $certName = "Windows Azure CRP Certificate Generator"          # Azure Resource Manager VM
    
    $fileName = (Get-ChildItem Cert:\LocalMachine\My |
                    Where-Object {$_.Subject -eq 'DC=$certName'}
                ).PrivateKey.CspKeyContainerInfo.UniqueKeyContainerName
    
  2. 通过运行 icacls 命令来备份 ACL:

    icacls C:\ProgramData\Microsoft\Crypto\RSA\MachineKeys /save machinekeys_permissions_before.aclfile /t
    
  3. icacls运行以下命令以更正 MachineKeys 权限:

    icacls C:\ProgramData\Microsoft\Crypto\RSA\MachineKeys\$fileName /grant SYSTEM:(F)
    icacls C:\ProgramData\Microsoft\Crypto\RSA\MachineKeys\$fileName /grant Administrators:(RX)
    
  4. 再次运行 icacls 以将更新 的 MachineKeys ACL 重定向到文本文件:

    icacls C:\ProgramData\Microsoft\Crypto\RSA\MachineKeys /t > machinekeys_permissions_after.txt
    
  5. 在文本编辑器中查看machinekeys_permissions_after.txt文件,以验证权限更改是否按预期显示。

  6. 再次尝试扩展,或尝试通过运行 WaAppAgent.exeWindowsAzureGuestAgent.exe 工具重启来宾代理服务。

如果此过程不起作用,可以尝试在 C:\ProgramData\Microsoft\Crypto\SystemKeys\* 通配符文件夹而不是 C:\ProgramData\Microsoft\Crypto\RSA\MachineKeys\$fileName 文件夹中再次运行icacls命令(步骤 2-4)。

详细信息

联系我们寻求帮助

如果你有任何疑问或需要帮助,请创建支持请求联系 Azure 社区支持。 你还可以将产品反馈提交到 Azure 反馈社区