Error in web app deployed from AI Foundry; all queries result in error

Barry Briggs 110 Reputation points
2025-04-10T19:06:30.53+00:00

Redeploy (working) web app from Azure AI Foundry. Tried with and without chat history enabled.

Get Error code: 400 - {'error': {'requestid': '7a5c4617-80ed-40bd-b2d3-11771466a883', 'code': 400, 'message': 'Failed to get managed identity token. Response: {"error":{"code":"ManagedIdentityIsNotEnabled","message":"Managed Identity (MI) is not set for this account while the encryption key source is 'Microsoft.KeyVault', customer managed storage or Network Security Perimeter is used."}}'}}Tried editing AZURE_OPENAI_KEYs per older posts to no avail.

Azure AI Search
Azure AI Search
An Azure search service with built-in artificial intelligence capabilities that enrich information to help identify and explore relevant content at scale.
1,283 questions
{count} votes

1 answer

Sort by: Most helpful
  1. Suresh Chikkam 1,330 Reputation points Microsoft External Staff
    2025-04-15T13:06:12.0166667+00:00

    Hi Barry Briggs,

    Thanks for all the details. Based on what you have shared, the issue is not with encryption or Key Vault, it’s most likely that the AI Foundry Web App is trying to access Azure Cognitive Search using Managed Identity, which hasn’t been enabled or granted the right permissions.

    Even if you didn’t set this up manually, the default app is often wired to use Managed Identity for security. So, when you switched to a new index, the app likely tried to use MI for authentication and failed which explains the ManagedIdentityIsNotEnabled error.

    You have two ways to fix this:

    Option 1: Enable Managed Identity for your Web App and grant it access to the Cognitive Search index.

    Here’s how:

    In the Azure Portal, go to your Web App → Identity → enable System-assigned identity.

    • Then go to your Azure Cognitive Search resource → Access Control (IAM) → assign the Search Index Data Reader role to the Web App’s identity.

    Docs for reference: Enable Managed Identity, Assign Search roles

    Option 2: If you’d rather not use Managed Identity, you can modify the Web App code to authenticate with the Azure Search API key instead. This matches how it works in the Foundry Playground.

    var searchClient = new SearchClient(
        new Uri("https://<your-search-service>.search.windows.net"),
        "<index-name>",
        new AzureKeyCredential("<your-api-key>"));
    

    Either approach will work it just depends on whether you want to stick with the default (Managed Identity) or go with API keys for now.

    Hope it helps!


    Please do not forget to click "Accept the answer” and Yes wherever the information provided helps you, this can be beneficial to other community members.

    User's image

    If you have any other questions or still running into more issues, let me know in the "comments" and I would be happy to help you.


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.