設定 Azure 事件方格自訂主題或網域的私人端點

您可以使用私人端點,不經過公用網際網路,安全地透過私人連結,允許從虛擬網路直接至自訂主題和網域的事件輸入。 私人端點會針對您的自訂主題或網域使用 VNet 位址空間中的 IP 位址。 如需更多概念性資訊,請參閱網路安全性

本文描述如何設定自訂主題或網域的私人端點。

注意

目前系統主題不支援私人端點。

使用 Azure 入口網站

本節說明如何使用 Azure 入口網站來建立主題或網域的私人端點。

注意

本節所示的步驟多數適用於自訂主題。 您可以使用類似步驟來建立網域的私人端點。

建立新主題時

本節說明如何啟用事件方格主題或網域的私人網路存取。 如需建立新主題的逐步指示,請參閱建立自訂主題

  1. 在 [建立主題] 精靈的 [基本] 頁面上,填入必要欄位之後,選取頁面底部的 [下一步:網路功能]

    Image showing the selection of Networking link at the bottom of the page.

  2. 若要允許透過私人端點存取事件方格主題,請選取 [私人存取] 選項。

    Image showing the selection of Private access option on the Networking page of the Create topic wizard.

  3. 如需新增私人端點的步驟,請參閱下一節。

對於現有主題

  1. 登入 Azure 入口網站,然後瀏覽至您的主題或網域。

  2. 切換至主題頁面的 [網路] 索引標籤。 在 [公用存取] 索引標籤中,選取 [僅限私人端點]

    Screenshot that shows the Public network access page with Private endpoints only option selected.

  3. 切換至 [私人端點連線] 索引標籤,然後選取工具列上的 [+ 私人端點]

    Screenshot showing the selection of + Private endpoint link on the Private endpoint connection tab.

  4. 在 [基本] 頁面上,遵循下列步驟:

    1. 選取您要在其中建立私人端點的 Azure 訂閱

    2. 選取私人端點資源的 Azure 資源群組

    3. 輸入端點名稱

    4. 視需要更新網路介面名稱

    5. 選取端點的區域。 私人端點必須與虛擬網路位於相同區域,但可與目的地私人連結資源位於不同區域 (在此範例中為事件方格主題)。

    6. 完成時,選取頁面底部的 [下一步: 資源 >] 按鈕。

      Screenshot showing the Basics page of the Create a private endpoint wizard.

  5. 在 [資源] 頁面上,遵循下列步驟,確認已針對 [目標子資源] 選取主題,然後 選取頁面底部的 [下一步: 虛擬網络 >] 按鈕。

    Screenshot showing the Resource page of the Create a private endpoint wizard.

  6. 在 [虛擬網路] 頁面上,您會選取虛擬網路中要部署私人端點的子網路。

    1. 選取虛擬網路。 下拉式清單只會列出目前所選訂閱與位置中的虛擬網路。

    2. 選取您所選虛擬網路中的子網路

    3. 指定您要以靜態或動態方式配置 IP 位址

    4. 選取現有的 [應用程式安全性群組],或建立新的群組然後與私人端點產生關聯。

    5. 選取頁面底部的 [下一步: DNS >] 按鈕。

      Screenshot showing the Networking page of the Creating a private endpoint wizard.

  7. 在 [DNS] 頁面上,選取是否要整合私人端點與私人 DNS 區域,然後選取頁面底部的 [下一步: 標記]

    Screenshot showing the DNS page of the Creating a private endpoint wizard.

  8. 在 [標記] 頁面上,建立想要與私人端點資源建立關聯的任何標記 (名稱和值)。 然後選取頁面底部的 [檢閱 + 建立] 按鈕。

  9. 在 [檢閱 + 建立] 上,檢閱所有設定,然後選取 [建立] 來建立私人端點。

當您建立私人端點時,必須核准連線。 如果正要建立私人端點的資源位於目錄中,則在具有足夠權限的情況下,即可核准連線要求。 如果正要連線到位於另一個目錄中的 Azure 資源,則必須等候該資源的擁有者核准連線要求。

佈建狀態有四種:

