CodexBloom - Programming Q&A Platform

implementing Azure Key Vault Secret Retrieval in Azure Functions with Managed Identity

πŸ‘€ Views: 20 πŸ’¬ Answers: 1 πŸ“… Created: 2025-07-15
azure key-vault azure-functions managed-identity csharp

I'm dealing with Quick question that's been bugging me - I'm sure I'm missing something obvious here, but This might be a silly question, but I'm experiencing difficulties accessing secrets stored in Azure Key Vault from my Azure Function..... I'm using .NET 5 and have configured my Azure Function to use a system-assigned managed identity. When I attempt to retrieve a secret using the Azure.Security.KeyVault.Secrets library, I get the following behavior: `"KeyVaultSecretNotFoundException: Secret not found"`. I've verified that the secret exists in the Key Vault, and I've also ensured that the managed identity is granted the "Get" permission for secrets in the Key Vault access policies. Here’s the relevant portion of my code: ```csharp using Azure.Identity; using Azure.Security.KeyVault.Secrets; public static async Task<string> GetSecretAsync(string secretName) { var client = new SecretClient(new Uri("https://<your-key-vault-name>.vault.azure.net/"), new DefaultAzureCredential()); KeyVaultSecret secret = await client.GetSecretAsync(secretName); return secret.Value; } ``` The function is running in the correct Azure environment, and I have the environment variable `AzureServicesAuthConnectionString` set properly. However, I still encounter the same behavior. I've tried adding some logging around the `GetSecretAsync` call to confirm that the secret name is being passed correctly, and it is. Am I missing something in terms of configuration, or is there another way to troubleshoot this scenario? Any guidance would be appreciated! How would you solve this? For context: I'm using Csharp on macOS. I'm working on a web app that needs to handle this. I'm on macOS using the latest version of Csharp.