Can you create a new version of a secret through Azure CLI?

Valenzuela, Anthony O 20 Reputation points
2023-06-12T15:20:58.3966667+00:00

Is it possible to create a new version of a secret in a Key Vault through Azure CLI? I am trying to update all my secrets in a vault with a new version and an expiration date but using

az keyvault secret set

only updates my current version of the secret.

Azure Key Vault
Azure Key Vault
An Azure service that is used to manage and protect cryptographic keys and other secrets used by cloud apps and services.
1,456 questions
0 comments No comments
{count} votes

Accepted answer
  1. JamesTran-MSFT 36,911 Reputation points Microsoft Employee Moderator
    2023-06-12T19:54:16.4166667+00:00

    @Valenzuela, Anthony O

    Thank you for your post!

    I understand that you're trying to update all of your Secret versions and expiration dates within your Key Vault using Azure CLI. However, when using the az keyvault secret set command, this only updates the current Secret version and not all of the Secrets within your Key Vault. To hopefully point you in the right direction or help resolve your issue, I'll share my findings below.

    Findings:

    When it comes to the az keyvault secret CLI commands, az keyvault secret set will only update the current Secret version and not all of the Secrets within your Key Vault, since it only references one Secret at a time through --name. For more info.

    To update all of the Secrets within your Key Vault, you can try using the az keyvault secret list command to list all of the Secrets, and then use a loop to update each Secret individually. For example:

    for secret in $(az keyvault secret list --vault-name "KVName" --query "[].id" -o tsv); do
        az keyvault secret set-attributes --id $secret --expires "2024-06-14T22:00:00Z"
    done
    

    User's image

    Additional Links:

    I hope this helps!

    If you have any other questions, please let me know. Thank you for your time and patience throughout this issue.


    If the information helped address your question, please Accept the answer. This will help us and also improve searchability for others in the community who might be researching similar information.


2 additional answers

Sort by: Most helpful
  1. Sam Cogan 10,812 Reputation points Microsoft Employee Volunteer Moderator
    2023-06-12T16:07:00.1866667+00:00

    That command is adding a new version. You cannot change a version in Key Vault once it is created, so any change is always a new version.

    0 comments No comments

  2. Valenzuela, Anthony O 20 Reputation points
    2023-06-15T18:02:40.9066667+00:00

    Perfect thank you! Is it possible to also create a new version of the same secret? Say for example, I wanted to create a new version of my secret with either the same or different secret value, with an expiration date.

    0 comments No comments

Your answer

Answers can be marked as Accepted Answers by the question author, which helps users to know the answer solved the author's problem.