azure 获取服务主体的“角色和管理员”

0s7z1bwu  于 2023-04-22  发布在  其他
关注(0)|答案(1)|浏览(209)

在Azure Portal中,当我查看服务主体的“角色和管理员”选项卡时,我看到几个角色,包括几个自定义角色:

我可以使用PowerShell来获取角色定义:

PS C:\> Get-MgRoleManagementDirectoryRoleDefinition -Filter "DisplayName eq 'My Custom Role'"

Id                                   Description        DisplayName    IsBuiltIn IsEnabled ResourceScopes TemplateId                           Version
--                                   -----------        -----------    --------- --------- -------------- ----------                           -------
00000000-0000-0000-0000-000000000000 Used for My Stuff  My Custom Role False     True      {/}            00000000-0000-0000-0000-000000000000

但是,当我检查是否为我的服务主体分配了角色时,它没有显示。

PS C:\> Get-MgServicePrincipal -ServicePrincipalId $ServicePrincipalId 

Id                                   DisplayName          AppId                                SignInAudience
--                                   -----------          -----                                --------------
00000000-0000-0000-0000-000000000000 my-service-principal 00000000-0000-0000-0000-000000000000 AzureADMyOrg

PS C:\> Get-MgRoleManagementDirectoryRoleAssignment -Filter "principalId eq '$ServicePrincipalId'"
PS C:>

或者,如果我使用角色的GUID来查看分配给该角色的每个人,我仍然什么也得不到:

PS C:> Get-MgRoleManagementDirectoryRoleAssignment -Filter "RoleDefinitionId eq '00000000-0000-0000-0000-000000000000'"
PS C:>

谁能告诉我我做错了什么?

*注意:我使用Get-AzureADMSRoleDefinition等得到类似的结果 *

nzk0hqpo

nzk0hqpo1#

我尝试在我的环境中复制相同的结果,并得到以下结果:

我有一个名为SriApp的应用程序,其角色如下:

当我运行与您相同的命令时,我成功地获得了响应,其中包含分配给服务主体的角色列表,如下所示:

Connect-MgGraph -Scopes "Directory.Read.All"
Get-MgRoleManagementDirectoryRoleDefinition -Filter "DisplayName eq 'Devi Custom role'"
$ServicePrincipalId = "35cf4958-adcf-4c07-891b-dxxxxxxxx"
Get-MgServicePrincipal -ServicePrincipalId $ServicePrincipalId 
Get-MgRoleManagementDirectoryRoleAssignment -Filter "principalId eq '$ServicePrincipalId'"
Get-MgRoleManagementDirectoryRoleAssignment -Filter "RoleDefinitionId eq '74d0febe-1007-4ff4-a793-753cxxxxxxx'"

答复:

确认,您可以通过使用应用程序名称进行搜索来检查PIM中的活动分配,如下所示:

  • 转到Azure门户-〉特权身份管理-〉Azure AD角色-〉分配-〉活动分配 *

如果在分配角色时选择了【目录】级的作用域,则会在每个应用程序下体现,而不是真实的分配。
当我检查另一个名为Sri的应用程序时,即使我没有手动分配它们,它也具有如下相同的角色:

现在,我用上面的应用程序运行了相同的命令来更改$ServicePrincipalId,并得到了相同的响应,没有任何如下结果:

Connect-MgGraph -Scopes "Directory.Read.All"
Get-MgRoleManagementDirectoryRoleDefinition -Filter "DisplayName eq 'Devi Custom role'"
$ServicePrincipalId = "7b6320e7-19ab-496c-b1c8-dxxxxxxxxxx"
Get-MgServicePrincipal -ServicePrincipalId $ServicePrincipalId 
Get-MgRoleManagementDirectoryRoleAssignment -Filter "principalId eq '$ServicePrincipalId'"

答复:

在您的情况下,通过检查PIM中的active assignments及其名称来确认是否为服务主体分配了角色,并为列表角色给予有效的服务主体ID。

相关问题