使用 Azure 托管标识从 VS Code 连接到 Azure 自动化时出错

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

大约 8 个月前,我构建了几个自动化操作手册,这些操作手册使用系统分配的托管身份成功运行。我使用了此线程使用托管身份访问 Azure AD 中的代码摘录,以使用托管身份连接到 Azure AD。从 Azure 自动化门户执行时,此代码可以完美运行。

Connect-azaccount -identity
$context = [Microsoft.Azure.Commands.Common.Authentication.Abstractions.AzureRmProfileProvider]::Instance.Profile.DefaultContext
$graphToken = [Microsoft.Azure.Commands.Common.Authentication.AzureSession]::Instance.AuthenticationFactory.Authenticate($context.Account, $context.Environment, $context.Tenant.Id.ToString(), $null, [Microsoft.Azure.Commands.Common.Authentication.ShowDialog]::Never, $null, "https://graph.microsoft.com").AccessToken
$aadToken = [Microsoft.Azure.Commands.Common.Authentication.AzureSession]::Instance.AuthenticationFactory.Authenticate($context.Account, $context.Environment, $context.Tenant.Id.ToString(), $null, [Microsoft.Azure.Commands.Common.Authentication.ShowDialog]::Never, $null, "https://graph.windows.net").AccessToken
Write-Output "Hi I'm $($context.Account.Id)"
Connect-AzureAD -AadAccessToken $aadToken -AccountId $context.Account.Id -TenantId $context.tenant.id | out-null
Write-Output "Success!`n"

由于 AzureAD PowerShell 模块即将弃用,我正在将脚本转换为使用 Microsoft Graph 与 AzureAD。我最近在 VS Code 中安装了 Azure 自动化扩展来编辑 Runbook。当我在 VSC 中测试 Runbook 时,它失败了,因为它无法获取令牌。我收到此错误,

Connect-azaccount -identity
     |  ~~~~~~~~~~~~~~~~~~~~~~~~~~~
     | ManagedIdentityCredential authentication unavailable. Multiple attempts failed to obtain a token from the managed identity endpoint.

查看 Azure 中的托管身份 IAM 属性,我是所有者和用户访问管理员。该身份没有拒绝分配。如何允许本地计算机上的 VSC 从托管标识获取令牌来运行 Runbook?有没有更好的办法?也许使用图表?

感谢您的宝贵时间。

附注我在发帖前回顾了 Stack Overflow 提出的 2 个问题。第一个与我的问题不符,第二个是关于用户分配的托管身份,而不是系统分配的。

azure azure-automation azure-managed-identity
1个回答
0
投票

您收到此错误的原因是系统分配的托管标识无法在本地使用(用户分配的托管标识也是如此)。它只能在 Azure 中使用。

系统分配的托管标识是分配给 Azure 资源的标识(基本上是 Entra ID 用户)。由此

link
:

© www.soinside.com 2019 - 2024. All rights reserved.