As Azure Runbook has some limitation to integrate with Azuredevops server pipeline, which is hosted in onprem, we were looking for a bash script to find the secret in a listed keyvault list and if the secrets in the keyvault is about to expire in next 60 days only, then trigger the release pipeline with the specific secret and kv to extend the date to next 2 years followed by the release approval. We are struggling here to find the secret with its expire and to estimate the remaining days
(az keyvault secret list --vault-name kv-01 --query "[?attributes.expires ].{Id:id, expires:attributes.expires}" | jq '.[].expires' '+%s'
Looping through keyvaults failing
inlineScript: |
#Azure Key Vault details
keyvaults=$(az keyvault list --query "[].{Name:name}")
echo "keyvaults are as below $keyvaults"
#Iterate through the kvs
for row in $(echo "${keyvaults}" | jq -c '.[]'); do
keyVaultName=$(echo "$row" | jq -r '.Name')
done
#Get the current date in UTC
currentDate=$(date -u +"%Y-%m-%dT%H:%M:%SZ")
echo "currentDate is $currentDate".....
.................<As same as given in the same accepted answer>.......................
..................... .



To find secrets in an
Azure Key Vaultthat are going to expire in the next 60 days and to estimate the remaining days for each secret, you can use the below bash script.The above script will display already expired secrets, secrets about to expire in 60 days, and secrets that are not yet expired in the
Key Vault.Output: