Azure / Azure/azure-powershell

Confusing Error Message for Backup-AzApiManagement Command

Open
#26,536 4 comments 0 reactions 0 assignees View on GitHub
act-observability-squad API Management bug customer-reported Service Attention
Dominant language
C#
Stars
4.8k
Forks
4.3k
Avg merge
2d 17h
Merged PRs (30d)
51

Description

### Description

When using the Backup-AzApiManagement command with only backup operation permissions, the command returns the error message 'Long running operation failed with status 'Forbidden'.

However, the backup operation actually succeeds. It appears this error occurs due to insufficient permissions to access the URL in the location header returned by the [backup operation's REST call](https://learn.microsoft.com/en-us/rest/api/apimanagement/api-management-service/backup?view=rest-apimanagement-2024-05-01&tabs=HTTP), specifically the permissions to get the [operation results](https://learn.microsoft.com/en-us/rest/api/apimanagement/operations-results/get?view=rest-apimanagement-2024-05-01&tabs=HTTP).

This error message is very misleading and makes it difficult to understand what permissions are actually required to execute the command successfully. Could you please update the error message to provide clearer guidance on the necessary permissions? thanks in advance!

### Issue script & Debug output

PS /home/> Backup-AzApiManagement -ResourceGroupName $rg -Name $intApimName -StorageContext $storageContext -TargetContainerName $container -TargetBlobName $blob
DEBUG: 1+ >>>> Backup-AzApiManagement -ResourceGroupName $rg -Name $intApimName -StorageContext $storageContext -TargetContainerName $container -TargetBlobName $blob
DEBUG: 17+ function Get-ConciseViewPositionMessage >>>> {

DEBUG: 29+ >>>> $posmsg = ''

DEBUG: 30+ >>>> $headerWhitespace = ''

DEBUG: 31+ >>>> $offsetWhitespace = ''

DEBUG: 32+ >>>> $message = ''

DEBUG: 33+ >>>> $prefix = ''

DEBUG: 39+ if ( >>>> (($err.CategoryInfo.Category -eq 'ParserError' -and $err.Exception -is 'System.Management.Automation.ParentContainsErrorRecordException') -or $myinv.ScriptName -or $myinv.ScriptLineNumber -gt 1) -and $myinv.ScriptName -notmatch '\.psm1$') {

DEBUG: 113+ if ( >>>> ! $err.ErrorDetails -or ! $err.ErrorDetails.Message) {

DEBUG: 114+ if ( >>>> $err.CategoryInfo.Category -eq 'ParserError' -and $err.Exception.Message.Contains("~$newline")) {

DEBUG: 118+ elseif ( >>>> $err.Exception) {

DEBUG: 119+ >>>> $message += $err.Exception.Message

DEBUG: 133+ if ( >>>> $myinv -and $myinv.ScriptName -or $err.CategoryInfo.Category -eq 'ParserError') {

DEBUG: 173+ >>>> $posmsg += "${errorColor}" + $message

DEBUG: 175+ >>>> $reason = 'Error'

DEBUG: 176+ if ( >>>> $err.Exception -and $err.Exception.WasThrownFromThrowStatement) {

DEBUG: 180+ elseif ( >>>> $myinv.MyCommand -and $myinv.MyCommand.Name -and (Get-Command -Name $myinv.MyCommand -ErrorAction Ignore))

DEBUG: 182+ >>>> $reason = $myinv.MyCommand

DEBUG: 201+ >>>> $errorMsg = 'Error'

DEBUG: 203+ >>>> "${errorColor}${reason}: ${posmsg}${resetcolor}"

DEBUG: 204+ >>>> }

DEBUG: 1+ & >>>> { Set-StrictMode -Version 1; $this.Exception.InnerException.PSMessageDetails }
DEBUG: 1+ & { >>>> Set-StrictMode -Version 1; $this.Exception.InnerException.PSMessageDetails }
DEBUG: 1+ & { Set-StrictMode -Version 1; >>>> $this.Exception.InnerException.PSMessageDetails }
DEBUG: 1+ & { Set-StrictMode -Version 1; $this.Exception.InnerException.PSMessageDetails >>>> }
DEBUG: 1+ & >>>> { Set-StrictMode -Version 1; $this.Exception.InnerException.PSMessageDetails }
DEBUG: 1+ & { >>>> Set-StrictMode -Version 1; $this.Exception.InnerException.PSMessageDetails }
DEBUG: 1+ & { Set-StrictMode -Version 1; >>>> $this.Exception.InnerException.PSMessageDetails }
DEBUG: 1+ & { Set-StrictMode -Version 1; $this.Exception.InnerException.PSMessageDetails >>>> }
Backup-AzApiManagement: Long running operation failed with status 'Forbidden'.

### Environment data

NA

### Module versions

PS /home/> Get-Module -Name Az.ApiManagement -ListAvailable

Directory: /usr/local/share/powershell/Modules

ModuleType Version PreRelease Name PSEdition ExportedCommands
---------- ------- ---------- ---- --------- ----------------
Script 4.0.4 Az.ApiManagement Core,Desk {Add-AzApiManagementApiToGateway, Add-AzApiManagementApiToProduct, Add-AzApiManagementProductToGroup, Add-AzApiManagementRegion…}

### Error output

_No response_

Contributor guide

Open the contributing guide

Research direction

Start at the Backup-AzApiManagement command and its long-running operation handling in the Az.ApiManagement module. Compare the backup REST call's location header with the operations-results GET permission path. Done means the error guidance distinguishes a successful backup from inaccessible operation results and explains the required permissions.

Written by the indexing model from the issue text.

Assessment

Tech stack
azure, powershell
Domain
api, cloud
Issue type
Bug
Difficulty
3/5
Estimated time
1-2 days
Activity status
Quiet
Clarity
Mostly clear
Newbie friendliness
55/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.