Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Azure ExpiredAuthenticationToken during New-AzureRmResourceGroupDeployment when deploying resources via Visual Studio

I'm trying to deploy an HDInsight cluster using an ARM template via Visual Studio. I've created an Azure Resource Group project in Visual Studio 2015, and added my resource definitions to the template JSON files.

However when I've gone to deploy it (by right-clicking the project, choosing Deploy -> New Deployment, entering my parameters), the output of Visual Studio shows (I've snipped out some boring stuff):

17:19:23 - Build started.

17:19:23 - Project "LaunchHdInsightCluster.deployproj" (StageArtifacts target(s)):

[snip]

17:20:27 - [VERBOSE] 17:20:27 - Resource Microsoft.HDInsight/clusters 'groupbhdinsight' provisioning status is running

17:31:06 - [ERROR] New-AzureRmResourceGroupDeployment : ExpiredAuthenticationToken: The access token expiry UTC time '3/14/2016 5:31:06 PM' is earlier than current UTC time '3/14/2016 5:31:07 PM'.

Note that the deploy only ran for 12 minutes before the access token expired - obviously for deploying an HDInsight cluster this is a problem (takes on average 20 minutes).

I'm just trying to understand what's going on under the hood here, as I can't find documentation for this. i.e:

What creates the access token and how? How long does it last for? I wasn't asked for any Azure creds when deploying - I'm assuming it must be the fact that I'm signed into Visual Studio using the same account I use in Azure, and it 'borrows' the authentication session, but this is just a guess

What determines the expiry time of the access token so I can prevent this happening again?

How do I refresh my authentication token?

like image 734
James Allen Avatar asked Mar 14 '16 18:03

James Allen


2 Answers

What's happening here is that the Azure Resource Group deployment in VS uses the PowerShell Script in the project to do deployment (even though the output is hosted in VS, we use that PS script to do the work). The PowerShell script is authenticated by using the token from your VS sign in. That token is only good for an hour and then VS will refresh it. Once it's handed off to PowerShell though, PowerShell doesn't automatically refresh it. So if you have the token for 59 minutes, it's going to expire soon after you start the deployment. The token could last for an hour, or anything less than that. We're working on a fix for this (i.e. have PowerShell automatically refresh the token) but that's a month or so out yet. See: https://github.com/Azure/azure-powershell/issues/1068

Workarounds: Unfortunately there's no good work around from VS. But...

  • As observed the deployment will continue just fine in Azure, it's just that VS/PS can no longer poll for status. You can monitor the deployment via the portal or PowerShell.
  • If you drop to PowerShell and run the script, PowerShell will automatically refresh the token when you login with credentials - you can get the exact command that VS runs by sifting through the output window - this doc also gives an overview of running the script manually: https://azure.microsoft.com/en-us/documentation/articles/vs-azure-tools-resource-groups-how-script-works/

Hope that helps...

like image 137
bmoore-msft Avatar answered Oct 07 '22 19:10

bmoore-msft


I bet it was a transient issue. I retried deployment (needed to modify my ARM template) and now it succeeded.

Please check your Azure Resource Group in the portal. You will likely have your resources up and running.

@Cleverguy25 provided an explanation of how I believe the deployment process work.

like image 39
Igor Soloydenko Avatar answered Oct 07 '22 19:10

Igor Soloydenko