source

PowerShell 원격 - 정책에서 사용자 자격 증명 위임을 허용하지 않습니다.

factcode 2023. 9. 1. 21:22
반응형

PowerShell 원격 - 정책에서 사용자 자격 증명 위임을 허용하지 않습니다.

powershell이 처음이라 자격 증명 위임을 사용하는 데 문제가 있습니다.다음 스크립트가 있습니다.

$session = New-PSSession myserver -Authentication CredSSP -Credential DOMAIN\Administrator
Invoke-Command -Session $session -ScriptBlock { <Some PowerShell Command> }

실행하기 전에 다음 작업을 수행했습니다.

  1. 달려.Enable-PSRemoting내 서버에서.
  2. 달려.Enable-WSManCredSSP Server내 서버에서.
  3. 달려.Restart-Service WinRM내 서버에서.
  4. 달려.Enable-WSManCredSSP Client –DelegateComputer myserver의뢰인의
  5. 서버와 클라이언트를 모두 재부팅했습니다.

그러나 스크립트를 실행하면 다음 오류 메시지가 표시됩니다.

[myserver] Connecting to remote server failed with the following error message : The WinRM client cannot process the request. A computer policy does not allow the delegation of
 the user credentials to the target computer. Use gpedit.msc and look at the following policy: Computer Configuration -> Administrative Templates -> System -> Credentials Delega
tion -> Allow Delegating Fresh Credentials.  Verify that it is enabled and configured with an SPN appropriate for the target computer. For example, for a target computer name "m
yserver.domain.com", the SPN can be one of the following: WSMAN/myserver.domain.com or WSMAN/*.domain.com. For more information, see the about_Remote_Troubleshooting Help topic.
    + CategoryInfo          : OpenError: (System.Manageme....RemoteRunspace:RemoteRunspace) [], PSRemotingTransportException
    + FullyQualifiedErrorId : PSSessionOpenFailed

오류 메시지에 언급된 대로 정책을 확인했지만, 모든 것이 정상인 것 같습니다.또 뭐가 저를 가로막고 있을까요?

서버에서 다음을 수행합니다.

Enable-WSManCredSSP -Role Server

클라이언트에서 다음을 수행합니다.

set-item wsman:localhost\client\trustedhosts -value *

Enable-WSManCredSSP -Role Client –DelegateComputer *

사용하다gpedit.msc클라이언트에서 새 자격 증명을 WSMAN에 위임할 수 있음/*:

  1. 확대한다.Local Computer Policy,확대한다.Computer Configuration,확대한다.Administrative Templates,확대한다.System를 클릭합니다.Credential Delegation.
  2. 에서Settings창, 두 번 클릭Allow Delegating Fresh Credentials with NTLM-only Server Authentication.
  3. 에서Allow Delegating Fresh Credentials with NTLM-only Server Authentication대화 상자에서 다음을 수행합니다.
  4. 클릭Enabled.
  5. 에서Options영역, 클릭Show.
  6. 값에 입력합니다.WSMAN/*를 클릭합니다.OK반드시Concatenate OS defaults with input above를 선택한 다음 을 클릭합니다.OK.

이제 다음 명령이 작동합니다(암호 프롬프트 후).

Invoke-Command { dir \\fileserver\devtools } -computer appserver01 -authentication credssp -credential domain\user

MSDN 포럼을 참조하십시오.

TechNet 참조

페이지 덕분에 드디어 작동하게 되었습니다.적절한 레지스트리 키를 직접 설정하여 필요한 인증 정보 위임 정책을 설정하는 스크립트를 제공합니다.관리자 권한으로 해당 스크립트를 실행한 후 서버에 대한 CredSSP 연결을 성공적으로 설정할 수 있었습니다.

Enable-WSManCredSSP -Role client -DelegateComputer *.mydomain.com

$allowed = @('WSMAN/*.mydomain.com')

$key = 'hklm:\SOFTWARE\Policies\Microsoft\Windows\CredentialsDelegation'
if (!(Test-Path $key)) {
    md $key
}
New-ItemProperty -Path $key -Name AllowFreshCredentials -Value 1 -PropertyType Dword -Force            

$key = Join-Path $key 'AllowFreshCredentials'
if (!(Test-Path $key)) {
    md $key
}
$i = 1
$allowed |% {
    # Script does not take into account existing entries in this key
    New-ItemProperty -Path $key -Name $i -Value $_ -PropertyType String -Force
    $i++
}

솔루션을 완전히 자동화해야 했습니다. 특히 GPO 편집기로 이동하는 솔루션의 파트 섹션이 그렇습니다.

원격 PS 사용

Enable-PSRemoting -force

CredSSP 사용

Enable-WSManCredSSP -Role Server -Force
Enable-WSManCredSSP -Role Client -DelegateComputer locahost -Force
Enable-WSManCredSSP -Role Client -DelegateComputer $env:COMPUTERNAME -Force
Enable-WSManCredSSP -Role Client -DelegateComputer $domain -Force
Enable-WSManCredSSP -Role Client -DelegateComputer "*.$domain" -Force
Set-Item -Path "wsman:\localhost\service\auth\credSSP" -Value $True -Force

레지스트리를 통해 NTLM 새 자격 증명 사용:

New-Item -Path HKLM:\SOFTWARE\Policies\Microsoft\Windows\CredentialsDelegation -Name AllowFreshCredentialsWhenNTLMOnly -Force
New-ItemProperty -Path HKLM:\SOFTWARE\Policies\Microsoft\Windows\CredentialsDelegation\AllowFreshCredentialsWhenNTLMOnly -Name 1 -Value * -PropertyType String

그 후에야 PS 세션에서 실행하고 AD 작업을 수행할 수 있는 로컬 관리자로서 powershell 스크립트를 시작할 수 있었습니다.

$secpasswd = ConvertTo-SecureString $adPassword -AsPlainText -Force
$credential = New-Object System.Management.Automation.PSCredential ("$domain\Admin", $secpasswd)
$adminSession = New-PSSession -Credential $credential -Authentication Credssp;

$sb = {
  param($p1, $p2)

  whoami

  New-ADUser ....
}

Invoke-Command -Session $adminSession -Script $sb -ArgumentList $domain,$userPassword

위의 Akira의 답변에 따라 inpedit.msc를 확장하여 "신선 자격 증명 위임 허용"이 아닌 "NTLM 전용 서버 인증으로 신규 자격 증명 위임 허용"을 설정해야 했습니다.

언급URL : https://stackoverflow.com/questions/18113651/powershell-remoting-policy-does-not-allow-the-delegation-of-user-credentials

반응형