user14346079
user14346079

Reputation: 101

How to store JSON value within azure key vault

I am straggling to understand what is the best practice to store data in json format within azure key vault or alternatively to map each single key to my "appsettings.json" files. i read a lot on that issue but i couldn't figure it out how exactly it can be done

How would i retrieve json string formatted and map it to an object or assign each key vault into my appsettings.json

This is how my json looks like.

{
   "Container":{
      "Machine1":{
         "url":"some address "
      }
    }
}

Thanks, appreciate a lots your help

Upvotes: 3

Views: 7278

Answers (2)

Joy Wang
Joy Wang

Reputation: 42063

Of course, you can store JSON value to azure keyvault, follow the steps below.

1.Install the Az powershell module, follow this doc - https://learn.microsoft.com/en-us/powershell/azure/install-az-ps?view=azps-3.8.0

2.Then use Connect-AzAccount to login your account, make sure your account has the correct secret permission in Access policies of your keyvault, if not, add it in the portal.

3.Then use the commands below(you cannot store the json value directly in the portal, the Azure Portal currently only supports single-line secret values).

$string = '{
   "Container":{
      "Machine1":{
         "url":"some address "
      }
    }
}'
$Secret = ConvertTo-SecureString -String $string -AsPlainText -Force
Set-AzKeyVaultSecret -VaultName "keyvaultname" -Name "testjson" -SecretValue $Secret

4.Check it in the portal -> your keyvault -> Secrets, it works fine.

enter image description here

Upvotes: 8

Shane Bala
Shane Bala

Reputation: 47

key vault is not designed to store JSON in this manner. Please read the following document to get a better understanding of Azure Key Vault. https://learn.microsoft.com/en-us/azure/key-vault/general/overview

Upvotes: -2

Related Questions