Windows上的厨房EC2 - 最终WinRM :: WinRMAuthorizationError

问题描述 投票:0回答:1

我正在使用Kitchen EC2驱动程序在亚马逊的Windows Server 2012R2,2016和1803 AMI上测试一些Windows“基础”烹饪书。我遇到了在通过Kitchen执行配方的特定持续时间之后发生的问题,而不是遇到特定的代码行。

在配方收敛期间的某个时刻,它会以WinRM :: WinRMAuthorizationError停止。如果我重新运行收敛,它会立即引发我同样的错误。我已经尝试过更改和移动配方中的资源,看起来它不是配方的特定部分的问题,它只是随机发生,然后继续发生。

这开始是因为我试图删除我们的自定义用户数据脚本,而是使用Kitchen-EC2驱动程序生成的脚本。它们大致相同,但它们只是以稍微不同的方式做事。

我打算做更多的故障排除(this似乎是一个很好的资源)但是考虑到我正在尝试使用vanilla设置,我希望我错过了一些明显的东西。

.kitchen.yml的相关部分:

transport:
  name: 'winrm'
  elevated: true
  username: 'Administrator'
  ssh_key: ~/.ssh/test-kitchen

默认用户数据:

# Logic for determining $logfile is removed...
$logfile='C:\Program Files\Amazon\Ec2ConfigService\Logs\kitchen-ec2.log'

# Allow script execution
Set-ExecutionPolicy -ExecutionPolicy RemoteSigned -Force

# PS Remoting and & winrm.cmd basic config
Enable-PSRemoting -Force -skipnetworkprofilecheck

& winrm.cmd set winrm/config '@{MaxTimeoutms="1800000"}' >> $logfile
& winrm.cmd set winrm/config/winrs '@{MaxMemoryPerShellMB="1024"}' >> $logfile
& winrm.cmd set winrm/config/winrs '@{MaxShellsPerUser="50"}' >> $logfile
& winrm.cmd set winrm/config/winrs '@{MaxMemoryPerShellMB="1024"}' >> $logfile

# Firewall Config
& netsh advfirewall firewall set rule name="Windows Remote Management (HTTP-In)" profile=public protocol=tcp localport=5985 remoteip=localsubnet new remoteip=any  >> $logfile
Set-ItemProperty -Name LocalAccountTokenFilterPolicy -Path HKLM:\software\Microsoft\Windows\CurrentVersion\Policies\system -Value 1
chef test-kitchen
1个回答
0
投票

我最好的猜测是这与我使用的AMI有关,这是一张CIS图像。

更具体地说,我认为userdata脚本确实适用于初始WinRM授权。但是,某些与用户数据中的winrm.cmd命令冲突的CIS AMI组策略可能会在以后应用并终止连接。我的想法是,后来作为正常配方的一部分运行gpupdate正在重新应用它们。

我认为在userdata中运行这些命令是有帮助的。它需要安装包含Set-PolicyFileEntry命令的模块。

Set-PolicyFileEntry -Path $MachineDir -Key Software\Policies\Microsoft\Windows\WinRM\Client -ValueName AllowBasic -Data 1 -Type DWord  
Set-PolicyFileEntry -Path $MachineDir -Key Software\Policies\Microsoft\Windows\WinRM\Service -ValueName AllowBasic -Data 1 -Type DWord 
Set-PolicyFileEntry -Path $MachineDir -Key Software\Policies\Microsoft\WindowsFirewall\DomainProfile -ValueName EnableFirewall -Data 0 -Type DWord 
Set-PolicyFileEntry -Path $MachineDir -Key Software\Policies\Microsoft\WindowsFirewall\PublicProfile -ValueName EnableFirewall -Data 0 -Type DWord 
Set-PolicyFileEntry -Path $MachineDir -Key Software\Policies\Microsoft\WindowsFirewall\PrivateProfile -ValueName EnableFirewall -Data 0 -Type DWord 
Set-PolicyFileEntry -Path $MachineDir -Key Software\Microsoft\Windows\CurrentVersion\Policies\System -ValueName LocalAccountTokenFilterPolicy -Data 1 -Type DWord 

gpupdate
© www.soinside.com 2019 - 2024. All rights reserved.