0

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#?

1
  • You could update the Enabled in SecretProperties of secret, refer to the SDK. Commented Jan 15, 2021 at 1:32

2 Answers 2

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.

Sign up to request clarification or add additional context in comments.

Comments

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.

Comments

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.