|
| 1 | +--- |
| 2 | +title: Quickstart - Create a network security perimeter - Azure CLI |
| 3 | +description: Learn how to create a network security perimeter for an Azure resource using Azure CLI. This example demonstrates the creation of a network security perimeter for an Azure Key Vault. |
| 4 | +author: mbender-ms |
| 5 | +ms.author: mbender |
| 6 | +ms.service: azure-private-link |
| 7 | +ms.topic: quickstart |
| 8 | +ms.date: 11/06/2024 |
| 9 | +#CustomerIntent: As a network administrator, I want to create a network security perimeter for an Azure resource using Azure CLI, so that I can control the network traffic to and from the resource. |
| 10 | +--- |
| 11 | + |
| 12 | +# Quickstart: Create a network security perimeter - Azure CLI |
| 13 | + |
| 14 | +Get started with network security perimeter by creating a network security perimeter for an Azure key vault using Azure CLI. A [network security perimeter](network-security-perimeter-concepts.md) allows [Azure PaaS (PaaS)](./network-security-perimeter-concepts.md#onboarded-private-link-resources)resources to communicate within an explicit trusted boundary. Next, You create and update a PaaS resources association in a network security perimeter profile. Then you create and update network security perimeter access rules. When you're finished, you delete all resources created in this quickstart. |
| 15 | + |
| 16 | +[!INCLUDE [network-security-perimeter-preview-message](../../includes/network-security-perimeter-preview-message.md)] |
| 17 | + |
| 18 | +## Prerequisites |
| 19 | + |
| 20 | +- An Azure account with an active subscription. [Create an account for free](https://azure.microsoft.com/free/?WT.mc_id=A261C142F). |
| 21 | + |
| 22 | +[!INCLUDE [network-security-perimeter-add-preview](../../includes/network-security-perimeter-add-preview.md)] |
| 23 | + |
| 24 | +- The [latest Azure CLI](/cli/azure/install-azure-cli), or you can use Azure Cloud Shell in the portal. |
| 25 | + - This article **requires version 2.38.0 or later** of the Azure CLI. If using Azure Cloud Shell, the latest version is already installed. |
| 26 | +- After upgrading to the latest version of Azure CLI, import the network security perimeter commands using `az extension add --name nsp`. |
| 27 | + |
| 28 | +[!INCLUDE [azure-cli-prepare-your-environment.md](~/reusable-content/azure-cli/azure-cli-prepare-your-environment-no-header.md)] |
| 29 | + |
| 30 | + |
| 31 | + |
| 32 | + |
| 33 | +## Connect to your Azure account and select your subscription |
| 34 | + |
| 35 | +To get started, connect to [Azure Cloud Shell](https://shell.azure.com) or use your local CLI environment. |
| 36 | + |
| 37 | +1. If using Azure Cloud Shell, sign in and select your subscription. |
| 38 | +1. If you installed CLI locally, sign in with the following command: |
| 39 | + |
| 40 | + ```azurecli-interactive |
| 41 | + # Sign in to your Azure account |
| 42 | + az login |
| 43 | + ``` |
| 44 | +
|
| 45 | +1. Once in your shell, select your active subscription locally with the following command: |
| 46 | +
|
| 47 | + ```azurecli-interactive |
| 48 | + # List all subscriptions |
| 49 | + az account set --subscription <Azure Subscription> |
| 50 | +
|
| 51 | + # Re-register the Microsoft.Network resource provider |
| 52 | + az provider register --namespace Microsoft.Network |
| 53 | + ``` |
| 54 | + |
| 55 | +## Create a resource group and key vault |
| 56 | +
|
| 57 | +Before you can create a network security perimeter, you have to create a resource group and a key vault resource. |
| 58 | +This example creates a resource group named **resource-group** in the WestCentralUS location and a key vault named **key-vault-YYYYDDMM** in the resource group with the following commands: |
| 59 | +
|
| 60 | +```azurecli-interactive |
| 61 | +az group create \ |
| 62 | + --name resource-group \ |
| 63 | + --location westcentralus |
| 64 | +
|
| 65 | +# Create a key vault using a datetime value to ensure a unique name |
| 66 | +
|
| 67 | +key_vault_name="key-vault-$(date +%s)" |
| 68 | +az keyvault create \ |
| 69 | + --name $key_vault_name \ |
| 70 | + --resource-group resource-group \ |
| 71 | + --location westcentralus \ |
| 72 | + --query 'id' \ |
| 73 | + --output tsv |
| 74 | +``` |
| 75 | + |
| 76 | +## Create a network security perimeter |
| 77 | + |
| 78 | +In this step, create a network security perimeter with the `az network perimeter create` command. |
| 79 | + |
| 80 | +> [!NOTE] |
| 81 | +> Please do not put any personal identifiable or sensitive data in the network security perimeter rules or other network security perimeter configuration. |
| 82 | +
|
| 83 | +```azurecli-interactive |
| 84 | +az network perimeter create\ |
| 85 | + --name network-security-perimeter \ |
| 86 | + --resource-group resource-group \ |
| 87 | + -l westcentralus |
| 88 | +``` |
| 89 | + |
| 90 | +## Create and update PaaS resources’ association with a new profile |
| 91 | + |
| 92 | +In this step, you create a new profile and associate the PaaS resource, the Azure Key Vault with the profile using the `az network perimeter profile create` and `az network perimeter association create` commands. |
| 93 | + |
| 94 | +> [!NOTE] |
| 95 | +> For the `--private-link-resource` and `--profile` parameter values, replace `<PaaSArmId>` and `<networkSecurityPerimeterProfileId>` with the values for the key vault and the profile ID, respectively. |
| 96 | +
|
| 97 | +1. Create a new profile for your network security perimeter with the following command: |
| 98 | + |
| 99 | + ```azurecli-interactive |
| 100 | + # Create a new profile |
| 101 | + az network perimeter profile create \ |
| 102 | + --name network-perimeter-profile \ |
| 103 | + --resource-group resource-group \ |
| 104 | + --perimeter-name network-security-perimeter |
| 105 | +
|
| 106 | + ``` |
| 107 | +2. Associate the Azure Key Vault (PaaS resource) with the network security perimeter profile with the following commands. |
| 108 | +
|
| 109 | + ```azurecli-interactive |
| 110 | + |
| 111 | + # Get key vault id |
| 112 | + az keyvault show \ |
| 113 | + --name $key_vault_name \ |
| 114 | + --resource-group resource-group \ |
| 115 | + --query 'id' |
| 116 | + |
| 117 | + # Get the profile id |
| 118 | + az network perimeter profile show \ |
| 119 | + --name network-perimeter-profile \ |
| 120 | + --resource-group resource-group \ |
| 121 | + --perimeter-name network-security-perimeter |
| 122 | + |
| 123 | + # Associate the Azure Key Vault with the network security perimeter profile |
| 124 | + # Replace <PaaSArmId> and <networkSecurityPerimeterProfileId> with the ID values for your key vault and profile |
| 125 | + az network perimeter association create \ |
| 126 | + --name network-perimeter-association \ |
| 127 | + --perimeter-name network-security-perimeter \ |
| 128 | + --resource-group resource-group \ |
| 129 | + --access-mode Learning \ |
| 130 | + --private-link-resource "{id:<PaaSArmId>}" \ |
| 131 | + --profile "{id:<networkSecurityPerimeterProfileId>}" |
| 132 | + |
| 133 | + ``` |
| 134 | + |
| 135 | +1. Update association by changing the access mode to **enforced** with the `az network perimeter association create` command as follows: |
| 136 | +
|
| 137 | + ```azurecli-interactive |
| 138 | + az network perimeter association create \ |
| 139 | + --name network-perimeter-association \ |
| 140 | + --perimeter-name network-security-perimeter \ |
| 141 | + --resource-group resource-group \ |
| 142 | + --access-mode Enforced \ |
| 143 | + --private-link-resource "{id:<PaaSArmId>}" \ |
| 144 | + --profile "{id:<networkSecurityPerimeterProfileId>}" |
| 145 | + ``` |
| 146 | + |
| 147 | +## Manage network security perimeter access rules |
| 148 | +
|
| 149 | +In this step, you create, update, and delete a network security perimeter access rules with public IP address prefixes using the `az network perimeter profile access-rule` command. |
| 150 | +
|
| 151 | +1. Create an inbound access rule with a public IP address prefix for the profile created with the following command: |
| 152 | +
|
| 153 | + ```azurecli-interactive |
| 154 | +
|
| 155 | + # Create an inbound access rule |
| 156 | + az network perimeter profile access-rule create \ |
| 157 | + --name access-rule \ |
| 158 | + --profile-name network-perimeter-profile \ |
| 159 | + --perimeter-name network-security-perimeter \ |
| 160 | + --resource-group resource-group \ |
| 161 | + --address-prefixes "[192.0.2.0/24]" |
| 162 | +
|
| 163 | + ``` |
| 164 | +
|
| 165 | +1. Update your inbound access rule with another public IP address prefix with the following command: |
| 166 | +
|
| 167 | + ```azurecli-interactive |
| 168 | + |
| 169 | + # Update the inbound access rule |
| 170 | + az network perimeter profile access-rule create\ |
| 171 | + --name access-rule \ |
| 172 | + --profile-name network-perimeter-profile \ |
| 173 | + --perimeter-name network-security-perimeter \ |
| 174 | + --resource-group resource-group \ |
| 175 | + --address-prefixes "['198.51.100.0/24', '192.0.2.0/24']" |
| 176 | +
|
| 177 | + ``` |
| 178 | +
|
| 179 | +1. If you need to delete an access rule, use the following command: |
| 180 | +
|
| 181 | + ```azurepowershell-interactive |
| 182 | + # Delete the access rule |
| 183 | + az network perimeter profile access-rule delete \ |
| 184 | + --Name network-perimeter-association \ |
| 185 | + --profile-name network-perimeter-profile \ |
| 186 | + --perimeter-name network-security-perimeter \ |
| 187 | + --resource-group resource-group |
| 188 | +
|
| 189 | +[!INCLUDE [network-security-perimeter-note-managed-id](../../includes/network-security-perimeter-note-managed-id.md)] |
| 190 | +
|
| 191 | +## Delete all resources |
| 192 | +
|
| 193 | +To delete a network security perimeter and other resources in this quickstart, use the following commands: |
| 194 | +
|
| 195 | +```azurecli-interactive |
| 196 | +
|
| 197 | + # Delete the network security perimeter association |
| 198 | + az network perimeter association delete \ |
| 199 | + --name network-perimeter-association \ |
| 200 | + --resource-group resource-group \ |
| 201 | + --perimeter-name network-security-perimeter |
| 202 | +
|
| 203 | + # Delete the network security perimeter |
| 204 | + az network perimeter delete \ |
| 205 | + --resource-group resource-group \ |
| 206 | + --name network-security-perimeter --yes |
| 207 | + |
| 208 | + # Delete the key vault |
| 209 | + az keyvault delete \ |
| 210 | + --name $key_vault_name \ |
| 211 | + --resource-group resource-group |
| 212 | + |
| 213 | + # Delete the resource group |
| 214 | + az group delete \ |
| 215 | + --name resource-group \ |
| 216 | + --yes \ |
| 217 | + --no-wait |
| 218 | +
|
| 219 | +``` |
| 220 | + |
| 221 | +[!INCLUDE [network-security-perimeter-delete-resources](../../includes/network-security-perimeter-delete-resources.md)] |
| 222 | + |
| 223 | +## Next steps |
| 224 | + |
| 225 | +> [!div class="nextstepaction"] |
| 226 | +> [Diagnostic logging for Azure Network Security Perimeter](./network-security-perimeter-diagnostic-logs.md) |
0 commit comments