从Azure自动化帐户运行时Get-AzureBlobContent引发错误

时间:2019-05-14 12:01:13

标签: azure azure-storage azure-storage-blobs azure-powershell azure-automation

尝试从我的Azure自动化帐户中的Azure存储帐户下载blob(JSON文件)时遇到错误。看来是授权问题。

这在我的本地笔记本电脑上可用,但在Azure自动化帐户上不可用。即使我将容器设为“公开”也不起作用

我已经为资源组上的自动化帐户的服务原理分配了OWNER特权(自动化帐户+存储帐户位于此RG),尤其是在存储帐户上:

enter image description here

下面是代码:

$connectionName = "AzureRunAsConnection"
try
{
    # Get the connection "AzureRunAsConnection "
    $servicePrincipalConnection=Get-AutomationConnection -Name $connectionName         

    "Logging in to Azure..."
    Add-AzureRmAccount `
        -ServicePrincipal `
        -TenantId $servicePrincipalConnection.TenantId `
        -ApplicationId $servicePrincipalConnection.ApplicationId `
        -CertificateThumbprint $servicePrincipalConnection.CertificateThumbprint 
}
catch {
    if (!$servicePrincipalConnection)
    {
        $ErrorMessage = "Connection $connectionName not found."
        throw $ErrorMessage
    } else{
        Write-Error -Message $_.Exception
        throw $_.Exception
    }
}

$config_file_resource_group_name = "vg-datalake-manjunath"
$config_file_storage_account_name = "datalakelog"
$primary_key = (Get-AzureRmStorageAccountKey -ResourceGroupName $config_file_resource_group_name -AccountName $config_file_storage_account_name).value[0]
 $config_file_context = New-AzureStorageContext -StorageAccountName $config_file_storage_account_name -StorageAccountKey $primary_key

 Get-AzureStorageBlobContent -Blob "mw_services.json" -Container "fwconfigfiles" -Destination "C:\temp\mw_services.json" -Context $config_file_context

 get-content "C:\temp\mw_services.json" | write-output

错误:

Get-AzureStorageBlobContent : The remote server returned an error: (403) Forbidden. HTTP Status Code: 403 - HTTP Error 
Message: This request is not authorized to perform this operation.
At line:30 char:2
+  Get-AzureStorageBlobContent -Blob "mw_services.json" -Container "fwc ...
+  ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
    + CategoryInfo          : CloseError: (:) [Get-AzureStorageBlobContent], StorageException
    + FullyQualifiedErrorId : 
StorageException,Microsoft.WindowsAzure.Commands.Storage.Blob.Cmdlet.GetAzureStorageBlobContentCommand

1 个答案:

答案 0 :(得分:0)

可能的原因是您可能配置为选择要访问的网络。 enter image description here

如果启用此选项,并且是否选中“允许访问受信任的Microsoft服务”,则会收到此错误,因为MS信任的服务下未列出自动化。参见https://docs.microsoft.com/en-us/azure/storage/common/storage-network-security#trusted-microsoft-servicesenter image description here