> For the complete documentation index, see [llms.txt](https://cortex-docs.paloaltonetworks.com/llms.txt). Markdown versions of documentation pages are available by appending `.md` to page URLs; this page is available as [Markdown](https://cortex-docs.paloaltonetworks.com/appsec-rules/iac-security/public-exposure/appsec2-azure-31.md).

# Azure Virtual Network subnet is not configured with a Network Security Group misconfiguration detect

## Rule Details

|                        |                                      |
| ---------------------- | ------------------------------------ |
| Cortex AppSec Rule ID  | APPSEC2\_AZURE\_31                   |
| Category - Subcategory | Public Exposure - VPC VCN VNet       |
| Provider               | AZURE                                |
| Severity               | LOW                                  |
| Framework              | Terraform, Terraform Plan            |
| Mapped CSPM/KSPM Rule  | 4780e61a-51ac-46ff-822c-421a97b6c96e |

## Impact

This rule checks whether a Virtual Network (VNET) subnet in the Azure environment is configured with a Network Security Group (NSG). The NSG includes rules to allow or deny traffic to a subnet, providing security for the VNET. If a subnet is not associated with an NSG, it may be exposed to potential cybersecurity threats. Therefore, not having a NSG for a VNET subnet is considered a security risk.

## How to Fix

*Resource:* azurerm\_subnet, azurerm\_network\_security\_group, azurerm\_subnet\_network\_security\_group\_association

* *Arguments:* name, subnet\_id

To fix this issue, you need to associate your Azure Virtual Network (VNet) subnet with a Network Security Group (NSG).

The above configuration shows how to create an NSG and attach it to a subnet. Applying policies via Network Security Groups helps to restrict inbound, outbound traffic that is operating to and from resources connected to Azure VNets.

## By associating an NSG to a subnet, you define rules for inbound and outbound traffic. This improves security by ensuring that only allowed traffic is permitted into and out of the subnet. \[source,go]

resource "azurerm\_network\_security\_group" "example" { name = "example-nsg" location = azurerm\_resource\_group.example.location resource\_group\_name = azurerm\_resource\_group.example.name }

## resource "azurerm\_subnet\_network\_security\_group\_association" "example" { subnet\_id = azurerm\_subnet.example.id network\_security\_group\_id = azurerm\_network\_security\_group.example.id }


---

# Agent Instructions
This documentation is published with GitBook. GitBook is the documentation platform designed so that both humans and AI agents can read, navigate, and reason over technical content effectively. Learn more at gitbook.com.

## Querying This Documentation
If you need additional information that is not directly available in this page, you can query the documentation dynamically by asking a question.

Perform an HTTP GET request on the current page URL with the `ask` query parameter, and the optional `goal` query parameter:

```
GET https://cortex-docs.paloaltonetworks.com/appsec-rules/iac-security/public-exposure/appsec2-azure-31.md?ask=<question>&goal=<endgoal>
```

`ask` is the immediate question: it should be specific, self-contained, and written in natural language.
`goal` is optional and describes the broader end goal you are ultimately trying to accomplish on behalf of the user. GitBook uses it to tailor the answer towards what is most useful for that goal.

The response will contain a direct answer to the question and relevant excerpts and sources from the documentation.

Use this mechanism when the answer is not explicitly present in the current page, you need clarification or additional context, or you want to retrieve related documentation sections.
