Below is the Key-Vault problem which I am facing. I have a Key-Vault which stores some keys which is used in web-app and functions using @Microsoft.KeyVault(SecretUri=) The value of the secret will change every three days using an automation. That will change the version number (GUID) as well and then the app setting value (atleast one in case of Primary and Secondary) will become invalid. Is there any way I can refer the latest value from the KeyVault in app settings. Updating the app settings in all the website will be a tedious process.
For my App Service, I did have success using a Key Vault reference in the form below with no version:
@Microsoft.KeyVault(SecretUri=https://<vault_name>.vault.azure.net/secrets/<secret_name>/)
However, I did have to Stop and Start (not Restart) the App Service to pull in the new secret value from the key vault.
"@Microsoft.KeyVault(VaultName=myvault-kv-dev;SecretName=myKeyName)"
nad even when I stop and start it does not refresh my secrets. I have to do redeploy. It is not good because it is my main purpose to avoid redeploy when secret change... –
Donald Key Vault references are currently in preview.
A Key Vault reference is of the form @Microsoft.KeyVault({referenceString}), where {referenceString} is replaced by one of the following options:
SecretUri=secretUri
where SecretUri
should be the full data-plane URI of a secret in Key Vault, including a version, e.g., https://myvault.vault.azure.net/secrets/mysecret/ec96f02080254f109c51a1f14cdb1931
VaultName=vaultName;SecretName=secretName;SecretVersion=secretVersion
where VaultName
should the name of your Key Vault resource. The SecretName
should be the name of the target secret. The SecretVersion
should be the version of the secret to use.
For example, a complete reference would look like the following:
@Microsoft.KeyVault(SecretUri=https://myvault.vault.azure.net/secrets/mysecret/ec96f02080254f109c51a1f14cdb1931)
Alternatively:
@Microsoft.KeyVault(VaultName=myvault;SecretName=mysecret;SecretVersion=ec96f02080254f109c51a1f14cdb1931)
In the current preview, versions
are required. When rotating secrets
, you will need to update the version in your application configuration.
Restarting the app service didn't take effect immediately, so this is what I did.
- Delete the secret variable from KeyVault.
- Purge the deleted variable (so that you can create a new one with the same name)
- Create the secret variable again using the same name and with its new value.
- Optional: Resave any configuration settings having
@Microsoft.KeyVault(SecretUri=...
so it refreshes its internals. Although we did not change anything, sometimes you get a dreaded error Keyword not supported: @microsoft.keyvault(secreturi... blah blah
With Azure Python SDK you can do something like this:
kv_client.get_secret("https://%kvname%.vault.azure.net/", name, KeyVaultId.version_none)
# or this
kv_client.get_secret("https://%kvname%.vault.azure.net/", name, "")
both of these will pull the latest version of the secret. so I assume that doing this in the code in c# would be more or less identical (or at least possible). Not so sure about the appsettings of web apps =\.
You can, probably, use some sort of automation (like powershell) to update those.
On the Web App > Configuration > Connection strings, juste update the current value of the property for whatever and then back to the original value did the trick. No need to restart the service.
© 2022 - 2024 — McMap. All rights reserved.