Network Watchers - Get VM Security Rules

Gets the configured and effective security group rules on the specified VM.

POST https://management.azure.com/subscriptions/{subscriptionId}/resourceGroups/{resourceGroupName}/providers/Microsoft.Network/networkWatchers/{networkWatcherName}/securityGroupView?api-version=2023-09-01

URI Parameters

Name In Required Type Description
networkWatcherName
path True

string

The name of the network watcher.

resourceGroupName
path True

string

The name of the resource group.

subscriptionId
path True

string

The subscription credentials which uniquely identify the Microsoft Azure subscription. The subscription ID forms part of the URI for every service call.

api-version
query True

string

Client API version.

Request Body

Name Required Type Description
targetResourceId True

string

ID of the target VM.

Responses

Name Type Description
200 OK

SecurityGroupViewResult

Request successful. The operation returns security group rules on the VM.

202 Accepted

SecurityGroupViewResult

Accepted and the operation will complete asynchronously.

Other Status Codes

ErrorResponse

Error response describing why the operation failed.

Security

azure_auth

Azure Active Directory OAuth2 Flow.

Type: oauth2
Flow: implicit
Authorization URL: https://login.microsoftonline.com/common/oauth2/authorize

Scopes

Name Description
user_impersonation impersonate your user account

Examples

Get security group view

Sample Request

POST https://management.azure.com/subscriptions/subid/resourceGroups/rg1/providers/Microsoft.Network/networkWatchers/nw1/securityGroupView?api-version=2023-09-01

{
  "targetResourceId": "/subscriptions/subid/resourceGroups/rg2/providers/Microsoft.Compute/virtualMachines/vm1"
}

Sample Response

{
  "networkInterfaces": [
    {
      "id": "/subscriptions/subid/resourceGroups/rg2/providers/Microsoft.Network/networkInterfaces/nic1",
      "securityRuleAssociations": {
        "subnetAssociation": {
          "id": "/subscriptions/subid/resourceGroups/rg2/providers/Microsoft.Network/virtualNetworks/vnet1/subnets/subnet1",
          "securityRules": [
            {
              "name": "fe_rule",
              "id": "/subscriptions/subid/resourceGroups/rg2/providers/Microsoft.Network/networkSecurityGroups/AppNSG/securityRules/fe_rule",
              "etag": "W/\"00000000-0000-0000-0000-000000000000\"",
              "properties": {
                "provisioningState": "Succeeded",
                "description": "Allow Frontend",
                "protocol": "Tcp",
                "sourcePortRange": "*",
                "destinationPortRange": "*",
                "sourceAddressPrefix": "10.1.0.0/24",
                "destinationAddressPrefix": "*",
                "access": "Allow",
                "priority": 100,
                "direction": "Inbound"
              }
            }
          ]
        },
        "defaultSecurityRules": [
          {
            "name": "AllowVnetInBound",
            "id": "/subscriptions//resourceGroups//providers/Microsoft.Network/networkSecurityGroups//defaultSecurityRules/",
            "properties": {
              "provisioningState": "Succeeded",
              "description": "Allow inbound traffic from all VMs in VNET",
              "protocol": "*",
              "sourcePortRange": "*",
              "destinationPortRange": "*",
              "sourceAddressPrefix": "VirtualNetwork",
              "destinationAddressPrefix": "VirtualNetwork",
              "access": "Allow",
              "priority": 65000,
              "direction": "Inbound"
            }
          }
        ],
        "effectiveSecurityRules": [
          {
            "name": "DefaultOutboundDenyAll",
            "protocol": "All",
            "sourcePortRange": "0-65535",
            "destinationPortRange": "0-65535",
            "sourceAddressPrefix": "*",
            "destinationAddressPrefix": "*",
            "access": "Deny",
            "priority": 65500,
            "direction": "Outbound"
          }
        ]
      }
    }
  ]
}
Location: https:/management.azure.com/subscriptions/subid/resourceGroups/rg1/providers/Microsoft.Network/networkWatchers/nw1/queryStatus?api-version=2023-09-01
{
  "networkInterfaces": [
    {
      "id": "/subscriptions/subid/resourceGroups/rg2/providers/Microsoft.Network/networkInterfaces/nic1",
      "securityRuleAssociations": {
        "subnetAssociation": {
          "id": "/subscriptions/subid/resourceGroups/rg2/providers/Microsoft.Network/virtualNetworks/vnet1/subnets/subnet1",
          "securityRules": [
            {
              "name": "fe_rule",
              "id": "/subscriptions/subid/resourceGroups/rg2/providers/Microsoft.Network/networkSecurityGroups/AppNSG/securityRules/fe_rule",
              "etag": "W/\"00000000-0000-0000-0000-000000000000\"",
              "properties": {
                "provisioningState": "Succeeded",
                "description": "Allow Frontend",
                "protocol": "Tcp",
                "sourcePortRange": "*",
                "destinationPortRange": "*",
                "sourceAddressPrefix": "10.1.0.0/24",
                "destinationAddressPrefix": "*",
                "access": "Allow",
                "priority": 100,
                "direction": "Inbound"
              }
            }
          ]
        },
        "defaultSecurityRules": [
          {
            "name": "AllowVnetInBound",
            "id": "/subscriptions//resourceGroups//providers/Microsoft.Network/networkSecurityGroups//defaultSecurityRules/",
            "properties": {
              "provisioningState": "Succeeded",
              "description": "Allow inbound traffic from all VMs in VNET",
              "protocol": "*",
              "sourcePortRange": "*",
              "destinationPortRange": "*",
              "sourceAddressPrefix": "VirtualNetwork",
              "destinationAddressPrefix": "VirtualNetwork",
              "access": "Allow",
              "priority": 65000,
              "direction": "Inbound"
            }
          }
        ],
        "effectiveSecurityRules": [
          {
            "name": "DefaultOutboundDenyAll",
            "protocol": "All",
            "sourcePortRange": "0-65535",
            "destinationPortRange": "0-65535",
            "sourceAddressPrefix": "*",
            "destinationAddressPrefix": "*",
            "access": "Deny",
            "priority": 65500,
            "direction": "Outbound"
          }
        ]
      }
    }
  ]
}

