azure-pipelines-tasks: AzureFIleCopyV3 Invalid header format

Question, Bug, or Feature?
Type: Bug

Enter Task Name: AzureFileCopyV3

Environment

  • Server - Azure Pipelines

SelenityAllocate / Spend Management / Copy Release Zip to Caching / Release-479

  • Agent - Hosted

Windows - 2.194.0

Issue Description

We have been using AzureFileCopyV3 for some time without issue. Last week it started failing. We confirmed that no changes had been made to our pipeline configuration. We noticed that the version of the task had changed from Version : 3.209.0 to Version : 3.214.0

The function that is reporting the error has been recently altered in the PR which increased the version. MSAL Upgrade for Common Library (Powershell) (#17205)

Service connection is successfuly verifying

Task logs

Get-AzureRMAccessToken - started - endpoint=@{Url=https://management.azure.com/; Data=; Auth=} - scheme=ServicePrincipal
2022-12-19T12:07:02.5437151Z ##[debug]MSAL - useMSAL = True
2022-12-19T12:07:02.5550617Z ##[debug]MSAL - Get-EnvironmentAuthUrl - endpoint=@{Url=https://management.azure.com/; Data=; Auth=}
2022-12-19T12:07:02.5565407Z ##[debug]MSAL - Get-EnvironmentAuthUrl - useMSAL=True
2022-12-19T12:07:02.5580479Z ##[debug]MSAL - Get-EnvironmentAuthUrl - envAuthUrl=https://login.microsoftonline.com/
2022-12-19T12:07:02.6464062Z ##[debug]MSAL - ServicePrincipal - clientSecret is used.
2022-12-19T12:07:02.6611436Z ##[debug]Fetching Access Token - MSAL
2022-12-19T12:07:02.8510168Z ##[debug]Get-AzureRMAccessToken - started - endpoint=@{Url=https://management.azure.com/; Data=; Auth=} - scheme=ServicePrincipal
2022-12-19T12:07:02.8525617Z ##[debug]MSAL - useMSAL = True
2022-12-19T12:07:02.8551467Z ##[debug]Fetching Access Token - MSAL
2022-12-19T12:07:02.8870901Z ##[debug]GET https://management.azure.com//subscriptions/{subscription}/resourceGroups/{resourceGroup}?api-version=2016-02-01 with 0-byte payload
2022-12-19T12:07:02.9165834Z ##[debug]Exception : The remote server returned an error: (401) Unauthorized.
2022-12-19T12:07:02.9255378Z ##[debug]Exception message - System.Net.WebException: The remote server returned an error: (401) Unauthorized.
2022-12-19T12:07:02.9267621Z ##[debug]   at Microsoft.PowerShell.Commands.WebRequestPSCmdlet.GetResponse(WebRequest request)
2022-12-19T12:07:02.9280705Z ##[debug]   at Microsoft.PowerShell.Commands.WebRequestPSCmdlet.ProcessRecord()
2022-12-19T12:07:02.9431306Z ##[debug]Exception message extracted from response {"error":{"code":"AuthenticationFailedInvalidHeader","message":"Authentication failed. The 'Authorization' header is provided in an invalid format."}}
2022-12-19T12:07:02.9844099Z ##[debug]Processed: ##vso[task.logissue code=AuthenticationFailedInvalidHeader;type=error]
2022-12-19T12:07:02.9898286Z ##[debug]Exception : ExceptionMessage: Authentication failed. The 'Authorization' header is provided in an invalid format. (in function: Get-AzRmResourceGroup)

Error logs

ExceptionMessage: ExceptionMessage: Authentication failed. The ‘Authorization’ header is provided in an invalid format. (in function: Get-AzRmResourceGroup) (in function: Get-AzRMStorageKeys)

tasklog_28.zip

About this issue

  • Original URL
  • State: closed
  • Created 2 years ago
  • Reactions: 3
  • Comments: 16 (3 by maintainers)

Most upvoted comments

@JonathanLydall I had the same problem today and i resolved it by updating Azure modules on the server where my agents were hosted. I can use my selfHosted agent pools again , hope this helps!

Thank you @Cbrbeats, it did.

For anyone else with the same issue and wanting to know how to do the upgrade, I ran the following from an admin elevated PowerShell session:

Install-Module -Name Az -Scope AllUsers -Force -AllowClobber

When I initially made the pipeline I had a task which would run this every time, but on the hardware for that agent it would add minutes for each run, so I removed it but kept comments in the .yml of what command to run which came in useful today for this.

Hi @ozanovus,

In case it helps you, we’ve been experiencing this problem, but only on our self-hosted agent. As a workaround since the same day this issue was logged we’ve switched to using an Azure hosted windows-latest agent which works fine. To answer your questions:

  1. Windows 10 22H2 (OS Build 19045.2364)
  2. The service connection looks like this: image
  3. For administrative reasons I’m not able to change the service connection at this time.
  4. Our task is as follows:
- task: AzureFileCopy@4
  displayName: Copy installers to Azure Blob Storage
  inputs:
    sourcePath: '$(Pipeline.Workspace)\${{ parameters.artifactName }}\*'
    azureSubscription: 'Intent Architect Azure Resource Group'
    destination: 'azureBlob'
    storage: '<storageAccountName>'
    containerName: '<containerName>'
    additionalArgumentsForBlobCopy: '--log-level=INFO --exclude-pattern "*.yml"'
    copyFilesInParallel: false
  1. The agent is not behind any sort of proxy.

For future reference in case any other user experience similar issue; I wanted to add some references for updating Azure Az PowerShell module.

1. Checking Azure Az PowerShell Module Version:

You can check installed Az Module versions with the command below.

Get-InstalledModule -Name Az -AllVersions -OutVariable AzVersions

If your version is older than latest one (currently latest version is 9.4.0); we recommend you to update your Az Module .

2. Updating Azure Az PowerShell Module

Recommended way is to visit the official page which has instructions for different Powershell versions according to needings. https://learn.microsoft.com/en-us/powershell/azure/install-az-ps

Example command for installation from the page (you can also change CurrentUser to AllUsers depending on your needings/environment): Install-Module -Name Az -Scope CurrentUser -Repository PSGallery -Force

@JonathanLydall
I had the same problem today and i resolved it by updating Azure modules on the server where my agents were hosted. I can use my selfHosted agent pools again , hope this helps!