Better you need to avoid the conn string format that uses the storage key and instead leverage Azure Active Directory (Azure AD) auth.
Here is how you can configure it:
- Create a Service Principal: If you haven't already, register an application in Azure Active Directory and assign the necessary role (such as "Storage Blob Data Contributor") to the service principal on the target Azure Storage account.
- Add necessary information to the configuration: In your Function App's
local.settings.json
or in the Azure portal under "Configuration" for the Function App, define the following environment variables:-
AZURE_CLIENT_ID
: The client ID of the service principal. -
AZURE_CLIENT_SECRET
: The client secret for the service principal. -
AZURE_TENANT_ID
: The tenant ID of your Azure AD. -
STORAGE_ACCOUNT_NAME
: Your Azure Storage account name.
-
- Use Azure SDK with DefaultAzureCredential: When connecting to the storage account, use the Azure SDKs that support Azure AD authentication, such as the
@azure/storage-blob
package in Node.js orAzure.Storage.Blobs
in C#. - Azure Function's
function.json
: If you need to configure this in yourfunction.json
, you typically won’t pass the connection string directly like in the storage key approach. Instead, use environment variables and pass the account name and the authentication details programmatically in your function code. This method removes the need to store sensitive keys in your configuration and uses the more secure AAD authentication via the service principal