Wednesday, 23 November 2016

What is 'Double Hop Authentication' in Windows and why should I care?

If you've tried to use Invoke-Command to run commands with credentials on a remote machine and received unexpected Access Denied messages then you may have run across Double Hop Authentication issues.If the command you tried to run needs to pass credentials to a second machine in order to execute, then you will likely receive an Access Denied message like the following.You do not have permission to perform the operation. Contact your administrator if you believe you should havepermission to perform this operation. + CategoryInfo : PermissionDenied: (:) [Get-VM], VirtualizationOperationFailedException + FullyQualifiedErrorId : AccessDenied,Microsoft.HyperV.PowerShell.Commands.GetVMCommand + PSComputerName : HYPERV1The most recent example I've seen is when attempting to run System Center Configuration Manager PowerShell commands on a remote machine using Jenkins. The error message above isn't much help, but since I'm running Invoke-Command with the -Credentials and -Computer parameters - and then trying to authenticate to a further machine - 'Double Hop' is probably the issue.Another example is trying to run something like the following:Invoke-Command -Computer hyperv1 -Credential $Cred -ScriptBlock { Get-VM -ComputerName hyperv2 }The server hyperv1 will attempt to authenticate to hyperv2, but it is not authorised to cache and forward the credentials.

How can I fix it?In order to be able to pass credentials via a remote machine to another machine, you need to configure CredSSP (Credential Security Service Provider.) This does have security issues, since you are trusting the remote machine to cache and re-send your credentials to the second machine. You should only configure this for machines you fully trust.To configure your machine to use CredSSP perform the following steps in an administratively elevated PowerShell console.Client Steps: Enable-WSManCredSSP -Role "Client" -DelegateComputer "server.domain.com"Server Steps: Enable-WSManCredSSP -Role "Server"If you haven't already configured an HTTPS listener on the server you can do so with this command. winrm quickconfig -transport:httpsThere are pre-requesites to this such as having a valid not self-signed certificate for the FQDN of the server machine.Once completed you should now be able to re-run your command specifying -Authentication CredSSPAn example of the Hyper-V command that didn't work before is:Invoke-Command -Computer hyperv1 -Credential $Cred -ScriptBlock { Get-VM -ComputerName hyperv2 } -Authentication CredSSPFurther reading on the PowerShell command for configuring this here.The classic way to configure this is detailed on MSDN here.