内部仮想ネットワーク内の API Management を Application Gateway と統合する

適用対象: Developer | Premium

Azure API Management を内部モードの仮想ネットワーク内に構成できます。そうすると、このサービスには仮想ネットワーク内からのみアクセスできるようになります。 Azure Application Gateway は、レイヤー 7 ロード バランサーとして機能するサービスとしてのプラットフォーム (PaaS) です。 リバースプロキシ サービスとして機能し、そのオファリングの 1 つが Azure Web Application Firewall (WAF) です。

内部仮想ネットワーク内にプロビジョニングされた API Management を Application Gateway フロントエンドと組み合わせると、次のことが可能になります。

  • 内部コンシューマーと外部コンシューマーの両方における消費用に同一の API Management リソースを使用する。
  • 単一の API Management リソースを使用しながら、API Management 内で定義した API の一部を外部コンシューマーが利用できるようにする。
  • パブリック インターネットから API Management へのアクセスのオン/オフを切り替えるターンキー方式を提供する。

アーキテクチャに関するガイダンスについては、次を参照してください。

注意

この記事は、Application Gateway WAF_v2 SKU を使用する内容に更新されました。

前提条件

Note

Azure を操作するには、Azure Az PowerShell モジュールを使用することをお勧めします。 作業を開始するには、Azure PowerShell のインストールに関する記事を参照してください。 Az PowerShell モジュールに移行する方法については、「AzureRM から Az への Azure PowerShell の移行」を参照してください。

この記事で説明されている手順に従うには、以下が必要です。

  • 有効な Azure サブスクリプション

    Azure サブスクリプションをお持ちでない場合は、開始する前に Azure 無料アカウントを作成してください。

  • 証明書

    • API Management のカスタム ホスト名 (ゲートウェイ、開発者ポータル、管理エンドポイント) 用の Personal Information Exchange (PFX) ファイル。
    • PFX 証明書のルート証明書用の証明書 (CER) ファイル。

    詳細については、バックエンドの証明書に関するページを参照してください。 テスト目的で、必要に応じて自己署名証明書を生成します。

  • 最新バージョンの Azure PowerShell

シナリオ

この記事では、単一の API Management インスタンスを内部と外部のコンシューマーに使用して、オンプレミスとクラウドの両方の API の単一フロントエンドとして機能させる方法について説明します。 より新しいシングルテナント バージョン 2 (stv2) の型の API Management インスタンスを作成します。 Application Gateway でパブリック リスナーとプライベート リスナーを使用する方法について説明します。 Application Gateway で提供されているルーティング機能を使用して、API のサブセットのみを外部で使用するために公開する方法についても説明します。 この例では、それらの API は緑色で強調表示されています。

最初の設定例では、すべての API を仮想ネットワーク内からのみ管理します。 内部コンシューマーは、内部と外部のすべての API にアクセスできます。 トラフィックがインターネットに送信されることはありません。 ハイ パフォーマンス接続を Azure ExpressRoute 回線を介して提供できます。 この例では、内部コンシューマーはオレンジ色で強調表示されています。

URL ルート示す図。

API Management と Application Gateway の統合に必要なもの

  • バックエンド サーバー プール: このサーバー プールは、API Management の内部仮想 IP アドレスです。
  • バックエンド サーバー プール設定: すべてのプールには、ポート、プロトコル、cookie ベースのアフィニティなどの設定があります。 これらの設定は、プール内のすべてのサーバーに適用されます。
  • フロントエンド ポート: このパブリック ポートは、アプリケーション ゲートウェイで開かれています。 これにヒットしたトラフィックは、いずれかのバックエンド サーバーにリダイレクトされます。
  • リスナー: リスナーには、フロントエンド ポート、プロトコル (Http または Https。これらの値では大文字と小文字が区別されます)、およびトランスポート層セキュリティ (TLS) 証明書名 (TLS オフロードを構成する場合) があります。
  • ルール: ルールによってリスナーがバックエンド サーバー プールにバインドされます。
  • カスタムの正常性プローブ: Application Gateway では、BackendAddressPool 内でアクティブになっているサーバーを見つけるため、既定では IP アドレス ベースのプローブが使用されます。 API Management が応答するのは適切なホスト ヘッダーを持つ要求だけなので、既定のプローブは失敗します。 サービスが有効で要求を転送する必要があることを、アプリケーション ゲートウェイで判定しやすいように、カスタムの正常性プローブを定義します。
  • カスタム ドメイン証明書: インターネットから API Management にアクセスするには、ドメイン ネーム システム (DNS) レコードを作成し、そのホスト名を Application Gateway のフロントエンド IPアドレスにマップします。 このマッピングにより、API Management に送信されるホスト ヘッダーと証明書が有効であることが保証されます。 この例では、3 つの証明書を使用します。 これらは、API Management のゲートウェイ (バック エンド)、開発者ポータル、および管理エンドポイント用です。

