You need to enable JavaScript to run this app.
优惠活动
大模型
产品
解决方案
定价
更多

如何使用Azure PowerShell为Azure Container Registry分配用户标识

使用Azure PowerShell为Azure容器注册表分配用户标识

要为Azure容器注册表(ACR)分配用户分配的托管标识,可通过Set-AzContainerRegistry cmdlet实现(该命令用于更新ACR属性,可能未在文档中直接以"分配标识"为标题列出)。以下是具体操作步骤:

前提条件

  • 已安装Az.ContainerRegistry模块(可执行Install-Module -Name Az.ContainerRegistry完成安装)
  • 目标ACR需使用Standard或Premium SKU(Basic SKU不支持托管标识功能)
  • 已创建用户分配的托管标识(未创建的话可通过New-AzUserAssignedIdentity命令创建)

步骤1:获取用户分配标识的资源ID

先获取目标用户分配标识的资源ID:

# 替换为你的资源组名称和用户标识名称
$identity = Get-AzUserAssignedIdentity -ResourceGroupName "your-resource-group" -Name "your-user-identity-name"
$identityResourceId = $identity.Id

步骤2:将标识分配给ACR

使用Set-AzContainerRegistry更新ACR的身份配置:

# 替换为你的资源组名称和ACR名称
Set-AzContainerRegistry -ResourceGroupName "your-resource-group" -Name "your-acr-name" `
  -Identity @{
    UserAssignedIdentities = @{
      $identityResourceId = @{}
    }
  }

可选:同时启用系统分配+用户分配标识

如果需要同时配置系统分配标识和用户分配标识,可指定类型参数:

Set-AzContainerRegistry -ResourceGroupName "your-resource-group" -Name "your-acr-name" `
  -Identity @{
    Type = "SystemAssigned,UserAssigned"
    UserAssignedIdentities = @{
      $identityResourceId = @{}
    }
  }

步骤3:验证标识分配结果

执行以下命令确认标识已成功分配:

$acr = Get-AzContainerRegistry -ResourceGroupName "your-resource-group" -Name "your-acr-name"
$acr.Identity

输出结果中会显示已分配的用户标识信息,与你期望的界面效果一致。

内容的提问来源于stack exchange,提问作者RSW

相关产品推荐
方舟 Agent Plan

超全模态模型 × Harness 升级,最新支持 Deepseek-V4.1-Flash、GLM-5.3 系列、Doubao-Seedream-5.0-pro、Kimi-K3 (部分), 限时 9.9 元起

最近更新时间:2026.07.16 09:22:08