Is there a way to use a Managed Identity (either System or User-assigned) for authenticating a Function and Storage Account?
Example
- In a Python Azure Function's
function.jsonfile, there is abindingsobject:
"bindings": [
{
"name": "msg",
"type": "queueTrigger",
"direction": "in",
"queueName": "<my-queue-name>",
"connection": "CONN_STRING"
}
]
- The
connectionparameter refers to avalueinlocal.settings.jsonwhen run locally OR anApp Settingwhen deployed to Azure. - These can be either hardcoded in these areas or use a Key Vault Secret Reference
Question:
- Instead of using a Connection String (whether KV Reference or not), can I can grant the Functions Managed Identity a
Storage Queue ContributorRBAC role? - I don't want to handle these Connection Strings
Is this possible? If so, what value do I put in the connection parameter?
Instead of passing the Storage Account's connection string, you can achieve the same with an Identity-Based connection. Refer MSDOC:
You can use
AzureWebJobsStorage__queueServiceUrisetting to achieve your requirement.Storage Queue Data Contributorrole.Storage Queue Data ReaderandStorage Queue Data Message Processorroles in the Storage Account.local.setting.jsonAzureWebJobsStorage__accountNameto the name of the your storage account as its value.local.settings.json:
function_app.py:
Local Response:
Updated Solution:
To use an identity-based connection to a Storage Account which is not the AzureWebJobsStorage Account, assign the storage account as value to any new variable with pattern
"<CONNECTION_NAME_PREFIX>__queueServiceUri": "https://<storage_account_name>.queue.core.windows.net"local.settings.json:
Code Snippet:
Change the connection value in the
functionapp.pyasconnection =<CONNECTION_NAME_PREFIX>.