你当前正在访问 Microsoft Azure Global Edition 技术文档网站。 如果需要访问由世纪互联运营的 Microsoft Azure 中国技术文档网站,请访问 https://docs.azure.cn。
注释
本文档适用于 Microsoft Foundry(新)门户。
如果未设置 Key Vault 连接,Microsoft Foundry 会将连接详细信息存储在订阅外部Microsoft管理的 Key Vault 中。 若要管理自己的机密,请将 Azure Key Vault 连接到 Foundry。
Azure Key Vault 是一种云服务,用于安全地存储和访问机密。 机密是想要严格控制对访问权限的任何内容,例如 API 密钥、密码、证书或加密密钥。 有关详细信息,请参阅关于 Azure 密钥保管库。
注释
在设置 Key Vault 连接之前请先查看限制。
局限性
仅在需要时创建 Azure Key Vault 连接。
如果使用自带 Azure Key Vault,请查看以下限制:
将 Azure Key Vault 连接限制为每个 Foundry 资源一个。 仅当 Foundry 资源或项目级别不存在其他连接时,才删除 Azure Key Vault 连接。
Foundry 不支持机密迁移。 自行删除并重新创建连接。
删除底层的 Azure Key Vault 会导致 Foundry 资源中断。 Azure Key Vault 为不使用 Microsoft Entra ID 的连接存储机密。 依赖于这些连接的任何 Foundry 功能都停止工作。
删除 Foundry 资源在自带 (BYO) Azure Key Vault 中存储的连接机密可能会中断与其他服务的连接。
使用 Foundry(经典版)门户
在 Foundry(经典)门户中创建与 Azure Key Vault 的连接。
-
登录到 Microsoft Foundry。 确保 New Foundry 开关处于关闭状态。 这些步骤适用于 Foundry(经典)。
选择或创建项目。
在左下窗格中选择 管理中心 。 可能需要滚动才能找到它。
检查“资源”或“项目”部分中是否有连接。 如果连接存在,则 Azure Key Vault 不可用。
在“资源”部分中,选择“已连接资源”。
在“已连接的资源”部分,选择“+ 新建连接”。
选择“Azure 密钥保管库”。
选择 Azure Key Vault,然后选择“连接”。
完成这些步骤后,可能需要几分钟才能使用连接。
使用 Bicep 模板
使用此模板:
/*
Set up your Key Vault connection
Select which RBAC role to assign:
1. Key Vault Administrator: 00482a5a-887f-4fb3-b363-3b7fe8e74483 - https://learn.microsoft.com/en-us/azure/role-based-access-control/built-in-roles/security#key-vault-administrator
2. Key Vault Contributor: f25e0fa2-a7c8-4377-a976-54943a77a395 - https://learn.microsoft.com/en-us/azure/role-based-access-control/built-in-roles/security#key-vault-contributor
3. Key Vault Secret Officer: b86a8fe4-44ce-4948-aee5-eccb2c155cd7 - https://learn.microsoft.com/en-us/azure/role-based-access-control/built-in-roles/security#key-vault-secrets-officer
This template defaults to using the Key Vault Secret Officer role.
Run command:
az deployment group create \
--name AzDeploy \
--resource-group {RESOURCE-GROUP-NAME} \
--template-file connection-key-vault.bicep \
--parameters aiFoundryName={Foundry-resource-name} keyVaultName={KV-resource-name}
az deployment group create --name AzDeploy --resource-group {RESOURCE-GROUP-NAME} --template-file connection-key-vault.bicep --parameters aiFoundryName={Foundry-resource-name} keyVaultName={KV-resource-name}
*/
param aiFoundryName string = '<your-account-name>'
param keyVaultName string
//param resourceGroupName string = '<your-resource-group-name>'
resource aiFoundry 'Microsoft.CognitiveServices/accounts@2025-04-01-preview' existing = {
name: aiFoundryName
scope: resourceGroup()
}
// Conditionally refers your existing Azure Key Vault resource
resource existingKeyVault 'Microsoft.KeyVault/vaults@2024-11-01' existing = {
name: keyVaultName
scope: resourceGroup()
}
resource connection 'Microsoft.CognitiveServices/accounts/connections@2025-04-01-preview' = {
name: '${aiFoundryName}-keyvault'
parent: aiFoundry
properties: {
category: 'AzureKeyVault'
target: existingKeyVault.id
authType: 'AccountManagedIdentity'
isSharedToAll: true
metadata: {
ApiType: 'Azure'
ResourceId: existingKeyVault.id
location: existingKeyVault.location
}
}
}
// Include RBAC on Key Vault for Foundry
resource rbacAssignment 'Microsoft.Authorization/roleAssignments@2020-04-01-preview' = {
name: guid(existingKeyVault.id, 'KeyVaultSecretsOfficer')
scope: existingKeyVault
properties: {
roleDefinitionId: '/providers/Microsoft.Authorization/roleDefinitions/b86a8fe4-44ce-4948-aee5-eccb2c155cd7'
principalId: aiFoundry.identity.principalId
}
}
// All following connections should be created with the dependsOn property for both the key vault connection and the role assignment
Key Vault 连接管理
创建
请确保 Foundry 资源或项目级别不存在其他连接。 如果存在其他连接,服务将阻止创建 Key Vault 连接。 如果选择连接时 UI 未显示 Key Vault 连接类别,则此问题可能是原因。 删除其他连接,然后重试。
创建 Key Vault 连接时,不会使用 Azure 中的托管 Key Vault。
删除
在从 Foundry 中删除 Azure Key Vault 连接之前,请删除所有其他连接。 删除 Foundry 资源和项目级别的所有其他连接后,请删除 Key Vault 连接。 Foundry 不支持机密迁移。
更新或更改
若要从 Azure Key Vault 1 切换到 Azure Key Vault 2,请删除 Azure Key Vault 1 连接,然后创建 Azure Key Vault 2 连接。 按照删除和创建的步骤进行操作,并手动重新创建任何连接密钥。
Key Vault 机密生命周期
从托管 Key Vault 中删除连接时,将删除相应的机密。 删除 Key Vault 连接也会删除其机密。
授予 Foundry 对密钥保管库的访问权限
根据密钥保管库的预配方式,可能需要应用其他权限。 检查 Azure Key Vault 是否使用基于角色的访问控制 (RBAC) 或访问策略,然后继续。
基于角色的访问控制 (RBAC)
创建 Key Vault 连接后,在 Azure 门户中分配适当的 RBAC 角色。 Key Vault 参与者和 Key Vault 管理员是两个工作角色。 对于最小权限,请使用 Key Vault 机密主管。
访问策略
与 RBAC 角色类似,请将相应的密钥保管库访问策略(如果适用)分配给 Foundry 资源的托管标识。
基础结构即代码模板
最佳做法是,在设置 ARM、Bicep 或 Terraform 模板以创建资源时,确保 Azure Key Vault 连接是创建的第一个连接,并使所有其他连接都依赖于 Key Vault 连接成功。 此顺序有助于减少 Key Vault 连接失败。 如果不遵循此最佳做法,模板可能会遇到连接之间的竞争条件。 因此,由于 Foundry 不支持机密迁移,因此部署可能有时会正常工作,有时会失败。
创建 Foundry 资源和 Key Vault 连接后,将相应的 RBAC 角色分配给 Foundry 资源。 使所有其他连接都取决于此角色分配是否成功。 如果 Key Vault 使用访问策略而不是 RBAC,则同样适用。
按照基础结构中的此顺序作为代码模板
- 创建 Foundry 资源。
- 创建 Foundry 项目。
- 创建 Azure Key Vault 连接。
- 为 Foundry 资源在 Key Vault 上分配适当的 RBAC 角色。
- (可选)验证 RBAC 角色是否生效。
- 在资源或项目级别创建任何其他连接,并为步骤 3 和 4 设置
dependsOn字段。
删除
为了清理,如果使用模板自动删除资源,请按相反的顺序执行创建步骤:
- 删除 Foundry 资源或项目级别的所有连接。
- 删除 Azure Key Vault 连接。
- 删除所有 Foundry 项目。
- 删除 Foundry 资源。