虚拟机自定义脚本扩展未从 Azure 存储帐户下载文件

问题描述 投票:0回答:1

尝试在 Azure 虚拟机上使用“CustomScriptExtension”,但返回以下错误:

Failed to download all specified files. Exiting. Error Message: CustomScript failed to download the blob https://test.blob.core.windows.net/test/Test.ps1 because the server returned a response of \\\"**The remote server returned an error: (409) Conflict. Public access is not permitted on this storage account**.

以下是以下步骤:

  1. 创建虚拟机并分配其托管标识。

  2. 创建存储帐户并提供以下基于角色的托管身份访问权限

    存储帐户贡献者

    存储 Blob 数据读取器

  3. 创建了一个简单的 powershell 脚本并上传到存储容器 blob。

  4. 创建了二头肌模板

param arcMachineName string = 'TestServer'
param location string = resourceGroup().location
resource customscriptextension 'Microsoft.Compute/virtualMachines/extensions@2022-03-01' = {  
  name: '${arcMachineName}/customScriptExtension'
  location: location
  properties: {
    publisher: 'Microsoft.Compute'
    type: 'CustomScriptExtension'
    typeHandlerVersion: '1.10'
    autoUpgradeMinorVersion: true
    settings: {
      fileUris: [
        'https://test.blob.core.windows.net/test/Test.ps1'
      ]
      commandToExecute: 'powershell -ExecutionPolicy Unrestricted -File ${scriptFileName}'
      managedIdentity : []
    }
  }
}
  1. 使用以下方法运行二头肌:

    az deployment group create --resource-group "test-rg" --template-file "test.bicep"

有人可以告诉我我在这里缺少什么吗?

azure azure-blob-storage azure-storage azure-virtual-machine
1个回答
0
投票

我尝试使用上述要求对 Azure VM 自定义脚本扩展部署进行验证和故障排除,并且能够成功配置

您遇到的错误消息“远程服务器返回错误:(409) 冲突。此存储帐户不允许公共访问”,表示存在与访问 Blob 存储相关的权限问题。

enter image description here

存储帐户内的我的 Blob 文件容器

enter image description here

  1. 托管身份权限:要访问存储 blob,VM 的托管身份必须具有您分配的“存储帐户贡献者”和“存储 Blob 数据读取者”角色。验证 VM 和托管标识是否已正确链接,并且托管标识是否具有所需的权限。 .

  2. 存储帐户访问级别:该错误表明存储帐户不允许公共访问。这通常是一种良好的安全实践,但这意味着必须明确授予任何访问权限。确保托管标识有权访问特定容器和 blob。

  3. Blob URL:检查 URL

    https://test.blob.core.windows.net/test/Test.ps1
    是否正确。 Blob 必须位于指定的容器中,并且 URL 必须准确指向它

运行部署命令之前的必备资源。

enter image description here

我的

test.bicep
文件:

// test.bicep
// This template deploys a Custom Script Extension to an Azure VM.

param vmName string = 'testvmvkserver'
param location string = resourceGroup().location
param scriptFileUri string = 'https://demovksbtest.blob.core.windows.net/test/Test.ps1'

resource customScriptExtension 'Microsoft.Compute/virtualMachines/extensions@2022-03-01' = {
  name: '${vmName}/customScriptExtension'
  location: location
  properties: {
    publisher: 'Microsoft.Compute'
    type: 'CustomScriptExtension'
    typeHandlerVersion: '1.10'
    autoUpgradeMinorVersion: true
    settings: {
      fileUris: [
        scriptFileUri
      ]
      commandToExecute: 'powershell -ExecutionPolicy Unrestricted -File Test.ps1'
    }
  }
}

我的演示

Test.ps1
文件:

# Test.ps1
# This script simply outputs the date and a list of running processes.

# Output the current date and time
Write-Output "Current Date and Time:"
Get-Date

# Output a list of running processes
Write-Output "List of Running Processes:"
Get-Process | Format-Table -AutoSize

现在运行部署组创建命令

az deployment group create --resource-group "testvk-rg" --template-file "test.bicep"

输出:

enter image description here

enter image description here

enter image description here

© www.soinside.com 2019 - 2024. All rights reserved.