適用対象: Azure Local 2311.2 以降。Windows Server 2022、Windows Server 2019、Windows Server 2016
この記事では、Windows PowerShell を使用して Azure Local の Datacenter Firewall for Software Defined Networking (SDN) を使用してデータ トラフィック フローを管理するようにネットワーク セキュリティ グループ (NSG) を構成する手順について説明します。 サブネットまたはネットワーク インターフェイスに適用されるネットワーク セキュリティ グループを作成することで、データセンター ファイアウォールを有効にして設定します。
この記事のサンプル スクリプトでは、 NetworkController モジュールからエクスポートされた Windows PowerShell コマンドを使用します。 Windows Admin Center を使用して、ネットワーク セキュリティ グループを構成および管理することもできます。
すべてのトラフィックを許可するようにデータセンター ファイアウォールを構成する
SDN をデプロイしたら、新しい環境で基本的なネットワーク接続をテストする必要があります。 これを行うには、制限なしですべてのネットワーク トラフィックを許可するデータセンター ファイアウォールの規則を作成します。
次の表の項目を使用して、すべての受信および送信ネットワーク トラフィックを許可する一連の規則を作成します。
発信元 IP | 宛先 IP | プロトコル | 発信元ポート | 宛先ポート | 通信方向 | アクション | 優先順位 |
---|---|---|---|---|---|---|---|
* | * | すべて | * | * | 受信 | 許可 | 100 |
* | * | すべて | * | * | 送信 | 許可 | 110 |
この例では、2 つのルールに従ってネットワーク セキュリティ グループを作成します。
- AllowAll_Inbound - すべてのネットワーク トラフィックが、このネットワーク セキュリティ グループが構成されているネットワーク インターフェイスに渡すことができます。
- AllowAllOutbound - すべてのトラフィックがネットワーク インターフェイスから送信されるようにします。 リソース ID「AllowAll-1」で識別されるこのネットワーク セキュリティ グループを、仮想サブネットとネットワーク インターフェイスで使用する準備が整いました。
このコマンドは、Network Controller REST エンドポイントにアクセスできるコンピューターから実行できます。 まず、PowerShell セッションを開始します。 この例では、 Enter-PSSession コマンドレットを使用し、 <computer-name>
をネットワーク コントローラー REST エンドポイントを持つコンピューターの名前に置き換えます。
Enter-PSSession <computer-name>
次に、次のスクリプトを実行して、ネットワーク セキュリティ グループを作成します。
$ruleproperties = new-object Microsoft.Windows.NetworkController.AclRuleProperties
$ruleproperties.Protocol = "All"
$ruleproperties.SourcePortRange = "0-65535"
$ruleproperties.DestinationPortRange = "0-65535"
$ruleproperties.Action = "Allow"
$ruleproperties.SourceAddressPrefix = "*"
$ruleproperties.DestinationAddressPrefix = "*"
$ruleproperties.Priority = "100"
$ruleproperties.Type = "Inbound"
$ruleproperties.Logging = "Enabled"
$aclrule1 = new-object Microsoft.Windows.NetworkController.AclRule
$aclrule1.Properties = $ruleproperties
$aclrule1.ResourceId = "AllowAll_Inbound"
$ruleproperties = new-object Microsoft.Windows.NetworkController.AclRuleProperties
$ruleproperties.Protocol = "All"
$ruleproperties.SourcePortRange = "0-65535"
$ruleproperties.DestinationPortRange = "0-65535"
$ruleproperties.Action = "Allow"
$ruleproperties.SourceAddressPrefix = "*"
$ruleproperties.DestinationAddressPrefix = "*"
$ruleproperties.Priority = "110"
$ruleproperties.Type = "Outbound"
$ruleproperties.Logging = "Enabled"
$aclrule2 = new-object Microsoft.Windows.NetworkController.AclRule
$aclrule2.Properties = $ruleproperties
$aclrule2.ResourceId = "AllowAll_Outbound"
$acllistproperties = new-object Microsoft.Windows.NetworkController.AccessControlListProperties
$acllistproperties.AclRules = @($aclrule1, $aclrule2)
New-NetworkControllerAccessControlList -ResourceId "AllowAll" -Properties $acllistproperties -ConnectionUri <NC REST FQDN>
注
ネットワーク コントローラーの Windows PowerShell コマンド リファレンスは、 ネットワーク コントローラーコマンドレットにあります。
ネットワーク セキュリティ グループを使用してサブネットのトラフィックを制限する
この例では、192.168.0.0/24 サブネット内の仮想マシン (VM) が相互に通信できないようにするネットワーク セキュリティ グループを作成します。 この種類のネットワーク セキュリティ グループは、攻撃者がサブネット内で横方向に拡散する能力を制限しつつ、VM がサブネット外からのリクエストを受信したり、他のサブネット上の他のサービスと通信したりすることを可能にするのに役立ちます。
発信元 IP | 宛先 IP | プロトコル | 発信元ポート | 宛先ポート | 通信方向 | アクション | 優先順位 |
---|---|---|---|---|---|---|---|
192.168.0.1 | * | すべて | * | * | 受信 | 許可 | 100 |
* | 192.168.0.1 | すべて | * | * | 送信 | 許可 | 101 |
192.168.0.0/24 | * | すべて | * | * | 受信 | ブロック | 1:02 |
* | 192.168.0.0/24 | すべて | * | * | 送信 | ブロック | 1:03 |
* | * | すべて | * | * | 受信 | 許可 | 104 |
* | * | すべて | * | * | 送信 | 許可 | 105 |
リソース ID Subnet-192-168-0-0 で識別される、以下のサンプル スクリプトによって作成されたネットワーク セキュリティ グループを、"192.168.0.0/24" サブネット アドレスを使用する仮想ネットワーク サブネットに適用できるようになりました。 その仮想ネットワーク サブネットに接続されているネットワーク インターフェイスには、上記のネットワーク セキュリティ グループ ルールが自動的に適用されます。
以下は、Network Controller REST API を使用して、このネットワーク セキュ リティ グループを作成するスクリプトの例です。
import-module networkcontroller
$ncURI = "https://mync.contoso.local"
$aclrules = @()
$ruleproperties = new-object Microsoft.Windows.NetworkController.AclRuleProperties
$ruleproperties.Protocol = "All"
$ruleproperties.SourcePortRange = "0-65535"
$ruleproperties.DestinationPortRange = "0-65535"
$ruleproperties.Action = "Allow"
$ruleproperties.SourceAddressPrefix = "192.168.0.1"
$ruleproperties.DestinationAddressPrefix = "*"
$ruleproperties.Priority = "100"
$ruleproperties.Type = "Inbound"
$ruleproperties.Logging = "Enabled"
$aclrule = new-object Microsoft.Windows.NetworkController.AclRule
$aclrule.Properties = $ruleproperties
$aclrule.ResourceId = "AllowRouter_Inbound"
$aclrules += $aclrule
$ruleproperties = new-object Microsoft.Windows.NetworkController.AclRuleProperties
$ruleproperties.Protocol = "All"
$ruleproperties.SourcePortRange = "0-65535"
$ruleproperties.DestinationPortRange = "0-65535"
$ruleproperties.Action = "Allow"
$ruleproperties.SourceAddressPrefix = "*"
$ruleproperties.DestinationAddressPrefix = "192.168.0.1"
$ruleproperties.Priority = "101"
$ruleproperties.Type = "Outbound"
$ruleproperties.Logging = "Enabled"
$aclrule = new-object Microsoft.Windows.NetworkController.AclRule
$aclrule.Properties = $ruleproperties
$aclrule.ResourceId = "AllowRouter_Outbound"
$aclrules += $aclrule
$ruleproperties = new-object Microsoft.Windows.NetworkController.AclRuleProperties
$ruleproperties.Protocol = "All"
$ruleproperties.SourcePortRange = "0-65535"
$ruleproperties.DestinationPortRange = "0-65535"
$ruleproperties.Action = "Deny"
$ruleproperties.SourceAddressPrefix = "192.168.0.0/24"
$ruleproperties.DestinationAddressPrefix = "*"
$ruleproperties.Priority = "102"
$ruleproperties.Type = "Inbound"
$ruleproperties.Logging = "Enabled"
$aclrule = new-object Microsoft.Windows.NetworkController.AclRule
$aclrule.Properties = $ruleproperties
$aclrule.ResourceId = "DenySubnet_Inbound"
$aclrules += $aclrule
$ruleproperties = new-object Microsoft.Windows.NetworkController.AclRuleProperties
$ruleproperties.Protocol = "All"
$ruleproperties.SourcePortRange = "0-65535"
$ruleproperties.DestinationPortRange = "0-65535"
$ruleproperties.Action = "Deny"
$ruleproperties.SourceAddressPrefix = "*"
$ruleproperties.DestinationAddressPrefix = "192.168.0.0/24"
$ruleproperties.Priority = "103"
$ruleproperties.Type = "Outbound"
$ruleproperties.Logging = "Enabled"
$aclrule = new-object Microsoft.Windows.NetworkController.AclRule
$aclrule.Properties = $ruleproperties
$aclrule.ResourceId = "DenySubnet_Outbound"
$ruleproperties = new-object Microsoft.Windows.NetworkController.AclRuleProperties
$ruleproperties.Protocol = "All"
$ruleproperties.SourcePortRange = "0-65535"
$ruleproperties.DestinationPortRange = "0-65535"
$ruleproperties.Action = "Allow"
$ruleproperties.SourceAddressPrefix = "*"
$ruleproperties.DestinationAddressPrefix = "*"
$ruleproperties.Priority = "104"
$ruleproperties.Type = "Inbound"
$ruleproperties.Logging = "Enabled"
$aclrule = new-object Microsoft.Windows.NetworkController.AclRule
$aclrule.Properties = $ruleproperties
$aclrule.ResourceId = "AllowAll_Inbound"
$aclrules += $aclrule
$ruleproperties = new-object Microsoft.Windows.NetworkController.AclRuleProperties
$ruleproperties.Protocol = "All"
$ruleproperties.SourcePortRange = "0-65535"
$ruleproperties.DestinationPortRange = "0-65535"
$ruleproperties.Action = "Allow"
$ruleproperties.SourceAddressPrefix = "*"
$ruleproperties.DestinationAddressPrefix = "*"
$ruleproperties.Priority = "105"
$ruleproperties.Type = "Outbound"
$ruleproperties.Logging = "Enabled"
$aclrule = new-object Microsoft.Windows.NetworkController.AclRule
$aclrule.Properties = $ruleproperties
$aclrule.ResourceId = "AllowAll_Outbound"
$aclrules += $aclrule
$acllistproperties = new-object Microsoft.Windows.NetworkController.AccessControlListProperties
$acllistproperties.AclRules = $aclrules
New-NetworkControllerAccessControlList -ResourceId "Subnet-192-168-0-0" -Properties $acllistproperties -ConnectionUri $ncURI
ネットワーク セキュリティ グループをネットワーク インターフェイスに追加する
ネットワーク セキュリティ グループを作成して仮想サブネットに割り当てた後、仮想サブネット上のデフォルトのネットワーク セキュリティ グループを個々のネットワーク インターフェイス用の特定のネットワーク セキュリティ グループで上書きする場合があります。 Windows Server 2019 Datacenter からは、SDN 仮想ネットワークだけでなく、SDN 論理ネットワークに接続されたネットワーク インターフェイスにも特定のネットワーク セキュリティ グループを直接適用できるようになりました。 ネットワーク インターフェイスに接続された仮想サブネットにネットワーク セキュリティー グループが設定されている場合、両方のネットワーク セキュリティー グループが適用され、ネットワーク インターフェイスのネットワーク セキュリティー グループが仮想サブネットのネットワーク セキュリティー グループよりも優先されます。
この例では、仮想ネットワークにネットワーク セキュリティ グループを追加する方法を示します。
ヒント
また、ネットワーク インターフェイスの作成と同時にネットワーク セキュリティー グループを追加できます。
ネットワーク セキュリティ グループを追加するネットワーク インターフェイスを取得または作成します。
$nic = get-networkcontrollernetworkinterface -ConnectionUri $uri -ResourceId "MyVM_Ethernet1"
ネットワーク インターフェイスに追加するネットワーク セキュリティ グループを取得または作成します。
$acl = get-networkcontrolleraccesscontrollist -ConnectionUri $uri -ResourceId "AllowAllACL"
ネットワーク セキュリティ グループをネットワーク インターフェイスの AccessControlList プロパティに割り当てます。
$nic.properties.ipconfigurations[0].properties.AccessControlList = $acl
ネットワーク コントローラーにネットワーク インターフェイスを追加します。
new-networkcontrollernetworkinterface -ConnectionUri $uri -Properties $nic.properties -ResourceId $nic.resourceid
ネットワーク インターフェイスから ネットワーク セキュリティ グループを削除する
この例では、ネットワーク インターフェイスから ネットワーク セキュリティ グループを削除する方法を説明します。 ネットワーク セキュリティ グループを削除すると、ネットワーク インターフェイスにデフォルトのルールが適用されます。 既定のルール セットでは、すべての送信トラフィックが許可されますが、すべての受信トラフィックはブロックされます。 すべての受信トラフィックを許可する場合は、前の 例 に従って、すべての受信トラフィックとすべての送信トラフィックを許可するネットワーク セキュリティ グループを追加する必要があります。
ネットワーク セキュリティ グループから削除するネットワーク インターフェイスを取得します。
$nic = get-networkcontrollernetworkinterface -ConnectionUri $uri -ResourceId "MyVM_Ethernet1"
ipConfiguration の AccessControlList プロパティに $null を割り当てます。
$nic.properties.ipconfigurations[0].properties.AccessControlList = $null
ネットワーク コントローラーにネットワーク インターフェイス オブジェクトを追加します。
new-networkcontrollernetworkinterface -ConnectionUri $uri -Properties $nic.properties -ResourceId $nic.resourceid
ファイアウォールの監査
データセンター ファイアウォールのファイアウォール監査機能は、SDN ファイアウォール ルールが処理したフローを記録します。 ログが有効なすべてのネットワーク セキュリティ グループが記録されます。 ログ ファイルは、 Azure Network Watcher フロー ログと一致する構文である必要があります。 これらのログは、診断に使用したり、後で分析するためにアーカイブしたりすることができます。
これは、ホスト マシンでファイアウォール監査が有効になっているスクリプト例です。? 最初に変数を更新し、 ネットワーク コントローラー がデプロイされた Azure ローカル インスタンスでこれを実行します。
$logpath = "C:\test\log1"
$servers = @("sa18n22-2", "sa18n22-3", "sa18n22-4")
$uri = "https://sa18n22sdn.sa18.nttest.microsoft.com"
# Create log directories on the hosts
invoke-command -Computername $servers {
param(
$Path
)
mkdir $path -force
} -argumentlist $LogPath
# Set firewall auditing settings on Network Controller
$AuditProperties = new-object Microsoft.Windows.NetworkController.AuditingSettingsProperties
$AuditProperties.OutputDirectory = $logpath
set-networkcontrollerauditingsettingsconfiguration -connectionuri $uri -properties $AuditProperties -force | out-null
# Enable logging on each server
$servers = get-networkcontrollerserver -connectionuri $uri
foreach ($s in $servers) {
$s.properties.AuditingEnabled = @("Firewall")
new-networkcontrollerserver -connectionuri $uri -resourceid $s.resourceid -properties $s.properties -force | out-null
}
有効にすると、各ホストの指定したディレクトリに新しいファイルが 1 時間ごとに 1 つずつ追加されます。 これらのファイルを定期的に処理し、ホストから削除する必要があります。 現在のファイルは長さが 0 で、次の 1 時間にフラッシュされるまでロックされます。
PS C:\test\log1> dir
Directory: C:\test\log1
Mode LastWriteTime Length Name
---- ------------- ------ ----
-a---- 7/19/2018 6:28 AM 17055 SdnFirewallAuditing.d8b3b697-5355-40e2-84d2-1bf2f0e0dc4a.20180719TL122803093.json
-a---- 7/19/2018 7:28 AM 7880 SdnFirewallAuditing.d8b3b697-5355-40e2-84d2-1bf2f0e0dc4a.20180719TL132803173.json
-a---- 7/19/2018 8:28 AM 7867 SdnFirewallAuditing.d8b3b697-5355-40e2-84d2-1bf2f0e0dc4a.20180719TL142803264.json
-a---- 7/19/2018 9:28 AM 10949 SdnFirewallAuditing.d8b3b697-5355-40e2-84d2-1bf2f0e0dc4a.20180719TL152803360.json
-a---- 7/19/2018 9:28 AM 0 SdnFirewallAuditing.d8b3b697-5355-40e2-84d2-1bf2f0e0dc4a.20180719TL162803464.json
これらのファイルには、フロー イベントのシーケンスが含まれています。次に例を示します。
{
"records": [
{
"properties":{
"Version":"1.0",
"flows":[
{
"flows":[
{
"flowTuples":["1531963580,192.122.0.22,192.122.255.255,138,138,U,I,A"],
"portId":"9",
"portName":"7290436D-0422-498A-8EB8-C6CF5115DACE"
}
],
"rule":"Allow_Inbound"
}
]
},
"operationName":"NetworkSecurityGroupFlowEvents",
"resourceId":"a0a0a0a0-bbbb-cccc-dddd-e1e1e1e1e1e1",
"time":"20180719:L012620622",
"category":"NetworkSecurityGroupFlowEvent",
"systemId":"d8b3b697-5355-40e2-84d2-1bf2f0e0dc4a"
},
ログ記録は、ログ記録が有効に設定されているルールに対してのみ行われます。次に例を示します。
{
"Tags": null,
"ResourceRef": "/accessControlLists/AllowAll",
"InstanceId": "4a63e1a5-3264-4986-9a59-4e77a8b107fa",
"Etag": "W/\"1535a780-0fc8-4bba-a15a-093ecac9b88b\"",
"ResourceMetadata": null,
"ResourceId": "AllowAll",
"Properties": {
"ConfigurationState": null,
"ProvisioningState": "Succeeded",
"AclRules": [
{
"ResourceMetadata": null,
"ResourceRef": "/accessControlLists/AllowAll/aclRules/AllowAll_Inbound",
"InstanceId": "ba8710a8-0f01-422b-9038-d1f2390645d7",
"Etag": "W/\"1535a780-0fc8-4bba-a15a-093ecac9b88b\"",
"ResourceId": "AllowAll_Inbound",
"Properties": {
"Protocol": "All",
"SourcePortRange": "0-65535",
"DestinationPortRange": "0-65535",
"Action": "Allow",
"SourceAddressPrefix": "*",
"DestinationAddressPrefix": "*",
"Priority": "101",
"Description": null,
"Type": "Inbound",
"Logging": "Enabled",
"ProvisioningState": "Succeeded"
}
},
{
"ResourceMetadata": null,
"ResourceRef": "/accessControlLists/AllowAll/aclRules/AllowAll_Outbound",
"InstanceId": "068264c6-2186-4dbc-bbe7-f504c6f47fa8",
"Etag": "W/\"1535a780-0fc8-4bba-a15a-093ecac9b88b\"",
"ResourceId": "AllowAll_Outbound",
"Properties": {
"Protocol": "All",
"SourcePortRange": "0-65535",
"DestinationPortRange": "0-65535",
"Action": "Allow",
"SourceAddressPrefix": "*",
"DestinationAddressPrefix": "*",
"Priority": "110",
"Description": null,
"Type": "Outbound",
"Logging": "Enabled",
"ProvisioningState": "Succeeded"
}
}
],
"IpConfigurations": [
],
"Subnets": [
{
"ResourceMetadata": null,
"ResourceRef": "/virtualNetworks/10_0_1_0/subnets/Subnet1",
"InstanceId": "00000000-0000-0000-0000-000000000000",
"Etag": null,
"ResourceId": null,
"Properties": null
}
]
}
}
次のステップ
関連情報については、以下をご覧ください。