服務動作 服務取用者私人端點狀態 描述
None 待定 連線會手動建立並等待私人連結資源擁有者進行核准。
核准 核准 已自動或手動核准連線並可供使用。
拒絕​​ 已拒絕 私人連結資源擁有者已拒絕連線。
移除 已中斷連接 私人連結資源擁有者已移除連線,而私人端點變成參考性,且應該刪除以進行清除。

如何管理私人端點連線

下列各節說明如何核准或拒絕私人端點連線。

  1. 登入 Azure 入口網站
  2. 在搜尋列中,輸入事件方格主題事件方格網域
  3. 選取您想要管理的主題網域
  4. 選取 [網路] 索引標籤。
  5. 如果有任何暫止的連線,您會在佈建狀態中看到以 [擱置] 列出的連線。

核准私人端點

您可以核准處於擱置中狀態的私人端點。 若要核准,請遵循下列步驟:

注意

本節所示的步驟多數適用於主題。 您可以使用類似步驟來核准網域的私人端點。

  1. 選取您想要核准的私人端點,然後選取工具列上的 [核准]

    Private endpoint - pending state

  2. 在 [核准連線] 對話方塊上,輸入註解 (選用),然後選取 [是]

    Private endpoint - approve

  3. 確認您看到端點的狀態為 [已核准]

    Private endpoint - approved state

拒絕私人端點

您可以拒絕處於擱置中狀態或已核准狀態的私人端點。 若要拒絕,請遵循下列步驟:

注意

本節所示的步驟適用於主題。 您可以使用類似步驟來拒絕網域的私人端點。

  1. 選取您想要拒絕的私人端點,然後選取工具列上的 [拒絕]

    Screenshot that shows the

  2. 在 [拒絕連線] 對話方塊上,輸入註解 (選用),然後選取 [是]

    Private endpoint - reject

  3. 確認您看到端點的狀態為 [已拒絕]

    Private endpoint - rejected state

    注意

    一旦遭到拒絕,就無法在 Azure 入口網站核准私人端點。

使用 Azure CLI

若要建立私人端點,請使用 az network private-endpoint create 方法,如下列範例所示:

az network private-endpoint create \
    --resource-group <RESOURECE GROUP NAME> \
    --name <PRIVATE ENDPOINT NAME> \
    --vnet-name <VIRTUAL NETWORK NAME> \
    --subnet <SUBNET NAME> \
    --private-connection-resource-id "/subscriptions/<SUBSCRIPTION ID>/resourceGroups/<RESOURCE GROUP NAME>/providers/Microsoft.EventGrid/topics/<TOPIC NAME>" \
    --connection-name <PRIVATE LINK SERVICE CONNECTION NAME> \
    --location <LOCATION> \
    --group-ids topic

如需範例中使用的參數描述,請參閱 az network private-endpoint create 的文件。 要在此範例中要注意的幾個重點如下:

  • 針對 private-connection-resource-id,指定主題網域的資源識別碼。 前述範例會使用類型:主題。
  • 針對 group-ids,指定 topicdomain。 在上述範例中,使用了 topic

若要刪除私人端點,請使用 az network private-endpoint delete 方法,如下列範例所示:

az network private-endpoint delete --resource-group <RESOURECE GROUP NAME> --name <PRIVATE ENDPOINT NAME>

注意

本節所示的步驟適用於主題。 您可以使用類似步驟來建立網域的私人端點。

必要條件

執行下列命令來更新 CLI 的 Azure 事件方格延伸模組:

az extension update -n eventgrid

如果未安裝延伸模組,請執行下列命令來安裝:

az extension add -n eventgrid

建立私人端點

若要建立私人端點,請使用 az network private-endpoint create 方法,如下列範例所示:

az network private-endpoint create \
    --resource-group <RESOURECE GROUP NAME> \
    --name <PRIVATE ENDPOINT NAME> \
    --vnet-name <VIRTUAL NETWORK NAME> \
    --subnet <SUBNET NAME> \
    --private-connection-resource-id "/subscriptions/<SUBSCRIPTION ID>/resourceGroups/<RESOURCE GROUP NAME>/providers/Microsoft.EventGrid/topics/<TOPIC NAME>" \
    --connection-name <PRIVATE LINK SERVICE CONNECTION NAME> \
    --location <LOCATION> \
    --group-ids topic

