在Azure管道中使用托管身份:GetUserAccessToken:无法获取身份的访问令牌。 AAD返回了静默失败

问题描述 投票:0回答:2

我正在尝试在Azure Pipelines中运行Azure Resource Group Deployment task。我已经部署了Azure Pipelines self-hosted agent on an Azure VM running Windows,并且在我的Azure DevOps组织中设置了Azure Resource Manager service connection to a VM with a managed service identity

但是,当尝试使用具有托管身份的服务连接来配置Azure资源组部署任务时,出现以下错误:

GetUserAccessToken:无法获取标识的访问令牌。 AAD返回了静默失败。

截屏:

enter image description here

我已经确认我已将对VM的托管身份的访问权限(贡献者)授予目标资源组:

enter image description here

该服务连接的作用域还仅限于Azure订阅:

enter image description here

感谢您对诊断此问题的任何帮助。谢谢!

azure azure-devops azure-pipelines azure-resource-manager azure-managed-identity
2个回答
0
投票

通常在会话期满后无法获取访问令牌。

解决这些问题:

  1. 退出Azure Pipelines或TFS。
  2. 打开InPrivate或隐身浏览器窗口并导航到https://visualstudio.microsoft.com/team-services/
  3. 如果提示您退出,请这样做。
  4. 使用适当的凭据登录。
  5. 从列表中选择要使用的组织。
  6. 选择要向其中添加服务连接的项目。
  7. 通过打开“设置”页面创建所需的服务连接。然后,选择服务>新建服务连接> Azure资源管理器。

参考:

https://docs.microsoft.com/en-us/azure/devops/pipelines/release/azure-rm-endpoint?view=azure-devops#sessionexpired


0
投票

看来是因为出现了问题,因为已验证到Azure DevOps的用户帐户正在检索订阅信息。 Azure DevOps是不使用托管身份以检索订阅信息。

特别是,我最初的Azure DevOps用户帐户已启用MFA以对Azure订阅进行身份验证(例如,portal.azure.com),但not却已启用MFA进行身份验证至Azure DevOps(例如,开发人员。 azure.com/)。我认为这是导致无法获取访问令牌的问题:

enter image description here

我在我的Azure AD中创建了一个不同的用户帐户,授予它对我的Azure DevOps组织的访问权限,并确保此新用户帐户对目标订阅具有读取权限,并且[没有打开MFA。这解决了使用托管身份时获取订阅信息的问题:

enter image description here
© www.soinside.com 2019 - 2024. All rights reserved.