Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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

like image 840
user14346079 Avatar asked Nov 25 '25 09:11

user14346079


1 Answers

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

like image 57
Joy Wang Avatar answered Nov 28 '25 00:11

Joy Wang



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!