Settings keys to Azure Key Vault for sub-levels
Asked Answered
P

1

8

For user secret management, I use user secrets for the development stage and I want to use Azure key vault for release and staging. I have this configuration

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

Problem arises when i want to set ConnectionStrings:DefaultConnection or SmtpSettings:SenderPassword in in Azure key vault.

Is there any way to assign and use value to nested properties? For example like I do for user-secrets with

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

but for Azure key vault

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

: is not allowed, Parameter 'secret_name' must conform to the following pattern: '^[0-9a-zA-Z-]+$'.

Pointing answered 16/5, 2021 at 21:29 Comment(0)
M
19

You should use -- as it stated in 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
Map answered 17/5, 2021 at 0:17 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.