【问题标题】:Azure VM Scaleset custom script extension not working - possibly failing to get VM identity?Azure VM Scaleset 自定义脚本扩展不起作用 - 可能无法获取 VM 标识?
【发布时间】:2021-03-03 17:58:16
【问题描述】:

我正在尝试使用如下自定义脚本扩展部署到我的虚拟机规模集。

az vmss extension set --debug --name 'CustomScriptExtension' `
    --resource-group 'my-rg' `
    --publisher 'Microsoft.Compute'  `
    --version '1.9.5' `
    --vmss-name 'myvmss' `
    --settings '{\"commandToExecute\": \"powershell.exe ./download-package.ps1\", \"fileUris\": [\"https://[REDACTED].blob.core.windows.net/upload/download-package.ps1\"]}' `
    --protected-settings '{\"managedIdentity\": {\"objectId\": \"[REDACTED]\"}}'

运行时出现以下错误:

cli.azure.cli.core.azclierror:部署失败。相关 ID:73f4d16b-afe0-4373-8773-1d7dd7d26940。 VM 在处理扩展“CustomScriptExtension”时报告失败。错误消息:“无法下载所有指定的文件。正在退出。错误消息:引发了 'Microsoft.WindowsAzure.GuestAgent.Plugins.CustomScriptHandler.Downloader.MsiNotFoundException' 类型的异常。”

有关故障排除的更多信息,请访问https://aka.ms/VMExtensionCSEWindowsTroubleshoot 部署失败。相关 ID:73f4d16b-afe0-4373-8773-1d7dd7d26940。 VM 在处理扩展“CustomScriptExtension”时报告失败。错误消息:“无法下载所有指定的文件。正在退出。错误消息:引发了 'Microsoft.WindowsAzure.GuestAgent.Plugins.CustomScriptHandler.Downloader.MsiNotFoundException' 类型的异常。”

要下载的文件需要身份验证,因此我为规模集分配了系统分配的身份,并在托管 powershell 文件的存储帐户上授予它Storage Blob Data Reader 角色。

VM 上的自定义扩展日志提示无法获取 vm 的身份:

[7108+00000001] [11/20/2020 09:12:28.79] [INFO] Handler successfully enabled
[7108+00000001] [11/20/2020 09:12:28.80] [INFO] Loading configuration for sequence number 1
[7108+00000001] [11/20/2020 09:12:28.84] [INFO] HandlerSettings = ProtectedSettingsCertThumbprint: [REDACTED], ProtectedSettings: {[REDACTED]}, PublicSettings: {FileUris: [https://[REDACTED].blob.core.windows.net/upload/download-package.ps1], CommandToExecute: powershell.exe ./download-package.ps1}
[7108+00000001] [11/20/2020 09:12:29.26] [INFO] Downloading files specified in configuration...
[7108+00000001] [11/20/2020 09:12:30.90] [INFO] Attempting to get MSI from IMDS
[7108+00000001] [11/20/2020 09:12:31.04] [WARN] WebClient: non retryable error occurred System.Net.WebException: The remote server returned an error: (400) Bad Request.
   at System.Net.WebClient.DownloadDataInternal(Uri address, WebRequest& request)
   at System.Net.WebClient.DownloadString(Uri address)
   at Microsoft.WindowsAzure.GuestAgent.Plugins.MsiUtils.WebClient.<>c__DisplayClass3_0.<DownloadStringWithRetries>b__0()
   at Microsoft.WindowsAzure.GuestAgent.Plugins.MsiUtils.WebClientWithRetryAbstract.ActionWithRetries(Action action)
[7108+00000001] [11/20/2020 09:12:31.14] [ERROR] Unknown exception occurred while attempting to get MSI token System.Net.WebException: The remote server returned an error: (400) Bad Request.
   at System.Net.WebClient.DownloadDataInternal(Uri address, WebRequest& request)
   at System.Net.WebClient.DownloadString(Uri address)
   at Microsoft.WindowsAzure.GuestAgent.Plugins.MsiUtils.WebClient.<>c__DisplayClass3_0.<DownloadStringWithRetries>b__0()
   at Microsoft.WindowsAzure.GuestAgent.Plugins.MsiUtils.WebClientWithRetryAbstract.ActionWithRetries(Action action)
   at Microsoft.WindowsAzure.GuestAgent.Plugins.MsiUtils.WebClient.DownloadStringWithRetries(Uri address)
   at Microsoft.WindowsAzure.GuestAgent.Plugins.MsiUtils.MsiProvider.GetMsiHelper(NameValueCollection queries)
[7108+00000001] [11/20/2020 09:12:31.14] [INFO] Msi was not obtained

我可以通过Invoke-WebRequest -Method Get -Uri 'http://169.254.169.254/metadata/identity/oauth2/token?api-version=2018-02-01&amp;resource=https://management.azure.com/' 从元数据端点检索身份令牌,这样看起来设置正确。

任何关于问题可能是什么或如何进一步诊断此问题的建议将不胜感激。

【问题讨论】:

标签: azure azure-virtual-machine azure-vm-scale-set


【解决方案1】:

以下是您可以尝试的几个修复方法

  1. 托管标识的对象 ID 可能不正确。
  2. 还请将 commandToExecute 和 FileUris 移动到受管理身份的受保护设置中。
  3. 如果要使用系统分配的托管标识,您不需要传递 clientId 或 objectID,更多信息在这里https://docs.microsoft.com/en-us/azure/virtual-machines/extensions/custom-script-windows#property-managedidentity

编辑:当您将 commandToExecute 和 fileUris 添加到受保护的设置时,请显式传递一个空的 json 对象作为设置。否则扩展会因重复设置而失败。

【讨论】:

  • 感谢您的回复。你的观点是正确的,我已经更新了我的代码(将 commandToExecute 和 FileUris 移动到受保护的设置中,并将托管标识设置为一个空块以使用系统分配的标识)。不幸的是,它仍然无法访问 blob 存储中的文件,现在它得到了 403。如果我将 blob 公开或使用访问密钥,它就可以工作,所以我认为这不是连接问题。我只是无法使用托管身份对其进行身份验证。
猜你喜欢
  • 1970-01-01
  • 2019-01-26
  • 1970-01-01
  • 2021-06-26
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2018-04-05
相关资源
最近更新 更多