powershell - 服务器无法验证请求。验证证书是否有效并且与此订阅关联

标签 powershell azure deployment automation teamcity

尝试编写脚本以在 Azure 上创建的 VM 上自动执行 Azure 中的部署。昨天一切都还很美好。我完成了设置,所有服务都部署到各自的订阅中。

我的证书区域中还挂着许多 Azure 管理证书。我已经把它们全部清理掉了,因为除了一个之外,所有的都已经很旧了。然后,我重新导入了最新的发布设置文件,希望从头开始,一切都会再次顺利。

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

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

没问题,只需使用handy-dandy 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 上执行所有这些自动化操作,并在 VM 上安装了 Teamcity。 当我尝试直接在 VM Powershell 上运行脚本时,它工作正常 但是当我尝试运行 Teamcity 配置时出现错误,它在 PowerShell 构建步骤中失败。

它通过命令返回虚拟机上的订阅 获取Azure订阅

[11:31:07][Step 3/3] SubscriptionId : *******

[11:31:07][Step 3/3] SubscriptionName : ****

[11:31:07][Step 3/3] Environment : AzureCloud

[11:31:07][Step 3/3] SupportedModes : AzureServiceManagement

[11:31:07][Step 3/3] DefaultAccount : *******

[11:31:07][Step 3/3] Accounts : *******

[11:31:07][Step 3/3] IsDefault : True

[11:31:07][Step 3/3] IsCurrent : True

[11:31:07][Step 3/3] CurrentStorageAccountName : *******

[11:31:07][Step 3/3] TenantId :

[11:31:07][Step 3/3] SubscriptionId : *******

[11:31:07][Step 3/3] SubscriptionName : *******

[11:31:07][Step 3/3] Environment : AzureCloud

[11:31:07][Step 3/3] SupportedModes : AzureServiceManagement

[11:31:07][Step 3/3] DefaultAccount : *******

[11:31:07][Step 3/3] Accounts : *******

[11:31:07][Step 3/3] IsDefault : False

[11:31:07][Step 3/3] IsCurrent : False

[11:31:07][Step 3/3] CurrentStorageAccountName : tarifficapi

[11:31:07][Step 3/3] TenantId :

[11:31:07][Step 3/3]

[11:31:07][Step 3/3]

[11:31:07][Step 3/3]

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

[11:31:21][Step 3/3] request. Verify that the certificate is valid and is >associated with this

[11:31:21][Step 3/3] subscription.

[11:31:21][Step 3/3] At line:1 char:1

[11:31:21][Step 3/3] + Set-AzureService -ServiceName $service -Label $deploymentLabel

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

[11:31:21][Step 3/3] Exception

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

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

有人知道这里出了什么问题吗?

最佳答案

我终于找到了解决办法

我收到的错误消息是

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

这有点误导,因为正如您在下面的代码中看到的那样(特别是最后一行),我确实设置了当前存储,但为什么我收到此消息?

[05:14:33][Step 3/3] Set-AzureService : ForbiddenError: The server failed to >authenticate the [05:14:33][Step 3/3] request. Verify that the certificate is valid and is >associated with this [05:14:33][Step 3/3] subscription. [05:14:33][Step 3/3] At line:1 char:1 [05:14:33][Step 3/3] + Set-AzureService -ServiceName $service -Label >$deploymentLabel [05:14:33][Step 3/3] + >~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ [05:14:33][Step 3/3] + CategoryInfo : CloseError: (:) [Set->AzureService], ComputeCloud [05:14:33][Step 3/3] Exception [05:14:33][Step 3/3] + FullyQualifiedErrorId : >Microsoft.WindowsAzure.Commands.ServiceManagemen [05:14:33][Step 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 gets from Azure") 最后“Get-AzureSubscription”,查看 在 Powershell 上添加订阅。

希望这对某人有帮助:)

关于powershell - 服务器无法验证请求。验证证书是否有效并且与此订阅关联,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/32094863/

相关文章:

Azure Key Vault 不允许在专用终结点连接中从 azure 门户添加 secret

jakarta-ee - Java EE 定时器服务、编程定时器和应用程序部署

eclipse - 使用 Eclipse 插件进行 AppEngine 部署期间出现错误 401 未经授权(无效的 OAuth token )

Windows 8.1 无法从 cmd 或 powershell 提示符启动 Powershell - "This app can' t run on your PC"

powershell - 将 Powershell 脚本和文件包装在一起?

arrays - 未显示所有属性

python - 为什么 Azure ML 笔记本和 Azure ML 终端中的 env 不同?

c# - 如何在azure中启动虚拟机?

Powershell:使用参数集重载 C# 风格的函数?

java - 部署带有图像的 jar 文件时遇到问题