Azure 实例元数据服务和证书相关问题

适用于:✔️ Windows VM

概述

注释

新的 Azure 实例元数据服务故障排除工具 运行命令现在可用于简化此方案诊断。

Azure 实例元数据服务(IMDS)是一个 REST API,可在已知不可路由的 IP 地址(169.254.169.254)中获取。 只能从 VM 中访问它。 VM 与 IMDS 之间的通信绝不会离开主机。 在查询 IMDS 时,HTTP 客户端必须绕过 VM 中的 Web 代理。 IMDS IP 地址 (169.254.169.254) 必须以与 168.63.129.16 IP 地址相同的方式进行处理。 有关其他信息,请阅读 Azure 实例元数据服务(IMDS)

症状

Azure 虚拟机无法与 Azure 实例元数据服务(IMDS)终结点建立连接。

  • 依赖于 IMDS 服务运行的应用程序/客户端无法按预期工作
  • Windows Server 2022/2025 Azure Edition 激活水印将继续显示
  • 适用于 Windows EOS 版本的扩展安全更新可能无法正确安装或正常运行

测试 IMDS 服务响应时,遇到以下错误:需要重现问题或 IMDS 终结点无法正常工作。

需要未成功的响应

原因

对于进程至关重要的中间证书已过期或缺失。

有关详细信息,请参阅 Azure 实例元数据服务证明数据 TLS:关键更改在此处

决议

如何确定是否缺少任何证书

运行以下 PowerShell 脚本以检查缺少的证书:

# Get the signature
# Powershell 5.1 does not include -NoProxy
$attestedDoc = Invoke-RestMethod -Headers @{"Metadata"="true"} -Method GET -Uri http://169.254.169.254/metadata/attested/document?api-version=2018-10-01
#$attestedDoc = Invoke-RestMethod -Headers @{"Metadata"="true"} -Method GET -NoProxy -Uri http://169.254.169.254/metadata/attested/document?api-version=2018-10-01
 
# Decode the signature
$signature = [System.Convert]::FromBase64String($attestedDoc.signature)
 
# Get certificate chain
$cert = [System.Security.Cryptography.X509Certificates.X509Certificate2]($signature)
$chain = New-Object -TypeName System.Security.Cryptography.X509Certificates.X509Chain
 
if (-not $chain.Build($cert)) {
   # Print the Subject of the issuer
   Write-Host $cert.Subject
   Write-Host $cert.Thumbprint
   Write-Host "------------------------"
   Write-Host $cert.Issuer
   Write-Host "------------------------"
   Write-Host "Certificate not found: '$($cert.Issuer)'" -ForegroundColor Red
   Write-Host "Please refer to the following link to download missing certificates:" -ForegroundColor Yellow
   Write-Host "https://learn.microsoft.com/en-us/azure/security/fundamentals/azure-ca-details?tabs=certificate-authority-chains" -ForegroundColor Yellow
} else {
   # Print the Subject of each certificate in the chain
   foreach($element in $chain.ChainElements) {
       Write-Host $element.Certificate.Subject
       Write-Host $element.Certificate.Thumbprint
       Write-Host "------------------------"
   }
 
   # Get the content of the signed document
   Add-Type -AssemblyName System.Security
   $signedCms = New-Object -TypeName System.Security.Cryptography.Pkcs.SignedCms
   $signedCms.Decode($signature);
   $content = [System.Text.Encoding]::UTF8.GetString($signedCms.ContentInfo.Content)
   Write-Host "Attested data: " $content
   $json = $content | ConvertFrom-Json
}

如果缺少任何证书,你将看到类似于以下证书的输出:

CN=metadata.azure.com, O=Microsoft Corporation, L=Redmond, S=WA, C=US
3ACCC393D3220E40F09A69AC3251F6F391172C32
------------------------
CN=Microsoft Azure RSA TLS Issuing CA 04, O=Microsoft Corporation, C=US
------------------------
Certificate not found: 'CN=Microsoft Azure RSA TLS Issuing CA 04, O=Microsoft Corporation, C=US'
Please refer to the following link to download missing certificates:
https://learn.microsoft.com/en-us/azure/security/fundamentals/azure-ca-details?tabs=certificate-authority-chains

若要修复证书问题,请转到 解决方案 2:确保防火墙和代理配置为允许证书下载

解决方案 2:确保防火墙和代理配置为允许证书下载

  1. 如果使用 Windows Server 2022,请检查是否已安装 KB 5036909 。 如果没有,请安装它。 可以从Microsoft更新目录获取它

  2. 如果已安装 Windows Server 2022 的更新,但仍遇到此问题或使用 Windows Server 2025,请验证系统的防火墙和代理是否已配置为允许下载证书。 有关详细信息,请参阅 证书下载和吊销列表

    或者,可以直接从 根和从属证书颁发机构链下载并安装所有证书。

    注释

    请确保在安装向导中选择存储位置作为 本地计算机

  3. 以管理员身份打开命令提示符,导航到 c:\windows\system32,并运行 fclip.exe

  4. 重启 VM 或注销,然后再次登录。 你将看到主页上的水印不再显示,“设置激活“应用程序状态”字段将报告成功。

其他资源

联系我们以获得帮助

如果有疑问,可以询问 Azure 社区支持。 您还可以向Azure反馈社区提交产品反馈。