在 Azure DevOps 中将变量组链接到 Azure Key Vault 时授权按钮不起作用 - 为什么?

Authorize button when Linking Variable Group to Azure Key Vault in Azure DevOps is not working - why?

我正在尝试 link Azure Key Vault 机密到 Azure Pipelines(Azure DevOps 的一部分)中的变量组。 Microsoft 文档 here.

但是,"Authorize" 按钮似乎不起作用。它不停地旋转。 Screenshot.

我的目标 Azure Key Vault 已经将服务主体包含在其具有获取和列表权限的访问策略中。 Screenshot.

有人以前见过这个问题吗?

首先,请确保服务连接正常。然后刷新页面再试一次。或者,您也可以在浏览器的私人会话中尝试。

正如消息所说“The specified Azure service connection needs to have "Get, List" secret management permissions on the selected key vault.

基本上,我们需要点击“Authorize”按钮来让 Azure Pipelines 为特定的服务连接设置这些权限。

如果不行,我们也可以手动设置特定服务连接的权限。

  1. 进入项目设置->服务连接->Select 特定的 ARM 服务连接

  2. 单击编辑弹出更新 xxx 的身份验证对话框

  3. 点击“use the full version of the service connection dialog.” link,得到Service principal client ID

  4. 转到 Azure 门户中的 key vault -> Access Policies -> 添加一个新的 访问策略 -> Select 模板(例如 Key&Secret Management) -> Select Get, List 秘密权限.

  5. 单击 Select Principal -> 复制并粘贴 Service principal client ID 搜索 user/application -> Select 搜索到的 user/application

  6. 之后你可以看到新的APPLICATION访问策略。

    成功添加应用程序访问策略后重试。


更新:

一般在 Azure DevOps 中,我们需要先创建一个 ARM service connection(可以访问 azure 源的客户端),然后再通过 ARM 模板部署 Azure Key Vault。

实际上,当您 select Azure subscription 然后单击 Azure resource group deployment task 中的 Authorize , ARM 服务连接自动创建。您只需要检查 AppID 并获取要在 ARM 模板中使用的 ObjectID

我们可以按照上面的步骤得到Service principal client IDAppID)。之后我们可以通过运行以下命令通过AppID获取ObjectId:(详见Find service principal object ID using PowerShell

$(Get-AzureADServicePrincipal -Filter "AppId eq 'a89c3dee-f5bf-4ea1-a805-d4c729a4add3'").ObjectId 

然后您可以在通过 ARM 模板部署 Azure Key Vault 时指定 ObjectId

对于使用 ARM 模板的 Azure Key Vault 部署,此解决方法似乎也是一个错误。

如果通过 ARM 模板通过引用服务主体的对象 ID将相关服务主体添加到 Azure Key Vault (AKV) 访问策略(as Microsoft documentation calls for ),随后出现 Azure Pipelines 的权限错误。

但是,如果我通过引用服务主体的应用程序(客户端)ID 手动将服务主体添加到 AKV 的访问策略,权限错误将完全消失。

再次感觉像是一个错误。由于这个手动步骤,现在我的自动部署管道无法正常工作。

此外,在 AKV ARM 模板中,如果我将必填字段 objectId 与可选字段 applicationId 组合,服务主体将显示为 "compound identity"。这 不会 修复 Azure Pipelines 中的权限问题。我没有看到不手动添加服务主体的方法。