如需範例中使用的參數描述,請參閱 az network private-endpoint create 的文件。 要在此範例中要注意的幾個重點如下:

  • 針對 private-connection-resource-id,指定主題網域的資源識別碼。 前述範例會使用類型:主題。
  • 針對 group-ids,指定 topicdomain。 在上述範例中,使用了 topic

若要刪除私人端點,請使用 az network private-endpoint delete 方法,如下列範例所示:

az network private-endpoint delete --resource-group <RESOURECE GROUP NAME> --name <PRIVATE ENDPOINT NAME>

注意

本節所示的步驟適用於主題。 您可以使用類似步驟來建立網域的私人端點。

範例指令碼

以下範例指令碼會建立下列 Azure 資源:

  • 資源群組
  • 虛擬網路
  • 虛擬網路中的子網路
  • Azure 事件方格主題
  • 主題的私人端點

注意

本節所示的步驟適用於主題。 您可以使用類似步驟來建立網域的私人端點。

subscriptionID="<AZURE SUBSCRIPTION ID>"
resourceGroupName="<RESOURCE GROUP NAME>"
location="<LOCATION>"
vNetName="<VIRTUAL NETWORK NAME>"
subNetName="<SUBNET NAME>"
topicName = "<TOPIC NAME>"
connectionName="<ENDPOINT CONNECTION NAME>"
endpointName=<ENDPOINT NAME>

# resource ID of the topic. replace <SUBSCRIPTION ID>, <RESOURCE GROUP NAME>, and <TOPIC NAME> 
# topicResourceID="/subscriptions/<SUBSCRIPTION ID>/resourceGroups/<RESOURCE GROUP NAME>/providers/Microsoft.EventGrid/topics/<TOPIC NAME>"

# select subscription
az account set --subscription $subscriptionID

# create resource group
az group create --name $resourceGroupName --location $location

# create vnet 
az network vnet create \
    --resource-group $resourceGroupName \
    --name $vNetName \
    --address-prefix 10.0.0.0/16

# create subnet
az network vnet subnet create \
    --resource-group $resourceGroupName \
    --vnet-name $vNetName \
    --name $subNetName \
    --address-prefixes 10.0.0.0/24

# disable private endpoint network policies for the subnet
az network vnet subnet update \
    --resource-group $resourceGroupName \
    --vnet-name $vNetName \
    --name $subNetName \
    --disable-private-endpoint-network-policies true

# create event grid topic. update <LOCATION>
az eventgrid topic create \
    --resource-group $resourceGroupName \
    --name $topicName \
    --location $location

# verify that the topic was created.
az eventgrid topic show \
    --resource-group $resourceGroupName \
    --name $topicName

# create private endpoint for the topic you created
az network private-endpoint create \
    --resource-group $resourceGroupName \
    --name $endpointName \
    --vnet-name $vNetName \
    --subnet $subNetName \
    --private-connection-resource-id $topicResourceID \
    --connection-name $connectionName \
    --location $location \
    --group-ids topic

# get topic 
az eventgrid topic show \
    --resource-group $resourceGroupName \
    --name $topicName

核准私人端點

下列範例 CLI 程式碼片段示範如何核准私人端點連線。

az eventgrid topic private-endpoint-connection approve \
    --resource-group $resourceGroupName \
    --topic-name $topicName \
    --name  $endpointName \
    --description "connection approved"

拒絕私人端點

下列範例 CLI 程式碼片段示範如何拒絕私人端點連線。

az eventgrid topic private-endpoint-connection reject \
    --resource-group $resourceGroupName \
    --topic-name $topicName \
    --name $endpointName \
    --description "Connection rejected"

停用公用網路存取

預設會為事件方格主題或網域啟用公用網路存取。 若要僅允許透過私人端點存取,請執行下列命令來停用公用網路存取:

az eventgrid topic update \
    --resource-group $resourceGroupName \
    --name $topicName \
    --public-network-access disabled

使用 PowerShell

本節說明如何使用 PowerShell 為主題或網域建立私人端點。 以下是具有註解的範例指令碼。


# name of an Azure resource group to be created
$resourceGroupName = "contosorg"

# location where you want the resources to be created
$location ="eastus"

# name of the VNet to be created
$vnetName = "contosovnet"

# name of the subnet to be created in the VNet
$subnetName = "example-privatelinksubnet"

# name of the Event Grid topic to be created
$egridTopicName = "contosotopic"

