Azure Runbook 脚本无法使用系统分配的标识登录

标签 azure azure-runbook

我正在尝试设置 Powershell Runbook 来访问 Azure 资源。

我正在按照 this page 上的说明进行操作.

我已为自动化帐户分配了系统身份,但示例脚本根本不起作用。

# Sign in to your Azure subscription
$sub = Get-AzSubscription -ErrorAction SilentlyContinue
if(-not($sub))
{
     Connect-AzAccount
}

输出:

Run Connect-AzAccount to login.
Port 8400 is taken with exception 'A socket operation encountered a dead network'; trying to connect to the next port.
Port 8401 is taken with exception 'A socket operation encountered a dead network'; trying to connect to the next port.
<snip>
Port 8998 is taken with exception 'A socket operation encountered a dead network'; trying to connect to the next port.
Port 8999 is taken with exception 'A socket operation encountered a dead network'; trying to connect to the next port.
Unable to acquire token for tenant 'organizations' with error 'Cannot find an open port.'
Cannot find an open port.

我尝试将贡献者和所有者角色添加到身份中,但这没有帮助。
我不确定我错过了什么,帮忙吗?

我正在使用 terraform 来支撑基础设施,因此我的设置可能与 terraform 的设置不相符。

最佳答案

您使用的代码片段用于身份验证以启用身份。

该页面下方的代码片段是您需要使用的:

https://learn.microsoft.com/en-us/azure/automation/enable-managed-identity-for-automation#authenticate-access-with-system-assigned-managed-identity

您会注意到它使用 Connect-AzAccount -Identity

# Ensures you do not inherit an AzContext in your runbook
Disable-AzContextAutosave -Scope Process

# Connect to Azure with system-assigned managed identity
$AzureContext = (Connect-AzAccount -Identity).context

# set and store context
$AzureContext = Set-AzContext -SubscriptionName $AzureContext.Subscription -DefaultProfile $AzureContext

关于Azure Runbook 脚本无法使用系统分配的标识登录,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/72379254/

相关文章:

c# - 如何在 Azure AD B2C 中配置 Microsoft 帐户身份提供商以重定向到我的 URL

c# - 将大量 XML 插入 sql azure 数据库的正确方法

azure - 如何在 Bicep 中显示 Azure Runbook 脚本的路径?

azure - 'Allow Azure services and resources to access this server' 创建的防火墙规则的名称是什么

c# - 我在哪里可以在 azure 应用程序中找到 "authenticationKey"值来创建 "ClientCredential"对象

Azure Monitor...还是 Log Analytics?还是应用洞察?还是运营洞察?或者

java - 使用 Spring Boot 时 Azure 中的连接字符串

azure - 在 Runbook 中使用时找不到 'Start-AzVM' 命令

azure - 通过 Azure Powershell 禁用 AKS 节点池的自动缩放

powershell - 如何在具有 AutomationConnection 的 Powershell Runbook 中使用 Connect-AzAccount