azure - ARM 模板中创建的对象的 secret 可以自动添加到 Key Vault 中吗

标签 azure azure-resource-manager azure-keyvault azure-rm-template

如果我有一个可以创建的 Azure ARM 模板:

  • Azure 容器注册表
  • Azure key 保管库

是否可以使用 ARM 模板将 Azure 容器注册表的用户名和密码自动添加到 Azure Key Vault?

是否有某种方法可以为此目的引用 ARM 模板中的 Azure 容器注册表用户名和密码 secret ?

更新

@EdBoykin 的答案是正确的,这就是我的结论:

{
  "type": "Microsoft.KeyVault/vaults/secrets",
  "name": "[concat(parameters('key_vault_name'), '/AzureContainerRegistryKey1')]",
  "apiVersion": "2015-06-01",
  "properties": {
    "contentType": "text/plain",
    "value": "[listCredentials(resourceId('Microsoft.ContainerRegistry/registries', parameters('container_registry_name')), '2017-10-01').passwords[0].value]"
  },
  "dependsOn": [
    "[concat('Microsoft.KeyVault/vaults/', parameters('key_vault_name'))]",
    "[concat('Microsoft.ContainerRegistry/registries/', parameters('container_registry_name'))]"
  ]
}

最佳答案

穆罕默德, 要在 KeyVault 中创建 secret ,您需要创建一个如下所示的 ARM 模板。确保更新“dependson”部分,以便该资源依赖于您首先创建的 ACR。用户名将是 ACR 资源名称。因此,无论您在 ARM 脚本中将其设置为什么,您都可以将其作为 key 保管库 secret 存储在 key 保管库中。

对于密码或 key ,这就是您要做的。以下是用于添加 KeyVault secret 的示例模板

{
  "type": "Microsoft.KeyVault/vaults/secrets",
  "name": "[concat(variables('keyVaultName'), '/{YourACRKey1SecretName}')]",
  "apiVersion": "2015-06-01",
  "properties": {
    "contentType": "text/plain",
    "value": "[listCredentials(resourceId('Microsoft.ContainerRegistry/registries', parameters('YourACRName')), '2017-10-01').passwords[0].value]"
  },
  "dependsOn": []
}

{YourACRKey1SecretName} 应更改为您的 ACR Key1 值的 secret 名称。

要在 key 保管库中设置其他 key ,请使用新名称创建另一个 key 保管库 secret 资源,并将其用作值:

对于键 2

[listCredentials(resourceId('Microsoft.ContainerRegistry/registries', parameters('YourACRName')), '2017-10-01').passwords[1].value]

关于azure - ARM 模板中创建的对象的 secret 可以自动添加到 Key Vault 中吗,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/53012377/

相关文章:

c# - SQL Azure 连接因大型 json 字符串而关闭

Azure 应用程序注册登录 URL

Typescript 未在基于容器的 Azure Function App 中构建

python - Azure 数据库摄取速度

azure - 使用 ARM 模板删除现有资源

azure - 如何在 ARM 模板中引用 "deployment name"

reactjs - 尝试使用 React 访问 Azure Key Vault 时无法解析 node_modules 中的 'url' 错误

sql-server - 如何使用 Azure Key Vault 加密 SQL 中的数据列?

Azure KeyVaultAccessForbidden - "not enabled for deployment"

c# - 对于Azure Key Vault,我应该在哪里存储tenantId、clientId和clientSecret?