Hello SohamPrasad, To resolve a 500 Internal Server Error when connecting to Kusto DB with a User Assigned Managed Identity, here are some key areas to check:
- Verify Permissions for Managed Identity
Ensure that your User Assigned Managed Identity (UAMI) has the correct permissions on the Kusto database. The managed identity should typically have the Database User role or a role with read/write access. You can check and assign roles in Kusto Database > Access control (IAM). - Configure Environment Variables in App Service
Make sure the App Service environment variables are correctly configured. Set the following:
AZURE_CLIENT_ID
: Set this to the Client ID of your User Assigned Managed Identity. This tells the App Service which managed identity to use when connecting to Kusto DB. To set environment variables, go to App Service > Settings > Configuration in the Azure Portal, and addAZURE_CLIENT_ID
under Application settings. - Verify Code Configuration for Managed Identity Authentication
Ensure your code uses the Azure Identity SDK to authenticate with the managed identity, usingAZURE_CLIENT_ID
to specify the correct identity:
Replacefrom azure.kusto.data import KustoConnectionStringBuilder from azure.identity import ManagedIdentityCredential credential = ManagedIdentityCredential(client_id="YOUR_MANAGED_IDENTITY_CLIENT_ID") kcsb = KustoConnectionStringBuilder.with_aad_managed_identity("https://<your-cluster-name>.<region>.kusto.windows.net", credential=credential)
"YOUR_MANAGED_IDENTITY_CLIENT_ID"
with your actual client ID, and"<your-cluster-name>.<region>.kusto.windows.net"
with your Kusto cluster endpoint. - Check Diagnostic Logs
Enable Diagnostic Logs in your App Service to review any error messages:
Go to App Service > Monitoring > App Service Logs and enable Application Logging (Filesystem).
References
If the information helped address your question, please Accept the answer.
Luis