Skip to content

Commit d8614af

Browse files
Merge pull request #313840 from duongau/firewall-freshness-review-564969-P2b
Azure Firewall P2b freshness review - tutorial step simplification and bug fixes
2 parents 857b37d + b3f7718 commit d8614af

4 files changed

Lines changed: 675 additions & 544 deletions

File tree

articles/firewall/firewall-sftp.md

Lines changed: 94 additions & 54 deletions
Original file line numberDiff line numberDiff line change
@@ -1,37 +1,36 @@
11
---
22
title: Access a storage account using SFTP over an Azure Firewall static public IP address
3-
description: In this article, you use Azure PowerShell to deploy Azure Firewall to access a storage account container via SFTP.
4-
services: firewall
3+
description: Access a storage account container via SFTP by using Azure Firewall and Azure PowerShell.
54
author: duongau
5+
ms.author: duau
66
ms.service: azure-firewall
77
ms.topic: how-to
8-
ms.date: 04/27/2023
9-
ms.author: harjsing
8+
ms.date: 03/28/2026
109
ms.custom: devx-track-azurepowershell
1110
# Customer intent: As a cloud administrator, I want to configure a secure SFTP connection to an Azure storage account via Azure Firewall, so that I can manage and transfer files securely while ensuring compliance with network security protocols.
1211
---
1312

14-
# Access a storage account using SFTP over an Azure Firewall static public IP address
13+
# Access a storage account by using SFTP over an Azure Firewall static public IP address
1514

16-
You can use Azure Firewall to access a storage account container via SFTP. Azure PowerShell is used to deploy a firewall in a virtual network and configured with DNAT rules to translate the SFTP traffic to the storage account container. The storage account container is configured with a private endpoint to allow access from the firewall. To connect to the container, you use the firewall public IP address and the storage account container name.
15+
Use Azure Firewall to access a storage account container through SFTP. Use Azure PowerShell to deploy a firewall in a virtual network and configure it with DNAT rules to translate the SFTP traffic to the storage account container. Configure the storage account container with a private endpoint to allow access from the firewall. To connect to the container, use the firewall public IP address and the storage account container name.
1716

18-
:::image type="content" source="media/firewall-sftp/accessing-storage-using-sftp.png" alt-text="Diagram showing SFTP to firewall to access a storage account container." lightbox="media/firewall-sftp/accessing-storage-using-sftp.png":::
17+
:::image type="content" source="media/firewall-sftp/accessing-storage-using-sftp.png" alt-text="Diagram that shows a customer connecting via SFTP to Azure Firewall, which routes traffic through a private endpoint to a storage account container." lightbox="media/firewall-sftp/accessing-storage-using-sftp.png":::
1918

2019
In this article, you:
2120

22-
- Deploy the network infrastructure
23-
- Create a firewall policy with the appropriate DNAT rule
24-
- Deploy the firewall
25-
- Create a storage account and container
26-
- Configure SFTP access to the storage account container
27-
- Create a private endpoint for the storage account container
28-
- Test the connection to the storage account container
21+
- Deploy the network infrastructure.
22+
- Create a firewall policy with the appropriate DNAT rule.
23+
- Deploy the firewall.
24+
- Create a storage account and container.
25+
- Configure SFTP access to the storage account container.
26+
- Create a private endpoint for the storage account container.
27+
- Test the connection to the storage account container.
2928

3029
If you don't have an Azure subscription, create a [free account](https://azure.microsoft.com/pricing/purchase-options/azure-account?cid=msft_learn) before you begin.
3130

3231
[!INCLUDE [updated-for-az](~/reusable-content/ce-skilling/azure/includes/updated-for-az.md)]
3332

34-
This article requires the latest Azure PowerShell modules. Run `Get-Module -ListAvailable Az` to find the version. If you need to upgrade, see [Install Azure PowerShell module](/powershell/azure/install-azure-powershell). If you're running PowerShell locally, you also need to run `Login-AzAccount` to create a connection with Azure.
33+
This article requires the latest Azure PowerShell modules. Run `Get-Module -ListAvailable Az` to find the version. If you need to upgrade, see [Install Azure PowerShell module](/powershell/azure/install-azure-powershell). If you're running PowerShell locally, you also need to run `Connect-AzAccount` to create a connection with Azure.
3534

3635
## Deploy the network infrastructure
3736

