Azure 为什么会出现错误';提供的信息不映射到AD对象id;使用服务主体执行新AzRoleAssignment时?

Azure 为什么会出现错误';提供的信息不映射到AD对象id;使用服务主体执行新AzRoleAssignment时?,azure,powershell,azure-devops,azure-keyvault,azure-rbac,Azure,Powershell,Azure Devops,Azure Keyvault,Azure Rbac,在Azure DevOps管道中使用Powershell,我正在尝试将密钥保管库的主体角色存储帐户密钥操作员服务角色分配给存储帐户 命令行 命令行在我将Azure与服务主体连接后运行: $credentials = New-Object -TypeName System.Management.Automation.PSCredential($servicePrincipalApplicationId, $clientSecret) Connect-AzAccount -ServicePrinc

在Azure DevOps管道中使用Powershell,我正在尝试将密钥保管库的主体角色
存储帐户密钥操作员服务角色
分配给存储帐户

命令行

命令行在我将Azure与服务主体连接后运行:

$credentials = New-Object -TypeName System.Management.Automation.PSCredential($servicePrincipalApplicationId, $clientSecret)

Connect-AzAccount -ServicePrincipal -Credential $credentials -Tenant $tenantId
以下是我执行的命令行:

New-AzRoleAssignment -ApplicationId $keyVaultServicePrincipalId -ResourceGroupName $resourceGroupName -ResourceName $storageAccountName -ResourceType "Microsoft.Storage/storageAccounts" -RoleDefinitionName "Storage Account Key Operator Service Role"
其中:

  • $KeyVault服务Principalid
    是Vault的密钥。其值为
    cfa8b339-82a2-471a-a3c9-0fc0be7a4093
  • $resourceGroupName
    是存储所在的资源组的名称。其值为
    accountsmanager test global rg
  • $storageAccountName
    是我的存储帐户的名称。其值为
    accountsmanagertest
服务负责人

以下是运行命令的服务主体的权限:

该命令作为在订阅中具有所有者角色的服务主体运行:

在该订阅中创建的资源组也归该服务主体所有:

问题

运行该命令时,出现以下错误:

New-AzRoleAssignment: The provided information does not map to an AD object id.

为什么我会得到错误
提供的信息没有映射到AD对象id。
当执行命令
New azroleasignment
时?

我也可以在我这方面重现这一点,有两个问题

1.在您的命令中,
ResourceType
应该是
Microsoft.Storage/storageAccounts
,而不是
Microsoft.Storage/storageAccount

2.在与DevOps servcie连接中使用的服务主体相关的广告应用程序的API权限中,您需要在
Azure Active Directory Graph
中添加应用程序权限
目录.Read.All
,而不是
Microsoft Graph

一段时间后生效,它会很好地工作


我一直在避免使用遗留权限,但它可以正常工作。很好的回答:)