Skip to content

Conversation

@PaulHigin
Copy link
Contributor

PR Summary

OMI does not support server certificate validation, so this change is to add a requirement that -SkipCACheck and -SkipCNCheck options are specified before a connection is allowed. This way users will be aware that no server certificate validation is performed.

This only applies to PSCore6 remoting clients on non-Windows platforms, when creating a remote session to a Windows machine via WinRM\OMI.

This is a breaking change because these skip check options are now required. If the skip check options are not included then the connection will be denied.

Examples:

# On a Linux or MacOS machine
New-PSSession -Cn <WindowsMachine> -Credential $cred -Authentication Basic -UseSSL
New-PSSession : HTTPS on Unix does not support CA or CN checks. Use the PSSessionOption -SkipCACheck and -SkipCNCheck if you are certain of the server you are connecting to.
At line:1 char:1
+ New-PSSession -cn paulhig-2 -Credential $cred -Authentication Basic - ...
+ ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
+ CategoryInfo          : ResourceUnavailable: (:) [New-PSSession], PSRemotingTransportException
+ FullyQualifiedErrorId : System.Management.Automation.Remoting.PSRemotingDataStructureException,Microsoft.PowerShell.Commands.NewPSSessionCommand

$so = New-PSSessionOption -SkipCACheck -SkipCNCheck
$session = New-PSSession -Cn <WindowsMachine> -Credential $cred -Authentication Basic -UseSSL -SessionOption $so

Enter-PSSession -Cn <WindowsMachine> -Credential $cred -Authentication Basic -UseSSL -SessionOption $so

PR Checklist

@adityapatwardhan
Copy link
Member

@PaulHigin Please resolve merge conflict.

Also, enable tests here for non-windows: https://github.com/PowerShell/PowerShell/blob/master/test/powershell/engine/Remoting/SessionOption.Tests.ps1

Copy link
Member

@adityapatwardhan adityapatwardhan left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Please enable SessionOption tests.

@adityapatwardhan adityapatwardhan added the Documentation Needed in this repo Documentation is needed in this repo label Nov 15, 2018
@PaulHigin
Copy link
Contributor Author

SessionOption.Tests.ps1 contains tests for WSMan SessionOption object, which we do not expose for non-Windows platforms. But I'll add tests for New-PSSessionOption.

@iSazonov
Copy link
Collaborator

PowerShell Committee for the breaking change?

@iSazonov iSazonov added the CL-Engine Indicates that a PR should be marked as an engine change in the Change Log label Nov 16, 2018
@TravisEz13 TravisEz13 added the Review - Committee The PR/Issue needs a review from the PowerShell Committee label Nov 16, 2018
@TravisEz13
Copy link
Member

Adding the committee to review the breaking change

throw "No Exception!"
}
catch {
$_.Exception.ErrorCode | Should -Be $expectedErrorCode
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We can use new Pester features:

$exc = { & $scriptBlock } | Should -Throw -ErrorId "..." -PassThru
$exc.Exception.ErrorCode | Should -Be $expectedErrorCode

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I like this pattern, however the ErrorId is not being checked. At least in my current version of Pester (4.4.2).

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Sample from the repo

It 'Empty dynamically generated set throws in C#' {
$exc = {
Get-TestValidateSet5 -Param1 "TestString1" -ErrorAction Stop
} | Should -Throw -ErrorId "ParameterArgumentValidationError,Test.Language.TestValidateSetCommand5" -PassThru
$exc.Exception.InnerException.ErrorRecord.FullyQualifiedErrorId | Should -BeExactly "ValidateSetGeneratedValidValuesListIsNull"

<value>Host system does not have the correct version of Hyper-V schema.</value>
</data>
<data name="UnixOnlyHttpsWithoutSkipCACheckNotSupported" xml:space="preserve">
<value>HTTPS on Unix does not currently support CA or CN checks. Use the PSSessionOption -SkipCACheck and -SkipCNCheck if you are certain of the server you are connecting to.</value>
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
<value>HTTPS on Unix does not currently support CA or CN checks. Use the PSSessionOption -SkipCACheck and -SkipCNCheck if you are certain of the server you are connecting to.</value>
<value>HTTPS on Unix does not currently support CA or CN checks. Use the PSSessionOption -SkipCACheck and -SkipCNCheck if you are certain you trust the server you are connecting to and the network in between.</value>

Copy link
Member

@TravisEz13 TravisEz13 left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

One comment about the message

@adityapatwardhan
Copy link
Member

I thought -cn would flag a PSScriptAnalyzer error, but verified that it does not. So signing off.

@adityapatwardhan adityapatwardhan merged commit 0657163 into PowerShell:master Nov 28, 2018
@adityapatwardhan
Copy link
Member

@PowerShell/powershell-committee I did not realize this was marked for committee review. If this does not pass review, I will revert.

@TravisEz13
Copy link
Member

@PowerShell/powershell-committee Also, consider if this should be back-ported to 6.1 and 6.0?

@PaulHigin PaulHigin deleted the Unix_SkipCA_Fix branch August 5, 2019 21:41
@joeyaiello joeyaiello removed the Review - Committee The PR/Issue needs a review from the PowerShell Committee label Mar 11, 2020
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Breaking-Change breaking change that may affect users CL-Engine Indicates that a PR should be marked as an engine change in the Change Log Documentation Needed in this repo Documentation is needed in this repo WG-Remoting PSRP issues with any transport layer

Projects

None yet

Development

Successfully merging this pull request may close these issues.

6 participants