Application Gateway を介して開発者ポータルと管理エンドポイントを外部に公開する

この記事では、アプリケーション ゲートウェイを介して、"開発者ポータル "と "管理エンドポイント" を外部の対象ユーザーにも公開します。 各エンドポイントのリスナー、プローブ、設定、ルールを作成するために追加の手順が必要です。 詳細はすべて、それぞれの手順で説明します。

Microsoft Entra ID またはサード パーティの認証を使用する場合は、Application Gateway で Cookie ベースのセッション アフィニティ機能を有効にします。

警告

開発者ポータルで行う OpenAPI 仕様のダウンロードが Application Gateway WAF によって中断されないようにするには、ファイアウォール規則 942200 - "Detects MySQL comment-/space-obfuscated injections and backtick termination" を無効にします。

以下の Application Gateway WAF ルールによって、ポータルの機能が中断されることがあります。

  • 管理モード用: 920300920330931130942100942110942180942200942260942340、および 942370
  • 発行されたポータル用: 942200942260942370942430、および 942440

変数の設定

このガイド全体を通じて、いくつかの変数を定義する必要があります。 名前付けは、クラウド導入フレームワークの略語ガイダンスに基づいています。

# These variables must be changed.
$subscriptionId = "00000000-0000-0000-0000-000000000000"      # GUID of your Azure subscription
$domain = "contoso.net"                                       # The custom domain for your certificate
$apimServiceName = "apim-contoso"                             # API Management service instance name, must be globally unique    
$apimDomainNameLabel = $apimServiceName                       # Domain name label for API Management's public IP address, must be globally unique
$apimAdminEmail = "admin@contoso.net"                         # Administrator's email address - use your email address

$gatewayHostname = "api.$domain"                              # API gateway host
$portalHostname = "portal.$domain"                            # API developer portal host
$managementHostname = "management.$domain"                    # API management endpoint host

$baseCertPath = "C:\Users\Contoso\"                           # The base path where all certificates are stored
$trustedRootCertCerPath = "${baseCertPath}trustedroot.cer"    # Full path to contoso.net trusted root .cer file
$gatewayCertPfxPath = "${baseCertPath}gateway.pfx"            # Full path to api.contoso.net .pfx file
$portalCertPfxPath = "${baseCertPath}portal.pfx"              # Full path to portal.contoso.net .pfx file
$managementCertPfxPath = "${baseCertPath}management.pfx"      # Full path to management.contoso.net .pfx file

$gatewayCertPfxPassword = "certificatePassword123"            # Password for api.contoso.net pfx certificate
$portalCertPfxPassword = "certificatePassword123"             # Password for portal.contoso.net pfx certificate
$managementCertPfxPassword = "certificatePassword123"         # Password for management.contoso.net pfx certificate

# These variables may be changed.
$resGroupName = "rg-apim-agw"                                 # Resource group name that will hold all assets
$location = "West US"                                         # Azure region that will hold all assets
$apimOrganization = "Contoso"                                 # Organization name    
$appgwName = "agw-contoso"                                    # The name of the Application Gateway

リソース マネージャーのリソース グループの作成

Azure Resource Manager のリソース グループを作成するには:

  1. Azure にサインインします。

    Connect-AzAccount
    
  2. 資格情報を使用して認証を行います。

  3. 目的のサブスクリプションを選択します。

    Get-AzSubscription -Subscriptionid $subscriptionId | Select-AzSubscription
    
  4. リソース グループを作成します。 既存のリソース グループを使用する場合は、この手順をスキップしてかまいません。

    New-AzResourceGroup -Name $resGroupName -Location $location
    

Resource Manager で、すべてのリソース グループの場所を指定する必要があります。 この場所は、そのリソース グループ内のリソースの既定の保存先として使用されます。 アプリケーション ゲートウェイを作成するためのすべてのコマンドで、同じリソース グループが使用されていることを確認します。

アプリケーション ゲートウェイの仮想ネットワークとサブネットを作成します。

