The server failed to authenticate the request. Verify that the certificate is valid and is associated with this subscription
I finally got the solution
The error message that I got was
Set-AzureService : ForbiddenError: The server failed to authenticate the request. Verify that the certificate is valid and is associated with this >subscription.
It’s a bit misleading because as you can see in the code below (esp: last line), I did set the current storage but why did I get this message?
[05:14:33][Step 3/3] Set-AzureService : ForbiddenError: The server failed to >authenticate the [05:14:33][Step 3/3] request. Verify that the certificate is valid and is >associated with this [05:14:33][Step 3/3] subscription. [05:14:33][Step 3/3] At line:1 char:1 [05:14:33][Step 3/3] + Set-AzureService -ServiceName $service -Label >$deploymentLabel [05:14:33][Step 3/3] + >~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ [05:14:33][Step 3/3] + CategoryInfo : CloseError: (:) [Set->AzureService], ComputeCloud [05:14:33][Step 3/3] Exception [05:14:33][Step 3/3] + FullyQualifiedErrorId : >Microsoft.WindowsAzure.Commands.ServiceManagemen [05:14:33][Step 3/3] t.HostedServices.SetAzureServiceCommand
The script was working fine when run in VM Powershell but failed when run with Teamcity.
To resolve this I followed the following Steps :
Open Windows Powershell on VM
- Run "Get-AzurePublishSettingsFile". It will ask you to login to Azureand you will get the publish setting file for your Azure Subscriptionassociated with your account.
- Then run "Add-AzureAccount", It will ask you to login and youraccount will be added to powershell. Login to Azure Portal(manage.windowsazure.com).
- Go to Settings => Management Certificates section. Get the ThumbPrintof the recently added PublishSettingCertificate.
- On Powershell run Import-AzurePublishSettingsFile "path of yourpublish setting file on VM"
- Run Add-AzureCertificate -serviceName "Your service Name"-certToDeploy (get-item cert:\CurrentUser\MY"Certificate ThumbPrint you got from Azure") Finally "Get-AzureSubscription", to see thesubscriptions added on Powershell.
Hope this helps some one :)
Is the user you used in PowerShell directly on the VM the same as the one configured for TeamCity?
I had the same error when I was trying to get the Azure subscriptions via PowerShell using Get-AzureSubscription in an Azure Runbook. It might be that our credential had some RBAC configuration issues.
In my case I created a new (organizational) account and used that instead, which solved my problem. Maybe worth trying?