@@ -50,19 +49,29 @@ $UserPrincipalName = "<your AD user principal name>"
5049
$ContainerName = "<container-name>"
5150
```
5251

53-
Create the network infrastructure. This includes a virtual network, subnets and a public IP address for the firewall.
52+
Create the network infrastructure. This step includes creating a virtual network, subnets, and a public IP address for the firewall.
5453

5554
```azurepowershell
56-
5755
# Create a new resource group
58-
New-AzResourceGroup -Name $rg -Location $location
56+
New-AzResourceGroup `
57+
-Name $rg `
58+
-Location $location
5959
6060
# Create new subnets for the firewall
61-
$FWsub = New-AzVirtualNetworkSubnetConfig -Name AzureFirewallSubnet -AddressPrefix 10.0.1.0/26
62-
$Worksub = New-AzVirtualNetworkSubnetConfig -Name Workload-SN -AddressPrefix 10.0.2.0/24
61+
$FWsub = New-AzVirtualNetworkSubnetConfig `
62+
-Name AzureFirewallSubnet `
63+
-AddressPrefix 10.0.1.0/26
64+
$Worksub = New-AzVirtualNetworkSubnetConfig `
65+
-Name Workload-SN `
66+
-AddressPrefix 10.0.2.0/24
6367
6468
# Create a new VNet
65-
$testVnet = New-AzVirtualNetwork -Name test-fw-vn -ResourceGroupName $rg -Location $location -AddressPrefix 10.0.0.0/16 -Subnet $FWsub, $Worksub
69+
$testVnet = New-AzVirtualNetwork `
70+
-Name test-fw-vn `
71+
-ResourceGroupName $rg `
72+
-Location $location `
73+
-AddressPrefix 10.0.0.0/16 `
74+
-Subnet $FWsub, $Worksub
6675
6776
# Create a public IP address for the firewall
6877
$pip = New-AzPublicIpAddress `
@@ -76,64 +85,98 @@ $pip = New-AzPublicIpAddress `
7685
## Create and configure the firewall policy
7786

7887
```azurepowershell
79-
8088
# Create a new firewall policy
81-
$policy = New-AzFirewallPolicy -Name "fw-pol" -ResourceGroupName "$rg" -Location $location
89+
$policy = New-AzFirewallPolicy `
90+
-Name "fw-pol" `
91+
-ResourceGroupName $rg `
92+
-Location $location
8293
8394
# Define new rules to add
84-
$newrule1 = New-AzFirewallPolicyNatRule -Name "dnat-rule1" -Protocol "TCP", "UDP" -SourceAddress "*" -DestinationAddress $pip.ipaddress -DestinationPort "22" -TranslatedAddress $staticEP -TranslatedPort "22"
95+
$newrule1 = New-AzFirewallPolicyNatRule `
96+
-Name "dnat-rule1" `
97+
-Protocol "TCP", "UDP" `
98+
-SourceAddress "*" `
99+
-DestinationAddress $pip.IpAddress `
100+
-DestinationPort "22" `
101+
-TranslatedAddress $staticEP `
102+
-TranslatedPort "22"
85103
86104
# Add the new rules to the local rule collection object
87-
$natrulecollection = New-AzFirewallPolicyNatRuleCollection -Name "NATRuleCollection" -Priority 100 -ActionType "Dnat" -Rule $newrule1
105+
$natrulecollection = New-AzFirewallPolicyNatRuleCollection `
106+
-Name "NATRuleCollection" `
107+
-Priority 100 `
108+
-ActionType "Dnat" `
109+
-Rule $newrule1
88110
89111
# Create a new rule collection group
90-
$natrulecollectiongroup = New-AzFirewallPolicyRuleCollectionGroup -Name "rcg-01" -ResourceGroupName "$rg" -FirewallPolicyName "fw-pol" -Priority 100
112+
$natrulecollectiongroup = New-AzFirewallPolicyRuleCollectionGroup `
113+
-Name "rcg-01" `
114+
-ResourceGroupName $rg `
115+
-FirewallPolicyName "fw-pol" `
116+
-Priority 100
91117
92118
# Add the new NAT rule collection to the rule collection group
93119
$natrulecollectiongroup.Properties.RuleCollection = $natrulecollection
94120
95121
# Update the rule collection
96-
Set-AzFirewallPolicyRuleCollectionGroup -Name "rcg-01 " -FirewallPolicyObject $policy -Priority 200 -RuleCollection $natrulecollectiongroup.Properties.rulecollection
97-
122+
Set-AzFirewallPolicyRuleCollectionGroup `
123+
-Name "rcg-01" `
124+
-FirewallPolicyObject $policy `
125+
-Priority 200 `
126+
-RuleCollection $natrulecollectiongroup.Properties.RuleCollection
98127
```
128+
99129
## Deploy the firewall
100130

101131
```azurepowershell
102-
103132
# Create the firewall
104133
$firewall = New-AzFirewall `
105134
-Name fw-01 `
106135
-ResourceGroupName $rg `
107136
-Location $location `
108-
-VirtualNetwork $testvnet `
137+
-VirtualNetwork $testVnet `
109138
-PublicIpAddress $pip `
110139
-FirewallPolicyId $policy.id
111-
112140
```
113141

114142
## Create a storage account and container
115143

