|
| 1 | +--- |
| 2 | +title: Configure IP firewall for Azure Event Grid topics or domains (Preview) |
| 3 | +description: This article describes how to configure firewall settings for Event Grid topics or domains. |
| 4 | +services: event-grid |
| 5 | +author: spelluru |
| 6 | + |
| 7 | +ms.service: event-grid |
| 8 | +ms.topic: conceptual |
| 9 | +ms.date: 03/11/2020 |
| 10 | +ms.author: spelluru |
| 11 | +--- |
| 12 | + |
| 13 | +# Configure IP firewall for Azure Event Grid topics or domains (Preview) |
| 14 | +By default, topic and domain are accessible from internet as long as the request comes with valid authentication and authorization. With IP firewall, you can restrict it further to only a set of IPv4 addresses or IPv4 address ranges in [CIDR (Classless Inter-Domain Routing)](https://en.wikipedia.org/wiki/Classless_Inter-Domain_Routing) notation. Publishers originating from any other IP address will be rejected and will receive a 403 (Forbidden) response. For more information about network security features supported by Event Grid, see [Network security for Event Grid](network-security.md). |
| 15 | + |
| 16 | +This article describes how to configure IP firewall settings for Azure Event Grid topics or domains. |
| 17 | + |
| 18 | +## Use Azure portal |
| 19 | +This section shows you how to use the Azure portal to create inbound IP firewall rules. The steps shown in this section are for topics. You can use similar steps to create inbound IP rules for **domains**. |
| 20 | + |
| 21 | +1. In the [Azure portal](https://portal.azure.com), Navigate to your event grid topic or domain, and switch to the **Networking** tab. |
| 22 | +2. Select **Public networks** to allow all network, including the internet, to access the resource. |
| 23 | + |
| 24 | + You can restrict the traffic using IP-based firewall rules. Specify a single IPv4 address or a range of IP addresses in Classless inter-domain routing (CIDR) notation. |
| 25 | + |
| 26 | +  |
| 27 | +3. Select **Private endpoints only** to allow only private endpoint connections to access this resource. Use the **Private endpoint connections** tab on this page to manage connections. |
| 28 | + |
| 29 | +  |
| 30 | +4. Select **Save** on the toolbar. |
| 31 | + |
| 32 | + |
| 33 | + |
| 34 | +## Use Azure CLI |
| 35 | +This section shows you how to use Azure CLI commands to create topics with inbound IP rules. The steps shown in this section are for topics. You can use similar steps to create inbound IP rules for **domains**. |
| 36 | + |
| 37 | + |
| 38 | +### Enable public network access for an existing topic |
| 39 | +By default, the public network access is enabled for topics and domains. You can restrict traffic by configuring inbound IP firewall rules. |
| 40 | + |
| 41 | +```azurecli-interactive |
| 42 | +az rest --method patch --uri "/subscriptions/<AZURE SUBSCRIPTION ID>/resourceGroups/<RESOURCE GROUP NAME>/providers/Microsoft.EventGrid/topics/<EVENT GRID TOPIC NAME>?api-version=2020-04-01-preview" --body "{\""properties\"": {\""publicNetworkAccess\"": \""Enabled\""}}" |
| 43 | +``` |
| 44 | + |
| 45 | +### Disable public network access for an existing topic |
| 46 | +When public network access is disabled for a topic or domain, traffic over public internet isn't allowed. Only private endpoint connections will be allowed to access these resources. |
| 47 | + |
| 48 | +```azurecli-interactive |
| 49 | +az rest --method patch --uri "/subscriptions/<AZURE SUBSCRIPTION ID>/resourceGroups/<RESOURCE GROUP NAME>/providers/Microsoft.EventGrid/topics/<EVENT GRID TOPIC NAME>?api-version=2020-04-01-preview" --body "{\""properties\"": {\""publicNetworkAccess\"": \""Disabled\""}}" |
| 50 | +``` |
| 51 | + |
| 52 | +### Create topic with inbound ip rules |
| 53 | +The following sample CLI command creates an event grid topic with inbound IP rules in one step. |
| 54 | + |
| 55 | +```azurecli-interactive |
| 56 | +az rest --method put \ |
| 57 | + --uri "/subscriptions/<AZURE SUBSCRIPTION ID>/resourceGroups/<RESOURCE GROUP NAME>/providers/Microsoft.EventGrid/topics/<EVENT GRID TOPIC NAME>?api-version=2020-04-01-preview" \ |
| 58 | + --body {\""location\"":\""<LOCATION>\", \""properties\"" :{\""publicNetworkAccess\"":\""enabled\"",\""InboundIpRules\"": [ {\""ipMask\"": \""<IP ADDRESS or IP ADDRESS RANGE in CIDR notation>\"", \""action\"": \""allow\""} ]}} |
| 59 | +``` |
| 60 | + |
| 61 | +### Create topic first and then add inbound ip rules |
| 62 | +This example creates an event grid topic first and then adds inbound IP rules for the topic in a separate command. It also updates the inbound IP rules that were set in the second command. |
| 63 | + |
| 64 | +```azurecli-interactive |
| 65 | +
|
| 66 | +# create the event grid topic first |
| 67 | +az rest --method put \ |
| 68 | + --uri "/subscriptions/<AZURE SUBSCRIPTION ID>/resourceGroups/<RESOURCE GROUP NAME>/providers/Microsoft.EventGrid/topics/<EVENT GRID TOPIC NAME>?api-version=2020-04-01-preview" \ |
| 69 | + --body {\""location\"":\""<LOCATION>\""} |
| 70 | +
|
| 71 | +# add inbound IP rules |
| 72 | +az rest --method put \ |
| 73 | + --uri "/subscriptions/<AZURE SUBSCRIPTION ID>/resourceGroups/<RESOURCE GROUP NAME>/providers/Microsoft.EventGrid/topics/<EVENT GRID TOPIC NAME>?api-version=2020-04-01-preview" |
| 74 | + --body {\""location\"":\""<LOCATION>\", \""properties\"" :{\""publicNetworkAccess\"":\""enabled\"", \""InboundIpRules\"": [ {\""ipMask\"": \""<IP ADDRESS or IP ADDRESS RANGE in CIDR notation>\"", \""action\"": \""allow\""} ]}} |
| 75 | +
|
| 76 | +# later, update topic with additional ip rules or remove them. |
| 77 | +az rest --method put \ |
| 78 | + --uri "/subscriptions/<AZURE SUBSCRIPTION ID>/resourceGroups/<RESOURCE GROUP NAME>/providers/Microsoft.EventGrid/topics/<EVENT GRID TOPIC NAME>?api-version=2020-04-01-preview" |
| 79 | + --body {\""location\"":\""<LOCATION>\", \""properties\"" :{\""publicNetworkAccess\"":\""enabled\"", \""InboundIpRules\"": [ {\""ipMask\"": \""<IP ADDRESS or IP ADDRESS RANGE in CIDR notation>\"", \""action\"": \""allow\""}, {\""ipMask\"": \""<IP ADDRESS or IP ADDRESS RANGE in CIDR notation>\"", \""action\"": \""allow\""} ]}} |
| 80 | +``` |
| 81 | + |
| 82 | + |
| 83 | +## Use PowerShell |
| 84 | +This section shows you how to use Azure PowerShell commands to create Azure Event Grid topics with inbound IP firewall rules. The steps shown in this section are for topics. You can use similar steps to create inbound IP rules for **domains**. |
| 85 | + |
| 86 | +### Prerequisite |
| 87 | +Follow instructions from [How to: Use the portal to create an Azure AD application and service principal that can access resources](../active-directory/develop/howto-create-service-principal-portal.md) to create an Azure Active Directory application and note down the following values: |
| 88 | + |
| 89 | +- Directory (tenant) ID |
| 90 | +- Application (Client) ID |
| 91 | +- Application (client) secret |
| 92 | + |
| 93 | +### Prepare token and headers for REST API calls |
| 94 | +Run the following prerequisite commands to get an authentication token to use with REST API calls, and authorization and other header information. |
| 95 | + |
| 96 | +```azurepowershell-interactive |
| 97 | +# replace <CLIENT ID> and <CLIENT SECRET> |
| 98 | +$body = "grant_type=client_credentials&client_id=<CLIENT ID>&client_secret=<CLIENT SECRET>&resource=https://management.core.windows.net" |
| 99 | +
|
| 100 | +# get the authentication token. Replace <TENANT ID> |
| 101 | +$Token = Invoke-RestMethod -Method Post ` |
| 102 | + -Uri https://login.microsoftonline.com/<TENANT ID>/oauth2/token ` |
| 103 | + -Body $body ` |
| 104 | + -ContentType 'application/x-www-form-urlencoded' |
| 105 | +
|
| 106 | +# set authorization and content-type headers |
| 107 | +$Headers = @{} |
| 108 | +$Headers.Add("Authorization","$($Token.token_type) "+ " " + "$($Token.access_token)") |
| 109 | +$Headers.Add("Content-Type","application/json") |
| 110 | +``` |
| 111 | + |
| 112 | +### Enable public network access for an existing topic |
| 113 | +By default, the public network access is enabled for topics and domains. You can restrict traffic by configuring inbound IP firewall rules. |
| 114 | + |
| 115 | +```azurepowershell-interactive |
| 116 | +$body = @{"properties"=@{"publicNetworkAccess"="enabled"}} | ConvertTo-Json -Depth 5 |
| 117 | +
|
| 118 | +Invoke-RestMethod -Method 'Patch' ` |
| 119 | + -Uri "https://management.azure.com/subscriptions/<AZURE SUBSCRIPTION ID>/resourceGroups/<RESOURCE GROUP NAME>/providers/Microsoft.EventGrid/topics/<EVENT GRID TOPIC NAME>?api-version=2020-04-01-preview" ` |
| 120 | + -Headers $Headers ` |
| 121 | + -Body $body ` |
| 122 | + | ConvertTo-Json -Depth 5 |
| 123 | +``` |
| 124 | + |
| 125 | +### Disable public network access for an existing topic |
| 126 | +When public network access is disabled for a topic or domain, traffic over public internet isn't allowed. Only private endpoint connections will be allowed to access these resources. |
| 127 | + |
| 128 | +```azurepowershell-interactive |
| 129 | +$body = @{"properties"=@{"publicNetworkAccess"="disabled"}} | ConvertTo-Json -Depth 5 |
| 130 | +
|
| 131 | +Invoke-RestMethod -Method 'Patch' ` |
| 132 | + -Uri "https://management.azure.com/subscriptions/<AZURE SUBSCRIPTION ID>/resourceGroups/<RESOURCE GROUP NAME>/providers/Microsoft.EventGrid/topics/<EVENT GRID TOPIC NAME>?api-version=2020-04-01-preview" ` |
| 133 | + -Headers $Headers ` |
| 134 | + -Body $body ` |
| 135 | + | ConvertTo-Json -Depth 5 |
| 136 | +``` |
| 137 | + |
| 138 | +### Create an event grid topic with inbound rules in one step |
| 139 | + |
| 140 | +```azurepowershell-interactive |
| 141 | +
|
| 142 | +# prepare the body for the REST PUT method. Notice that inbound IP rules are included. |
| 143 | +$body = @{"location"="<LOCATION>"; "sku"= @{"name"="basic"}; "properties"=@{"publicNetworkAccess"="enabled"; "inboundIpRules"=@(@{"ipmask"="<IP ADDRESS or IP ADDRESS RANGE in CIDR notation>";"action"="allow"})}} | ConvertTo-Json -Depth 5 |
| 144 | +
|
| 145 | +# create the event grid topic with inbound IP rules |
| 146 | +Invoke-RestMethod -Method 'Put' ` |
| 147 | + -Uri "https://management.azure.com/subscriptions/<AZURE SUBSCRIPTION ID>/resourceGroups/<RESOURCE GROUP NAME>/providers/Microsoft.EventGrid/topics/<EVENT GRID TOPIC NAME>?api-version=2020-04-01-preview" ` |
| 148 | + -Headers $Headers ` |
| 149 | + -Body $body |
| 150 | +
|
| 151 | +# verify that the topic was created |
| 152 | +Invoke-RestMethod -Method 'Get' ` |
| 153 | + -Uri "https://management.azure.com/subscriptions/<AZURE SUBSCRIPTION ID>/resourceGroups/<RESOURCE GROUP NAME>/providers/Microsoft.EventGrid/topics/<EVENT GRID TOPIC NAME>?api-version=2020-04-01-preview" ` |
| 154 | + -Headers $Headers ` |
| 155 | + | ConvertTo-Json -Depth 5 |
| 156 | +``` |
| 157 | + |
| 158 | + |
| 159 | +### Create event grid topic first and then add inbound ip rules |
| 160 | + |
| 161 | +```azurepowershell-interactive |
| 162 | +
|
| 163 | +# prepare the body for the REST PUT method. Notice that no inbound IP rules are specified. |
| 164 | +$body = @{"location"="<LOCATION>"; "sku"= @{"name"="basic"}; "properties"=@{"publicNetworkAccess"="enabled";}} | ConvertTo-Json -Depth 5 |
| 165 | +
|
| 166 | +# create the Event Grid topic |
| 167 | +Invoke-RestMethod -Method 'Put' ` |
| 168 | + -Uri "https://management.azure.com/subscriptions/<AZURE SUBSCRIPTION ID>/resourceGroups/<RESOURCE GROUP NAME>/providers/Microsoft.EventGrid/topics/<EVENT GRID TOPIC NAME>?api-version=2020-04-01-preview" ` |
| 169 | + -Headers $Headers ` |
| 170 | + -Body $body` |
| 171 | +
|
| 172 | +# verify that the topic was created |
| 173 | +Invoke-RestMethod -Method 'Get' ` |
| 174 | + -Uri "https://management.azure.com/subscriptions/<AZURE SUBSCRIPTION ID>/resourceGroups/<RESOURCE GROUP NAME>/providers/Microsoft.EventGrid/topics/<EVENT GRID TOPIC NAME>?api-version=2020-04-01-preview" ` |
| 175 | + -Headers $Headers ` |
| 176 | + | ConvertTo-Json -Depth 5 |
| 177 | +
|
| 178 | +# prepare the body for REST PUT method. Notice that it includes inbound IP rules now. This feature available in both basic and premium tiers. |
| 179 | +$body = @{"location"="<LOCATION>"; "sku"= @{"name"="basic"}; "properties"=@{"publicNetworkAccess"="enabled"; "inboundIpRules"=@(@{"ipmask"="<IP ADDRESS or IP ADDRESS RANGE in CIDR notation>";"action"="allow"}, @{"ipmask"="<IP ADDRESS or IP ADDRESS RANGE in CIDR notation>";"action"="allow"})}} | ConvertTo-Json -Depth 5 |
| 180 | +
|
| 181 | +# update the topic with inbound IP rules |
| 182 | +Invoke-RestMethod -Method 'Put' ` |
| 183 | + -Uri "https://management.azure.com/subscriptions/<AZURE SUBSCRIPTION ID>/resourceGroups/<RESOURCE GROUP NAME>/providers/Microsoft.EventGrid/topics/<EVENT GRID TOPIC NAME>?api-version=2020-04-01-preview" ` |
| 184 | + -Headers $Headers ` |
| 185 | + -Body $body |
| 186 | +
|
| 187 | +# verify that the topic was updated |
| 188 | +Invoke-RestMethod -Method 'Get' |
| 189 | + -Uri "https://management.azure.com/subscriptions/<AzURE SUBSCRIPTION ID>/resourceGroups/<RESOURCE GROUP NAME>/providers/Microsoft.EventGrid/topics/<EVENT GRID TOPIC NAME>?api-version=2020-04-01-preview" ` |
| 190 | + -Headers $Headers ` |
| 191 | + | ConvertTo-Json -Depth 5 |
| 192 | +
|
| 193 | +``` |
| 194 | + |
| 195 | +## Next steps |
| 196 | + |
| 197 | +* For information about monitoring event deliveries, see [Monitor Event Grid message delivery](monitor-event-delivery.md). |
| 198 | +* For more information about the authentication key, see [Event Grid security and authentication](security-authentication.md). |
| 199 | +* For more information about creating an Azure Event Grid subscription, see [Event Grid subscription schema](subscription-creation-schema.md). |
0 commit comments