I have been looking at an option to enable the secret key in the key vault from C# with managed identity. I have full permissions and I am able to create, delete and change the secrets but somehow, if I create a disabled secret key, I cannot read that to re-enable it. Could anyone help to know whether it is possible to enable the disabled key from c#?
Asked
Active
Viewed 1,776 times
0
-
You could update the `Enabled` in SecretProperties of secret, refer to the [SDK](https://learn.microsoft.com/en-us/dotnet/api/azure.security.keyvault.secrets.secretclient.updatesecretproperties?view=azure-dotnet). – unknown Jan 15 '21 at 01:32
2 Answers
2
Add my comment as an answer:
You could update the Enabled in SecretProperties of secret, refer to the SDK.
var kvUri = "https://" + keyVaultName + ".vault.azure.net";
var client = new SecretClient(new Uri(kvUri), new DefaultAzureCredential());
KeyVaultSecret secret = client.GetSecret("secret-name");
secret.Properties.Enabled = true;
SecretProperties updatedSecretProperties = client.UpdateSecretProperties(secret.Properties);
Console.WriteLine(updatedSecretProperties.Enabled);
For more details, you could see the official document.

unknown
- 6,778
- 1
- 5
- 14
0
Without getting the secret, if you know the name you can simply update it's properties:
var client = new SecretClient(
new Uri("https://myvault.vault.azure.net"),
new DefaultAzureCredential());
await client.UpdateSecretPropertiesAsync(
new SecretProperties("secret-name")
{
Enabled = true,
});
If you already have a KeyVaultSecret
, set it's Properties.Enabled
to true and pass Properties
to the same method above.

Heath
- 2,986
- 18
- 21