【问题标题】:How to set user assigned identity with Azure Powershell (not az cli)?如何使用 Azure Powershell(不是 az cli)设置用户分配的标识?
【发布时间】:2021-07-16 21:16:04
【问题描述】:

我正在尝试通过 Az Powershell module 将用户分配的身份设置为 azure Web 应用程序

这是我对 Set-AzResource 的尝试,它不起作用

$webApp = Get-AzWebApp -Name "somewebapp" -ResourceGroupName $ResourceGroupName

$site = Get-AzResource -Id $webApp.Id

$appIdentity = Get-AzUserAssignedIdentity -ResourceGroupName $ResourceGroupName -Name "someid"
$appIdentity2 = Get-AzUserAssignedIdentity -ResourceGroupName $ResourceGroupName -Name "someotherid"

$site.Identity.Type = "UserAssigned"
$site.Identity.UserAssignedIdentities = New-Object "System.Collections.Generic.Dictionary[System.String,Microsoft.Azure.Management.ResourceManager.Models.IdentityUserAssignedIdentitiesValue]"
$site.Identity.UserAssignedIdentities[$appIdentity.Id] = New-Object "Microsoft.Azure.Management.ResourceManager.Models.IdentityUserAssignedIdentitiesValue" -ArgumentList $appIdentity.ClientId, $appIdentity.PrincipalId
$site.Identity.UserAssignedIdentities[$appIdentity2.Id] = New-Object "Microsoft.Azure.Management.ResourceManager.Models.IdentityUserAssignedIdentitiesValue" -ArgumentList $appIdentity2.ClientId, $appIdentity2.PrincipalId

$site | Set-AzResource -Force

我看到的问题是Set-AzResource 只在 HTTP 请求的正文中发送“properties”属性,而忽略了“identity”属性:

{
  "properties": {
    "name": "somewebapp",
    "state": "Running",
    ...
  }
}

如何通过 Az powershell 模块在 Web 应用程序上设置用户分配的身份? Set-AzWebApp 也没有任何参数(-AssignIdentity 参数用于系统分配的标识)。

作为参考,使用 azure cli 执行此操作确实工作:

az webapp identity assign --resource-group "rg-someresourcegroup" --name "somewebapp" --identities @($appIdentity.Id, $appIdentity2.Id)

编辑:我找到了this issue,这似乎证实了我的怀疑,确实不支持。

【问题讨论】:

    标签: azure powershell


    【解决方案1】:

    正如document 所示,Azure 应用服务的当前版本的 Azure PowerShell 命令行开关不支持用户分配的身份。

    【讨论】:

    • 谢谢!这确实证实了通过 Azure PowerShell commandlet 确实不可能。
    猜你喜欢
    • 1970-01-01
    • 2021-12-06
    • 1970-01-01
    • 1970-01-01
    • 2022-08-24
    • 1970-01-01
    • 2022-01-12
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多