116144
```azurepowershell
117-
118-
New-AzStorageAccount -ResourceGroupName $rg -Name $StorageAccountName -SkuName Standard_LRS -Location $location -EnableHierarchicalNamespace $true -PublicNetworkAccess enabled
145+
New-AzStorageAccount `
146+
-ResourceGroupName $rg `
147+
-Name $StorageAccountName `
148+
-SkuName Standard_LRS `
149+
-Location $location `
150+
-EnableHierarchicalNamespace $true `
151+
-PublicNetworkAccess Enabled
119152
120153
# Get the subscription and user information
121-
$subscriptionId = (Get-AzSubscription -SubscriptionName "$SubscriptionName").SubscriptionId
122-
$user = Get-AzADUser -UserPrincipalName $UserPrincipalName
154+
$subscriptionId = (Get-AzSubscription `
155+
-SubscriptionName $SubscriptionName).SubscriptionId
156+
$user = Get-AzADUser `
157+
-UserPrincipalName $UserPrincipalName
123158
124159
# Give the user contributor role
125-
New-AzRoleAssignment -ObjectId $user.id -RoleDefinitionName "Storage Blob Data Contributor" -Scope "/subscriptions/$subscriptionId/resourceGroups/$rg/providers/Microsoft.Storage/storageAccounts/$StorageAccountName"
160+
New-AzRoleAssignment `
161+
-ObjectId $user.Id `
162+
-RoleDefinitionName "Storage Blob Data Contributor" `
163+
-Scope "/subscriptions/$subscriptionId/resourceGroups/$rg/providers/Microsoft.Storage/storageAccounts/$StorageAccountName"
126164
127-
#Create the container and then disable public network access
165+
# Create the container and then disable public network access
128166
$ctx = New-AzStorageContext -StorageAccountName $StorageAccountName
129-
New-AzStorageContainer -Name $ContainerName -Context $ctx
130-
Set-AzStorageAccount -ResourceGroupName $rg -Name $StorageAccountName -PublicNetworkAccess disabled -Force
167+
New-AzStorageContainer `
168+
-Name $ContainerName `
169+
-Context $ctx
170+
Set-AzStorageAccount `
171+
-ResourceGroupName $rg `
172+
-Name $StorageAccountName `
173+
-PublicNetworkAccess Disabled `
174+
-Force
131175
```
132176

133177
### Configure SFTP access to the storage account container
134178

135179
```azurepowershell
136-
137180
Set-AzStorageAccount `
138181
-ResourceGroupName $rg `
139182
-Name $StorageAccountName `
@@ -158,15 +201,15 @@ $localuserPassword = New-AzStorageLocalUserSshPassword `
158201
# Examine and manually save the password
159202
160203
$localuserPassword
161-
162204
```
163205

164206
## Create a private endpoint for the storage account container
165207

166208
```azurepowershell
167-
168209
# Place the previously created storage account into a variable
169-
$storage = Get-AzStorageAccount -ResourceGroupName $rg -Name $StorageAccountName
210+
$storage = Get-AzStorageAccount `
211+
-ResourceGroupName $rg `
212+
-Name $StorageAccountName
170213
171214
# Create the private endpoint connection
172215
$pec = @{
@@ -192,29 +235,28 @@ $ipconfig = New-AzPrivateEndpointIpConfiguration @ip
192235
$pe = @{
193236
ResourceGroupName = $rg
194237
Name = 'StorageEP'
195-
Location = 'eastus'
196-
Subnet = $testvnet.Subnets[1]
238+
Location = $location
239+
Subnet = $testVnet.Subnets[1]
197240
PrivateLinkServiceConnection = $privateEndpointConnection
198241
IpConfiguration = $ipconfig
199242
}
200243
201244
New-AzPrivateEndpoint @pe
202-
203245
```
246+
204247
## Test the SFTP connection
205248

206-
Now, test to ensure you can connect to the storage account container using SFTP. You can use any SFTP client to test the connection. In this example, we use sftp from a command prompt.
249+
Now, test the connection to make sure you can connect to the storage account container by using SFTP. You can use any SFTP client to test the connection. In this example, use `sftp` from a command prompt.
207250

208-
For example, for a storage account named `teststorageaccount`, a container named `testcontainer`, a local account named `testuser`, and a firewall public IP address of `13.68.216.252`, you would use the following command:
251+
For example, for a storage account named `teststorageaccount`, a container named `testcontainer`, a local account named `testuser`, and a firewall public IP address of `13.68.216.252`, use the following command:
209252

210253
```
211254
212255
```
213256

214257
Enter the password you saved earlier when prompted.
215258

216-
217-
You should see something similar to the following output:
259+
You see something similar to the following output:
218260

219261
```
220262
@@ -223,16 +265,14 @@ Connected to 13.68.216.252.
223265
sftp>
224266
```
225267

226-
You should now be connected to the storage account container using SFTP. You can use `put` and `get` commands to upload and download files. Use `ls` to list the files in the container, and `lls` to list the files in the local directory.
268+
You're now connected to the storage account container by using SFTP. You can use `put` and `get` commands to upload and download files. Use `ls` to list the files in the container, and `lls` to list the files in the local directory.
227269

228270
## Clean up resources
229271

230-
When no longer needed, you can use the following command to remove the resource group, firewall, firewall policy, and all related resources.
272+
When you no longer need the resources, use the following command to remove the resource group, firewall, firewall policy, and all related resources.
231273

232274
```azurepowershell
233-
234275
Remove-AzResourceGroup -Name $rg -Force
235-
236276
```
237277

238278
## Next steps

0 commit comments

Comments
 (0)