如何为 Azure AD 用户管理 Azure AD 应用程序角色
How to manage Azure AD App Roles for Azure AD Users
1:是否有人知道可以管理 Azure AD 中企业应用程序的 Azure AD 用户角色分配(清单中定义的 appRoles)的工具?
我说的是如何将角色(特定于应用程序)分配给现有的 Azure AD 用户。为此,使用 Azure 门户是一个非常缓慢的过程。
当然,我们可以创建这个工具,但如果这样的工具已经存在就好了。今天使用许多 Azure AD 企业应用程序的大型组织有哪些?
2:在门户中手动编辑清单文件真的是最佳做法吗?将文件(AppRoles 部分)放在应用程序代码的 git 中会更有意义。
Is anyone aware of a tool that can manage Roles for Azure AD Users
据我所知,没有任何特定工具可用于管理应用程序角色。
总的来说,您应该能够将以下选项用于 add/edit/update 与应用程序角色相关的选项并为现有 AD 用户分配权限:
注意:另请注意,如果您要处理大量用户,您可以考虑将安全组分配给应用程序角色,而不是为单个用户分配安全组。这是一个值得考虑的选项,尽管它需要 Azure AD 高级许可证。 (更新 - 另请参阅此答案末尾 Philippe Signoret 的评论,内容涉及将组分配给应用程序角色、委派所分配组的管理和 self-service group management)
Azure 门户,通过编辑应用程序清单 json(您已经知道这一点)
PowerShell -
我在最后添加了这个脚本。您可以在使用 New-AzureADApplication
创建新应用程序或使用 Set-AzureADApplication
.
创建现有应用程序时执行此操作
要将这些角色分配给现有用户,您可以使用 New-AzureADUserAppRoleAssignment
,如下面更新的脚本所示。
Azure AD 图 API -
您可以使用 AppRole Type 和 Application 实体来管理应用角色本身。 Documentation here
您可以使用 AppRoleAssignment 实体将这些角色分配给现有的 Azure AD 用户等。Documentation here
Microsoft Graph API -
Documentation here - 请注意这仅在测试版中可用 - 因此它还不适用于生产应用程序。
对于您的生产应用程序,您可以从 json 文件(源代码管理的一部分,如 git 等)读取应用程序角色,并将其提供给一个编程选项,如 PowerShell 或 Azure广告图 API.
这是 PowerShell 脚本。另请查看这些 SO Post,我们在其中讨论了类似但仅在 PowerShell 范围内的内容。
(此问题讨论使用 PowerShell 解析 json 文件和更新应用程序清单)
Connect-AzureAD -TenantId <Tenant GUID>
# Create an application role of given name and description
Function CreateAppRole([string] $Name, [string] $Description)
{
$appRole = New-Object Microsoft.Open.AzureAD.Model.AppRole
$appRole.AllowedMemberTypes = New-Object System.Collections.Generic.List[string]
$appRole.AllowedMemberTypes.Add("User");
$appRole.DisplayName = $Name
$appRole.Id = New-Guid
$appRole.IsEnabled = $true
$appRole.Description = $Description
$appRole.Value = $Name;
return $appRole
}
# ObjectId for application from App Registrations in your AzureAD
$appObjectId = "<Your Application Object Id>"
$app = Get-AzureADApplication -ObjectId $appObjectId
$appRoles = $app.AppRoles
Write-Host "App Roles before addition of new role.."
Write-Host $appRoles
$newRole = CreateAppRole -Name "MyNewApplicationRole" -Description "This is my new Application Role"
$appRoles.Add($newRole)
Set-AzureADApplication -ObjectId $app.ObjectId -AppRoles $appRoles
完成上述脚本添加 AppRole 后,为用户分配角色就非常简单,直接命令即可。这是一个示例脚本 -
# Assign the values to the variables
$username = "<You user's UPN>"
$app_name = "<Your App's display name>"
$app_role_name = "<App role display name>"
# Get the user to assign, and the service principal for the app to assign to
$user = Get-AzureADUser -ObjectId "$username"
$sp = Get-AzureADServicePrincipal -Filter "displayName eq '$app_name'"
$appRole = $sp.AppRoles | Where-Object { $_.DisplayName -eq $app_role_name }
# Assign the user to the app role
New-AzureADUserAppRoleAssignment -ObjectId $user.ObjectId -PrincipalId
$user.ObjectId -ResourceId $sp.ObjectId -Id $appRole.Id
延迟响应,但迟到总比不到好,Terraform 对此提供支持:
https://www.terraform.io/docs/providers/azuread/r/application.html
1:是否有人知道可以管理 Azure AD 中企业应用程序的 Azure AD 用户角色分配(清单中定义的 appRoles)的工具?
我说的是如何将角色(特定于应用程序)分配给现有的 Azure AD 用户。为此,使用 Azure 门户是一个非常缓慢的过程。
当然,我们可以创建这个工具,但如果这样的工具已经存在就好了。今天使用许多 Azure AD 企业应用程序的大型组织有哪些?
2:在门户中手动编辑清单文件真的是最佳做法吗?将文件(AppRoles 部分)放在应用程序代码的 git 中会更有意义。
Is anyone aware of a tool that can manage Roles for Azure AD Users
据我所知,没有任何特定工具可用于管理应用程序角色。
总的来说,您应该能够将以下选项用于 add/edit/update 与应用程序角色相关的选项并为现有 AD 用户分配权限:
注意:另请注意,如果您要处理大量用户,您可以考虑将安全组分配给应用程序角色,而不是为单个用户分配安全组。这是一个值得考虑的选项,尽管它需要 Azure AD 高级许可证。 (更新 - 另请参阅此答案末尾 Philippe Signoret 的评论,内容涉及将组分配给应用程序角色、委派所分配组的管理和 self-service group management)
Azure 门户,通过编辑应用程序清单 json(您已经知道这一点)
PowerShell -
我在最后添加了这个脚本。您可以在使用
创建现有应用程序时执行此操作New-AzureADApplication
创建新应用程序或使用Set-AzureADApplication
.要将这些角色分配给现有用户,您可以使用
New-AzureADUserAppRoleAssignment
,如下面更新的脚本所示。Azure AD 图 API -
您可以使用 AppRole Type 和 Application 实体来管理应用角色本身。 Documentation here
您可以使用 AppRoleAssignment 实体将这些角色分配给现有的 Azure AD 用户等。Documentation here
Microsoft Graph API -
Documentation here - 请注意这仅在测试版中可用 - 因此它还不适用于生产应用程序。
对于您的生产应用程序,您可以从 json 文件(源代码管理的一部分,如 git 等)读取应用程序角色,并将其提供给一个编程选项,如 PowerShell 或 Azure广告图 API.
这是 PowerShell 脚本。另请查看这些 SO Post,我们在其中讨论了类似但仅在 PowerShell 范围内的内容。
Connect-AzureAD -TenantId <Tenant GUID>
# Create an application role of given name and description
Function CreateAppRole([string] $Name, [string] $Description)
{
$appRole = New-Object Microsoft.Open.AzureAD.Model.AppRole
$appRole.AllowedMemberTypes = New-Object System.Collections.Generic.List[string]
$appRole.AllowedMemberTypes.Add("User");
$appRole.DisplayName = $Name
$appRole.Id = New-Guid
$appRole.IsEnabled = $true
$appRole.Description = $Description
$appRole.Value = $Name;
return $appRole
}
# ObjectId for application from App Registrations in your AzureAD
$appObjectId = "<Your Application Object Id>"
$app = Get-AzureADApplication -ObjectId $appObjectId
$appRoles = $app.AppRoles
Write-Host "App Roles before addition of new role.."
Write-Host $appRoles
$newRole = CreateAppRole -Name "MyNewApplicationRole" -Description "This is my new Application Role"
$appRoles.Add($newRole)
Set-AzureADApplication -ObjectId $app.ObjectId -AppRoles $appRoles
完成上述脚本添加 AppRole 后,为用户分配角色就非常简单,直接命令即可。这是一个示例脚本 -
# Assign the values to the variables
$username = "<You user's UPN>"
$app_name = "<Your App's display name>"
$app_role_name = "<App role display name>"
# Get the user to assign, and the service principal for the app to assign to
$user = Get-AzureADUser -ObjectId "$username"
$sp = Get-AzureADServicePrincipal -Filter "displayName eq '$app_name'"
$appRole = $sp.AppRoles | Where-Object { $_.DisplayName -eq $app_role_name }
# Assign the user to the app role
New-AzureADUserAppRoleAssignment -ObjectId $user.ObjectId -PrincipalId
$user.ObjectId -ResourceId $sp.ObjectId -Id $appRole.Id
延迟响应,但迟到总比不到好,Terraform 对此提供支持: https://www.terraform.io/docs/providers/azuread/r/application.html