TeamCity 远程 Powershell 访问突然被拒绝

TeamCity Remote Powershell Access Denied Suddenly

免责声明:我不是 DevOps 的人所以请原谅任何无知。我正在学习这些东西以扩展我的理解。

我在 Windows Server 2019 实例上启用了远程 Powershell,以便在从我的构建服务器(以及 Windows Server 2019)部署文件期间 stop/start 计划任务。

我以远程服务器上的 Adminstrator 用户身份在 Administrator Powershell 中执行了以下步骤:
1.启用RSRemoting.
2. 删除现有的监听器。
3. 创建自签名证书并导出到 crt 文件。

$Cert = New-SelfSignedCertificate -CertstoreLocation Cert:\LocalMachine\My -DnsName "<subdomain.domain.com>"
  1. 创建监听器。
  2. 创建防火墙规则以允许安全的 PSRemoting 并禁用不安全的连接。
  3. 复制证书以构建服务器。
  4. 在生成服务器上导入证书。

在构建服务器中,我在 Powershell 中使用以下命令测试了配置:

$username = 'Administrator'
$pass = ConvertTo-SecureString -string '<password here>' -AsPlainText -Force
$cred = New-Object -typename System.Management.Automation.PSCredential -argumentlist $username, $pass
Invoke-Command -ComputerName <subdomain.domain.com> -UseSSL -ScriptBlock {whoami} -Credential $cred

win-<some stuff>\administrator 的响应很好。但是,当我从 TeamCity 构建步骤中执行远程 Powersehll 命令时,我得到一个丑陋的 Connecting to remote server <subdomain.domain.com> failed with the following error message : Access is denied..

奇怪的是,这两天前就成功了,我有几个构建能够完成所有远程操作。从今天早上开始,它就停止工作了-噗!

如果我伪造凭据,我会得到一个不正确的 username/password 错误,所以它肯定会到达服务器。

另一个有趣的发现是,如果我 运行

[bool](Test-WSMan)

在远程服务器上,我得到 True 返回,但是如果我 运行 在构建服务器上使用 -ComputerName <subdomain.domain.com> 相同的命令,我得到
WinRM cannot complete the operation. Verify that the specified computer name is valid, that the computer is accessible over the network, and that a firewall exception for the WinRM service is enabled and allows access from this computer. By default, the WinRM firewall exception for public profiles limits access to remote computers within the same local subnet. 返回。
远程主机和生成服务器都作为默认 Administrator.

登录

有什么想法吗?

经过更多研究并寻求一些帮助后,有人建议我调整 TeamCity Build AgentTeamCity Server 服务。这些需要 Log On As 一个 User 而不是 Local System。我无法解释我以前的设置是如何工作的。我遇到的 Access is denied 错误与上面提到的 Remote Powershell 配置无关。