【问题标题】:The server failed to authenticate the request. Verify that the certificate is valid and is associated with this subscription服务器未能对请求进行身份验证。验证证书是否有效并且与此订阅相关联
【发布时间】:2015-11-12 17:10:09
【问题描述】:

尝试编写脚本以在 Azure 上创建的 VM 上自动部署 Azure。昨天一切都只是花花公子。我进行了设置,所有服务都部署到了它们各自的订阅中。

我的证书区也有许多 Azure 管理证书。我已经把它们全部清除了,因为除了一个很旧。然后我重新导入了最新的发布设置文件,希望从头开始,一切都会再次快乐。

然后我今天登录,运行我的一个部署,它说:

The server failed to authenticate the request. 
Verify that the certificate is valid and is associated with this subscription.

没问题,只需使用方便的 add-azureaccount,它会让我重新登录,重新运行部署并再次显示:

Set-AzureService : ForbiddenError: The server failed to authenticate the
request. Verify that the certificate is valid and is associated with this
subscription.

有人知道如何通过服务器验证吗?

我在 Azure 上创建并在 VM 上安装 Teamcity 的 VM 上进行的所有这些自动化操作。 当我尝试直接在 VM Powershell 上运行脚本时,它工作正常 但是当我尝试运行 Teamcity 配置时出现错误,它在 PowerShell 构建步骤中失败。

它虽然通过命令返回 VM 上的订阅 获取 Azure 订阅

[11:31:07][步骤 3/3] SubscriptionId : *******

[11:31:07][步骤 3/3] 订阅名称:****

[11:31:07][步骤 3/3] 环境:AzureCloud

[11:31:07][步骤 3/3] SupportedModes:AzureServiceManagement

[11:31:07][步骤 3/3] 默认帐户:*******

[11:31:07][步骤 3/3] 帐户:*******

[11:31:07][步骤 3/3] IsDefault : True

[11:31:07][步骤 3/3] IsCurrent : True

[11:31:07][步骤 3/3] CurrentStorageAccountName : *******

[11:31:07][步骤 3/3] 租户 ID:

[11:31:07][步骤 3/3] SubscriptionId : *******

[11:31:07][步骤 3/3] 订阅名称 : *******

[11:31:07][步骤 3/3] 环境:AzureCloud

[11:31:07][步骤 3/3] SupportedModes:AzureServiceManagement

[11:31:07][步骤 3/3] 默认帐户:*******

[11:31:07][步骤 3/3] 帐户:*******

[11:31:07][步骤 3/3] IsDefault : False

[11:31:07][步骤 3/3] IsCurrent : False

[11:31:07][步骤 3/3] CurrentStorageAccountName : 关税 API

[11:31:07][步骤 3/3] 租户 ID:

[11:31:07][步骤 3/3]

[11:31:07][步骤 3/3]

[11:31:07][步骤 3/3]

[11:31:21][Step 3/3] Set-AzureService : ForbiddenError: The server failed to >authenticate

[11:31:21][步骤 3/3] 请求。验证证书是否有效并且>与此相关

[11:31:21][步骤 3/3] 订阅。

[11:31:21][步骤 3/3] 在 line:1 char:1

[11:31:21][步骤 3/3] + Set-AzureService -ServiceName $service -Label $部署标签

[11:31:21][步骤 3/3] + >~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ [11:31:21][步骤 3/3] + CategoryInfo : CloseError: (:) [Set->AzureService], ComputeCloud

[11:31:21][步骤 3/3] 例外

[11:31:21][步骤 3/3] + FullyQualifiedErrorId : >Microsoft.WindowsAzure.Commands.ServiceManagemen

[11:31:21][步骤 3/3] t.HostedServices.SetAzureServiceCommand

谁能知道这里出了什么问题?

【问题讨论】:

  • 我在 azure 自动化上也面临同样的问题,我正在尝试使用 ssh 公钥创建 vm,但在此命令上遇到相同的错误 Set-AzureSubscription -SubscriptionName 'xxxxxxxx' -SubscriptionId xx -CurrentStorageAccountName 'xxxx' -Certificate $Certificate ,如何解决问题。请
  • 我知道这个问题已经很老了,但万一它仍然造成麻烦/其他人也有同样的问题。迁移到新的 publishsettings 证书时,我遇到了同样的问题。由于某种原因默认使用旧的 azure 证书帐户的机器。要解决此问题,请运行 Get-AzureAccount。如果有与旧/过期证书关联的帐户,请运行Remove-AzureAccount <certificateThumbprint>

标签: powershell azure deployment automation teamcity


【解决方案1】:

我终于找到了解决办法

我得到的错误信息是

Set-AzureService : ForbiddenError: The server failed to authenticate the 要求。验证证书是否有效并与此 >订阅相关联。

这有点误导,因为您可以在下面的代码中看到(尤其是最后一行),我确实设置了当前存储,但为什么会收到此消息?

[05:14:33][Step 3/3] Set-AzureService : ForbiddenError: The server failed to >authenticate [05:14:33][步骤 3/3] 请求。验证证书是否有效并且 > 与此相关联 [05:14:33][步骤 3/3] 订阅。 [05:14:33][步骤 3/3] 在 line:1 char:1 [05:14:33][步骤 3/3] + Set-AzureService -ServiceName $service -Label >$deploymentLabel [05:14:33][步骤 3/3] + >~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ [05:14:33][步骤 3/3] + CategoryInfo : CloseError: (:) [Set->AzureService], ComputeCloud [05:14:33][步骤 3/3] 例外 [05:14:33][步骤 3/3] + FullyQualifiedErrorId : >Microsoft.WindowsAzure.Commands.ServiceManagemen [05:14:33][步骤 3/3] t.HostedServices.SetAzureServiceCommand

脚本在 VM Powershell 中运行时运行良好,但在 Teamcity 中运行时失败。

为了解决这个问题,我遵循了以下步骤:

在虚拟机上打开 Windows Powershell

  • 运行“Get-AzurePublishSettingsFile”。它会要求您登录到 Azure 您将获得 Azure 订阅的发布设置文件 与您的帐户相关联。
  • 然后运行“Add-AzureAccount”,它会要求你登录和你的 帐户将被添加到 powershell。登录到 Azure 门户 (manage.windowsazure.com)。
  • 转到设置 => 管理证书部分。获取指纹 最近添加的 PublishSettingCertificate。
  • 在 Powershell 上运行 Import-AzurePublishSettingsFile“你的路径 在虚拟机上发布设置文件”
  • 运行 Add-AzureCertificate -serviceName "您的服务名称" -certToDeploy(get-item cert:\CurrentUser\MY"Certificate ThumbPrint you got from Azure") 最后“Get-AzureSubscription”,查看 在 Powershell 上添加订阅。

希望这对某人有所帮助:)

【讨论】:

    【解决方案2】:

    您在 PowerShell 中直接在 VM 上使用的用户是否与为 TeamCity 配置的用户相同?

    当我尝试使用 Azure Runbook 中的 Get-AzureSubscription 通过 PowerShell 获取 Azure 订阅时,我遇到了同样的错误。可能是我们的凭证存在一些 RBAC 配置问题。

    在我的情况下,我创建了一个新的(组织)帐户并改用它,这解决了我的问题。也许值得一试?

    【讨论】:

      猜你喜欢
      • 2020-01-29
      • 2016-04-04
      • 2014-09-19
      • 1970-01-01
      • 1970-01-01
      • 2016-01-31
      • 2014-02-01
      • 2014-12-20
      • 2021-06-21
      相关资源
      最近更新 更多