Definitions

Name Description
ApplicationSecurityGroup

An application security group in a resource group.

EffectiveNetworkSecurityRule

Effective network security rules.

EffectiveSecurityRuleProtocol

The network protocol this rule applies to.

ErrorDetails

Common error details representation.

ErrorResponse

The error object.

NetworkInterfaceAssociation

Network interface and its custom security rules.

ProvisioningState

The current provisioning state.

SecurityGroupNetworkInterface

Network interface and all its associated security rules.

SecurityGroupViewParameters

Parameters that define the VM to check security groups for.

SecurityGroupViewResult

The information about security rules applied to the specified VM.

SecurityRule

Network security rule.

SecurityRuleAccess

Whether network traffic is allowed or denied.

SecurityRuleAssociations

All security rules associated with the network interface.

SecurityRuleDirection

The direction of the rule. The direction specifies if rule will be evaluated on incoming or outgoing traffic.

SecurityRuleProtocol

Network protocol this rule applies to.

SubnetAssociation

Subnet and it's custom security rules.

ApplicationSecurityGroup

An application security group in a resource group.

Name Type Description
etag

string

A unique read-only string that changes whenever the resource is updated.

id

string

Resource ID.

location

string

Resource location.

name

string

Resource name.

properties.provisioningState

ProvisioningState

The provisioning state of the application security group resource.

properties.resourceGuid

string

The resource GUID property of the application security group resource. It uniquely identifies a resource, even if the user changes its name or migrate the resource across subscriptions or resource groups.

tags

object

Resource tags.

type

string

Resource type.

EffectiveNetworkSecurityRule

Effective network security rules.

Name Type Description
access

SecurityRuleAccess

Whether network traffic is allowed or denied.

destinationAddressPrefix

string

The destination address prefix.

destinationAddressPrefixes

string[]

The destination address prefixes. Expected values include CIDR IP ranges, Default Tags (VirtualNetwork, AzureLoadBalancer, Internet), System Tags, and the asterisk (*).

destinationPortRange

string

The destination port or range.

destinationPortRanges

string[]

The destination port ranges. Expected values include a single integer between 0 and 65535, a range using '-' as separator (e.g. 100-400), or an asterisk (*).

direction

SecurityRuleDirection

The direction of the rule.

expandedDestinationAddressPrefix

string[]

Expanded destination address prefix.

expandedSourceAddressPrefix

string[]

The expanded source address prefix.

name

string

The name of the security rule specified by the user (if created by the user).

priority

integer

The priority of the rule.

protocol

EffectiveSecurityRuleProtocol

The network protocol this rule applies to.

sourceAddressPrefix

string

The source address prefix.

sourceAddressPrefixes

string[]

The source address prefixes. Expected values include CIDR IP ranges, Default Tags (VirtualNetwork, AzureLoadBalancer, Internet), System Tags, and the asterisk (*).

sourcePortRange

string

The source port or range.

sourcePortRanges

string[]

