Skip to content

Commit e621281

Browse files
Update api-management-howto-integrate-internal-vnet-appgateway.md
This PR includes several necessary updates as well as some cosmetic ones: - [Functional] Add API Management NSG rules and API Management public IP to create an `stv2` instead of an `stv1` API Management instance. - [Functional] Add `Priority` to `New-AzApplicationGatewayRequestRoutingRule` as the newer API version requires this parameter. - [Cosmetic] Extract the desired domain name to a `$domain` variable for ease-of-use. - [Cosmetic] Standardize on `contoso.net` by removing mentions of `contoso.com`. Fixes MicrosoftDocs/azure-docs#108050 ------- cc: @dlepow
1 parent 83f415f commit e621281

File tree

1 file changed

+48
-20
lines changed

1 file changed

+48
-20
lines changed

articles/api-management/api-management-howto-integrate-internal-vnet-appgateway.md

Lines changed: 48 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -52,7 +52,7 @@ To follow the steps described in this article, you must have:
5252

5353
## Scenario
5454

55-
In this article, you learn how to use a single API Management instance for internal and external consumers and make it act as a single front end for both on-premises and cloud APIs. You'll also understand how to expose only a subset of your APIs for external consumption by using routing functionality available in Application Gateway. In the example, the APIs are highlighted in green.
55+
In this article, you learn how to use a single API Management instance for internal and external consumers and make it act as a single front end for both on-premises and cloud APIs. You'll create an API Management instance of the newer single-tenant version 2 (stv2) type. You'll also understand how to expose only a subset of your APIs for external consumption by using routing functionality available in Application Gateway. In the example, the APIs are highlighted in green.
5656

5757
In the first setup example, all your APIs are managed only from within your virtual network. Internal consumers can access all your internal and external APIs. Traffic never goes out to the internet. High-performance connectivity can be delivered via Azure ExpressRoute circuits. In the example, the internal consumers are highlighted in orange.
5858

