Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

how to get the latest secret version value from azure key vault in one rest api call

I can get the secret from azure key vault in rest api if I already know the version number using this endpoint:

https://my-key-vault-dev.vault.azure.net/secrets/MyTestSecret/13f8347b8518483f8236670197497c93?api-version=2016-10-01

But what if I don't know what the latest version number is?

I guess I could get the latest version number query list first:

GET {vaultBaseUrl}/secrets/{secret-name}/versions?api-version=2016-10-01

Is it possible to do it all in one query? For example, something like this would be great:

https://my-key-vault-dev.vault.azure.net/secrets/MyTestSecret/?api-version=2016-10-01
like image 214
Bill Software Engineer Avatar asked Jan 24 '18 22:01

Bill Software Engineer


People also ask

How do you get secrets from key vault?

Retrieve a secret from Key VaultUse https://<your-unique-keyvault-name>.vault.azure.net/secrets/ExamplePassword to get the current version. Now, you have created a Key Vault, stored a secret, and retrieved it.

How do you access Azure key vault secret through REST API using postman?

Access Token RequestCreate a new request in Postman, name it as “Get Access Token For Key Vault” and change it's request type to “POST”. {{directoryId}} is an environment variable. So when we send the request {{directoryId}} will be replaced with the value we specified earlier.


2 Answers

Now we can easily get the current version secrets by without mentioning version parameter

https://docs.microsoft.com/en-us/rest/api/keyvault/getsecret/getsecret

enter image description here

like image 144
vijay Avatar answered Sep 29 '22 00:09

vijay


Microsoft.Azure.KeyVault library passes String.Empty as an version to the call when there is no specific version requested, so your suggestion should work.

In my case it is just https://mykeyvault.vault.azure.net/secrets/testSecret/

like image 34
Wojciech Sroczyński Avatar answered Sep 29 '22 01:09

Wojciech Sroczyński