# name of the private link service connection to be created
$privateLinkServiceConnectionName = "spegridplsconn"

# name of the private endpoint connection to be created
$privateEndpointConnectionName = "spegridpe11"

#

# create resource group
New-AzResourceGroup -Name $resourceGroupName -Location $location

# create virtual network
$virtualNetwork = New-AzVirtualNetwork `
                    -ResourceGroupName $resourceGroupName `
                    -Location $location `
                    -Name $vnetName  `
                    -AddressPrefix 10.0.0.0/16

# create subnet with endpoint network policy disabled
$subnetConfig = Add-AzVirtualNetworkSubnetConfig `
                    -Name $subnetName `
                    -AddressPrefix 10.0.0.0/24 `
                    -PrivateEndpointNetworkPoliciesFlag "Disabled" `
                    -VirtualNetwork $virtualNetwork

# update virtual network
$virtualNetwork | Set-AzVirtualNetwork

# get virtual network (optional)
$virtualNetwork = Get-AzVirtualNetwork `
                    -ResourceGroupName $resourceGroupName `
                    -Name $vnetName 

# create an Event Grid topic with public network access disabled. 
$topic = New-AzEventGridTopic -ResourceGroupName $resourceGroupName -Name $egridTopicName -Location $location -PublicNetworkAccess disabled

# create a private link service connection to the Event Grid topic. 
# For topics, set GroupId to 'topic'. For domains, it's 'domain'
$privateEndpointConnection = New-AzPrivateLinkServiceConnection `
                                -Name "privateLinkServiceConnectionName" `
                                -PrivateLinkServiceId $topic.id `
                                -GroupId "topic"

# get subnet info
$subnet = $virtualNetwork | Select -ExpandProperty subnets `
                             | Where-Object  {$_.Name -eq $subnetName }  

# now, you are ready to create a private endpoint 
$privateEndpoint = New-AzPrivateEndpoint -ResourceGroupName $resourceGroupName  `
                                        -Name privateEndpointConnectionName   `
                                        -Location $location `
                                        -Subnet  $subnet   `
                                        -PrivateLinkServiceConnection $privateEndpointConnection

# verify that the endpoint is created
Get-AzPrivateEndpoint -ResourceGroupName $resourceGroupName  -Name privateEndpointConnectionName  

核准私人端點連線

下列範例 PowerShell 程式碼片段示範如何核准私人端點。

注意

本節所示的步驟適用於主題。 您可以使用類似步驟來核准網域的私人端點。


# list all private endpoints for the topic
$topic = Get-AzEventGridTopic -ResourceGroup <RESOURCE GROUP NAME> - Name <TOPIC NAME>
$endpointList = Get-AzPrivateEndpointConnection -PrivateLinkResourceId $topic.Id

# filter the private endpoints using a name
 $pseEndpoint = $endpointList | Where-Object {     $_.Name.StartsWith('<MYENDPOINTNAME>') }

# approve the endpoint connection
Approve-AzPrivateEndpointConnection -ResourceId $pseEndpoint.Id

# get the endpoint connection to verify that it's approved
Get-AzPrivateEndpointConnection -ResourceId $pseEndpoint.Id

拒絕私人端點連線

下列範例示範如何使用 PowerShell 拒絕私人端點。 您可以從上一個 GET 命令的結果取得私人端點的 GUID。

注意

本節所示的步驟適用於主題。 您可以使用類似步驟來拒絕網域的私人端點。

# list all private endpoints for the topic
$topic = Get-AzEventGridTopic -ResourceGroup <RESOURCE GROUP NAME> - Name <TOPIC NAME>
$endpointList = Get-AzPrivateEndpointConnection -PrivateLinkResourceId $topic.Id


# filter the private endpoints using a name
 $pseEndpoint = $endpointList | Where-Object {     $_.Name.StartsWith('<MYENDPOINT>') }

# deny or reject the private endpoint connection
Deny-AzPrivateEndpointConnection -ResourceId $pseEndpoint.Id

# get the endpoint connection to verify that it's rejected
Get-AzPrivateEndpointConnection -ResourceId $pseEndpoint.Id

您可以核准連線,甚至在 API 拒絕連線之後。 如果您使用 Azure 入口網站,則無法核准已遭拒絕的端點。

下一步