How to set expiry date for all the azure key vault secrets ?

Deshmukh, Vijit 496 Reputation points
2024-05-31T12:48:31.83+00:00

Hi Team,

I want to set expiry for all the secrets under one azure key vault.

After searching many articles I found this :

"az keyvault secret set-attributes --vault-name 'your-keyvault-name' --name 'your-secret-name' --expires '2024-12-31T23:59:59Z'"

But this for setting up individual secret expiry.

Please help to set expiry for all the secrets at Once.

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,173 questions
0 comments No comments
{count} votes

2 answers

Sort by: Most helpful
  1. Babafemi Bulugbe 2,985 Reputation points MVP
    2024-05-31T16:45:37.35+00:00

    Hello Deshmukh, Vijit,

    Thank you for posting your query in the Microsoft Q&A Community.

    If the above cli command works for you, You can modify it to loop through each of the secrets within your tenant. Use the code below as a sample

    VAULT_NAME="your-keyvault-name"
    
    EXPIRY_DATE="2024-12-31T23:59:59Z"
    
    secret_names=$(az keyvault secret list --vault-name $VAULT_NAME --query "[].name" -o tsv)
    
    for secret_name in $secret_names; do
    
    az keyvault secret set-attributes --vault-name $VAULT_NAME --name $secret_name --expires $EXPIRY_DATE
    
    done
    

    Let me know if this helps

    Babafemi

    0 comments No comments

  2. Deshmukh, Vijit 496 Reputation points
    2024-06-03T11:05:23.32+00:00

    Hi @Babafemi Bulugbe Error message : ERROR: <urllib3.connection.HTTPSConnection object at 0x00000283D0AAFAD0>: Failed to establish a new connection: [Errno 11001] getaddrinfo failed

    In azure devops pipeline