Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

WinRM SPN Issue workaround #11

Open
garetjax67 opened this issue Dec 27, 2019 · 2 comments
Open

WinRM SPN Issue workaround #11

garetjax67 opened this issue Dec 27, 2019 · 2 comments
Assignees
Labels
enhancement New feature or request question Further information is requested

Comments

@garetjax67
Copy link

As described in this posting WinRM does not allow connections if the HTTP/ SPN is registered with a domain account vs computer account.
https://social.technet.microsoft.com/Forums/windows/en-US/a4c5c787-ea65-4150-8d16-2a19c569a589/enterpssession-winrm-cannot-process-the-request-kerberos-authentication-error-0x80090322?forum=winserverpowershell

You can workaround this issue with your module if you:
On the offending computer create port specific SPNs:
SetSPN.exe -s HTTP/$($env:COMPUTERNAME):5985 $env:COMPUTERNAME
SetSPN.exe -s HTTP/$($env:COMPUTERNAME).$($env:USERDNSDOMAIN):5985 $env:COMPUTERNAME

The modify your module like this (I am sure you can find a more graceful way):
~line 311
Try{
$DotNetData.$Computer = Invoke-Command @PSRSplat #-ComputerName $Computer -ScriptBlock (Get-Item function:\SetDataHashObject).ScriptBlock `
#-ArgumentList $Computer, $true -ErrorAction Stop
# -Verbose:$(if ($VerbosePreference -match 'Stop|Continue') { $true } else { $false })
}
catch {
Try{
$SessionOptions = New-PSSessionOption -IncludePortInSPN
$session = New-PSSession -Computername $computer -SessionOption $SessionOptions -Credential $Credential
$DotNetData.$Computer = Invoke-Command -Session $session -ScriptBlock (Get-Item function:\SetDataHashObject).ScriptBlock -ArgumentList $Computer, $true -ErrorAction Stop
Remove-PSSession $session
}
catch{
$DotNetData.$Computer | Add-Member -MemberType NoteProperty -Name Error -Value "PSRemoting Port failure: $_"
}
}

@EliteLoser
Copy link
Owner

EliteLoser commented Jan 27, 2020

I don't feel like it's within the scope of my module to do this, but not sure. I wouldn't be setting up the SPNs (didn't read the Technet post (yet), but assuming those commands do a sensible thing), but only allowing for -IncludePortInSPN, unknown to me at this point, so maybe...

Also not sure if it should be parameterized or default fallback behavior. This is why my answer has lingered. Sharing initial thoughts. If it's default fallback behavior here, then it should be in every script that uses PowerShell remoting, I guess... (then Microsoft might as well implement it themselves by default?). I'm not sure.

How common is this "SPN" issue globally, I wonder? More questions than answers here, I'm afraid. I can always implement the code, but should I? Your method seems OK enough with regards to code quality/sanity, btw, except for a few details I would handle differently. A nested try/catch block (I don't recall using "finally {}" yet, heh) would probably be the easiest at least.

You might want to read up on GitHub syntax, you can post a code block much more readable than that.

A minor stylistic detail in the code is that $($var).$($var2) is something I think is better written without two subexpressions, but rather by delimiting with the "variable name delimiters": brackets (no idea what the official term is, maybe I just invented it). Like this: ${var}.${var2}.

@EliteLoser EliteLoser self-assigned this Jan 27, 2020
@EliteLoser EliteLoser added enhancement New feature or request question Further information is requested labels Jan 27, 2020
@EliteLoser
Copy link
Owner

(I know you don't need the variable name delimiters with a period, as it's not an allowed variable name character and parsed as a literal period in the string "$var1.$var2")

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request question Further information is requested
Projects
None yet
Development

No branches or pull requests

2 participants