Forum Discussion

jdm23133's avatar
jdm23133
Copper Contributor
Jul 02, 2025

Why can't my Function Access my Key Vault?

I am developing an automation for the first time with Azure Functions. In Azure, I have set up a Key Vault to store login credentials used in the Function. My account has the following roles: Contributor, Key Vault Administrator, Key Vault Secrets User, and Owner. Furthermore, the Managed Identity for my Function has the roles Key Vault Administrator, Key Vault Secrets User. In spite of all this, when I try to run my function locally with an HTTP endpoint using Postman, I get the following error:

Azure.RequestFailedException: Caller is not authorized to perform action on resource.

Did I give myself or my managed identity the wrong roles?

4 Replies

  • BrianVeldman's avatar
    BrianVeldman
    Copper Contributor

    You either use RBAC or access policies. RBAC is the recommended model, as it is newer and more flexible. Could you create a simple function to retrieve a secret from the Key Vault using RBAC? Also, how is your network access configured?

  • Take this:

     

    1. Use Access Policies (Not Just RBAC)
    Even though you've assigned RBAC roles like Key Vault Secrets User, Key Vaults created with the "Vault access policy" permission model require explicit Access Policies.
    •    Go to your Key Vault in the Azure Portal.
    •    Under Access Policies, add your Function App's managed identity.
    •    Grant it Get and List permissions for secrets.

    2. Confirm Managed Identity Is Enabled
    Make sure your Azure Function has its System Assigned Managed Identity turned on:
    •    Go to your Function App > Identity.
    •    Under System Assigned, ensure it's On.
    •    Copy the Object ID—you’ll need it for access policies or role assignments.

    3. Check Local Development Authentication
    When running locally, your function doesn't use the managed identity—it uses your local Azure CLI or Visual Studio credentials.
    •    Run az login to authenticate your CLI.
    •    Ensure your local user has Key Vault Secrets User role or is added to the Access Policy.

    4. Verify Key Vault URL and Secret Name
    Double-check that your code is using the correct format:

    var kvUri = "https://<your-keyvault-name>.vault.azure.net/";
    var client = new SecretClient(new Uri(kvUri), new DefaultAzureCredential());
    KeyVaultSecret secret = client.GetSecret("<your-secret-name>");
    

     

    • jdm23133's avatar
      jdm23133
      Copper Contributor

      When I navigate to 'Access Policies' within my vault, it says 'Access policies not available' and tells me to go back to the 'Access control (IAM)' page. Is there a way to get past this message and set up Access Policies when I already have RBAC?

      • BrianVeldman's avatar
        BrianVeldman
        Copper Contributor

        You either use RBAC or access policies. RBAC is the recommended model, as it is newer and more flexible. Could you create a simple function to retrieve a secret from the Key Vault using RBAC? Also, how is your network access configured?

Resources