Note
Access to this page requires authorization. You can try signing in or changing directories.
Access to this page requires authorization. You can try changing directories.
Azure Functions access keys act as shared secrets that authorize access to function endpoints. This article describes the kinds of access keys that Functions supports, and how to work with access keys.
While access keys provide some protection against unwanted access, consider other options to secure HTTP endpoints in production. For example, don't distribute shared secrets in a public app. If a public client calls your function, consider implementing these or other security mechanisms:
- Enable App Service Authentication/Authorization
- Use Azure API Management (APIM) to authenticate requests
- Deploy your function app to a virtual network
- Deploy your function app in isolation
Access keys provide the basis for HTTP authorization in HTTP-triggered functions. For more information, see Authorization level.
Access key types
The scope of an access key and the actions it supports depend on the type of access key.
| Key type | Key name | HTTP auth level | Description |
|---|---|---|---|
| Function | default or user defined |
function |
Allows access only to a specific function endpoint. |
| Host | default or user defined |
function |
Allows access to all function endpoints in a function app. |
| 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, don't share this key with third parties or distribute it in native client applications. |
| 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 internal components call. For example, the Event Grid trigger 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. 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. |
Each key has a name for reference. The function app and function levels each have a default key named default. Function keys take precedence over host keys. When two keys have the same name, the function key is always used.
The following table compares the uses for various kinds of access keys:
| Action | Scope | Key type |
|---|---|---|
| Execute a function | Specific function | Function |
| Execute a function | Any function | Function or host |
Call an admin endpoint |
Function app | Master |
| Call Durable Task extension APIs | Function app* | System |
| Call an extension-specific webhook (internal) | Function app* | System |
*Scope determined by the extension.
Access key requirements
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, use the default access key generation process instead.
Functions-generated access keys include special signature and checksum values that indicate the type of access key and that Azure Functions generated it. These extra components in the key make it easier to determine the source of these kinds of secrets during security scanning and other automated processes.
To allow Functions to generate your keys, don't supply the key value to any of the APIs that you can use to generate keys.
Access key storage
Your function app in Azure stores keys and encrypts them at rest. By default, the AzureWebJobsStorage setting stores keys in a Blob storage container in the provided account. Use the AzureWebJobsSecretStorageType setting to override this default behavior and store keys in one of these alternate locations:
| Location | Value | Description |
|---|---|---|
| A second storage account | blob |
Stores keys in Blob storage in a storage account that's different from 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 setting. You must maintain the AzureWebJobsSecretStorageSas setting when the SAS URL changes. |
| Azure Key Vault | keyvault |
Stores keys in the key vault set in AzureWebJobsSecretStorageKeyVaultUri. |
| 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. |
| Kubernetes Secrets | kubernetes |
Stores keys in the resource set in AzureWebJobsKubernetesSecretName. Supported only when your function app is deployed to Kubernetes. The Azure Functions Core Tools generates the values automatically when you use it to deploy your app to a Kubernetes cluster. Immutable secrets aren't supported. |
| Azure Container Apps secrets | containerapps |
Keys are stored in the Azure Container Apps secrets store, which is the internal secrets management system for Container Apps. Supported only when your function app is deployed to Azure Container Apps. For information, see Configure the Container Apps secret store. |
When you use Key Vault for key storage, the app settings you need depend on how the app authenticates to Key Vault: a system-assigned managed identity, a user-assigned managed identity, or an app registration.
| Setting name | System-assigned | User-assigned | App registration |
|---|---|---|---|
AzureWebJobsSecretStorageKeyVaultUri |
Yes | Yes | Yes |
AzureWebJobsSecretStorageKeyVaultClientId |
No | Yes | Yes |
AzureWebJobsSecretStorageKeyVaultClientSecret |
No | No | Yes |
AzureWebJobsSecretStorageKeyVaultTenantId |
No | No | Yes |
Important
Secrets aren't scoped to individual function apps through the AzureWebJobsSecretStorageKeyVaultUri setting. If multiple function apps are configured to use the same Key Vault they share the same secrets, potentially leading to key collisions or overwrites. To avoid unintended behavior, we recommend that you use a separate Key Vault instance for each function app.
Call endpoints with access keys
You can call HTTP-triggered functions by using a URL that includes the function name. When you set the authorization level of a function to any value other than anonymous, you must also provide an access key in your request. You can include the access key in the URL by using the ?code= query string or in the request header (x-functions-key). For more information, see Access key authorization.
To access the runtime REST APIs (under /admin/), you must provide the master key (_master) in the x-functions-key request header. You can disable administrative endpoints by setting the functionsRuntimeAdminIsolationEnabled site property.
Get your function access keys
You can get function and host keys programmatically by using these Azure Resource Manager APIs:
To learn how to call Azure Resource Manager APIs, see the Azure REST API reference.
Note
When you deploy your function app to Azure Container Apps and use AzureWebJobsSecretStorageType=ContainerApps, you must use Container Apps-specific methods to retrieve function keys. For more information, see Manage access keys in Container Apps documentation.
Use these methods to get access keys without using the REST APIs.
Sign in to the Azure portal, and then search for and select Function App.
Select the function app you want to work with.
In the left menu, expand Functions, and then select App keys.
The App keys page appears. On this page, the host keys are displayed, which you can use to access any function in the app. The system key is also displayed, which gives anyone administrator-level access to all function app APIs.
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.
Tip
You can also get access keys for your functions by using the Azure Functions Core Tools command func azure functionapp list-functions with the --show-keys option. For more information, see the Azure Functions Core Tools reference.
Renew or create access keys
When you renew or create your access key values, you must manually redistribute the updated key values to all clients that call your function.
You can renew function and host keys programmatically or create new ones by using these Azure Resource Manager APIs:
- Create Or Update Function Secret
- Create Or Update Function Secret Slot
- Create Or Update Host Secret
- Create Or Update Host Secret Slot
To learn how to call Azure Resource Manager APIs, see the Azure REST API reference.
You can use these methods to get access keys without having to manually create calls to the REST APIs.
Sign in to the Azure portal, and then search for and select Function App.
Select the function app you want to work with.
In the left menu, expand Functions, and then select App keys.
The App keys page appears. On this page, the host keys are displayed, which you can use to access any function in the app. The system key is also displayed, which gives anyone administrator-level access to all function app APIs.
Select Renew key value next to the key you want to renew, and then select Renew and save.
You can also renew a function key in the Function keys tab of a specific HTTP-triggered function.
Delete access keys
You can delete function and host keys programmatically by using these Azure Resource Manager APIs:
To learn how to call Azure Resource Manager APIs, see the Azure REST API reference.