マネージド ID を使用したイベント配信

この記事では、Azure Event Grid システム トピック、カスタム トピック、または doメイン にマネージド サービス ID を使用する方法について説明します。 これを使用して、Service Bus のキューとトピック、イベント ハブ、ストレージ アカウントなどの、サポートされている配信先にイベントを転送します。

前提条件

  1. システム割り当て ID またはユーザー割り当て ID をシステム トピック、カスタム トピック、またはドメインに割り当てます。

  2. 配信先 (Service Bus キューなど) の適切なロール (Service Bus データ送信者など) に ID を追加する。 詳細な手順については、配信先の Azure ロールへの ID の追加に関する記事を参照してください。

    Note

    現時点では、プライベート エンドポイントを使用してイベントを配信することはできません。 詳細については、この記事の最後にある「プライベート エンドポイント」セクションを参照してください。

ID を使用するイベント サブスクリプションを作成する

マネージド ID を使用して Event Grid カスタム トピックまたはシステム トピックを作成メインし、その ID を宛先の適切なロールに追加したら、その ID を使用するサブスクリプションを作成する準備が整います。

Azure Portal の使用

イベント サブスクリプションを作成する際、 [エンドポイントの詳細] セクションにエンドポイントに対するシステム割り当て ID またはユーザー割り当て ID の使用を有効にするオプションが表示されます。

Service Bus キューを配信先として使用してイベント サブスクリプションを作成する際に、システム割り当て ID を有効にする例を次に示します。

Screenshot that shows how to enable an identity when creating an event subscription for a Service Bus queue.

また、 [追加機能] タブで、配信不能処理でシステム割り当て ID の使用を有効にすることもできます。

Screenshot that shows how to enable a system-assigned identity for dead-lettering.

イベント サブスクリプションの作成後に、マネージド ID を有効にすることができます。 イベント サブスクリプションの [イベント サブスクリプション] ページで [Additional Features]\(追加機能\) タブに移動し、オプションを確認してください。 このページで配信不能の ID を有効にすることもできます。

Screenshot that shows how to enable a system-assigned identity on an existing event subscription.

トピックでユーザー割り当て ID を有効にしている場合は、Manged Identity Type のドロップダウン リストにユーザー割り当て ID オプションが有効になっていることがわかります。 [Managed Identity Type]\(マネージド ID の種類\)[User Assigned]\(ユーザー割り当て\) を選択すると、イベントの配信に使用するユーザー割り当て ID を選択できるようになります。

Screenshot that shows how to enable a user-assigned identity on an event subscription.

Azure CLI の使用 - Service Bus キュー

このセクションでは、Azure CLI を使用してシステム割り当て ID の使用を有効にし、イベントを Service Bus キューに配信する方法について学びます。 ID は Azure Service Bus データ送信者ロールのメンバーである必要があります。 また、配信不能処理に使用されるストレージ アカウントのストレージ BLOB データ共同作成者ロールのメンバーである必要もあります。

変数の定義

最初に、CLI コマンドで使用する次の変数の値を指定します。

subid="<AZURE SUBSCRIPTION ID>"
rg = "<RESOURCE GROUP of EVENT GRID CUSTOM TOPIC>"
topicname = "<EVENT GRID TOPIC NAME>"

# get the service bus queue resource id
queueid=$(az servicebus queue show --namespace-name <SERVICE BUS NAMESPACE NAME> --name <QUEUE NAME> --resource-group <RESOURCE GROUP NAME> --query id --output tsv)
sb_esname = "<Specify a name for the event subscription>" 

配信用に、マネージド ID を使用してイベント サブスクリプションを作成する

このサンプル コマンドでは、エンドポイントの種類が Service Bus キューに設定された Event Grid カスタム トピックのイベント サブスクリプションを 作成します

az eventgrid event-subscription create  
    --source-resource-id /subscriptions/$subid/resourceGroups/$rg/providers/Microsoft.EventGrid/topics/$topicname
    --delivery-identity-endpoint-type servicebusqueue  
    --delivery-identity systemassigned 
    --delivery-identity-endpoint $queueid
    -n $sb_esname 

配信および配信不能処理用に、マネージド ID を使用してイベント サブスクリプションを作成する

このサンプル コマンドでは、エンドポイントの種類が Service Bus キューに設定された Event Grid カスタム トピックのイベント サブスクリプションを 作成します。 また、システム マネージド ID を配信不能処理に使用することも指定します。

storageid=$(az storage account show --name demoStorage --resource-group gridResourceGroup --query id --output tsv)
deadletterendpoint="$storageid/blobServices/default/containers/<BLOB CONTAINER NAME>"

az eventgrid event-subscription create  
    --source-resource-id /subscriptions/$subid/resourceGroups/$rg/providers/Microsoft.EventGrid/topics/$topicname 
    --delivery-identity-endpoint-type servicebusqueue
    --delivery-identity systemassigned 
    --delivery-identity-endpoint $queueid
    --deadletter-identity-endpoint $deadletterendpoint 
    --deadletter-identity systemassigned 
    -n $sb_esnameq 

Azure CLI の使用 - Event Hubs

このセクションでは、Azure CLI を使用し、システム割り当て ID の使用を有効にして、イベントをイベント ハブに配信する方法を学びます。 ID は、Azure Event Hubs データ送信者ロールのメンバーである必要があります。 また、配信不能処理に使用されるストレージ アカウントのストレージ BLOB データ共同作成者ロールのメンバーである必要もあります。

変数の定義

