Skip to content

Commit 4012680

Browse files
Merge pull request #232461 from halkazwini/nw-automate-nsg
Network Watcher: Updates: Automate NSG auditing with Azure Network Watcher Security group view
2 parents 748502c + 6fd9eef commit 4012680

File tree

1 file changed

+18
-16
lines changed

1 file changed

+18
-16
lines changed

articles/network-watcher/network-watcher-nsg-auditing-powershell.md

Lines changed: 18 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -1,35 +1,37 @@
11
---
2-
title: Automate NSG auditing - Security group view
2+
title: Automate NSG auditing with security group view
33
titleSuffix: Azure Network Watcher
44
description: This page provides instructions on how to configure auditing of a Network Security Group
55
services: network-watcher
66
author: halkazwini
77
ms.service: network-watcher
88
ms.topic: how-to
99
ms.workload: infrastructure-services
10-
ms.date: 03/01/2022
10+
ms.date: 03/28/2023
1111
ms.author: halkazwini
12-
ms.custom: engagement-fy23
12+
ms.custom: template-how-to, engagement-fy23
1313
---
1414

15-
# Automate NSG auditing with Azure Network Watcher Security group view
15+
# Automate NSG auditing with Azure Network Watcher security group view
1616

17-
Customers are often faced with the challenge of verifying the security posture of their infrastructure. This challenge is no different for their VMs in Azure. It is important to have a similar security profile based on the Network Security Group (NSG) rules applied. Using the Security Group View, you can now get the list of rules applied to a VM within an NSG. You can define a golden NSG security profile and initiate Security Group View on a weekly cadence and compare the output to the golden profile and create a report. This way you can identify with ease all the VMs that do not conform to the prescribed security profile.
17+
> [!NOTE]
18+
> The security group view API is no longer being maintained and will be deprecated soon. Please use the [Effective security rules feature](./network-watcher-security-group-view-overview.md) which provides the same functionality.
1819
19-
If you are unfamiliar with Network Security Groups, see [Network Security Overview](../virtual-network/network-security-groups-overview.md).
20+
Customers are often faced with the challenge of verifying the security posture of their infrastructure. This challenge is no different for their VMs in Azure. It's important to have a similar security profile based on the Network Security Group (NSG) rules applied. Using the Security Group View, you can now get the list of rules applied to a VM within an NSG. You can define a golden NSG security profile and initiate Security Group View on a weekly cadence and compare the output to the golden profile and create a report. This way you can identify with ease all the VMs that don't conform to the prescribed security profile.
2021

22+
To learn more about network security groups, see [Network security groups overview](../virtual-network/network-security-groups-overview.md).
2123

2224
[!INCLUDE [updated-for-az](../../includes/updated-for-az.md)]
2325

24-
## Before you begin
26+
## Prerequisites
2527

26-
In this scenario, you compare a known good baseline to the security group view results returned for a virtual machine.
28+
- If you don't have an Azure account with an active subscription, [create one for free](https://azure.microsoft.com/free/?WT.mc_id=A261C142F).
29+
- A virtual machine (VM).
2730

28-
This scenario assumes you have already followed the steps in [Create a Network Watcher](network-watcher-create.md) to create a Network Watcher. The scenario also assumes that a Resource Group with a valid virtual machine exists to be used.
2931

3032
## Scenario
3133

32-
The scenario covered in this article gets the security group view for a virtual machine.
34+
In this scenario, you compare a known good baseline to the security group view results returned for a virtual machine.
3335

3436
In this scenario, you will:
3537

@@ -109,7 +111,7 @@ The first step in this example is to work with an existing baseline. The followi
109111

110112
## Convert rule set to PowerShell objects
111113

112-
In this step, we are reading a json file that was created earlier with the rules that are expected to be on the Network Security Group for this example.
114+
In this step, we're reading a json file that was created earlier with the rules that are expected to be on the Network Security Group for this example.
113115

114116
```powershell
115117
$nsgbaserules = Get-Content -Path C:\temp\testvm1-nsg.json | ConvertFrom-Json
@@ -123,7 +125,7 @@ The next step is to retrieve the Network Watcher instance. The `$networkWatcher`
123125
$networkWatcher = Get-AzResource | Where {$_.ResourceType -eq "Microsoft.Network/networkWatchers" -and $_.Location -eq "WestCentralUS" }
124126
```
125127

126-
## Get a VM
128+
## Retrieve virtual machine configuration
127129

128130
A virtual machine is required to run the `Get-AzNetworkWatcherSecurityGroupView` cmdlet against. The following example gets a VM object.
129131

@@ -139,9 +141,9 @@ The next step is to retrieve the security group view result. This result is comp
139141
$secgroup = Get-AzNetworkWatcherSecurityGroupView -NetworkWatcher $networkWatcher -TargetVirtualMachineId $VM.Id
140142
```
141143

142-
## Analyzing the results
144+
## Analyze the results
143145

144-
The response is grouped by Network interfaces. The different types of rules returned are effective and default security rules. The result is further broken down by how it is applied, either on a subnet or a virtual NIC.
146+
The response is grouped by Network interfaces. The different types of rules returned are effective and default security rules. The result is further broken down by how it's applied, either on a subnet or a virtual NIC.
145147

146148
The following PowerShell script compares the results of the Security Group View to an existing output of an NSG. The following example is a simple example of how the results can be compared with `Compare-Object` cmdlet.
147149

@@ -151,7 +153,7 @@ Compare-Object -ReferenceObject $nsgbaserules `
151153
-Property Name,Description,Protocol,SourcePortRange,DestinationPortRange,SourceAddressPrefix,DestinationAddressPrefix,Access,Priority,Direction
152154
```
153155

154-
The following example is the result. You can see two of the rules that were in the first rule set were not present in the comparison.
156+
The following example is the result. You can see two of the rules that were in the first rule set weren't present in the comparison.
155157

156158
```
157159
Name : My2ndRuleDoNotDelete
@@ -181,4 +183,4 @@ SideIndicator : <=
181183

182184
## Next steps
183185

184-
If settings have been changed, see [Manage Network Security Groups](../virtual-network/manage-network-security-group.md) to track down the network security group and security rules that are in question.
186+
See [Create, change, or delete a network security group](../virtual-network/manage-network-security-group.md) to track down the network security group and security rules that are in question.

0 commit comments

Comments
 (0)