向事件网格自定义主题或域分配系统托管标识Assign a system-managed identity to an Event Grid custom topic or domain

本文介绍如何为事件网格自定义主题或域启用系统托管标识。This article shows you how to enable a system-managed identity for an Event Grid custom topic or a domain. 若要了解托管标识,请参阅什么是 Azure 资源托管标识To learn about managed identities, see What are managed identities for Azure resources.

在创建时启用标识Enable identity at the time of creation

使用 Azure 门户Using Azure portal

在 Azure 门户中创建自定义主题或域时,可以为其启用系统分配的标识。You can enable system-assigned identity for a custom topic or a domain while creating it in the Azure portal. 下图显示了如何为自定义主题启用系统托管标识。The following image shows how to enable a system-managed identity for a custom topic. 基本上,你可以在主题创建向导的“高级”页面上选择“启用系统分配的标识”选项 。Basically, you select the option Enable system assigned identity on the Advanced page of the topic creation wizard. 在域创建向导的“高级”页上也可以看到此选项。You'll see this option on the Advanced page of the domain creation wizard too.

在创建自定义主题时启用标识

使用 Azure CLIUsing Azure CLI

你还可以使用 Azure CLI 创建具有系统分配的标识的自定义主题或域。You can also use the Azure CLI to create a custom topic or domain with a system-assigned identity. 使用 az eventgrid topic create 命令,将 --identity 参数设置为 systemassignedUse the az eventgrid topic create command with the --identity parameter set to systemassigned. 如果不为此参数指定值,则使用默认值 noidentityIf you don't specify a value for this parameter, the default value noidentity is used.

# create a custom topic with a system-assigned identity
az eventgrid topic create -g <RESOURCE GROUP NAME> --name <TOPIC NAME> -l <LOCATION>  --identity systemassigned

类似地,可以使用 az eventgrid domain create 命令创建具有系统托管标识的域。Similarly, you can use the az eventgrid domain create command to create a domain with a system-managed identity.

为现有自定义主题或域启用标识Enable identity for an existing custom topic or domain

本部分介绍如何为现有的自定义主题或域启用系统托管标识。In this section, you learn how to enable a system-managed identity for an existing custom topic or domain.

使用 Azure 门户Using Azure portal

下面的过程展示了如何为自定义主题启用系统托管标识。The following procedure shows you how to enable system-managed identity for a custom topic. 为域启用标识的步骤类似。The steps for enabling an identity for a domain are similar.

  1. 转到 Azure 门户Go to the Azure portal.

  2. 在顶部的搜索栏中,搜索“事件网格主题”。Search for event grid topics in the search bar at the top.

  3. 选择要为其启用托管标识的自定义主题。Select the custom topic for which you want to enable the managed identity.

  4. 切换到“标识”选项卡。Switch to the Identity tab.

  5. 打开启用标识的开关。Turn on the switch to enable the identity.

  6. 在工具栏上选择“保存”,保存该设置。Select Save on the toolbar to save the setting.

    自定义主题的“标识”页面

你可以使用类似的步骤为事件网格域启用标识。You can use similar steps to enable an identity for an event grid domain.

使用 Azure CLIUse the Azure CLI

使用 az eventgrid topic update 命令并将 --identity 设置为 systemassigned,为现有的自定义主题启用系统分配的标识。Use the az eventgrid topic update command with --identity set to systemassigned to enable system-assigned identity for an existing custom topic. 如果要禁用标识,请将该值指定为 noidentityIf you want to disable the identity, specify noidentity as the value.

# Update the topic to assign a system-assigned identity. 
az eventgrid topic update -g $rg --name $topicname --identity systemassigned --sku basic 

更新现有域的命令也是类似的 (az eventgrid domain update)。The command for updating an existing domain is similar (az eventgrid domain update).

后续步骤Next steps

在目标(例如,服务总线队列)上将标识添加到相应角色(例如,服务总线数据发送方)。Add the identity to an appropriate role (for example, Service Bus Data Sender) on the destination (for example, a Service Bus queue). 有关详细步骤,请参阅授予托管标识对事件网格目标的访问权限For detailed steps, see Grant managed identity the access to Event Grid destination.