Azure Virtual Network Manager を使用してネットワーク トラフィックをブロックする方法 - Azure PowerShell

この記事では、ポート80および443へのネットワークトラフィックをブロックするセキュリティルールの作成方法を紹介し、それらをルールコレクションに追加できます。 詳細については、セキュリティ管理規則に関するページを参照してください。

前提条件

セキュリティ規則の構成を開始する前に、次の手順を確認してください。

セキュリティ管理者の設定を作成する

New-AzNetworkManagerSecurityAdminConfigurationを使ってセキュリティ管理者の設定を作成しましょう。 この構成には、以下のセクションで作成するルールコレクションとルールが収められています。

$config = @{
    Name = 'SecurityConfig'
    ResourceGroupName = 'myAVNMResourceGroup'
    NetworkManagerName = 'myAVNM'
}
$securityconfig = New-AzNetworkManagerSecurityAdminConfiguration @config

ネットワークグループを構成グループに追加します

セキュリティ管理者の設定は、1つ以上のネットワークグループに適用されます。 これらのステップでは、ネットワークグループを変数に保存し、設定グループに追加します。

  1. Get-AzNetworkManagerGroupを使ってネットワークグループを変数に格納します。

    $ng = @{
        Name = 'myNetworkGroup'
        ResourceGroupName = 'myAVNMResourceGroup'
        NetworkManagerName = 'myAVNM'
    }
    $networkgroup = Get-AzNetworkManagerGroup @ng   
    
  2. New-AzNetworkManagerSecurityGroupItemを使ってネットワークグループのセキュリティグループアイテムを作成します。

    $groupItem = New-AzNetworkManagerSecurityGroupItem -NetworkGroupId $networkgroup.id
    
  3. 構成グループを作成し、前の手順のグループ項目を追加します。

    [System.Collections.Generic.List[Microsoft.Azure.Commands.Network.Models.PSNetworkManagerSecurityGroupItem]]$configGroup = @()  
    $configGroup.Add($groupItem) 
    

ルールコレクションの作成

New-AzNetworkManagerSecurityAdminRuleCollectionを使ってセキュリティ管理者のルールコレクションを作成できます。 このコレクションは、前回のセクションで作成した構成グループに適用されます。

$collection = @{
    Name = 'myRuleCollection'
    ResourceGroupName = 'myAVNMResourceGroup'
    NetworkManagerName = 'myAVNM'
    ConfigName = 'SecurityConfig'
}
$rulecollection = New-AzNetworkManagerSecurityAdminRuleCollection @collection -AppliesToGroup $configGroup

ポート80と443の拒否ルールを作成する

これらのステップでは、ルールのアドレスプレフィックスとポートを定義し、ポート80および443への送信トラフィックを拒否する Block_HTTP_HTTPS というルールを作成します。

  1. New-AzNetworkManagerAddressPrefixItemを使って送信元アドレスと宛先アドレスのプレフィックスとポートを定義します。

    $sourceip = @{
        AddressPrefix = 'Internet'
        AddressPrefixType = 'ServiceTag'
    }
    $sourceprefix = New-AzNetworkManagerAddressPrefixItem @sourceip
    
    $destinationip = @{
        AddressPrefix = '10.0.0.0/24'
        AddressPrefixType = 'IPPrefix'
    }
    $destinationprefix = New-AzNetworkManagerAddressPrefixItem @destinationip
    
    [System.Collections.Generic.List[string]]$sourcePortList = @() 
    $sourcePortList.Add("65500") 
    
    [System.Collections.Generic.List[string]]$destinationPortList = @() 
    $destinationPortList.Add("80")
    $destinationPortList.Add("443")
    
  2. New-AzNetworkManagerSecurityAdminRuleを使ってセキュリティルールを作成します。

    $rule = @{
        Name = 'Block_HTTP_HTTPS'
        ResourceGroupName = 'myAVNMResourceGroup'
        NetworkManagerName = 'myAVNM'
        SecurityAdminConfigurationName = 'SecurityConfig'
        RuleCollectionName = 'myRuleCollection'
        Protocol = 'TCP'
        Access = 'Deny'
        Priority = '100'
        Direction = 'Outbound'
        SourceAddressPrefix = $sourceprefix
        SourcePortRange = $sourcePortList
        DestinationAddressPrefix = $destinationprefix
        DestinationPortRange = $destinationPortList
    }
    $securityrule = New-AzNetworkManagerSecurityAdminRule @rule
    

デプロイをコミットする

Deploy-AzNetworkManagerCommitを使ってセキュリティ構成をターゲット地域にコミットします。 先に作成したセキュリティ管理者設定から $configIds リストを作成し、それをコミットに渡します。

[System.Collections.Generic.List[string]]$configIds = @()
$configIds.Add($securityconfig.Id)

$regions = @("westus")
$deployment = @{
    Name = 'myAVNM'
    ResourceGroupName = 'myAVNMResourceGroup'
    ConfigurationId = $configIds
    TargetLocation = $regions
    CommitType = 'SecurityAdmin'
}
Deploy-AzNetworkManagerCommit @deployment 

セキュリティ構成を削除する

セキュリティ設定が不要な場合は、以下の条件が正しいことを確認してください。そうすればセキュリティ設定自体を削除できます:

  • どのリージョンにも構成のデプロイはありません。
  • セキュリティ構成に関連付けられている規則コレクション内のすべてのセキュリティ規則を削除します。

セキュリティ構成のデプロイを削除する

セキュリティ展開を解除するには、 Deploy-AzNetworkManagerCommitを組み合わせた構成をデプロイしてください。

[System.Collections.Generic.List[string]]$configIds = @()
[System.Collections.Generic.List[string]]$regions = @()   
$regions.Add("westus")     
$removedeployment = @{
    Name = 'myAVNM'
    ResourceGroupName = 'myAVNMResourceGroup'
    ConfigurationId = $configIds
    TargetLocation = $regions
    CommitType = 'SecurityAdmin'
}
Deploy-AzNetworkManagerCommit @removedeployment

セキュリティ規則を削除する

以前作成したセキュリティルールを Remove-AzNetworkManagerSecurityAdminRuleで削除してください。

$removerule = @{
    Name = 'Block_HTTP_HTTPS'
    ResourceGroupName = 'myAVNMResourceGroup'
    NetworkManagerName = 'myAVNM'
    SecurityAdminConfigurationName = 'SecurityConfig'
    RuleCollectionName = 'myRuleCollection'
}
Remove-AzNetworkManagerSecurityAdminRule @removerule

セキュリティ規則コレクションを削除する

$removecollection = @{
    Name = 'myRuleCollection'
    ResourceGroupName = 'myAVNMResourceGroup'
    NetworkManagerName = 'myAVNM'
    SecurityAdminConfigurationName = 'SecurityConfig'
}
Remove-AzNetworkManagerSecurityAdminRuleCollection @removecollection

構成の削除

セキュリティ設定を Remove-AzNetworkManagerSecurityAdminConfigurationで削除してください。

$removeconfig = @{
    Name = 'SecurityConfig'
    ResourceGroupName = 'myAVNMResourceGroup'
    NetworkManagerName = 'myAVNM'
}
Remove-AzNetworkManagerSecurityAdminConfiguration @removeconfig

次のステップ

セキュリティ管理規則の詳細を確認する