gpt4 book ai didi

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

转载 作者:行者123 更新时间:2023-12-02 23:14:54 26 4
gpt4 key购买 nike

我正在尝试设置 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/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com