I am following this tutorial which explains how to access an Azure text analytics service from a Python application using service principal. In the end, a password is used. The approach works for dev/test but for prod, the recommended way is to use managed identities.
The service principal has get, list access to the key vault.
The process gives me some parameters of service principal which I use in the Python code:
{
"appId": "...",
"displayName": "api://ai-app-mc",
"password": "...",
"tenant": "..."
}
How do I go about using managed identities such that I can access an Azure AI service from Python code without having to store any password or key in the code or .env file?
The code in the tutorial runs from Visual Studio. If I want to use managed identities, can I still use Visual Studio do I need to deploy the application in a VM and then assign managed identity to the VM and then give the managed identify access to the AzureAI` service? The tasks I have done so far:
- went to Azure AI service and enabled managed identify. I suppose this decides who can access the service.
- I created a Cognitive services user for the resource group
I suppose I have to assign roles but shall I do it at subscription level, resource group level?
Where does the Python code I want to run come in?
Follow below steps.
Cognitive Services Language Readerrole to your managed identity.Here, I used
ManagedIdentityCredential, which by default usessystem-assigned identity, and by providing the client id, you can useuser-assigned identity.Output: