Randy Minder
Randy Minder

Reputation: 48402

Unable to retrieve secret in Azure Function - Access Denied

I have the following Azure Function, or at least the relevant part of it:

    using Microsoft.Azure.Services.AppAuthentication;
    using Microsoft.Azure.KeyVault;
    using Microsoft.Azure.KeyVault.Models;
    using System;
    using System.Configuration;
    using System.Data.SqlClient;
    using System.Threading.Tasks;

    public static async Task Run(TimerInfo myTimer, TraceWriter log)
    {
        AzureServiceTokenProvider tokenProvider = new AzureServiceTokenProvider();

        var keyVaultClient = new KeyVaultClient(new KeyVaultClient.AuthenticationCallback(tokenProvider.KeyVaultTokenCallback));
        var secret = await keyVaultClient.GetSecretAsync("https://xxxxx.vault.azure.net/secrets/TwiloAccountSid");

        ...
    }

When this executes I get an Access Denied error attempting to retrieve the secret. The Azure Function has been registered with Managed Service Identity. It appears there is something else I need to do.

Upvotes: 1

Views: 738

Answers (1)

Tom Sun
Tom Sun

Reputation: 24529

It appears there is something else I need to do.

As SuWat ch mentioned that if we want to access the KeyVault, we also need to add the permisson to let azure function to access it. For more detail steps, you could refer to this guide.

enter image description here

Upvotes: 3

Related Questions