次の例では、リソース マネージャーを使用して仮想ネットワークを作成する方法を示します。 この例の仮想ネットワークは、Application Gateway と API Management の別々のサブネットで構成されています。

  1. Application Gateway の IP アドレスを設定します。

    Note

    パブリック リスナーとプライベート リスナーが存在するため、パブリック IP アドレスとプライベート IP アドレスが必要です。 静的パブリック IP アドレスは作成する必要がありますが、プライベート IP アドレスはアプリケーション ゲートウェイに関連付けられているサブネットから選択する必要があります。 プライベート IP アドレスは任意に選択されています。

    $appGatewayExternalIP = New-AzPublicIpAddress -ResourceGroupName $resGroupName -name "pip-ag" -location $location -AllocationMethod Static -Sku Standard -Force
    $appGatewayInternalIP = "10.0.0.100"
    
    [String[]]$appGwNsgDestIPs = $appGatewayInternalIP, $appGatewayExternalIP.IpAddress
    
  2. Application Gateway サブネットのネットワーク セキュリティ グループ (NSG) と NSG ルールを作成します。

    $appGwRule1 = New-AzNetworkSecurityRuleConfig -Name appgw-in -Description "AppGw inbound" `
        -Access Allow -Protocol * -Direction Inbound -Priority 100 -SourceAddressPrefix `
        GatewayManager -SourcePortRange * -DestinationAddressPrefix * -DestinationPortRange 65200-65535
    
    $appGwRule2 = New-AzNetworkSecurityRuleConfig -Name appgw-in-internet -Description "AppGw inbound Internet" `
        -Access Allow -Protocol "TCP" -Direction Inbound -Priority 110 -SourceAddressPrefix `
        Internet -SourcePortRange * -DestinationAddressPrefix $appGwNsgDestIPs -DestinationPortRange 443
    
    $appGwNsg = New-AzNetworkSecurityGroup -ResourceGroupName $resGroupName -Location $location -Name `
        "nsg-agw" -SecurityRules $appGwRule1, $appGwRule2
    
  3. API Management サブネットのネットワーク セキュリティ グループ (NSG) と NSG ルールを作成します。 API Management stv2 には、いくつかの特定の NSG ルールが必要です

    $apimRule1 = New-AzNetworkSecurityRuleConfig -Name APIM-Management -Description "APIM inbound" `
        -Access Allow -Protocol Tcp -Direction Inbound -Priority 100 -SourceAddressPrefix ApiManagement `
        -SourcePortRange * -DestinationAddressPrefix VirtualNetwork -DestinationPortRange 3443
    
    $apimRule2 = New-AzNetworkSecurityRuleConfig -Name AllowAppGatewayToAPIM -Description "Allows inbound App Gateway traffic to APIM" `
        -Access Allow -Protocol Tcp -Direction Inbound -Priority 110 -SourceAddressPrefix "10.0.0.0/24" `
        -SourcePortRange * -DestinationAddressPrefix "10.0.1.0/24" -DestinationPortRange 443
    
    $apimRule3 = New-AzNetworkSecurityRuleConfig -Name AllowAzureLoadBalancer -Description "Allows inbound Azure Infrastructure Load Balancer traffic to APIM" `
        -Access Allow -Protocol Tcp -Direction Inbound -Priority 120 -SourceAddressPrefix AzureLoadBalancer `
        -SourcePortRange * -DestinationAddressPrefix "10.0.1.0/24" -DestinationPortRange 6390
    
    $apimRule4 = New-AzNetworkSecurityRuleConfig -Name AllowKeyVault -Description "Allows outbound traffic to Azure Key Vault" `
        -Access Allow -Protocol Tcp -Direction Outbound -Priority 100 -SourceAddressPrefix "10.0.1.0/24" `
        -SourcePortRange * -DestinationAddressPrefix AzureKeyVault -DestinationPortRange 443
    
    $apimNsg = New-AzNetworkSecurityGroup -ResourceGroupName $resGroupName -Location $location -Name `
        "nsg-apim" -SecurityRules $apimRule1, $apimRule2, $apimRule3, $apimRule4
    
  4. 仮想ネットワークを作成するときに、Application Gateway 用に使用するサブネット変数にアドレス範囲 10.0.0.0/24 を割り当てます。

    $appGatewaySubnet = New-AzVirtualNetworkSubnetConfig -Name "appGatewaySubnet" -NetworkSecurityGroup $appGwNsg -AddressPrefix "10.0.0.0/24"
    
  5. 仮想ネットワークを作成するときに、API Management 用に使用するサブネット変数にアドレス範囲 10.0.1.0/24 を割り当てます。

    $apimSubnet = New-AzVirtualNetworkSubnetConfig -Name "apimSubnet" -NetworkSecurityGroup $apimNsg -AddressPrefix "10.0.1.0/24"
    
  6. vnet-contoso という名前の仮想ネットワークを作成します。 サブネット 10.0.0.0/24 および 10.0.1.0/24 と共に、プレフィックス 10.0.0.0/16 を使用します。

    $vnet = New-AzVirtualNetwork -Name "vnet-contoso" -ResourceGroupName $resGroupName `
      -Location $location -AddressPrefix "10.0.0.0/16" -Subnet $appGatewaySubnet,$apimSubnet
    
  7. 次の手順用のサブネット変数を割り当てます。

    $appGatewaySubnetData = $vnet.Subnets[0]
    $apimSubnetData = $vnet.Subnets[1]
    

仮想ネットワーク内に API Management インスタンスを作成する

以下の例は、内部アクセス専用に構成した仮想ネットワーク内に API Management インスタンスを作成する方法を示しています。

  1. API Management stv2 には、一意の DomainNameLabel を持つパブリック IP が必要です。

    $apimPublicIpAddressId = New-AzPublicIpAddress -ResourceGroupName $resGroupName -name "pip-apim" -location $location `
        -AllocationMethod Static -Sku Standard -Force -DomainNameLabel $apimDomainNameLabel
    
  2. 作成したサブネット $apimSubnetData を使用して、API Management の仮想ネットワーク オブジェクトを作成します。

    $apimVirtualNetwork = New-AzApiManagementVirtualNetwork -SubnetResourceId $apimSubnetData.Id
    
  3. その仮想ネットワーク内に API Management インスタンスを作成します。 この例では、Developer サービス レベルにサービスを作成します。 API Management インスタンスの名前は一意のものに置き換えます。

    $apimService = New-AzApiManagement -ResourceGroupName $resGroupName -Location $location -Name $apimServiceName -Organization $apimOrganization `
        -AdminEmail $apimAdminEmail -VirtualNetwork $apimVirtualNetwork -VpnType "Internal" -Sku "Developer" -PublicIpAddressId $apimPublicIpAddressId.Id
    

このレベルに API Management インスタンスを作成してアクティブにするのに、30 分から 40 分かかる場合があります。 前記のコマンドが成功したら、内部仮想ネットワークの API Management サービスにアクセスするために必要な DNS 構成に関する記事を参照して、アクセスを確認します。

API Management でカスタム ドメイン名を設定する

API Management でカスタム ドメイン名を設定するには:

  1. ドメインの秘密キーと信頼されたルート証明書を含む証明書の詳細を使用して以下の変数を初期化します。 この例では、api.contoso.netportal.contoso.netmanagement.contoso.net を使用します。

    $certGatewayPwd = ConvertTo-SecureString -String $gatewayCertPfxPassword -AsPlainText -Force
    $certPortalPwd = ConvertTo-SecureString -String $portalCertPfxPassword -AsPlainText -Force
    $certManagementPwd = ConvertTo-SecureString -String $managementCertPfxPassword -AsPlainText -Force
    
  2. API Management エンドポイント用の Hostname 構成オブジェクトを作成して設定します。

    $gatewayHostnameConfig = New-AzApiManagementCustomHostnameConfiguration -Hostname $gatewayHostname `
      -HostnameType Proxy -PfxPath $gatewayCertPfxPath -PfxPassword $certGatewayPwd
    
    $portalHostnameConfig = New-AzApiManagementCustomHostnameConfiguration -Hostname $portalHostname `
      -HostnameType DeveloperPortal -PfxPath $portalCertPfxPath -PfxPassword $certPortalPwd
    
    $managementHostnameConfig = New-AzApiManagementCustomHostnameConfiguration -Hostname $managementHostname `
      -HostnameType Management -PfxPath $managementCertPfxPath -PfxPassword $certManagementPwd
    
    $apimService.ProxyCustomHostnameConfiguration = $gatewayHostnameConfig
    $apimService.PortalCustomHostnameConfiguration = $portalHostnameConfig
    $apimService.ManagementCustomHostnameConfiguration = $managementHostnameConfig
    
    Set-AzApiManagement -InputObject $apimService
    

