How to fix internal server error 500 for kusto db using user managed identity ?

SohamPrasad Girde (Wipro Designit Services, Inc.) 40 Reputation points Microsoft Vendor
2024-11-07T15:56:52.2233333+00:00

Hi ,

     I am trying to use user assigned managed identity to connect with KUSTO db but getting internal server error 500 . kusto db already given the permissions to my managed identity .

I am concern about the app service environment variable is that playing any role ?

Your support much appreciated. Thanks you

Azure Data Explorer
Azure Data Explorer
An Azure data analytics service for real-time analysis on large volumes of data streaming from sources including applications, websites, and internet of things devices.
533 questions
Azure App Service
Azure App Service
Azure App Service is a service used to create and deploy scalable, mission-critical web apps.
7,957 questions
{count} votes

2 answers

Sort by: Most helpful
  1. Luis Arias 7,531 Reputation points
    2024-11-07T21:00:44.9933333+00:00

    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 add AZURE_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, using AZURE_CLIENT_ID to specify the correct identity:
         from 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)
      
      Replace "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

    1 person found this answer helpful.
    0 comments No comments

  2. Sander van de Velde | MVP 33,231 Reputation points MVP
    2024-11-08T11:34:04.0766667+00:00

    Hello SohamPrasad,

    welcome to this moderated Azure community forum.

    Please check out the excellent answer from @Luis Arias.

    I add an extra answer because there are multiple ways of connecting to ADX programmatically.

    Check out this blog post with more details.


    If the response helped, do "Accept Answer". If it doesn't work, please let us know the progress. All community members with similar issues will benefit by doing so. Your contribution is highly appreciated.


Your answer

Answers can be marked as Accepted Answers by the question author, which helps users to know the answer solved the author's problem.