gpt4 book ai didi

azure - 获取有权访问 Azure 资源的用户和组

转载 作者:行者123 更新时间:2023-12-03 02:15:39 28 4
gpt4 key购买 nike

我有一个名为devtest的资源。我想使用 azure cliREST APIIAM -> 角色分配 Blade 获取列表:

enter image description here

如何以编程方式检索该信息(group-id显示名称等)?是否可以获得有权访问资源的用户和组的列表?

例如,使用 graph 可以获取签名用户所属的组:

POST https://graph.microsoft.com/v1.0/me/getMemberGroups
Request Body:
{
"securityEnabledOnly": true
}

Response:
{
"@odata.context": "https://graph.microsoft.com/v1.0/$metadata#Collection(Edm.String)",
"value": [
// group ids here
]
}

但是如何对资源执行类似的操作并获取在该资源中具有角色的用户和组的列表?

编辑:

当我们转到角色分配 Blade 时,Azure调用端点:

POST https://graph.windows.net/{subscriptionId}/getObjectsByObjectIds

Request body:
{ "objectIds":[ "bunch unknown ids here" ],"includeDirectoryObjectReferences":true }

我收到的回复如下:

enter image description here

这与我在角色分配选项卡中看到的内容相关,但并非所有职位都会返回。在此回复中,我们没有有关角色的信息,如何深入了解它们?

最佳答案

您可以使用以下 cmdlet 列出资源及其各自组的所有角色分配(如果角色分配的对象类型不是 User,则不会为您提供任何输出)。

这是脚本:

 connect-azuread  # Manadatory to authenticate with azuread & to further run Get-azureadusermembership cmdlet
$rbac=Get-AzRoleAssignment -ResourceGroupName '<RgName>' -ResourceName '<ResourceName>' -ResourceType 'Microsoft.KeyVault/vaults' | Where-Object -Property ObjectType -EQ User| select -Property SignInName,ObjectId,RoleDefinitionName
Write-output $rbac
foreach($item in $rbac)
{
Get-AzureADUserMembership -ObjectId $item.ObjectId | select -Property *
}

以下是供引用的示例输出:

enter image description here

enter image description here

关于azure - 获取有权访问 Azure 资源的用户和组,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/71293261/

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