Enabled same "user assigned managed identity" for Azure VMSS as well as for Azure function app.
Added the MI to the access policy of Azure key vault.
On below application hosts, using "DefaultAzureCredential" trying connect to the Azure key vault to read application secrets,
From the application deployed on Azure VMSS, with out any hassle can able to connect to the Azure key vault to read application secrets using "DefaultAzureCredential" api
Where as from Azure function can't able to connect to keyvault using "DefaultAzureCredential" api, it throws below exception
Error occurred while trying to connect to Key Vault. Azure.Identity: ManagedIdentityCredential authentication failed: Service request failed. Status: 400 (Bad Request)
Overcome the above issue in Azure function app by adding explicit "AZURE_CLIENT_ID" variable in appsettings and by assigning "user assigned managed identity" name to it.
Would like to know, why there is difference in behaviour of "DefaultAzureCredential"api while consuming it in Azure VMSS vs Azure function app where explicit mentioning of "AZURE_CLIENT_ID" required? what is the rationale here?
P.S: the above mentioned happening only with user assigned not system assigned managed identity.