azureazure-keyvaultazure-appservice

How to connect secrets value stored in Azure key vault to Azure app service env variables directly


I have a key vault and a app service hosted on Azure. I have a secret stored in that key vault that i want to consume its value directly in app service. I mean by directly that i be able to override the env. variable with the value of the secret directly withou any code interventions as it is showen in the screenshot. enter image description here

I created a managed identity for the app service and give access role to it from the key vault and they are perfectly connected.

I tried to use this pattern @Microsoft.KeyVault(SecretUri=https://key-vault.vault.azure.net/secrets/encryption-key) in order to try to get the value but did not succeed.

So I need a solution for it without also automating the flow using power automate. I need a solution on azure that enable me to read and get the value in the key vault and put it in the env.variables of the app service.


Solution

  • enter image description here

    My Secrets:

    enter image description here

    enter image description here

    put it in the env.variables of the app service

    @Microsoft.KeyVault(SecretUri=https://HarshuKVJuly.vault.azure.net/secrets/SampleSecret)
    

    enter image description here

    enter image description here

    enter image description here

    enter image description here

    @page
     
    @model IndexModel
    @{
        ViewData["Title"] = "Home page";
        var SampleSecret = Environment.GetEnvironmentVariable("SampleSecret");
    }
    
    <div class="text-center">
        <h1 class="display-4">Welcome</h1>
    <p>@SampleSecret</p></div>
    
    

    enter image description here