Nota
El acceso a esta página requiere autorización. Puede intentar iniciar sesión o cambiar directorios.
El acceso a esta página requiere autorización. Puede intentar cambiar los directorios.
在部署过程中,需要将安全值(例如密码)作为参数传递时,可从 Azure 密钥保管库检索值。 若要在部署托管应用程序时访问 Key Vault,必须授予对设备资源提供程序服务主体的访问权限。 托管应用程序服务使用此标识来运行操作。 若要在部署过程中从密钥保管库成功检索某个值,服务主体必须能够访问密钥保管库。
本文介绍如何配置 Key Vault 以与托管应用程序一起使用。
登录到 Azure 门户。
打开密钥保管库。 在搜索框中输入“密钥保管库”,或者选择“密钥保管库”。
选择访问配置。
选择“用于模板部署的 Azure 资源管理器”。 然后选择“应用”。
将“参与者”角色分配给密钥保管库范围内的“设备资源提供程序”用户 。 参与者角色是角色分配的一种特权管理员角色。 有关详细步骤,请转到使用 Azure 门户分配 Azure 角色。
设备资源提供程序 是 Microsoft Entra 租户中的服务主体。 在 Azure 门户中,可以通过以下方法验证其是否已注册:转到“Microsoft Entra ID”>“企业应用程序”,然后将搜索筛选器更改为“Microsoft 应用程序”。 搜索设备资源提供程序。 如果未找到服务主体,请注册 Microsoft.Solutions
资源提供程序。
若要将 Key Vault 中的机密传递给托管应用程序中的模板,必须使用链接或嵌套模板并在链接或嵌套模板的参数中引用 Key Vault。 提供 Key Vault 的资源 ID 和机密名称。
{
"$schema": "https://schema.management.azure.com/schemas/2019-04-01/deploymentTemplate.json#",
"contentVersion": "1.0.0.0",
"parameters": {
"location": {
"type": "string",
"defaultValue": "[resourceGroup().location]",
"metadata": {
"description": "The location where the resources will be deployed."
}
},
"vaultName": {
"type": "string",
"metadata": {
"description": "The name of the key vault that contains the secret."
}
},
"secretName": {
"type": "string",
"metadata": {
"description": "The name of the secret."
}
},
"vaultResourceGroupName": {
"type": "string",
"metadata": {
"description": "The name of the resource group that contains the key vault."
}
},
"vaultSubscription": {
"type": "string",
"defaultValue": "[subscription().subscriptionId]",
"metadata": {
"description": "The name of the subscription that contains the key vault."
}
}
},
"resources": [
{
"type": "Microsoft.Resources/deployments",
"apiVersion": "2022-09-01",
"name": "dynamicSecret",
"properties": {
"mode": "Incremental",
"expressionEvaluationOptions": {
"scope": "inner"
},
"template": {
"$schema": "https://schema.management.azure.com/schemas/2019-04-01/deploymentTemplate.json#",
"contentVersion": "1.0.0.0",
"parameters": {
"adminLogin": {
"type": "string"
},
"adminPassword": {
"type": "securestring"
},
"location": {
"type": "string"
}
},
"variables": {
"sqlServerName": "[concat('sql-', uniqueString(resourceGroup().id, 'sql'))]"
},
"resources": [
{
"type": "Microsoft.Sql/servers",
"apiVersion": "2022-05-01-preview",
"name": "[variables('sqlServerName')]",
"location": "[parameters('location')]",
"properties": {
"administratorLogin": "[parameters('adminLogin')]",
"administratorLoginPassword": "[parameters('adminPassword')]"
}
}
],
"outputs": {
"sqlFQDN": {
"type": "string",
"value": "[reference(variables('sqlServerName')).fullyQualifiedDomainName]"
}
}
},
"parameters": {
"location": {
"value": "[parameters('location')]"
},
"adminLogin": {
"value": "ghuser"
},
"adminPassword": {
"reference": {
"keyVault": {
"id": "[resourceId(parameters('vaultSubscription'), parameters('vaultResourceGroupName'), 'Microsoft.KeyVault/vaults', parameters('vaultName'))]"
},
"secretName": "[parameters('secretName')]"
}
}
}
}
}
],
"outputs": {
}
}
你已将 Key Vault 配置为在部署托管应用程序期间可访问。
- 有关从 Key Vault 传递值作为模板参数的信息,请转到使用 Azure Key Vault 在部署期间传递安全参数值。
- 若要详细了解密钥保管库安全性,请转到 Azure Key Vault 安全性和 Azure Key Vault 中的身份验证。
- 有关托管应用程序示例,请转到 Azure 托管应用程序的示例项目。
- 若要了解如何为托管应用程序创建 UI 定义文件,请转到 CreateUiDefinition 入门。