你当前正在访问 Microsoft Azure Global Edition 技术文档网站。 如果需要访问由世纪互联运营的 Microsoft Azure 中国技术文档网站,请访问 https://docs.azure.cn

在 Azure AI Foundry 中设置 Azure Key Vault 连接(预览版)

如果未设置 Key Vault 连接,Azure AI Foundry 会将连接详细信息存储在订阅外部Microsoft管理的 Key Vault 中。 若要管理自己的机密,请将 Azure Key Vault 连接到 Azure AI Foundry。

注释

在设置 Key Vault 连接之前查看限制。

局限性

仅在需要时创建 Azure Key Vault 连接。

如果自带 Azure Key Vault,请查看以下限制:

  • 将 Azure Key Vault 连接限制为每个 AI Foundry 资源一个。 仅当 AI Foundry 资源或项目级别不存在其他连接时,才删除 Azure Key Vault 连接。

  • AI Foundry 不支持机密迁移。 自行删除并重新创建连接。

  • 删除基础 Azure Key Vault 会中断 AI Foundry 资源。 Azure Key Vault 存储不使用 Entra ID 的连接的机密。 依赖于这些连接的任何 AI Foundry 功能都停止工作。

  • 删除 AI Foundry 资源在自带 (BYO) Azure Key Vault 中存储的连接机密可能会中断与其他服务的连接。

创建 Azure Key Vault 连接

创建与 Azure Key Vault 的连接。

  1. 在 Azure AI Foundry 门户中转到项目。 如果没有项目,请创建一个项目。

  2. 检查 “资源 ”或 “项目 ”部分中是否有连接。 如果连接存在, 则 Azure Key Vault 不可用。

  3. 在“ 资源 ”部分中,选择“ 已连接资源”。

  4. “已连接资源 ”部分中,选择“ + 新建连接”。

    “已连接资源”部分的屏幕截图,其中已选中“+ 新建连接”按钮,其中显示了 Azure Key Vault 作为可用选项。

  5. 选择 Azure Key Vault

    Azure Key Vault 选择对话框的屏幕截图,其中选择了 Azure Key Vault。

  6. 选择 Azure Key Vault,然后选择 “连接”。

创建 Key Vault 连接

使用此模板:

/*

Set up your Key Vault connection

Select which RBAC role to assign:
1. Key Vault Administrator:  00482a5a-887f-4fb3-b363-3b7fe8e74483 - https://free.blessedness.top/en-us/azure/role-based-access-control/built-in-roles/security#key-vault-administrator
2. Key Vault Contributor:    f25e0fa2-a7c8-4377-a976-54943a77a395 - https://free.blessedness.top/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://free.blessedness.top/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 连接管理

创建

仅当 Key Vault 连接是唯一的连接时,才创建 Key Vault 连接。 请确保 Foundry 资源或项目级别不存在其他连接。 如果存在其他连接,服务将阻止创建 Key Vault 连接。 如果选择连接时 UI 未显示 Key Vault 连接类别,可能是原因。 删除其他连接,然后重试。

创建 Key Vault 连接时,不会使用 Azure 中的托管 Key Vault。

删除

在从 AI 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 连接也会删除其机密。

授予 AI 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,则同样适用。

按照基础结构中的此顺序作为代码模板

  1. 创建 Foundry 资源。
  2. 创建 Foundry 项目。
  3. 创建 Azure Key Vault 连接。
  4. 为 Foundry 资源在 Key Vault 上分配适当的 RBAC 角色。
  5. (可选)验证 RBAC 角色是否已生效。
  6. 在资源或项目级别创建任何其他连接,并为步骤 3 和 4 设置 dependsOn 字段。

删除

为了清理,如果使用模板自动删除资源,请反向执行创建步骤:

  1. 删除 Foundry 资源或项目级别的所有连接。
  2. 删除 Azure Key Vault 连接。
  3. 删除所有 Foundry 项目。
  4. 删除 Foundry 资源。