如何在 Azure Key Vault 中存储 JSON 值

How to store JSON value within azure key vault

我正在努力了解在 Azure Key Vault 中以 json 格式存储数据或将每个密钥映射到我的“appsettings.json”文件的最佳做法是什么。我读了很多关于那个问题的书,但我无法弄清楚到底该怎么做

我如何检索 json 格式的字符串并将其映射到对象或将每个密钥保管库分配到我的 appsettings.json

这就是我的 json 的样子。

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

谢谢,非常感谢你的帮助

Key Vault 并非旨在以这种方式存储 JSON。 请阅读以下文档以更好地了解 Azure Key Vault。 https://docs.microsoft.com/en-us/azure/key-vault/general/overview

当然,您可以将 JSON 值存储到 azure keyvault,请按照以下步骤操作。

1.Install Az powershell 模块,遵循此文档 - https://docs.microsoft.com/en-us/powershell/azure/install-az-ps?view=azps-3.8.0

2.Then 使用 Connect-AzAccount 登录您的帐户,确保您的帐户在您的密钥库的 Access policies 中具有正确的秘密权限,如果没有,请将其添加到门户中。

3.Then 使用下面的命令(不能直接在门户中存储 json 值,Azure 门户目前仅支持 single-line 秘密值)。

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

4.Check 它在门户 -> 你的密钥库 -> Secrets,它工作正常。