![](/img/trans.png)
[英]Azure API Management not obtaining resource groups with service principal
[英]Azure service principal unable to assign permissions to resource groups
我正在嘗試構建一個azure Web應用程序來創建一個azure資源組並為特定用戶分配貢獻者權限。 我正在使用powershell腳本來執行此操作。 當我在我的本地運行時它會做它應該做的事情。 當我在azure web app上執行它時,它會拋出以下錯誤。
服務主體擁有訂閱的所有者權限,並且它具有目錄權限。
#Login to Azure using Service Principal
Login-AzureRmAccount -ServicePrincipal -Credential $SPcred -TenantId "XXXXX-xxxx-xxxxxxx"
#Create resource group
New-AzureRmResourceGroup -Name $Name -Location $Location -Force
if((Get-AzureRmResourceGroup -Name $Name).ProvisioningState = "Succeeded")
{
New-AzureRmRoleAssignment -ResourceGroupName $Name -SignInName XXXXXX -RoleDefinitionName Contributor
}
錯誤信息:
提供的信息不會映射到AD對象ID azure
您似乎需要使用Add-AzureADDirectoryRoleMember將目錄角色分配給您的服務主體。
您可以選擇所需的特定目錄角色,請參閱此鏈接 。
注意:您需要先安裝azure ad powershell模塊 。
在這種情況下,您可以嘗試將Application Administrator角色分配給您的服務主體。
# Fetch role instance $role = Get-AzureADDirectoryRole | Where-Object {$_.displayName -eq 'Application Administrator'} # If role instance does not exist, instantiate it based on the role template if ($role -eq $null) { # Instantiate an instance of the role template $roleTemplate = Get-AzureADDirectoryRoleTemplate | Where-Object {$_.displayName -eq 'Application Administrator'} Enable-AzureADDirectoryRole -RoleTemplateId $roleTemplate.ObjectId # Fetch role $role = Get-AzureADDirectoryRole | Where-Object {$_.displayName -eq 'Application Administrator'} } # Add the SP to role Add-AzureADDirectoryRoleMember -ObjectId $role.ObjectId -RefObjectId <your SP ObjectID>
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.