오늘 PowerShell Remoting을 통해서 여러 대의 윈도우 호스트들에 보안 패치를 설치하면서 생긴 WinRM 관련 문제와, WinRM 자체에 대해 정리해 보려고 합니다.
먼저 WinRM은 이런 프로토콜입니다.
https://docs.microsoft.com/en-us/windows/win32/winrm/portal
Windows Remote Management - Win32 apps
Windows Remote Management (Windows Remote Management) is the Microsoft implementation of WS-Management Protocol, a standard SOAP-based, firewall-friendly protocol that allows hardware and operating systems, from different vendors, to interoperate.
docs.microsoft.com
짧게 요약하자면 WS-Management Protocol을 구현한 것이 WinRM이고, 윈도우 기반 시스템들의 관리를 용이하게 하기 위한 프로토콜입니다. 프로토콜 메시지(XML 형식) 전송에는 HTTP를 사용합니다.
WinRM을 활용해서 시스템 정보를 얻거나 명령을 실행하고, 인터렉티브 세션을 열어(Enter-PSSession) 쉘을 사용할 수도 있습니다.
WinRM은 윈도우 서비스로 실행되고, WinRM이 실행 중인 원격 호스트에 적절한 인증을 거쳐 접속하면 아래 그림처럼 TCP/5985 포트(-UseSSL 한 경우 TCP/5986)를 통해 원격 호스트의 윈도우 커널과 연결됩니다.
오늘 겪은 오류는 아래와 같습니다.
PS C:\Users\iseop> Invoke-Command -ComputerName localhost -Command {$env:computername} -Authentication Credssp -Credential (Get-Credential)
cmdlet Get-Credential at command pipeline position 1
Supply values for the following parameters:
Credential
[localhost] Connecting to remote server localhost failed with the following error message : The WinRM client cannot
process the request. The authentication mechanism requested by the client is not supported by the server or
unencrypted traffic is disabled in the service configuration. Verify the unencrypted traffic setting in the service
configuration or specify one of the authentication mechanisms supported by the server. To use Kerberos, specify the
computer name as the remote destination. Also verify that the client computer and the destination computer are joined
to a domain. To use Basic, specify the computer name as the remote destination, specify Basic authentication and
provide user name and password. Possible authentication mechanisms reported by server: Negotiate For more
information, see the about_Remote_Troubleshooting Help topic.
+ CategoryInfo : OpenError: (localhost:String) [], PSRemotingTransportException
+ FullyQualifiedErrorId : AccessDenied,PSSessionStateBroken
Invoke-Command를 통해서 타겟 서버에 접속한 다음, 타겟 서버에서 다시 보안 패치 파일이 있는 공유 폴더에 접근해야 하기 때문에 WinRM 인증 방식으로 CredSSP를 사용하고, 이 크리덴셜을 타겟 서버에 위임할 수 있게 임시로 WinRM 관련 설정을 바꿔야 했습니다.
위 오류같은 경우 HTTPS가 아닌 HTTP를 사용하고 있기 때문에(-UseSSL 옵션 없음) 트래픽 암호화 문제는 아니고, 단지 WinRM 서비스들이 인증 매커니즘으로 CredSSP를 허용하지 않게 구성되어 있었기 때문이었습니다.
WinRM 서비스의 구성은 아래처럼 확인할 수 있고, 인증 관련 설정은 Auth 컨테이너 안에 있는 설정 아이템을 확인하면 됩니다.
PS C:\Users\iseop> ls WSMan:\localhost\Service\
WSManConfig: Microsoft.WSMan.Management\WSMan::localhost\Service
Type Name SourceOfValue Value
---- ---- ------------- -----
System.String RootSDDL O:NSG:BAD:P(A;;GA;;;BA)(A;;GR;;;IU)S:P(AU;FA;GA;;;WD)...
System.String MaxConcurrentOperations 4294967295
System.String MaxConcurrentOperationsPerUser 1500
System.String EnumerationTimeoutms 240000
System.String MaxConnections 300
System.String MaxPacketRetrievalTimeSeconds 120
System.String AllowUnencrypted false
Container Auth
Container DefaultPorts
System.String IPv4Filter *
System.String IPv6Filter *
System.String EnableCompatibilityHttpList... false
System.String EnableCompatibilityHttpsLis... false
System.String CertificateThumbprint
System.String AllowRemoteAccess true
PS C:\Users\iseop> ls WSMan:\localhost\Service\auth
WSManConfig: Microsoft.WSMan.Management\WSMan::localhost\Service\Auth
Type Name SourceOfValue Value
---- ---- ------------- -----
System.String Basic false
System.String Kerberos true
System.String Negotiate true
System.String Certificate false
System.String CredSSP false
System.String CbtHardeningLevel Relaxed
WinRM 서버의 Auth 설정을 변경하려면 Set-Item으로 위 WSManConfig를 수정하거나 Enable-WSManCredSSP -Role Server 명령을 사용하면 됩니다.
WinRM 클라이언트의 경우 WSManConfig를 수정하고 "Allow delegating fresh credentials" GPO를 적용하거나, Enable-WSManCredSSP -Role Client -DelegateComputer <크리덴셜을 위임 대상>
명령을 사용하면 됩니다.