仮想ネットワークで DNS 解決用のプライベート ゾーンを構成する

仮想ネットワーク内に DNS 解決用のプライベート DNS ゾーンを構成するには:

  1. プライベート DNS ゾーンを作成し、仮想ネットワークをリンクします。

    $myZone = New-AzPrivateDnsZone -Name $domain -ResourceGroupName $resGroupName
    
    $link = New-AzPrivateDnsVirtualNetworkLink -ZoneName $domain `
      -ResourceGroupName $resGroupName -Name "mylink" `
      -VirtualNetworkId $vnet.id
    
  2. API Management のプライベート IP アドレスにマップされる、カスタム ドメイン ホスト名の A レコードを作成します。

    $apimIP = $apimService.PrivateIPAddresses[0]
    
    New-AzPrivateDnsRecordSet -Name api -RecordType A -ZoneName $domain `
      -ResourceGroupName $resGroupName -Ttl 3600 `
      -PrivateDnsRecords (New-AzPrivateDnsRecordConfig -IPv4Address $apimIP)
    
    New-AzPrivateDnsRecordSet -Name portal -RecordType A -ZoneName $domain `
      -ResourceGroupName $resGroupName -Ttl 3600 `
      -PrivateDnsRecords (New-AzPrivateDnsRecordConfig -IPv4Address $apimIP)
    
    New-AzPrivateDnsRecordSet -Name management -RecordType A -ZoneName $domain `
      -ResourceGroupName $resGroupName -Ttl 3600 `
      -PrivateDnsRecords (New-AzPrivateDnsRecordConfig -IPv4Address $apimIP)
    

