为子级别设置 Azure Key Vault 的密钥

Settings keys to Azure Key Vault for sub-levels

对于用户机密管理,我在开发阶段使用用户机密,我想使用 Azure Key Vault 进行发布和暂存。 我有这个配置

"ConnectionStrings": {
  "DefaultConnection": "MySecretConnectionString"
},
"SmtpSettings": {
  "SmtpMailServer": "smtp.mailserver.somewhere",
  "SmtpPort": "465",
  "SenderLogin": "login",
  "SenderDisplayName": "Site ",
  "SenderPassword": "password",
  "SenderEmail": "site@mailserver.somewhere",
  "SecureSocketSettings": "SslOnConnect"
}

当我想在 Azure 密钥保管库中设置 ConnectionStrings:DefaultConnectionSmtpSettings:SenderPassword 时出现问题。

有什么方法可以为嵌套属性分配和使用值吗? 例如,就像我对用户机密所做的那样

dotnet user-secrets set "SmtpSettings:SenderPassword" "########" --project MyProject

但对于 Azure 密钥保管库

az keyvault secret set --name "SmtpSettings:SenderPassword" --value "######" --vault-name MyProjectVault

:不允许,Parameter 'secret_name' must conform to the following pattern: '^[0-9a-zA-Z-]+$'.

您应该按照 documentation

中所述使用 --

Azure Key Vault secret names are limited to alphanumeric characters and dashes. Hierarchical values (configuration sections) use -- (two dashes) as a delimiter, as colons aren't allowed in key vault secret names. Colons delimit a section from a subkey in ASP.NET Core configuration. The two-dash sequence is replaced with a colon when the secrets are loaded into the app's configuration.

az keyvault secret set --name "SmtpSettings--SenderPassword" --value "######" --vault-name MyProjectVault