首页 > 解决方案 > Azure Active Directory B2C 角色模板显示名称不一致

问题描述

我有一个用于在 ADB2C 租户中创建应用程序/资源的自动化脚本。最近,我在 AzureADPreview 中遇到了一个令人不安的问题。

基本上我创建一个应用程序,我创建它的服务主体,然后我为这个应用程序分配角色。特别是导致我出现问题的一个角色是:用户管理员,或者更好地说是用户管理员 | 用户帐户管理员。

我这是什么意思?基本上对于一个租户来说,cmdlet: Get-AzureADDirectoryRoleTemplate 要么返回用户管理员,要么返回用户帐户管理员,这很奇怪。

这是代码:

# Grant needed Service Principals Permissions
foreach ($displayName in $_.ServicePrincipal.ApplicationRoles) {
    $adDirectoryRole = Get-AzureADDirectoryRole | Where-Object { $_.displayName -eq $displayName }
    if ($null -eq $adDirectoryRole) {
        $adDirectoryRoleTemplate = Get-AzureADDirectoryRoleTemplate | Where-Object { $_.displayName -eq $displayName }
        Enable-AzureADDirectoryRole -RoleTemplateId $adDirectoryRoleTemplate.ObjectId | Out-Null
        $adDirectoryRole = Get-AzureADDirectoryRole | Where-Object { $_.displayName -eq $displayName }
    }

    Add-AzureADDirectoryRoleMember -ObjectId $adDirectoryRole.ObjectId -RefObjectId $servicePrincipal.ObjectId | Out-Null
}

Enable-AzureADDirectoryRole -RoleTemplateId $adDirectoryRoleTemplate.ObjectId | Out-Null当 DisplayName 不是用户帐户管理员时,该行有时会引发错误。

请不要告诉我 Azure 的 API 代码是这样的:

if (rand() > 0.5f) { role.DisplayName = 'User Administrator'; }
else { role.DisplayName = 'User Account Administrator'; }

到底是怎么回事?为什么会这样?抛出的错误

Enable-AzureADDirectoryRole : Error occurred while executing ActivateDirectoryRole
Code: Request_BadRequest
Message: Could not resolve request to a valid role template. A valid value must be specified for 'displayName' or 'roleTemplateId'.
RequestId: 6bc26cc3-ce6d-41d0-abe0-2635d9897b75
DateTimeStamp: Thu, 14 Jan 2021 14:50:19 GMT
Details: PropertyName  - roleTemplateId, PropertyErrorCode  - PropertyRequired
HttpStatusCode: BadRequest
HttpStatusDescription: Bad Request
HttpResponseStatus: Completed

PS模块:2.0.2.119 AzureADPreview

UPDATE

由于很多评论都没有抓住重点,我想我需要强调这个问题。

Depending当我在租户上进行上述查询时,我会得到不同的结果。根本不应该是这样,这是一个BUG。我不知道错误在哪里,在 Azure API 中,在 PowerShell 模块中,这是几天前开始发生的。我们没有改变任何东西,所以我将责任归咎于 Azure API。

我将附上一些照片,这样你就可以清楚地看到我对两个不同租户的结果。请理解,我对 5 个或更多租户进行了测试,并且每个租户都会发生这种随机性。

有的归来User Administrator,有的归来User Account Administrator。该特定租户的此值在部署后不会更改。但在部署时,该值会有所不同。

看看这些照片:

这是一位租​​户

这是另一个租户

这些结果来自不同的租户!!!

标签: powershellmoduleazure-active-directoryazure-ad-b2c

解决方案


在与 Azure 支持反复多次后,我们得出结论,这确实是一个错误。他们发表了一篇关于重命名一些用户角色的博客文章:

A 30-day notice announcing the proposed change was posted to the Message center in M365 Admin center in Message ID MC218295 as of July 2020 with information to customers to update their scripts by August 14, 2020.

更新于 1 月 20 日完成,今天 1 月 29 日,我所有的租户对该User Administrator角色具有相同的价值。


推荐阅读