Application Gateway 構成の作成

アプリケーション ゲートウェイを作成するには、すべての構成項目が設定されている必要があります。 以下の手順では、Application Gateway のリソースに必要な構成項目を作成します。

  1. gatewayIP01 という名前の Application Gateway の IP 構成を作成します。 Application Gateway が起動すると、構成されているサブネットから IP アドレスが取得されて、ネットワーク トラフィックがバックエンド IP プール内の IP アドレスにルーティングされます。 各インスタンスが IP アドレスを 1 つ取得することに注意してください。

    $gipconfig = New-AzApplicationGatewayIPConfiguration -Name "gatewayIP01" -Subnet $appGatewaySubnetData
    
  2. パブリック IP エンドポイントとプライベート IP エンドポイントに同じフロントエンド ポートを構成します。 このポートは、ユーザーの接続先ポートです。 両方に同じポートを使用することで、内部要求と外部要求を同じポートに対して行えるようになります。

    $fp01 = New-AzApplicationGatewayFrontendPort -Name "port01"  -Port 443
    
  3. 2 つのフロントエンド IP アドレス (1 つのパブリックと 1 つのプライベート) を構成します。 プライベート IP アドレスは、インデックス 0 で最初に作成されたアプリケーション ゲートウェイ サブネットから取得されます。

    $fipconfig01 = New-AzApplicationGatewayFrontendIPConfig `
      -Name "gateway-public-ip" -PublicIPAddress $appGatewayExternalIP
    
    $fipconfig02 = New-AzApplicationGatewayFrontendIPConfig `
      -Name "gateway-private-ip" -PrivateIPAddress $appGatewayInternalIP `
      -Subnet $vnet.Subnets[0]
    
  4. アプリケーション ゲートウェイの証明書を構成します。 これらは、通過するトラフィックの暗号化解除と再暗号化に使用されます。

    注意

    Application Gateway では、カスタム TLS オプションの定義、特定の TLS プロトコル バージョンの無効化、暗号スイートと優先順序の指定がサポートされています。 構成できる TLS オプションの詳細については、TLS ポリシーの概要に関するページを参照してください。

    $certGateway = New-AzApplicationGatewaySslCertificate -Name "gatewaycert" `
      -CertificateFile $gatewayCertPfxPath -Password $certGatewayPwd
    
    $certPortal = New-AzApplicationGatewaySslCertificate -Name "portalcert" `
      -CertificateFile $portalCertPfxPath -Password $certPortalPwd
    
    $certManagement = New-AzApplicationGatewaySslCertificate -Name "managementcert" `
      -CertificateFile $managementCertPfxPath -Password $certManagementPwd
    
  5. アプリケーション ゲートウェイ用の HTTP リスナーを作成します。 フロントエンド IP 構成、ポート、および TLS/SSL 証明書をリスナーに割り当てます。

    # Public/external listeners
    $gatewayListener = New-AzApplicationGatewayHttpListener -Name "gatewaylistener" `
      -Protocol "Https" -FrontendIPConfiguration $fipconfig01 -FrontendPort $fp01 `
      -SslCertificate $certGateway -HostName $gatewayHostname -RequireServerNameIndication true
    
    $portalListener = New-AzApplicationGatewayHttpListener -Name "portallistener" `
      -Protocol "Https" -FrontendIPConfiguration $fipconfig01 -FrontendPort $fp01 `
      -SslCertificate $certPortal -HostName $portalHostname -RequireServerNameIndication true
    
    $managementListener = New-AzApplicationGatewayHttpListener -Name "managementlistener" `
      -Protocol "Https" -FrontendIPConfiguration $fipconfig01 -FrontendPort $fp01 `
      -SslCertificate $certManagement -HostName $managementHostname -RequireServerNameIndication true
    
    # Private/internal listeners
    $gatewayListenerPrivate = New-AzApplicationGatewayHttpListener -Name "gatewaylistener-private" `
      -Protocol "Https" -FrontendIPConfiguration $fipconfig02 -FrontendPort $fp01 `
      -SslCertificate $certGateway -HostName $gatewayHostname -RequireServerNameIndication true
    
    $portalListenerPrivate = New-AzApplicationGatewayHttpListener -Name "portallistener-private" `
      -Protocol "Https" -FrontendIPConfiguration $fipconfig02 -FrontendPort $fp01 `
      -SslCertificate $certPortal -HostName $portalHostname -RequireServerNameIndication true
    
    $managementListenerPrivate = New-AzApplicationGatewayHttpListener -Name "managementlistener-private" `
      -Protocol "Https" -FrontendIPConfiguration $fipconfig02 -FrontendPort $fp01 `
      -SslCertificate $certManagement -HostName $managementHostname -RequireServerNameIndication true
    
  6. API Management の ContosoApi ゲートウェイ ドメイン エンドポイントに対するカスタム プローブを作成します。 パス /status-0123456789abcdef は、API Management のすべてのインスタンスでホストされる既定の正常性エンドポイントです。 api.contoso.net をカスタム プローブのホスト名として設定し、TLS/SSL 証明書を使用してセキュリティで保護します。

    注意

    ホスト名 contosoapi.azure-api.net は、contosoapi という名前のサービスがパブリック Azure に作成されると構成される既定のプロキシ ホスト名です。

    $apimGatewayProbe = New-AzApplicationGatewayProbeConfig -Name "apimgatewayprobe" `
      -Protocol "Https" -HostName $gatewayHostname -Path "/status-0123456789abcdef" `
      -Interval 30 -Timeout 120 -UnhealthyThreshold 8
    
    $apimPortalProbe = New-AzApplicationGatewayProbeConfig -Name "apimportalprobe" `
      -Protocol "Https" -HostName $portalHostname -Path "/signin" `
      -Interval 60 -Timeout 300 -UnhealthyThreshold 8
    
    $apimManagementProbe = New-AzApplicationGatewayProbeConfig -Name "apimmanagementprobe" `
      -Protocol "Https" -HostName $managementHostname -Path "/ServiceStatus" `
      -Interval 60 -Timeout 300 -UnhealthyThreshold 8
    
  7. バックエンド証明書の信頼されたルート証明書を構成します。 この証明書は、バックエンド証明書の信頼性を検証します。

    $trustedRootCert = New-AzApplicationGatewayTrustedRootCertificate `
      -Name "allowlistcert1" -CertificateFile $trustedRootCertCerPath
    
  8. その時間を過ぎると要求がキャンセルされるバックエンド要求のタイムアウト制限を含むアプリケーション ゲートウェイの HTTP バックエンド設定を構成します。 この値はプローブのタイムアウトとは異なります。

    $apimPoolGatewaySetting = New-AzApplicationGatewayBackendHttpSettings -Name "apimPoolGatewaySetting" `
      -Port 443 -Protocol "Https" -CookieBasedAffinity "Disabled" -Probe $apimGatewayProbe `
      -TrustedRootCertificate $trustedRootCert -PickHostNameFromBackendAddress -RequestTimeout 180
    
    $apimPoolPortalSetting = New-AzApplicationGatewayBackendHttpSettings -Name "apimPoolPortalSetting" `
      -Port 443 -Protocol "Https" -CookieBasedAffinity "Disabled" -Probe $apimPortalProbe `
      -TrustedRootCertificate $trustedRootCert -PickHostNameFromBackendAddress -RequestTimeout 180
    
    $apimPoolManagementSetting = New-AzApplicationGatewayBackendHttpSettings -Name "apimPoolManagementSetting" `
      -Port 443 -Protocol "Https" -CookieBasedAffinity "Disabled" -Probe $apimManagementProbe `
      -TrustedRootCertificate $trustedRootCert -PickHostNameFromBackendAddress -RequestTimeout 180
    
  9. それぞれのエンドポイントのドメイン名を使用して、各 API Management エンドポイントのバックエンド IP アドレス プールを構成します。

    $apimGatewayBackendPool = New-AzApplicationGatewayBackendAddressPool -Name "gatewaybackend" `
      -BackendFqdns $gatewayHostname
    
    $apimPortalBackendPool = New-AzApplicationGatewayBackendAddressPool -Name "portalbackend" `
      -BackendFqdns $portalHostname
    
    $apimManagementBackendPool = New-AzApplicationGatewayBackendAddressPool -Name "managementbackend" `
      -BackendFqdns $managementHostname
    
  10. アプリケーション ゲートウェイが基本的なルーティングを使用するためのルーティング規則を作成します。

    # Public/external gateway rules
    $gatewayRule = New-AzApplicationGatewayRequestRoutingRule -Name "gatewayrule" `
      -RuleType Basic -HttpListener $gatewayListener -BackendAddressPool $apimGatewayBackendPool `
      -BackendHttpSettings $apimPoolGatewaySetting -Priority 10
    
    $portalRule = New-AzApplicationGatewayRequestRoutingRule -Name "portalrule" `
      -RuleType Basic -HttpListener $portalListener -BackendAddressPool $apimPortalBackendPool `
      -BackendHttpSettings $apimPoolPortalSetting -Priority 20
    
    $managementRule = New-AzApplicationGatewayRequestRoutingRule -Name "managementrule" `
      -RuleType Basic -HttpListener $managementListener -BackendAddressPool $apimManagementBackendPool `
      -BackendHttpSettings $apimPoolManagementSetting -Priority 30
    
    # Private/internal gateway rules
    $gatewayRulePrivate = New-AzApplicationGatewayRequestRoutingRule -Name "gatewayrule-private" `
      -RuleType Basic -HttpListener $gatewayListenerPrivate -BackendAddressPool $apimGatewayBackendPool `
      -BackendHttpSettings $apimPoolGatewaySetting -Priority 11
    
    $portalRulePrivate = New-AzApplicationGatewayRequestRoutingRule -Name "portalrule-private" `
      -RuleType Basic -HttpListener $portalListenerPrivate -BackendAddressPool $apimPortalBackendPool `
      -BackendHttpSettings $apimPoolPortalSetting -Priority 21
    
    $managementRulePrivate = New-AzApplicationGatewayRequestRoutingRule -Name "managementrule-private" `
      -RuleType Basic -HttpListener $managementListenerPrivate -BackendAddressPool $apimManagementBackendPool `
      -BackendHttpSettings $apimPoolManagementSetting -Priority 31
    

    ヒント

    開発者ポータルの特定ページへのアクセスを制限するには、-RuleType とルーティングを変更します。

  11. Application Gateway のインスタンス数とサイズを構成します。 この例では、API Management リソースのセキュリティを強化するため、WAF_v2 SKU を使用します。

    運用環境のワークロードには少なくとも 2 つのインスタンス (Capacity) を使用します。 非運用環境のシナリオや一般的な実験には、1 つのインスタンスのみを使用することをお勧めします。 詳しくは、「Azure Application Gateway の価格」を参照してください。

    $sku = New-AzApplicationGatewaySku -Name "WAF_v2" -Tier "WAF_v2" -Capacity 2
    
  12. WAF モードを構成します。

    ヒント

    セットアップ中に短時間でファイアウォール規則をテストするには、脅威アラートを監視してログに記録するけれどトラフィックはブロックしない "検出" モードを構成してください。 その後、"防止" モードに移行する前にファイアウォール規則を更新することにより、規則によって検出された侵入と攻撃がブロックできます。

    $config = New-AzApplicationGatewayWebApplicationFirewallConfiguration -Enabled $true -FirewallMode "Prevention"
    
  13. 現在、TLS 1.0 が既定値であるため、最新の TLS1.2 ポリシーのいずれかを使用するようにアプリケーション ゲートウェイを設定します。

    $policy = New-AzApplicationGatewaySslPolicy -PolicyType Predefined -PolicyName AppGwSslPolicy20220101
    

