|
1 | 1 | ---
|
2 |
| -title: How to configure Azure Functions with a virtual network |
3 |
| -description: Article that shows you how to perform certain virtual networking tasks for Azure Functions. |
| 2 | +title: How to use a secured storage account with Azure Functions |
| 3 | +description: Article that shows you how to use a secured storage account in a virtual network as the default storage account for a function app in Azure Functions. |
4 | 4 | ms.topic: how-to
|
5 |
| -ms.date: 06/23/2023 |
| 5 | +ms.date: 01/31/2024 |
6 | 6 | ms.custom: template-how-to
|
7 | 7 | ---
|
8 | 8 |
|
9 |
| -# How to configure Azure Functions with a virtual network |
| 9 | +# How to use a secured storage account with Azure Functions |
10 | 10 |
|
11 |
| -This article shows you how to perform tasks related to configuring your function app to connect to and run on a virtual network. For an in-depth tutorial on how to secure your storage account, refer to the [Connect to a Virtual Network tutorial](functions-create-vnet.md). To learn more about Azure Functions and networking, see [Azure Functions networking options](functions-networking-options.md). |
| 11 | +This article shows you how to connect your function app to a secured storage account. For an in-depth tutorial on how to create your function app with inbound and outbound access restrictions, refer to the [Integrate with a virtual network](functions-create-vnet.md) tutorial. To learn more about Azure Functions and networking, see [Azure Functions networking options](functions-networking-options.md). |
12 | 12 |
|
13 | 13 | ## Restrict your storage account to a virtual network
|
14 | 14 |
|
15 |
| -When you create a function app, you either create a new storage account or link to an existing storage account. During function app creation, you can secure a new storage account behind a virtual network and integrate the function app with this network. At this time, you can't secure an existing storage account being used by your function app in the same way. |
| 15 | +When you create a function app, you either create a new storage account or link to an existing one. Currently, only [ARM template and Bicep deployments](functions-infrastructure-as-code.md#secured-deployments) support function app creation with an existing secured storage account. |
16 | 16 |
|
17 | 17 | > [!NOTE]
|
18 | 18 | > Securing your storage account is supported for all tiers in both Dedicated (App Service) and Elastic Premium plans. Consumption plans currently don't support virtual networks.
|
19 | 19 |
|
20 | 20 | For a list of all restrictions on storage accounts, see [Storage account requirements](storage-considerations.md#storage-account-requirements).
|
21 | 21 |
|
22 |
| -### During function app creation |
| 22 | +## Secure storage during function app creation |
23 | 23 |
|
24 |
| -You can create a new function app along with a new storage account secured behind a virtual network. The following links show you how to create these resources by using either the Azure portal or by using deployment templates: |
| 24 | +You can create a function app along with a new storage account secured behind a virtual network that is accessible via private endpoints. The following links show you how to create these resources by using either the Azure portal or by using deployment templates: |
25 | 25 |
|
26 |
| -# [Azure portal](#tab/portal) |
| 26 | +### [Azure portal](#tab/portal) |
27 | 27 |
|
28 | 28 | Complete the following tutorial to create a new function app a secured storage account: [Use private endpoints to integrate Azure Functions with a virtual network](functions-create-vnet.md).
|
29 | 29 |
|
30 |
| -# [Deployment templates](#tab/templates) |
| 30 | +### [Deployment templates](#tab/templates) |
31 | 31 |
|
32 | 32 | Use Bicep files or Azure Resource Manager (ARM) templates to create a secured function app and storage account resources. When you create a secured storage account in an automated deployment, you must also specifically set the `WEBSITE_CONTENTSHARE` setting and create the file share as part of your deployment. For more information, including links to example deployments, see [Secured deployments](functions-infrastructure-as-code.md#secured-deployments).
|
33 | 33 |
|
34 | 34 | ---
|
35 | 35 |
|
36 |
| -### Existing function app |
| 36 | +## Secure storage for an existing function app |
37 | 37 |
|
38 |
| -When you have an existing function app, you can't directly secure the storage account currently being used by the app. You must instead swap-out the existing storage account for a new, secured storage account. |
| 38 | +When you have an existing function app, you can't directly secure the storage account currently being used by the app. You must instead swap-out the existing storage account for a new, secured storage account. |
39 | 39 |
|
40 |
| -To secure the storage for an existing function app: |
| 40 | +### 1. Enable virtual network integration |
| 41 | + |
| 42 | +As a prerequisite, you need to enable virtual network integration for your function app. |
41 | 43 |
|
42 | 44 | 1. Choose a function app with a storage account that doesn't have service endpoints or private endpoints enabled.
|
43 | 45 |
|
44 | 46 | 1. [Enable virtual network integration](./functions-networking-options.md#enable-virtual-network-integration) for your function app.
|
45 | 47 |
|
46 |
| -1. Create or configure a second storage account. This is going to be the secured storage account that your function app uses instead. |
| 48 | +### 2. Create a secured storage account |
| 49 | + |
| 50 | +Set up a secured storage account for your function app: |
| 51 | + |
| 52 | +1. [Create a second storage account](../storage/common/storage-account-create.md). This is going to be the secured storage account that your function app will use instead. You can also use an existing storage account not already being used by Functions. |
| 53 | + |
| 54 | +1. Copy the connection string for this storage account. You need this string for later. |
47 | 55 |
|
48 |
| -1. [Create a file share](../storage/files/storage-how-to-create-file-share.md#create-a-file-share) in the new storage account. |
| 56 | +1. [Create a file share](../storage/files/storage-how-to-create-file-share.md#create-a-file-share) in the new storage account. Try to use the same name as the file share in the existing storage account. Otherwise, you'll need to copy the name of the new file share to configure an app setting later. |
49 | 57 |
|
50 | 58 | 1. Secure the new storage account in one of the following ways:
|
51 | 59 |
|
52 |
| - * [Create a private endpoint](../storage/common/storage-private-endpoints.md#creating-a-private-endpoint). When using private endpoint connections, the storage account must have private endpoints for the `file` and `blob` subresources. For Durable Functions, you must also make `queue` and `table` subresources accessible through private endpoints. |
| 60 | + * [Create a private endpoint](../storage/common/storage-private-endpoints.md#creating-a-private-endpoint). When you set up private endpoint connections, create private endpoints for the `file` and `blob` subresources. For Durable Functions, you must also make `queue` and `table` subresources accessible through private endpoints. If you're using a custom or on-premises DNS server, make sure you [configure your DNS server](../storage/common/storage-private-endpoints.md#dns-changes-for-private-endpoints) to resolve to the new private endpoints. |
| 61 | + |
| 62 | + * [Restrict traffic to specific subnets](../storage/common/storage-network-security.md#grant-access-from-a-virtual-network). Ensure that one of the allowed subnets is the one your function app is network integrated with. Double check that the subnet has a service endpoint to Microsoft.Storage. |
| 63 | + |
| 64 | +1. Copy the file and blob content from the current storage account used by the function app to the newly secured storage account and file share. [AzCopy](../storage/common/storage-use-azcopy-blobs-copy.md) and [Azure Storage Explorer](https://techcommunity.microsoft.com/t5/azure-developer-community-blog/azure-tips-and-tricks-how-to-move-azure-storage-blobs-between/ba-p/3545304) are common methods. If you use Azure Storage Explorer, you may need to allow your client IP address into your storage account's firewall. |
| 65 | + |
| 66 | +Now you're ready to configure your function app to communicate with the newly secured storage account. |
| 67 | + |
| 68 | +### 3. Enable application and configuration routing |
| 69 | + |
| 70 | +You should now route your function app's traffic to go through the virtual network. |
| 71 | + |
| 72 | +1. Enable [application routing](../app-service/overview-vnet-integration.md#application-routing) to route your app's traffic into the virtual network. |
| 73 | + |
| 74 | + * Navigate to the **Networking** tab of your function app. Under **Outbound traffic configuration**, select the subnet associated with your virtual network integration. |
| 75 | + |
| 76 | + * In the new page, check the box for **Outbound internet traffic** under **Application routing**. |
| 77 | + |
| 78 | +1. Enable [content share routing](../app-service/overview-vnet-integration.md#content-share) to have your function app communicate with your new storage account through its virtual network. |
53 | 79 |
|
54 |
| - * [Enable a service endpoint from the virtual network](../storage/common/storage-network-security.md#grant-access-from-a-virtual-network). When using service endpoints, enable the subnet dedicated to your function apps for storage accounts on the firewall. |
| 80 | + * In the same page, check the box for **Content storage** under **Configuration routing**. |
55 | 81 |
|
56 |
| -1. Copy the file and blob content from the current storage account used by the function app to the newly secured storage account and file share. |
| 82 | +### 4. Update application settings |
57 | 83 |
|
58 |
| -1. Copy the connection string for this storage account. |
| 84 | +Finally, you need to update your application settings to point at the new secure storage account. |
59 | 85 |
|
60 |
| -1. Update the **Application Settings** under **Configuration** for the function app to the following: |
| 86 | +1. Update the **Application Settings** under the **Configuration** tab of your function app to the following: |
61 | 87 |
|
62 | 88 | | Setting name | Value | Comment |
|
63 | 89 | |----|----|----|
|
64 |
| - | `AzureWebJobsStorage`| Storage connection string | This is the connection string for a secured storage account. | |
65 |
| - | `WEBSITE_CONTENTAZUREFILECONNECTIONSTRING` | Storage connection string | This is the connection string for a secured storage account. This setting is required for Consumption and Elastic Premium plan apps on both Windows and Linux. It's not required for Dedicated plan apps, which aren't dynamically scaled by Functions. | |
66 |
| - | `WEBSITE_CONTENTSHARE` | File share | The name of the file share created in the secured storage account where the project deployment files reside. This setting is required for Consumption and Elastic Premium plan apps on both Windows and Linux. It's not required for Dedicated plan apps, which aren't dynamically scaled by Functions. | |
67 |
| - | `WEBSITE_CONTENTOVERVNET` | 1 | A value of 1 enables your function app to scale when you have your storage account restricted to a virtual network. You should enable this setting when restricting your storage account to a virtual network. | |
| 90 | + | [`AzureWebJobsStorage`](./functions-app-settings.md#azurewebjobsstorage)<br>[`WEBSITE_CONTENTAZUREFILECONNECTIONSTRING`](./functions-app-settings.md#website_contentazurefileconnectionstring) | Storage connection string | Both settings contain the connection string for the new secured storage account, which you saved earlier. | |
| 91 | + | [`WEBSITE_CONTENTSHARE`](./functions-app-settings.md#website_contentshare) | File share | The name of the file share created in the secured storage account where the project deployment files reside. | |
68 | 92 |
|
69 | 93 | 1. Select **Save** to save the application settings. Changing app settings causes the app to restart.
|
70 | 94 |
|
|
0 commit comments