Edgar Hernandez
Edgar Hernandez

Reputation: 425

how to retrieve secrets from azure vault using java 5?

I have to retrieve secrets from Azure Vault but my app uses jdk 5. This is a problem because the azure libraries used and described in Microsoft docs require at minimum jdk 8 and upgrading the jdk is not an option.

The client's architect says that I can consume some vault api and use bouncy castle's tls api to achieve this but I'm not sure what is he talking about.

This sounds too low level. I'm asking for guidance, some superfluous explanation can get me going. How can I obtain secrets using Java 5?

Upvotes: 0

Views: 212

Answers (1)

unknown
unknown

Reputation: 7483

As the architect says, you could retrieve a secret from Key Vault by Key Vault REST API instead of azure libraries.

GET https://{yourvault}.vault.azure.net/secrets?api-version=7.1

This API is used to list secrets in a specified key vault. And you could get a specified secret from a given key vault by this link.


First, get access_token with Post via ApacheHttpClient.

POST https://login.microsoftonline.com/{tenant}/oauth2/v2.0/token
Content-Type: application/x-www-form-urlencoded

client_id={your-client-id}
&scope=https%3A%2F%2Fvault.azure.net%2F.default
&client_secret={your-client-secret}
&grant_type=client_credentials

Then, call the REST API with Get via ApacheHttpClient.

GET https://{yourvault}.vault.azure.net/secrets?api-version=7.1
Authorization: Bearer {access_token}

I try this with Postman, and it works well. You could use httpclient to obtain secrets by java.

enter image description here

Note:

Navigate to Azure Portal > Key vaults > your_key_vault > Access policies > Add Access Policy. In secret permissions field, select desired permissions and Select Principal section, select the application that you are using to access the secret.

Upvotes: 2

Related Questions