subid="<AZURE SUBSCRIPTION ID>"
rg = "<RESOURCE GROUP of EVENT GRID CUSTOM TOPIC>"
topicname = "<EVENT GRID CUSTOM TOPIC NAME>"

hubid=$(az eventhubs eventhub show --name <EVENT HUB NAME> --namespace-name <NAMESPACE NAME> --resource-group <RESOURCE GROUP NAME> --query id --output tsv)
eh_esname = "<SPECIFY EVENT SUBSCRIPTION NAME>" 

配信用に、マネージド ID を使用してイベント サブスクリプションを作成する

このサンプル コマンドでは、エンドポイントの種類が Event Hubs に設定された Event Grid カスタム トピックのイベント サブスクリプションを 作成します

az eventgrid event-subscription create  
    --source-resource-id /subscriptions/$subid/resourceGroups/$rg/providers/Microsoft.EventGrid/topics/$topicname 
    --delivery-identity-endpoint-type eventhub 
    --delivery-identity systemassigned 
    --delivery-identity-endpoint $hubid
    -n $sbq_esname 

配信用および配信不能にするために、マネージド ID を使用してイベント サブスクリプションを作成する

このサンプル コマンドでは、エンドポイントの種類が Event Hubs に設定された Event Grid カスタム トピックのイベント サブスクリプションを 作成します。 また、システム マネージド ID を配信不能処理に使用することも指定します。

storageid=$(az storage account show --name demoStorage --resource-group gridResourceGroup --query id --output tsv)
deadletterendpoint="$storageid/blobServices/default/containers/<BLOB CONTAINER NAME>"

az eventgrid event-subscription create
    --source-resource-id /subscriptions/$subid/resourceGroups/$rg/providers/Microsoft.EventGrid/topics/$topicname 
    --delivery-identity-endpoint-type servicebusqueue  
    --delivery-identity systemassigned 
    --delivery-identity-endpoint $hubid
    --deadletter-identity-endpoint $eh_deadletterendpoint
    --deadletter-identity systemassigned 
    -n $eh_esname 

Azure CLI の使用 - Azure Storage キュー

このセクションでは、Azure CLI を使用し、システム割り当て ID の使用を有効にして、イベントを Azure Storage キューに配信する方法を学びます。 ID は、ストレージ アカウントのストレージ キュー データ メッセージ送信者ロールのメンバーである必要があります。 また、配信不能処理に使用されるストレージ アカウントのストレージ BLOB データ共同作成者ロールのメンバーである必要もあります。

変数の定義

subid="<AZURE SUBSCRIPTION ID>"
rg = "<RESOURCE GROUP of EVENT GRID CUSTOM TOPIC>"
topicname = "<EVENT GRID CUSTOM TOPIC NAME>"

# get the storage account resource id
storageid=$(az storage account show --name <STORAGE ACCOUNT NAME> --resource-group <RESOURCE GROUP NAME> --query id --output tsv)

# build the resource id for the queue
queueid="$storageid/queueservices/default/queues/<QUEUE NAME>" 

sa_esname = "<SPECIFY EVENT SUBSCRIPTION NAME>" 

配信用に、マネージド ID を使用してイベント サブスクリプションを作成する

az eventgrid event-subscription create 
    --source-resource-id /subscriptions/$subid/resourceGroups/$rg/providers/Microsoft.EventGrid/topics/$topicname 
    --delivery-identity-endpoint-type storagequeue  
    --delivery-identity systemassigned 
    --delivery-identity-endpoint $queueid
    -n $sa_esname 

配信用および配信不能にするために、マネージド ID を使用してイベント サブスクリプションを作成する

storageid=$(az storage account show --name demoStorage --resource-group gridResourceGroup --query id --output tsv)
deadletterendpoint="$storageid/blobServices/default/containers/<BLOB CONTAINER NAME>"

az eventgrid event-subscription create  
    --source-resource-id /subscriptions/$subid/resourceGroups/$rg/providers/Microsoft.EventGrid/topics/$topicname 
    --delivery-identity-endpoint-type storagequeue  
    --delivery-identity systemassigned 
    --delivery-identity-endpoint $queueid
    --deadletter-identity-endpoint $deadletterendpoint 
    --deadletter-identity systemassigned 
    -n $sa_esname 

プライベート エンドポイント

現時点では、プライベート エンドポイントを使用してイベントを配信することはできません。 つまり、配信されたイベント トラフィックがプライベート IP 空間から外に出てはならないという、ネットワークの分離の厳格な要件がある場合はサポートされません。

ただし、要件で、暗号化されたチャネルを使用してイベントを送信する方法と、パブリック IP 空間を使用する送信者の既知の ID (この場合は Event Grid) が必要な場合は、この記事に示すように、Azure Event Grid カスタム トピックまたは doメイン を使用して Event Hubs、Service Bus、または Azure Storage サービスにイベントを配信できます。 その後、Azure Functions で構成されたプライベート リンクまたは仮想ネットワークにデプロイされた Webhook を使用して、イベントをプルできます。 「Azure Functions を使用してプライベート エンドポイントに接続する」のチュートリアルを参照してください。

この構成では、トラフィックはパブリック IP/インターネット経由で Event Grid から Event Hubs、Service Bus、または Azure Storage に送られますが、チャネルを暗号化でき、Event Grid のマネージド ID が使用されます。 Azure Functions、または仮想ネットワークにデプロイされた Webhook を、プライベート リンク経由で Event Hubs、Service Bus、または Azure Storage を使用するように構成すると、トラフィックのそのセクションは確実に Azure 内に留まります。

次のステップ

マネージド ID については、Azure リソースのマネージド ID とはに関する記事を参照してください。