azure-powershell icon indicating copy to clipboard operation
azure-powershell copied to clipboard

Executing New-AzurermResourceLock on Azure Automation results in an error

Open YoannGUILLO opened this issue 9 years ago • 6 comments

Cmdlet(s)

New-AzurermResourceLock (executed as Service Principal) on Azure Automation

PowerShell Version

Azure Automation Runbook (PowerShell)

Module Version

AzureRM.Resources Version: 3.6.0

Description

When executing New-AzurermResourceLock in an Azure Automation Runbook an error occured.

Debug Output

Logging in to Azure... New-AzurermResourceLock : The pipeline has been stopped. At line:10 char:1

  • New-AzurermResourceLock -LockLevel CanNotDelete -LockNotes "No deleti ...
  •   + CategoryInfo          : CloseError: (:) [New-AzureRmResourceLock], PipelineStoppedException
      + FullyQualifiedErrorId : Microsoft.Azure.Commands.ResourceManager.Cmdlets.Implementation.NewAzureResourceLockCmdlet
    
    

New-AzurermResourceLock : AuthorizationFailed : The client 'a073fd36-99e1-4a78-b6cb-840b55b45f82' with object id 'a073fd36-99e1-4a78-b6cb-840b55b45f82' does not have authorization to perform action 'Microsoft.Authorization/locks/write' over scope '/subscriptions/9b7bbcdc-0ef4-4fd7-b35b-f80193f65de2/resourceGroups/YOG001/providers/Microsoft.Authorization/locks/ResourceGroupLock'. At line:10 char:1

  • New-AzurermResourceLock -LockLevel CanNotDelete -LockNotes "No deleti ...
  •   + CategoryInfo          : CloseError: (:) [New-AzureRmResourceLock], ErrorResponseMessageException
      + FullyQualifiedErrorId : 
    

AuthorizationFailed,Microsoft.Azure.Commands.ResourceManager.Cmdlets.Implementation.NewAzureResourceLockCmdlet

Script/Steps for Reproduction

$ServicePrincipalConnection = Get-AutomationConnection -Name "AzureRunAsConnection"

Write-Output "Logging in to Azure..." Add-AzureRmAccount -ServicePrincipal -TenantId $servicePrincipalConnection.TenantId -ApplicationId $servicePrincipalConnection.ApplicationId -CertificateThumbprint $servicePrincipalConnection.CertificateThumbprint | Out-Null

New-AzurermResourceLock -LockLevel CanNotDelete -LockNotes "No deleting !" -LockName "ResourceGroupLock" -ResourceGroup "YOG001" -Force

YoannGUILLO avatar Mar 28 '17 14:03 YoannGUILLO

@ravbhatnagar Hey Gaurav, would you mind taking a look at this issue?

cormacpayne avatar Mar 30 '17 18:03 cormacpayne

Hello, some news about this problem ? It looks like to that problem : https://github.com/Azure/azure-powershell/issues/3549

YoannGUILLO avatar Apr 05 '17 13:04 YoannGUILLO

Still the same error after update the module AzureRM.Resources with the version 4.1.0

YoannGUILLO avatar Jun 09 '17 13:06 YoannGUILLO

@YoannGUILLO - What permissions were granted to the Service principal when it was created? From error message above, it looks like the service principal does not have permission to perform a write operation for 'Microsoft.Authorization/locks/write' over the indicated scope.

ravbhatnagar avatar Jun 09 '17 17:06 ravbhatnagar

I used the azure automation run as account created by default with my automation account, role assigned by default was contributor, I've set to owner and it work now. Incident can be closed thank for your support.

YoannGUILLO avatar Jun 12 '17 15:06 YoannGUILLO

Thanks for confirming! Closing this issue.

ravbhatnagar avatar Jun 13 '17 17:06 ravbhatnagar