@@ -115,7 +115,7 @@ Resource Manager requires that all resource groups specify a location. This loca
115115
116116
The following example shows how to create a virtual network by using Resource Manager. The virtual network in this example consists of separate subnets for Application Gateway and API Management.
117117
118-
1. Create network security groups (NSGs) and NSG rules for the Application Gateway and API Management subnets.
118+
1. Create a network security group (NSG) and NSG rules for the Application Gateway subnet.
119119
120120
```powershell
121121
$appGwRule1 = New-AzNetworkSecurityRuleConfig -Name appgw-in -Description "AppGw inbound" `
@@ -124,14 +124,32 @@ The following example shows how to create a virtual network by using Resource Ma
124124
$appGwRule2 = New-AzNetworkSecurityRuleConfig -Name appgw-in-internet -Description "AppGw inbound Internet" `
125125
-Access Allow -Protocol "TCP" -Direction Inbound -Priority 110 -SourceAddressPrefix `
126126
Internet -SourcePortRange * -DestinationAddressPrefix * -DestinationPortRange 443
127+
127128
$appGwNsg = New-AzNetworkSecurityGroup -ResourceGroupName $resGroupName -Location $location -Name `
128129
"NSG-APPGW" -SecurityRules $appGwRule1, $appGwRule2
130+
```
131+
132+
1. Create a network security group (NSG) and NSG rules for the API Management subnet. [API Management stv2 requires several specific rules](https://learn.microsoft.com/en-us/azure/api-management/api-management-using-with-internal-vnet?tabs=stv2#configure-nsg-rules).
133+
134+
```powershell
135+
$apimRule1 = New-AzNetworkSecurityRuleConfig -Name APIM-Management -Description "APIM inbound" `
136+
-Access Allow -Protocol Tcp -Direction Inbound -Priority 100 -SourceAddressPrefix ApiManagement `
137+
-SourcePortRange * -DestinationAddressPrefix VirtualNetwork -DestinationPortRange 3443
138+
$apimRule2 = New-AzNetworkSecurityRuleConfig -Name AllowAppGatewayToAPIM -Description "Allows inbound App Gateway traffic to APIM" `
139+
-Access Allow -Protocol Tcp -Direction Inbound -Priority 110 -SourceAddressPrefix "10.0.0.0/24" `
140+
-SourcePortRange * -DestinationAddressPrefix "10.0.1.0/24" -DestinationPortRange 443
141+
$apimRule3 = New-AzNetworkSecurityRuleConfig -Name AllowAzureLoadBalancer -Description "Allows inbound Azure Infrastructure Load Balancer traffic to APIM" `
142+
-Access Allow -Protocol Tcp -Direction Inbound -Priority 120 -SourceAddressPrefix AzureLoadBalancer `
143+
-SourcePortRange * -DestinationAddressPrefix "10.0.1.0/24" -DestinationPortRange 6390
144+
$apimRule4 = New-AzNetworkSecurityRuleConfig -Name AllowKeyVault -Description "Allows outbound traffic to Azure Key Vault" `
145+
-Access Allow -Protocol Tcp -Direction Outbound -Priority 100 -SourceAddressPrefix "10.0.1.0/24" `
146+
-SourcePortRange * -DestinationAddressPrefix AzureKeyVault -DestinationPortRange 443
147+
$apimRule5 = New-AzNetworkSecurityRuleConfig -Name DenyAll -Description "Denies all inbound traffic" `
148+
-Access Deny -Protocol * -Direction Inbound -Priority 4096 -SourceAddressPrefix "10.0.1.0/24" `
149+
-SourcePortRange * -DestinationAddressPrefix * -DestinationPortRange *
129150
130-
$apimRule1 = New-AzNetworkSecurityRuleConfig -Name apim-in -Description "APIM inbound" `
131-
-Access Allow -Protocol Tcp -Direction Inbound -Priority 100 -SourceAddressPrefix `
132-
ApiManagement -SourcePortRange * -DestinationAddressPrefix VirtualNetwork -DestinationPortRange 3443
133151
$apimNsg = New-AzNetworkSecurityGroup -ResourceGroupName $resGroupName -Location $location -Name `
134-
"NSG-APIM" -SecurityRules $apimRule1
152+
"NSG-APIM" -SecurityRules $apimRule1, $apimRule2, $apimRule3, $apimRule4, $apimRule5
135153
```
136154
137155
1. Assign the address range 10.0.0.0/24 to the subnet variable to be used for Application Gateway while you create a virtual network.
@@ -164,6 +182,13 @@ The following example shows how to create a virtual network by using Resource Ma
164182
165183
The following example shows how to create an API Management instance in a virtual network configured for internal access only.
166184
185+
1. API Management stv2 requires a public IP with a `DomainNameLabel`:
186+
187+
```powershell
188+
$apimPublicIpAddressId = New-AzPublicIpAddress -ResourceGroupName $resGroupName -name "pip-apim" -location $location `
189+
-AllocationMethod Static -Sku Standard -Force -DomainNameLabel "apim-contoso"
190+
```
191+
167192
1. Create an API Management virtual network object by using the subnet `$apimSubnetData` you created.
168193
169194
```powershell
@@ -173,10 +198,13 @@ The following example shows how to create an API Management instance in a virtua
173198
1. Create an API Management instance inside the virtual network. This example creates the service in the Developer service tier. Substitute a unique name for your API Management instance.
174199
175200
```powershell
201+
$domain = "contoso.net"
176202
$apimServiceName = "ContosoApi" # API Management service instance name, must be globally unique
177203
$apimOrganization = "Contoso" # Organization name
178-
$apimAdminEmail = "[email protected]" # Administrator's email address
179-
$apimService = New-AzApiManagement -ResourceGroupName $resGroupName -Location $location -Name $apimServiceName -Organization $apimOrganization -AdminEmail $apimAdminEmail -VirtualNetwork $apimVirtualNetwork -VpnType "Internal" -Sku "Developer"
204+
$apimAdminEmail = "[email protected]" # Administrator's email address
205+
206+
$apimService = New-AzApiManagement -ResourceGroupName $resGroupName -Location $location -Name $apimServiceName -Organization $apimOrganization `
207+
-AdminEmail $apimAdminEmail -VirtualNetwork $apimVirtualNetwork -VpnType "Internal" -Sku "Developer" -PublicIpAddressId $apimPublicIpAddressId.Id
180208
```
181209
182210
It can take between 30 and 40 minutes to create and activate an API Management instance in this tier. After the previous command succeeds, see [DNS configuration required to access internal virtual network API Management service](api-management-using-with-internal-vnet.md#dns-configuration) to confirm access to it.
@@ -188,9 +216,9 @@ To set up custom domain names in API Management:
188216
1. Initialize the following variables with the details of the certificates with private keys for the domains and the trusted root certificate. In this example, we use `api.contoso.net`, `portal.contoso.net`, and `management.contoso.net`.
189217
190218
```powershell
191-
$gatewayHostname = "api.contoso.net" # API gateway host
192-
$portalHostname = "portal.contoso.net" # API developer portal host
193-
$managementHostname = "management.contoso.net" # API management endpoint host
219+
$gatewayHostname = "api.$domain" # API gateway host
220+
$portalHostname = "portal.$domain" # API developer portal host
221+
$managementHostname = "management.$domain" # API management endpoint host
194222
$gatewayCertPfxPath = "C:\Users\Contoso\gateway.pfx" # Full path to api.contoso.net .pfx file
195223
$portalCertPfxPath = "C:\Users\Contoso\portal.pfx" # Full path to portal.contoso.net .pfx file
196224
$managementCertPfxPath = "C:\Users\Contoso\management.pfx" # Full path to management.contoso.net .pfx file
@@ -232,8 +260,8 @@ To configure a private DNS zone for DNS resolution in the virtual network:
232260
1. Create a private DNS zone and link the virtual network.
233261
234262
```powershell
235-
$myZone = New-AzPrivateDnsZone -Name "contoso.net" -ResourceGroupName $resGroupName
236-
$link = New-AzPrivateDnsVirtualNetworkLink -ZoneName contoso.net `
263+
$myZone = New-AzPrivateDnsZone -Name $domain -ResourceGroupName $resGroupName
264+
$link = New-AzPrivateDnsVirtualNetworkLink -ZoneName $domain `
237265
-ResourceGroupName $resGroupName -Name "mylink" `
238266
-VirtualNetworkId $vnet.id
239267
```
@@ -243,13 +271,13 @@ To configure a private DNS zone for DNS resolution in the virtual network:
243271
```powershell
244272
$apimIP = $apimService.PrivateIPAddresses[0]
245273
246-
New-AzPrivateDnsRecordSet -Name api -RecordType A -ZoneName contoso.net `
274+
New-AzPrivateDnsRecordSet -Name api -RecordType A -ZoneName $domain `
247275
-ResourceGroupName $resGroupName -Ttl 3600 `
248276
-PrivateDnsRecords (New-AzPrivateDnsRecordConfig -IPv4Address $apimIP)
249-
New-AzPrivateDnsRecordSet -Name portal -RecordType A -ZoneName contoso.net `
277+
New-AzPrivateDnsRecordSet -Name portal -RecordType A -ZoneName $domain `
250278
-ResourceGroupName $resGroupName -Ttl 3600 `
251279
-PrivateDnsRecords (New-AzPrivateDnsRecordConfig -IPv4Address $apimIP)
252-
New-AzPrivateDnsRecordSet -Name management -RecordType A -ZoneName contoso.net `
280+
New-AzPrivateDnsRecordSet -Name management -RecordType A -ZoneName $domain `
253281
-ResourceGroupName $resGroupName -Ttl 3600 `
254282
-PrivateDnsRecords (New-AzPrivateDnsRecordConfig -IPv4Address $apimIP)
255283
```
@@ -260,7 +288,7 @@ Create a Standard public IP resource **publicIP01** in the resource group.
260288
261289
```powershell
262290
$publicip = New-AzPublicIpAddress -ResourceGroupName $resGroupName `
263-
-name "publicIP01" -location $location -AllocationMethod Static -Sku Standard
291+
-name "pip-appgateway" -location $location -AllocationMethod Static -Sku Standard
264292
```
265293

266294
An IP address is assigned to the application gateway when the service starts.
@@ -369,13 +397,13 @@ All configuration items must be set up before you create the application gateway
369397
```powershell
370398
$gatewayRule = New-AzApplicationGatewayRequestRoutingRule -Name "gatewayrule" `
371399
-RuleType Basic -HttpListener $gatewayListener -BackendAddressPool $apimGatewayBackendPool `
372-
-BackendHttpSettings $apimPoolGatewaySetting
400+
-BackendHttpSettings $apimPoolGatewaySetting -Priority 10
373401
$portalRule = New-AzApplicationGatewayRequestRoutingRule -Name "portalrule" `
374402
-RuleType Basic -HttpListener $portalListener -BackendAddressPool $apimPortalBackendPool `
375-
-BackendHttpSettings $apimPoolPortalSetting
403+
-BackendHttpSettings $apimPoolPortalSetting -Priority 20
376404
$managementRule = New-AzApplicationGatewayRequestRoutingRule -Name "managementrule" `
377405
-RuleType Basic -HttpListener $managementListener -BackendAddressPool $apimManagementBackendPool `
378-
-BackendHttpSettings $apimPoolManagementSetting
406+
-BackendHttpSettings $apimPoolManagementSetting -Priority 30
379407
```
380408
381409
> [!TIP]

0 commit comments

Comments
 (0)