【问题标题】:Azure Automation - Unable to Remove-AzResourceLockAzure 自动化 - 无法删除-AzResourceLock
【发布时间】:2020-10-19 18:57:45
【问题描述】:

我在资源组级别删除 Azure Lock 时遇到问题。我是通过 Azure Runbook 进行的。

我验证良好(我能够获取任何我想要的详细信息)。这是代码:

# Ensures you do not inherit an AzureRMContext in your runbook
Disable-AzContextAutosave –Scope Process
"Logging in to Azure..."
$connection = Get-AutomationConnection -Name AzureRunAsConnection
Connect-AzAccount -ServicePrincipal -Tenant $connection.TenantID -ApplicationId $connection.ApplicationID -CertificateThumbprint $connection.CertificateThumbprint

如果我这样做了,比如说Get-AzResource -ResourceGroupName $RG,我就会得到我需要的信息。但问题是我实际上需要删除该资源组的一些资源,并且它有一个锁。

当我Remove-AzResourceLock -LockId $getAzureLock.LockId -Force 时,我被抛出这个:

Remove-AzResourceLock : AuthorizationFailed : The client XX with object id XX does not have authorization to perform action 'Microsoft.Authorization/locks/delete' over scope '/subscriptions/<redacted>/resourceGroups/<redacted>/providers/Microsoft.Authorization/locks/resourceDellock' or the scope is invalid. If access was recently granted, please refresh your credentials.

仅供参考,我已编辑订阅/对象 ID 信息。

为了我的一生,我无法绕过它。从访问控制 (IAM) 将应用程序添加为订阅级别的贡献者。

我尝试了很多东西,我只是累了写下来!我很抱歉。在过去的 4 个小时里,我一直在阅读和尝试一些东西。所以请原谅我!

请帮我解决这个问题..

【问题讨论】:

  • 顺便说一句,所有这些都可以从 VSCode 无缝运行。

标签: azure powershell azure-resource-group azure-runbook


【解决方案1】:

根据documentation,只有OwnerUser Access Administrator 内置角色有删除锁的权限,而Contributor 角色没有。

删除资源的管理锁或低于该资源的任何级别 资源。要删除管理锁,您必须有权访问 Microsoft.Authorization/* 或 Microsoft.Authorization/locks/* 操作。 在内置角色中,只有所有者和用户访问管理员是 授予这些操作

因此,您的解决方案是将Owner/User Access Administrator 角色授予您的服务主体,或者创建自定义角色并授予对Microsoft.Authorization/* 操作的适当权限。

【讨论】:

  • 你是谁?而且,它奏效了。我将角色更改为User Access Administrator,它有所帮助。非常感谢。
  • WHO ARE YOU? - 圣诞老人的大帮手:D
猜你喜欢
  • 1970-01-01
  • 2021-11-28
  • 1970-01-01
  • 2020-09-28
  • 2019-03-17
  • 2022-12-10
  • 2020-03-21
  • 1970-01-01
  • 2022-01-14
相关资源
最近更新 更多