アプリケーション ゲートウェイの作成

  1. 前述の手順の構成オブジェクトをすべて使用して、アプリケーション ゲートウェイを作成します。 インスタンスの作成には 15 分かかる場合があります。

    $appgw = New-AzApplicationGateway `
      -Name $appgwName `
      -ResourceGroupName $resGroupName `
      -Location $location `
      -Sku $sku `
      -SslPolicy $policy `
      -SslCertificates $certGateway, $certPortal, $certManagement `
      -TrustedRootCertificate $trustedRootCert `
      -BackendAddressPools $apimGatewayBackendPool, $apimPortalBackendPool, $apimManagementBackendPool `
      -BackendHttpSettingsCollection $apimPoolGatewaySetting, $apimPoolPortalSetting, $apimPoolManagementSetting `
      -GatewayIpConfigurations $gipconfig `
      -FrontendIpConfigurations $fipconfig01, $fipconfig02 `
      -FrontendPorts $fp01 `
      -HttpListeners $gatewayListener, $portalListener, $managementListener, $gatewayListenerPrivate, $portalListenerPrivate, $managementListenerPrivate `
      -RequestRoutingRules $gatewayRule, $portalRule, $managementRule, $gatewayRulePrivate, $portalRulePrivate, $managementRulePrivate `
      -Probes $apimGatewayProbe, $apimPortalProbe, $apimManagementProbe `
      -WebApplicationFirewallConfig $config
    
  2. API Management バックエンドの正常性状態を確認します。

    Get-AzApplicationGatewayBackendHealth -Name $appgwName -ResourceGroupName $resGroupName
    

