Azure DevOps -> 管道 -> 库 -> 访问 Azure Key Vault -> Key Vault 不允许从所有网络访问

Azure DevOps -> Pipelines -> Library -> Access Azure Key Vault -> Key Vault not allowing access from all networks

我们已经通过服务连接(服务主体身份验证)在 Azure DevOps 和 Azure Key Vault 之间建立了连接。然而,为了让它工作,我们需要将 Azure Key Vault -> Networking 标记为允许访问来自:All networks。鉴于我们在这里存储秘密,我们想使用选项 Private endpoint and selected networks 而不是 Allow trusted Microsoft services to bypass this firewall? 设置为 Yes.

像这样:

然而,这会导致 Azure DevOps -> Pipelines -> Library 出现错误:

The specified Azure service connection needs to have "Get, List" secret management permissions on the selected key vault. Click "Authorize" to enable Azure Pipelines to set these permissions or manage secret permissions in the Azure portal.

如果我们为 Azure Key Vault 设置 Allow access from: All networks,它会如前所述工作,但我们希望尽可能避免这种情况。

在管道中设置 Azure Key Vault 任务

或设置可变组然后切换回 Private endpoint and selected networks 会导致部署时出现类似错误。

MyKey: "Client address is not authorized and caller is not a trusted service.\r\nClient address: 111.222.333.44\r\nCaller: appid=;oid=00000000-0000-0000-0000-000000000000;iss=https://sts.windows.net//\r\nVault: My-Vault;location=northeurope. The specified Azure service connection needs to have Get, List secret management permissions on the selected key vault. To set these permissions, download the ProvisionKeyVaultPermissions.ps1 script from build/release logs and execute it, or set them from the Azure portal."

不幸的是,客户端地址每次都是新的,但 oidiss 值是相同的。根据文档,只有 IPv4 address or CIDR 可以添加到防火墙。有没有办法将 Azure 代理标记为受信任的 Microsoft 服务,或者这是一种不好的做法?不过,它确实比 All networks 安全得多。

(作者评论后更新)

您使用的是 Microsoft 托管代理吗?它们是动态的,也许您可​​以改为在 Azure 中的虚拟机上托管代理。您将知道机器的 IP 并在 KV 设置中允许它。

查看Self-Hosted Agents 在 Microsoft 文档中。

这仍然是一个悬而未决的问题 - Issue

可能有些解决方案如URL

中所述
  • 在您的管道中添加一个任务并将代理的 IP 列入白名单,然后一旦您从 keyvault 中获得值,就删除白名单。

  • 白名单 Azure DevOps IP 列表可能每周一次,但同样看起来不可靠

  • @Grand的建议其实也是解决方案之一