You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Copy file name to clipboardExpand all lines: articles/virtual-network/tutorial-restrict-network-access-to-resources.md
+41-87Lines changed: 41 additions & 87 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -633,11 +633,6 @@ The steps required to restrict network access to resources created through Azure
633
633
634
634
1. Select **Create**.
635
635
636
-
> [!IMPORTANT]
637
-
> Microsoft recommends that you use the most secure authentication flow available. The authentication flow described in this procedure requires a very high degree of trust in the application, and carries risks that are not present in other flows. You should only use this flow when other more secure flows, such as managed identities, aren't viable.
638
-
>
639
-
> For more information about connecting to a storage account using a managed identity, see [Use a managed identity to access Azure Storage](/entra/identity/managed-identities-azure-resources/tutorial-linux-managed-identities-vm-access?pivots=identity-linux-mi-vm-access-storage).
640
-
641
636
### [PowerShell](#tab/powershell)
642
637
643
638
1. Create an Azure storage account with [New-AzStorageAccount](/powershell/module/az.storage/new-azstorageaccount). Replace `<replace-with-your-unique-storage-account-name>` with a name that is unique across all Azure locations, between 3-24 characters in length, using only numbers and lower-case letters.
@@ -928,7 +923,7 @@ To test network access to a storage account, deploy a virtual machine to each su
928
923
929
924
### Create the first virtual machine
930
925
931
-
Create a virtual machine in the *subnet-public* subnet with [New-AzVM](/powershell/module/az.compute/new-azvm). When running the command that follows, you're prompted for credentials. The values that you enter are configured as the user name and password for the VM.
926
+
Create a virtual machine in the *subnet-public* subnet with [New-AzVM](/powershell/module/az.compute/new-azvm).
932
927
933
928
```azurepowershell-interactive
934
929
$vm1 = @{
@@ -937,7 +932,11 @@ $vm1 = @{
937
932
VirtualNetworkName = "vnet-1"
938
933
SubnetName = "subnet-public"
939
934
Name = "vm-public"
940
-
PublicIpAddressName = $null
935
+
Image = "Ubuntu2204"
936
+
AdminUsername = "azureuser"
937
+
PublicIpAddressName = $null
938
+
GenerateSshKey = $true
939
+
SshKeyName = "vm-public-key"
941
940
}
942
941
New-AzVm @vm1
943
942
```
@@ -953,7 +952,11 @@ $vm2 = @{
953
952
VirtualNetworkName = "vnet-1"
954
953
SubnetName = "subnet-private"
955
954
Name = "vm-private"
955
+
Image = "Ubuntu2204"
956
+
AdminUsername = "azureuser"
956
957
PublicIpAddressName = $null
958
+
GenerateSshKey = $true
959
+
SshKeyName = "vm-private-key"
957
960
}
958
961
New-AzVm @vm2
959
962
```
@@ -1074,73 +1077,41 @@ The virtual machine you created earlier that is assigned to the **subnet-private
1074
1077
1075
1078
### [PowerShell](#tab/powershell)
1076
1079
1077
-
The virtual machine you created earlier that is assigned to the **subnet-private** subnet is used to confirm access to the storage account. The virtual machine you created in the previous section that is assigned to the **subnet-1** subnet is used to confirm that access to the storage account is blocked.
1078
-
1079
-
### Get storage account access key
1080
-
1081
-
1. Sign-in to the [Azure portal](https://portal.azure.com/).
1082
-
1083
-
1. In the search box at the top of the portal, enter **Storage account**. Select **Storage accounts** in the search results.
1084
-
1085
-
1. In **Storage accounts**, select your storage account.
1086
-
1087
-
1. In **Security + networking**, select **Access keys**.
1088
-
1089
-
1. Copy the value of **key1**. You might need to select the **Show** button to display the key.
1090
-
1091
-
:::image type="content" source="./media/tutorial-restrict-network-access-to-resources/storage-account-access-key.png" alt-text="Screenshot of storage account access key.":::
1092
-
1093
1080
1. In the search box at the top of the portal, enter **Virtual machine**. Select **Virtual machines** in the search results.
1094
1081
1095
1082
1. Select **vm-private**.
1096
1083
1097
-
1. Select **Connect** then **Connect via Bastion** in **Overview**.
1084
+
1. Select **Bastion** in **Operations**.
1098
1085
1099
-
1.Enter the username and password you specified when creating the virtual machine. Select **Connect**.
1086
+
1.Select **SSH Private Key from Local File** for **Authentication Type**.
1100
1087
1101
-
1.Open Windows PowerShell. Use the following script to map the Azure file share to drive Z.
1088
+
1.Enter the username you specified when creating the virtual machine.
1102
1089
1103
-
* Replace `<storage-account-key>` with the key you copied in the previous step.
1090
+
1. Select the SSH private key file from your local machine.
1104
1091
1105
-
* Replace `<storage-account-name>` with the name of your storage account. In this example, it's **storage8675**.
* Replace `<storage-account-key>` with the key you retrieved in [Create a storage account](#create-a-storage-account).
1126
1097
1127
-
PowerShell returns output similar to the following example output:
1098
+
* Replace `<storage-account-name>` with the name of your storage account. In this example, it's **storage8675**.
1128
1099
1129
-
```output
1130
-
Name Used (GB) Free (GB) Provider Root
1131
-
---- --------- --------- -------- ----
1132
-
Z FileSystem \\storage8675.file.core.windows.net\f...
1100
+
```bash
1101
+
sudo mkdir /mnt/file-share
1102
+
1103
+
sudo mount -t cifs //<storage-account-name>.file.core.windows.net/file-share /mnt/file-share -o vers=3.0,username=<storage-account-name>,password=<storage-account-key>,dir_mode=0777,file_mode=0777,serverino
1133
1104
```
1134
1105
1135
-
The Azure file share successfully mapped to the Z drive.
1106
+
1. You receive the `$` prompt with no errors. The Azure file share successfully mounted to **/mnt/file-share**.
1136
1107
1137
1108
1. Confirm that the VM has no outbound connectivity to any other public IP addresses:
1138
1109
1139
-
```powershell
1140
-
ping bing.com
1110
+
```bash
1111
+
ping bing.com -c 4
1141
1112
```
1142
1113
1143
-
You receive no replies, because the network security group associated to the *Private* subnet doesn't allow outbound access to public IP addresses other than the addresses assigned to the Azure Storage service.
1114
+
You receive no replies, because the network security group associated to the *subnet-private* subnet doesn't allow outbound access to public IP addresses other than the addresses assigned to the Azure Storage service.
1144
1115
1145
1116
1. Close the Bastion connection to **vm-private**.
1146
1117
@@ -1239,50 +1210,33 @@ The virtual machine you created earlier that is assigned to the **subnet-private
1239
1210
1240
1211
### [PowerShell](#tab/powershell)
1241
1212
1242
-
### From vm-1
1213
+
### From vm-public
1243
1214
1244
1215
1. In the search box at the top of the portal, enter **Virtual machine**. Select **Virtual machines**in the search results.
1245
1216
1246
-
1. Select **vm-1**.
1217
+
1. Select **vm-public**.
1247
1218
1248
1219
1. Select **Bastion**in**Operations**.
1249
1220
1250
-
1.Enter the username and password you specified when creating the virtual machine. Select **Connect**.
1221
+
1. Select **SSH Private Key from Local File**for**Authentication Type**.
1251
1222
1252
-
1.Repeat the previous command to attempt to map the drive to the file share in the storage account. You might need to copy the storage account access key again for this procedure:
1223
+
1. Enter the username you specified when creating the virtual machine.
1. Attempt to mount the Azure file share. Replace `<storage-account-name>` with the account name and `<storage-account-key>` with the key you retrieved in [Create a storage account](#create-a-storage-account):
1230
+
1231
+
```bash
1232
+
sudo mkdir /mnt/file-share
1233
+
1234
+
sudo mount -t cifs //<storage-account-name>.file.core.windows.net/file-share /mnt/file-share -o vers=3.0,username=<storage-account-name>,password=<storage-account-key>,dir_mode=0777,file_mode=0777,serverino
1272
1235
```
1273
1236
1274
-
1.You should receive the following error message:
1237
+
1. Access is denied and you receive a `mount error(13): Permission denied` error. The mount fails because **vm-public** is in**subnet-public**, which doesn't have a service endpoint for Azure Storage.
0 commit comments