各バックエンド プールの正常性状態が正常であることを確認します。 異常なバックエンドや正常性状態が不明なバックエンドのトラブルシューティングを行う必要がある場合は、「Application Gateway のバックエンドの正常性に関する問題のトラブルシューティング」を参照してください。

インターネットから API Management エンドポイントにアクセスするための DNS レコードを作成する

アプリケーション ゲートウェイが作成されたら、インターネットから API Management への通信を構成します。 構成した各 API Management エンドポイントのホスト名をアプリケーション ゲートウェイの静的パブリック IP アドレスにマップする DNS A レコードを作成します。 この記事では、ホスト名の例は、api.contoso.netportal.contoso.netmanagement.contoso.net です。

接続の検証

簡単なテストを行うために、アプリケーション ゲートウェイのパブリック IP アドレスを API Management エンドポイントのホスト名にマップするエントリでコンピューターの hosts ファイルを一時的に修正することを検討してください。

  1. hosts ファイルを変更します。 たとえば、アプリケーション ゲートウェイのパブリック IP が 172.203.129.101 の場合、エントリは 172.203.129.101 api.contoso.net となる可能性があります。
  2. API Management の状態エンドポイント (前に正常性プローブに使用したものと同じパス) に対して curl コマンドを実行します: curl -v https://api.contoso.net/status-0123456789abcdef これにより、200 Service Operational 状態が返されます。これは、Application Gateway を介した API Management への通信が成功したことを示しています。

DNS の考慮事項

Application Gateway にプライベート経路とパブリック経路が追加されました。 同じドメインとポートを使用すると、スプリット ブレイン DNS 状況が生じます。その場合は、api.contoso.net をアプリケーション ゲートウェイの外部 IP アドレスに解決するように外部 DNS リゾルバーを設定する必要があるのに対して、内部 DNS リゾルバーは同じドメインをアプリケーション ゲートウェイの内部 IP アドレスに解決する必要があります。 この設定には、アプリケーションと API の内部または外部のターゲット設定のためにアプリケーションがドメインやポートを変更する必要がないという利点があります。 ターゲット設定の責任は、適切に DNS リゾルバーに委ねられます。

まとめ

仮想ネットワーク内に API Management を構成すると、ホストされている場所がオンプレミスであるかクラウドであるかを問わず、構成されているすべての API に単一のゲートウェイ インターフェイスが提供されます。 Application Gateway を API Management と統合すると、インターネット上で特定の API に選択的にアクセスできる柔軟性が得られます。 統合により、API Management インスタンスにはフロントエンドとして WAF も提供されます。

次のステップ