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/azure-functions/function-keys-how-to.md
+40-40Lines changed: 40 additions & 40 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -3,21 +3,21 @@ title: Work with access keys in Azure Functions
3
3
description: Learn about access keys in Azure Functions, including how to get and renew keys and how to use access keys when calling function endpoints.
4
4
ms.service: azure-functions
5
5
ms.topic: how-to
6
-
ms.date: 07/18/2024
6
+
ms.date: 07/13/2025
7
7
8
8
#CustomerIntent: As an Azure Functions developer, I want learn how to work with access keys so that I can properly harden both my function endpoints and my overall function app running in Azure.
9
9
---
10
10
11
11
# Work with access keys in Azure Functions
12
12
13
-
Azure Functions lets you use secret keys to make it more difficult to access your function endpoints. This article describes the various kinds of access keys supported by Functions, and how to work with access keys.
13
+
Azure Functions lets you use secret keys to make it more difficult to access your function endpoints. This article describes the kinds of access keys that Functions supports, and how to work with access keys.
14
14
15
15
While access keys provide some mitigation against unwanted access, you should consider other options to secure HTTP endpoints in production. For example, it's not a good practice to distribute shared secrets in a public app. If your function is being called from a public client, you should consider implementing these or other security mechanisms:
16
16
17
-
+[Enable App Service Authentication/Authorization](security-concepts.md#enable-app-service-authenticationauthorization)
18
-
+[Use Azure API Management (APIM) to authenticate requests](security-concepts.md#use-azure-api-management-apim-to-authenticate-requests)
19
-
+[Deploy your function app to a virtual network](security-concepts.md#deploy-your-function-app-to-a-virtual-network)
20
-
+[Deploy your function app in isolation](security-concepts.md#deploy-your-function-app-in-isolation)
17
+
-[Enable App Service Authentication/Authorization](security-concepts.md#enable-app-service-authenticationauthorization)
18
+
-[Use Azure API Management (APIM) to authenticate requests](security-concepts.md#use-azure-api-management-apim-to-authenticate-requests)
19
+
-[Deploy your function app to a virtual network](security-concepts.md#deploy-your-function-app-to-a-virtual-network)
20
+
-[Deploy your function app in isolation](security-concepts.md#deploy-your-function-app-in-isolation)
21
21
22
22
Access keys provide the basis for HTTP authorization in HTTP triggered functions. For more information, see [Authorization level](./functions-bindings-http-webhook-trigger.md#http-auth).
23
23
@@ -30,9 +30,9 @@ The scope of an access key and the actions it supports depend on the type of acc
30
30
|**Function**|`default` or user defined |`function`| Allows access only to a specific function endpoint. |
31
31
|**Host**|`default` or user defined |`function`| Allows access to all function endpoints in a function app. |
32
32
|**Master**|`_master`|`admin`| Special host key that also provides administrative access to the runtime REST APIs in a function app. Because the master key grants elevated permissions in your function app, you shouldn't share this key with third parties or distribute it in native client applications. |
33
-
|**System**| Depends on the extension | n/a | Specific extensions might require a system-managed key to access webhook endpoints. System keys are designed for extension-specific function endpoints that get called by internal components. For example, the [Event Grid trigger](functions-bindings-event-grid-trigger.md) requires that the subscription use a system key when calling the trigger endpoint. Durable Functions also uses system keys to call [Durable Task extension APIs](durable/durable-functions-http-api.md). <br/>System keys can only be created by specific extensions, and you can't explicitly set their values. Like other keys, you can generate a new value for the key from the portal or by using the key APIs. |
33
+
|**System**| Depends on the extension | n/a | Specific extensions might require a system-managed key to access webhook endpoints. System keys are designed for extension-specific function endpoints that get called by internal components. For example, the [Event Grid trigger](functions-bindings-event-grid-trigger.md) requires that the subscription use a system key when calling the trigger endpoint. Durable Functions also uses system keys to call [Durable Task extension APIs](durable/durable-functions-http-api.md). <br/>Only specific extensions can create system keys. You can't explicitly set their values. Like other keys, you can generate a new value for the key from the portal or by using the key APIs. |
34
34
35
-
Each key is named for reference, and there's a default key (named `default`) at the function and host level. Function keys take precedence over host keys. When two keys are defined with the same name, the function key is always used.
35
+
Each key is named for reference. There's a default key (named `default`) at the function and host level. Function keys take precedence over host keys. When two keys are defined with the same name, the function key is always used.
36
36
37
37
The following table compares the uses for various kinds of access keys:
38
38
@@ -48,9 +48,9 @@ The following table compares the uses for various kinds of access keys:
48
48
49
49
## Key requirements
50
50
51
-
In Functions, access keys are randomly generated 32-byte arrays that are encoded as URL-safe base-64 strings. While you can generate your own access keys and use them with Functions, we strongly recommend that you instead allow Functions to generate all of your access keys for you.
51
+
In Functions, access keys are randomly generated 32-byte arrays that are encoded as URL-safe base-64 strings. While you can generate your own access keys and use them with Functions, we strongly recommend that you instead allow Functions to generate all of your access keys for you.
52
52
53
-
Functions-generated access keys include special signature and checksum values that indicate the type of access key and that it was generated by Azure Functions. Having these extra components in the key itself makes it much easier to determine the source of these kinds of secrets located during security scanning and other automated processes.
53
+
Functions-generated access keys include special signature and checksum values that indicate the type of access key and that Azure Functions generated it. Having these extra components in the key itself makes it much easier to determine the source of these kinds of secrets located during security scanning and other automated processes.
54
54
55
55
To allow Functions to generate your keys for you, don't supply the key `value` to any of the APIs that you can use to generate keys.
56
56
@@ -60,12 +60,12 @@ Keys are stored as part of your function app in Azure and are encrypted at rest.
60
60
61
61
|Location | Value | Description |
62
62
|---------|---------|---------|
63
-
| A second storage account |`blob`| Stores keys in Blob storage in a storage account that's different that the one used by the Functions runtime. The specific account and container used is defined by a shared access signature (SAS) URL set in the [`AzureWebJobsSecretStorageSas`](functions-app-settings.md#azurewebjobssecretstoragesas) setting. You must maintain the `AzureWebJobsSecretStorageSas` setting when the SAS URL changes. |
63
+
| A second storage account |`blob`| Stores keys in Blob storage in a storage account that's different than the one used by the Functions runtime. The specific account and container used are defined by a shared access signature (SAS) URL set in the [`AzureWebJobsSecretStorageSas`](functions-app-settings.md#azurewebjobssecretstoragesas) setting. You must maintain the `AzureWebJobsSecretStorageSas` setting when the SAS URL changes. |
64
64
|[Azure Key Vault](/azure/key-vault/general/overview)|`keyvault`| The key vault set in [`AzureWebJobsSecretStorageKeyVaultUri`](functions-app-settings.md#azurewebjobssecretstoragekeyvaulturi) is used to store keys. |
65
-
| File system |`files`| Keys are persisted on the local file system, which is the default in Functions v1.x. File system storage isn't recommended. |
66
-
| Kubernetes Secrets |`kubernetes`| The resource set in [AzureWebJobsKubernetesSecretName](functions-app-settings.md#azurewebjobskubernetessecretname) is used to store keys. Supported only when your function app is deployed to Kubernetes. The [Azure Functions Core Tools](functions-run-local.md) generates the values automatically when you use it to deploy your app to a Kubernetes cluster. [Immutable secrets](https://kubernetes.io/docs/concepts/configuration/secret/#secret-immutable) aren't supported |
65
+
| File system |`files`| Keys are persisted on the local file system, which is the default in Functions v1.x. File system storage isn't recommended. |
66
+
| Kubernetes Secrets |`kubernetes`| The resource set in [AzureWebJobsKubernetesSecretName](functions-app-settings.md#azurewebjobskubernetessecretname) is used to store keys. Supported only when your function app is deployed to Kubernetes. The [Azure Functions Core Tools](functions-run-local.md) generates the values automatically when you use it to deploy your app to a Kubernetes cluster. [Immutable secrets](https://kubernetes.io/docs/concepts/configuration/secret/#secret-immutable) aren't supported.|
67
67
68
-
When using Key Vault for key storage, the app settings you need depend on the managed identity type, either system-assigned or user-assigned.
68
+
When you use Key Vault for key storage, the app settings you need depend on the managed identity type, either system-assigned or user-assigned.
@@ -78,18 +78,18 @@ When using Key Vault for key storage, the app settings you need depend on the ma
78
78
79
79
## Use access keys
80
80
81
-
HTTP triggered functions can generally be called by using a URL in the format: `https://<APP_NAME>.azurewebsites.net/api/<FUNCTION_NAME>`. When the authorization level of a given function is set a value other than `anonymous`, you must also provide an access key in your request. The access key can either be provided in the URL using the `?code=` query string or in the request header (`x-functions-key`). For more information, see [Access key authorization](functions-bindings-http-webhook-trigger.md#api-key-authorization).
81
+
HTTP triggered functions can generally be called by using a URL that includes the function name. When the authorization level of a given function is set as a value other than `anonymous`, you must also provide an access key in your request. The access key can either be provided in the URL using the `?code=` query string or in the request header (`x-functions-key`). For more information, see [Access key authorization](functions-bindings-http-webhook-trigger.md#api-key-authorization).
82
82
83
83
To access the runtime REST APIs (under `/admin/`), you must provide the master key (`_master`) in the `x-functions-key` request header. You can [remove the admin endpoints](./security-concepts.md#disable-administrative-endpoints) using the `functionsRuntimeAdminIsolationEnabled` site property.
84
84
85
85
## Get your function access keys
86
86
87
87
You can get function and host keys programmatically by using these Azure Resource Manager APIs:
88
88
89
-
+[List Function Keys](/rest/api/appservice/webapps/listfunctionkeys)
To learn how to call Azure Resource Manager APIs, see the [Azure REST API reference](/rest/api/azure/).
95
95
@@ -101,37 +101,37 @@ You can use these methods to get access keys without having to use the REST APIs
101
101
102
102
1. Select the function app you want to work with.
103
103
104
-
1. In the left pane, expand **Functions**, and then select **App keys**.
104
+
1. In the left menu, expand **Functions**, and then select **App keys**.
105
105
106
106
The **App keys** page appears. On this page the host keys are displayed, which can be used to access any function in the app. The system key is also displayed, which gives anyone administrator-level access to all function app APIs.
107
107
108
108
You can also practice least privilege by using the key for a specific function. You can get function-specific keys from the **Function keys** tab of a specific HTTP-triggered function.
109
109
110
110
### [Azure CLI](#tab/azure-cli)
111
111
112
-
Run the following script in Azure Cloud Shell, the output of which is the `default` host key, which can be used to access any HTTP triggered function in the function app.
112
+
Run the following command in Azure Cloud Shell. The output of the command is the `default` host key, which can be used to access any HTTP triggered function in the function app.
113
113
114
114
```azurecli-interactive
115
115
az functionapp keys list --resource-group <RESOURCE_GROUP> --name <APP_NAME> --query functionKeys.default --output tsv
116
116
```
117
117
118
-
In this script, replace `<RESOURCE_GROUP>` and `<APP_NAME>` with the resource group and your function app name, respective.
118
+
Replace `<RESOURCE_GROUP>` and `<APP_NAME>` with the resource group and your function app name.
119
119
120
120
Because the output contains sensitive information, either don't persist the output or secure any persisted file outputs.
121
121
122
122
### [Azure PowerShell](#tab/azure-powershell)
123
123
124
-
Run the following script, the output of which is the `default` host key, which can be used to access any HTTP triggered function in the function app.
124
+
Run the following script. The output is the `default` host key, which can be used to access any HTTP triggered function in the function app.
In this script, replace `<RESOURCE_GROUP>` and `<APP_NAME>` with the resource group and your function app name, respective.
134
+
In this script, replace `<RESOURCE_GROUP>` and `<APP_NAME>` with the resource group and your function app name.
135
135
136
136
---
137
137
@@ -141,10 +141,10 @@ When you renew or create your access key values, you must manually redistribute
141
141
142
142
You can renew function and host keys programmatically or create new ones by using these Azure Resource Manager APIs:
143
143
144
-
+[Create Or Update Function Secret](/rest/api/appservice/webapps/createorupdatefunctionsecret)
145
-
+[Create Or Update Function Secret Slot](/rest/api/appservice/webapps/createorupdatefunctionsecretslot)
146
-
+[Create Or Update Host Secret](/rest/api/appservice/webapps/createorupdatehostsecret)
147
-
+[Create Or Update Host Secret Slot](/rest/api/appservice/webapps/createorupdatehostsecretslot)
144
+
-[Create Or Update Function Secret](/rest/api/appservice/webapps/createorupdatefunctionsecret)
145
+
-[Create Or Update Function Secret Slot](/rest/api/appservice/webapps/createorupdatefunctionsecretslot)
146
+
-[Create Or Update Host Secret](/rest/api/appservice/webapps/createorupdatehostsecret)
147
+
-[Create Or Update Host Secret Slot](/rest/api/appservice/webapps/createorupdatehostsecretslot)
148
148
149
149
To learn how to call Azure Resource Manager APIs, see the [Azure REST API reference](/rest/api/azure/).
150
150
@@ -156,7 +156,7 @@ You can use these methods to get access keys without having to manually create c
156
156
157
157
1. Select the function app you want to work with.
158
158
159
-
1. In the left pane, expand **Functions**, and then select **App keys**.
159
+
1. In the left menu, expand **Functions**, and then select **App keys**.
160
160
161
161
The **App keys** page appears. On this page the host keys are displayed, which can be used to access any function in the app. The system key is also displayed, which gives anyone administrator-level access to all function app APIs.
162
162
@@ -166,13 +166,13 @@ You can also renew a function key in the **Function keys** tab of a specific HTT
166
166
167
167
### [Azure CLI](#tab/azure-cli)
168
168
169
-
Run the following script in Azure Cloud Shell, which renews the `default` host key with a new key value generated by Functions.
169
+
Run the following command in Azure Cloud Shell, which renews the `default` host key with a new key value generated by Functions.
170
170
171
171
```azurecli-interactive
172
172
az functionapp keys set --resource-group <RESOURCE_GROUP> --name <APP_NAME> --key-type functionKeys --key-name default
173
173
```
174
174
175
-
In this script, replace `<RESOURCE_GROUP>` and `<APP_NAME>` with the resource group and your function app name, respective. This script has been created to run in Azure Cloud Shell (Bash). You must modify it to run in a Windows terminal.
175
+
In this command, replace `<RESOURCE_GROUP>` and `<APP_NAME>` with the resource group and your function app name. This command runs in Azure Cloud Shell (Bash). You must modify it to run in a Windows terminal.
176
176
177
177
The new key value generated by Functions is displayed for your reference. This new key value must be securely distributed to any apps that rely on the host key. Because the output contains sensitive information, either don't persist the output or secure any persisted file outputs.
In this script, replace `<RESOURCE_GROUP>` and `<APP_NAME>` with the resource group and your function app name, respective.
205
+
In this script, replace `<RESOURCE_GROUP>` and `<APP_NAME>` with the resource group and your function app name.
206
206
207
207
The new key value generated by Functions is returned for your reference. It must be securely distributed to any apps that rely on the host key. Because the output contains sensitive information, either don't persist the output or secure any persisted file outputs.
208
208
@@ -212,16 +212,16 @@ The new key value generated by Functions is returned for your reference. It must
212
212
213
213
You can delete function and host keys programmatically by using these Azure Resource Manager APIs:
214
214
215
-
+[Delete Function Secret](/rest/api/appservice/webapps/deletefunctionsecret)
216
-
+[Delete Function Secret Slot](/rest/api/appservice/webapps/deletefunctionsecretslot)
0 commit comments