The source port ranges. Expected values include a single integer between 0 and 65535, a range using '-' as separator (e.g. 100-400), or an asterisk (*).

EffectiveSecurityRuleProtocol

The network protocol this rule applies to.

Name Type Description
All

string

Tcp

string

Udp

string

ErrorDetails

Common error details representation.

Name Type Description
code

string

Error code.

message

string

Error message.

target

string

Error target.

ErrorResponse

The error object.

Name Type Description
error

ErrorDetails

Error
The error details object.

NetworkInterfaceAssociation

Network interface and its custom security rules.

Name Type Description
id

string

Network interface ID.

securityRules

SecurityRule[]

Collection of custom security rules.

ProvisioningState

The current provisioning state.

Name Type Description
Deleting

string

Failed

string

Succeeded

string

Updating

string

SecurityGroupNetworkInterface

Network interface and all its associated security rules.

Name Type Description
id

string

ID of the network interface.

securityRuleAssociations

SecurityRuleAssociations

All security rules associated with the network interface.

SecurityGroupViewParameters

Parameters that define the VM to check security groups for.

Name Type Description
targetResourceId

string

ID of the target VM.

SecurityGroupViewResult

The information about security rules applied to the specified VM.

Name Type Description
networkInterfaces

SecurityGroupNetworkInterface[]

List of network interfaces on the specified VM.

SecurityRule

Network security rule.

Name Type Description
etag

string

A unique read-only string that changes whenever the resource is updated.

id

string

Resource ID.

name

string

The name of the resource that is unique within a resource group. This name can be used to access the resource.

properties.access

SecurityRuleAccess

The network traffic is allowed or denied.

properties.description

string

A description for this rule. Restricted to 140 chars.

properties.destinationAddressPrefix

string

The destination address prefix. CIDR or destination IP range. Asterisk '*' can also be used to match all source IPs. Default tags such as 'VirtualNetwork', 'AzureLoadBalancer' and 'Internet' can also be used.

properties.destinationAddressPrefixes

string[]

The destination address prefixes. CIDR or destination IP ranges.

properties.destinationApplicationSecurityGroups

ApplicationSecurityGroup[]

The application security group specified as destination.

properties.destinationPortRange

string

The destination port or range. Integer or range between 0 and 65535. Asterisk '*' can also be used to match all ports.

properties.destinationPortRanges

string[]

The destination port ranges.

properties.direction

SecurityRuleDirection

The direction of the rule. The direction specifies if rule will be evaluated on incoming or outgoing traffic.

properties.priority

integer

The priority of the rule. The value can be between 100 and 4096. The priority number must be unique for each rule in the collection. The lower the priority number, the higher the priority of the rule.

properties.protocol

SecurityRuleProtocol

Network protocol this rule applies to.

properties.provisioningState

ProvisioningState

The provisioning state of the security rule resource.

properties.sourceAddressPrefix

string

The CIDR or source IP range. Asterisk '*' can also be used to match all source IPs. Default tags such as 'VirtualNetwork', 'AzureLoadBalancer' and 'Internet' can also be used. If this is an ingress rule, specifies where network traffic originates from.

properties.sourceAddressPrefixes

string[]

The CIDR or source IP ranges.

properties.sourceApplicationSecurityGroups

ApplicationSecurityGroup[]

The application security group specified as source.

properties.sourcePortRange

string

The source port or range. Integer or range between 0 and 65535. Asterisk '*' can also be used to match all ports.

properties.sourcePortRanges

string[]

The source port ranges.

type

string

The type of the resource.

SecurityRuleAccess

Whether network traffic is allowed or denied.

Name Type Description
Allow

string

Deny

string

SecurityRuleAssociations

All security rules associated with the network interface.

Name Type Description
defaultSecurityRules

SecurityRule[]

Collection of default security rules of the network security group.

effectiveSecurityRules

EffectiveNetworkSecurityRule[]

Collection of effective security rules.

networkInterfaceAssociation

NetworkInterfaceAssociation

Network interface and it's custom security rules.

subnetAssociation

SubnetAssociation

Subnet and it's custom security rules.

SecurityRuleDirection

The direction of the rule. The direction specifies if rule will be evaluated on incoming or outgoing traffic.

Name Type Description
Inbound

string

Outbound

string

SecurityRuleProtocol

Network protocol this rule applies to.

Name Type Description
*

string

Ah

string

Esp

string

Icmp

string

Tcp

string

Udp

string

SubnetAssociation

Subnet and it's custom security rules.

Name Type Description
id

string

Subnet ID.

securityRules

SecurityRule[]

Collection of custom security rules.