gpt4 book ai didi

azure - 使用 Reader UMI : "Insufficient privileges to complete the operation" 获取 Azure 自动化下的 AzADUser

转载 作者:行者123 更新时间:2023-12-03 03:23:37 24 4
gpt4 key购买 nike

我有一个 Azure 自动化帐户,其 PowerShell Runbook 具有:

$AzureContext = (Connect-AzAccount -Identity).context
Get-AzADUser -UserPrincipalName '<<a href="https://stackoverflow.com/cdn-cgi/l/email-protection" class="__cf_email__" data-cfemail="c7aaa287aabea3a8aaa6aea9e9a4a8aa" rel="noreferrer noopener nofollow">[email protected]</a>>'

此外,我在与自动化帐户相同的订阅和资源组中拥有一个用户分配的托管标识,该帐户在资源组范围内具有读者角色分配。

此 UMI 应用于自动化帐户 (through <Automation account> | Identity -> User-assigned -> +Add).

当我在门户中运行上述 Runbook 时,我收到错误 Get-AzADUser ,详情*[Authorization_RequestDenied] : Insufficient privileges to complete the operation.*和工作流程详细信息:

*Az.MSGraph.internal\Get-AzADUser : 
Insufficient privileges to complete the operation. At
C:\Modules\Global\Az.Resources\MSGraph.Autorest\custom\Get-
AzADUser.ps1:199 char:9 + Az.MSGraph.internal\Get-AzADUser
@PSBoundParameters + ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
+ CategoryInfo : InvalidOperation: ({ ConsistencyLe...= , Expand = }:
<>f__AnonymousType5`7) [Get-AzADUser_List], Exception +
FullyQualifiedErrorId : Authorization_RequestDenied,Microsoft.Azure.PowerShell.Cmdlets.Resources.MSGraph.Cmdlets.GetAzADUser_List*

我并没有完全了解安全/权限模型,但我已经做了看起来足够的事情,所以我一定错过了一些东西。

有什么想法吗?

谢谢!

最佳答案

我创建了一个 Azure Web 应用程序并启用了托管身份,如下所示:

enter image description here

要从 Azure Active Directory 获取用户,请确保将 Directory.Read.All API 权限分配给托管标识。

使用以下PowerShell脚本分配权限:

$TenantID="TenantID"
$GraphAppId = "00000003-0000-0000-c000-000000000000"
$DisplayNameOfMSI="testruk"
$PermissionName = "Directory.Read.All"


Connect-AzureAD -TenantId $TenantID
$MSI = (Get-AzureADServicePrincipal -Filter "displayName eq '$DisplayNameOfMSI'")
Start-Sleep -Seconds 10
$GraphServicePrincipal = Get-AzureADServicePrincipal -Filter "appId eq '$GraphAppId'"
$AppRole = $GraphServicePrincipal.AppRoles | `
Where-Object {$_.Value -eq $PermissionName -and $_.AllowedMemberTypes -contains "Application"}
New-AzureAdServiceAppRoleAssignment -ObjectId $MSI.ObjectId -PrincipalId $MSI.ObjectId `
-ResourceId $GraphServicePrincipal.ObjectId -Id $AppRole.Id

enter image description here

API 权限已成功分配给服务主体,如下所示:

enter image description here

现在,我可以成功获取用户的:

$AzureContext = (Connect-AzAccount -Identity).context
Get-AzADUser -UserPrincipalName '<<a href="https://stackoverflow.com/cdn-cgi/l/email-protection" class="__cf_email__" data-cfemail="770f0f0f371a0e13181a161e195914181a" rel="noreferrer noopener nofollow">[email protected]</a>>'

enter image description here

关于azure - 使用 Reader UMI : "Insufficient privileges to complete the operation" 获取 Azure 自动化下的 AzADUser,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/76186704/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com