【问题标题】:Azure Credentials error in Azure AutomationAzure 自动化中的 Azure 凭据错误
【发布时间】:2015-06-04 18:31:08
【问题描述】:

我正在尝试创建 Azure 自动化作业以在订阅中创建一组标准的标签/值。

使用标签需要 AzureResourceManager,而自动化中没有开箱即用的 AzureResourceManager(去投票给这个feedback item!),所以我跟着these steps 上传了 ARM 模块。

当我测试我的运行手册时,我得到以下输出:

-------------------------
PSComputerName        : localhost
PSSourceJobInstanceId : a8b85213-ee0f-40ea-842f-d33f2e87c910
Id                    : xxxxx-56ad-42c2-97f4-e364456fc4a6
Name                  : xxxxx
Environment           : AzureCloud
Account               : my-service-principal-app-id
Properties            : {Default, Tenants, SupportedModes}
-------------------------
New-AzureTag : Your Azure credentials have not been set up or have expired, please run Add-AzureAccount to set up your 
Azure credentials.
At Add-SubscriptionTags:41 char:41
+ 
    + CategoryInfo          : CloseError: (:) [New-AzureTag], ArgumentException
    + FullyQualifiedErrorId : Microsoft.Azure.Commands.Tags.Tag.NewAzureTagCommand

这是我的运行手册:

workflow Add-SubscriptionTags
{
    param
    (
        # Subscription
        [Parameter(Mandatory=$true)]
        [ValidateNotNullOrEmpty()]
        [string]
        $SubscriptionName
    )

    # Get the PowerShell credential and prints its properties 
    $cred = Get-AutomationPSCredential -Name 'AzureMaint'

    # Connect to Azure
    Add-AzureAccount -Credential $cred -ServicePrincipal -Tenant 'xxx-49ab-8a9c-4abce32afc1e' | Write-Verbose

    # Set subscription
    $subscription = Select-AzureSubscription -SubscriptionName $SubscriptionName -PassThru
    write-output '-------------------------'
    write-output $subscription
    write-output '-------------------------'

    # Add tags (Requires AzureResourceManager module)
    New-AzureTag -Name 'Managed' -Value $true
    New-AzureTag -Name 'Managed' -Value $false
}

AzureMaint PSCredential 包含服务主体 ID 和密钥,并且服务主体已被授予指定订阅的参与者角色。我可以使用这些凭据在 ISE 中执行 Add-AzureAccount 并添加标签就好了。既然它成功打印了订阅信息,我认为这意味着Add-AzureAccount 是成功的,那么为什么我会收到错误消息?


更新:

我创建了一个没有 ARM 模块的新自动化帐户,但我仍然遇到同样的问题,尽管错误消息略有不同:

Your Azure credentials have not been set up or have expired, please run Add-AzureAccount 
to set up your Azure credentials. (Your Azure credentials have not been set up or
have expired, please run Add-AzureAccount to set up your Azure credentials. (Unable 
to retrieve service key for ServicePrincipal account xxx-4a00-becf-952fda93edc5.
Please run the Add-AzureAccount cmdlet to supply the credentials for this service principal.))

所以现在我想知道它是否不喜欢我使用服务主体?

【问题讨论】:

  • Azure 模块不支持服务主体进行身份验证,只有 ARM 模块支持。在 Azure 自动化之外,PowerShell ISE 中的 Azure 模块应该有同样的问题。

标签: azure azure-automation


【解决方案1】:

只是为了在这里更新,我们发现服务主体身份验证目前在 Azure 自动化中不起作用。鉴于您正在尝试使用服务主体,这就是您遇到问题的原因。

目前,user principal should be used 可以解决此问题。

请参阅以下内容了解更多信息:

Authenticating to Azure Resource Manager with a Service Principal in Azure Automation

https://github.com/Azure/azure-powershell/issues/655

【讨论】:

  • 是的,那个链接的问题也是我的。我有点放弃了这个;我可能应该删除它。
  • 我会保留它,我知道有人在看这个帖子。这就是我刚刚回复它的原因。
【解决方案2】:

尚未正式支持在 Azure 自动化中使用 ARM cmdlet。也就是说,各种各样的人已经成功地做到了这一点。您的 ARM 和 Azure PowerShell 模块是同一版本吗?如果它们并排加载但版本不同,则可能会发生奇怪的事情。

【讨论】:

  • 我使用的是 ARM 0.9.1,并且默认情况下在新的 Azure 自动化帐户中加载了任何 Azure 模块(门户网站说它是版本 19,这很值得)。
  • 更新问题 - 问题似乎与 ARM 无关。
  • 在新的 Azure 门户 (portal.azure.com) 中存在一个错误,其中模块版本未正确显示(在您的情况下为 19)。您可以在旧 Azure 门户 (manage.windowsazure.com) 中查看模块版本,或自行上传 Azure 模块的特定版本,以覆盖全局版本。
猜你喜欢
  • 1970-01-01
  • 1970-01-01
  • 2019-03-15
  • 2018-03-06
  • 1970-01-01
  • 2021-09-07
  • 2021-01-04
  • 1970-01-01
  • 1970-01-01
相关资源
最近更新 更多