I want to store a secret in Azure Key vault, pull into the application settings in an app service (which is working) and when I run the app I can retrieve the data.
Now I want to obtain this value in my local development using visual studio
Thanks to help from this video: https://www.youtube.com/watch?v=vEaCnhvggz0
If you skip to the 9 min mark I was able to
Using the value for this as:
@Microsoft.KeyVault(SecretUri=https://keyVaultName/secrets/SecretName/1121283182091283/)
Then reference Secret_Value in code using:
in my web.config:
<add key="Secret_Value" value="localDev" />
C#
var Secret = ConfigurationManager.AppSettings["Secret_Value"];
which when I run the app locally on VS this returns 'localDev' but correctly when I run on app service this returns the value from the KV
How do I grab the value on my local dev? because obv I cant do this:
<add key="Secret_Value" value="@Microsoft.KeyVault(SecretUri=https://keyVaultName/secrets/SecretName/1121283182091283/)" />
Is this possible? I know I can add KeyVault as Nuget package and obtian with something like:
var client = new SecretClient(new Uri(keyVaultURL), new DefaultAzureCredential());
var secret = client.GetSecret(CRM_Secret_KeyVaultName);
but I dont want this.
I want to pull the value from the local webconfig directly from the KV, is this possible? Without writing any extra code? thanks for any replies
so is there anyway to do it from local without writing code?
We cannot directly bind the Key Vault reference in the local configuration file.
I have tried to set and retrieve the secret with reference in local.
You can see it is not working.
In this case you can separate the local and production configurations.
Web.config
).OR
You can set the secret values in secrets.xml
.
AFAIK, you can retrieve the Azure Key Vault secrets either with code or with Key Vault Reference in the deployed Azure App Service only.
Thanks @RyanHill-MSFT for the comment.
Key Vault is a hosted service and therefore can't be used in local development. It is recommended that development secrets be used.
You can also refer the GitHub link which explains the same.