Skip to content

Support OpenSSH options for PSRP over SSH commands - #12802

Merged
Ilya (iSazonov) merged 4 commits into
PowerShell:masterfrom
BrannenGH:feature/SSHOptions
Jan 22, 2022
Merged

Ilya (iSazonov) merged 4 commits into
PowerShell:masterfrom
BrannenGH:feature/SSHOptions

Conversation

@BrannenGH

@BrannenGH Brannen Hall (BrannenGH) commented May 26, 2020 •

Copy link
Copy Markdown
Contributor

PR Summary

Fixes #12762

Add an -Options parameter to Invoke-Command and Start-PSSession to pass SSH options

  • Options parameter added to Invoke-Command
  • Options parameter added to Start-PSSession
  • Options parameter added to Enter-PSSession
  • Options parameter added to SSHConnection Hashtable

PR Context

PSRP over SSH uses OpenSSH to connect to remote machines. It would be helpful if we could pass OpenSSH options to cmdlets that support PSRP over SSH.

PR Checklist

@ghost ghost assigned Ilya (iSazonov) May 26, 2020
@msftclas

Microsoft Contribution License Agreements (msftclas) commented May 26, 2020 •

Copy link
Copy Markdown

CLA assistant check
All CLA requirements met.

@iSazonov Ilya (iSazonov) added the CL-General Indicates that a PR should be marked as a general cmdlet change in the Change Log label May 27, 2020
@iSazonov Ilya (iSazonov) added this to the 7.1.0-preview.4 milestone May 27, 2020

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

These changes look good to me, but can you also update the Enter-PSSession command? SSH remoting is supported by Invoke-Command, New-PSSession, and Enter-PSSession.
https://github.com/PowerShell/PowerShell/blob/master/src/System.Management.Automation/engine/remoting/commands/PushRunspaceCommand.cs#L51

@ghost ghost added the Waiting on Author The PR was reviewed and requires changes or comments from the author before being accept label May 29, 2020
@ghost ghost removed this from the 7.1.0-preview.4 milestone May 29, 2020
@iSazonov Ilya (iSazonov) added Review - Needed The PR is being reviewed and removed Waiting on Author The PR was reviewed and requires changes or comments from the author before being accept labels May 31, 2020

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

LGTM

@iSazonov

Copy link
Copy Markdown
Collaborator

Brannen Hall (@BrannenGH) Are you ready to remove WIP?

@ghost ghost removed the Review - Needed The PR is being reviewed label Jun 1, 2020
@BrannenGH Brannen Hall (BrannenGH) changed the title WIP: Support OpenSSH options for PSRP over SSH commands Support OpenSSH options for PSRP over SSH commands Jun 2, 2020
@BrannenGH

Copy link
Copy Markdown
Contributor Author

Paul Higinbotham (@PaulHigin) Ilya (@iSazonov) Thanks for reviewing this so quickly! WIP is removed. I'll take a look at the docs later this week. Let me know if you need anything else.

{
foreach (DictionaryEntry pair in this.Options)
{
startInfo.ArgumentList.Add(string.Format(CultureInfo.InvariantCulture, @"-o {0}={1}", pair.Key, pair.Value));

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

Since we get this through public API should we make additional validations?
I mean that Key and Value could contain composite values.
/cc Paul Higinbotham (@PaulHigin)

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

I see your point, right now the Format method will just try to convert whatever is passed in to a string, would we want to handle composite values any other way?

I also could try to add some validation to ensure that we're only passing options that OpenSSH would consider valid, but that would be a lot to maintain as well. Please let me know your thoughts.

Comment on lines +57 to +187
It "Verifies explicit Options parameter" {
$options = @{"Port"="22"}
$script:session = New-PSSession -HostName localhost -Options $options -ErrorVariable err
$err | Should -HaveCount 0
VerifySession $script:session
}

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

This test checks that the parameter is only recognized, but does not verify that it is being applied.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

I can definitely add more integration tests, it will take me a few days to get those done though.

@BrannenGH Brannen Hall (BrannenGH) changed the title Support OpenSSH options for PSRP over SSH commands WIP: Support OpenSSH options for PSRP over SSH commands Jun 5, 2020
@ghost ghost added the Review - Needed The PR is being reviewed label Jun 13, 2020
@ghost

Copy link
Copy Markdown

This pull request has been automatically marked as Review Needed because it has been there has not been any activity for 7 days.
Mainainer, Please provide feedback and/or mark it as Waiting on Author

@SteveL-MSFT Steve Lee (SteveL-MSFT) changed the title WIP: Support OpenSSH options for PSRP over SSH commands Support OpenSSH options for PSRP over SSH commands Jul 21, 2021
* Options parameter added to Invoke-Command
* Options parameter added to Start-PSSession
* Options parameter added to SSHConnection Hashtable
@ghost ghost removed the Review - Needed The PR is being reviewed label Sep 15, 2021
@ghost ghost added the Review - Needed The PR is being reviewed label Sep 23, 2021
@ghost

Copy link
Copy Markdown

This pull request has been automatically marked as Review Needed because it has been there has not been any activity for 7 days.
Maintainer, please provide feedback and/or mark it as Waiting on Author

@iSazonov

Copy link
Copy Markdown
Collaborator

/rebase

@ghost ghost removed the Review - Needed The PR is being reviewed label Jan 19, 2022
@iSazonov

Copy link
Copy Markdown
Collaborator

Paul Higinbotham (@PaulHigin) Is it ready to merge?

@PaulHigin

Copy link
Copy Markdown
Contributor

Ilya (@iSazonov) Yes, I feel this is ready to merge.

@pull-request-quantifier-deprecated

Copy link
Copy Markdown

This PR has 54 quantified lines of changes. In general, a change size of upto 200 lines is ideal for the best PR experience!


Quantification details

Label      : Small
Size       : +50 -4
Percentile : 21.6%

Total files changed: 6

Change summary by file extension:
.cs : +45 -4
.ps1 : +5 -0

Change counts above are quantified counts, based on the PullRequestQuantifier customizations.

Why proper sizing of changes matters

Optimal pull request sizes drive a better predictable PR flow as they strike a
balance between between PR complexity and PR review overhead. PRs within the
optimal size (typical small, or medium sized PRs) mean:

  • Fast and predictable releases to production:
    • Optimal size changes are more likely to be reviewed faster with fewer
      iterations.
    • Similarity in low PR complexity drives similar review times.
  • Review quality is likely higher as complexity is lower:
    • Bugs are more likely to be detected.
    • Code inconsistencies are more likely to be detetcted.
  • Knowledge sharing is improved within the participants:
    • Small portions can be assimilated better.
  • Better engineering practices are exercised:
    • Solving big problems by dividing them in well contained, smaller problems.
    • Exercising separation of concerns within the code changes.

What can I do to optimize my changes

  • Use the PullRequestQuantifier to quantify your PR accurately
    • Create a context profile for your repo using the context generator
    • Exclude files that are not necessary to be reviewed or do not increase the review complexity. Example: Autogenerated code, docs, project IDE setting files, binaries, etc. Check out the Excluded section from your prquantifier.yaml context profile.
    • Understand your typical change complexity, drive towards the desired complexity by adjusting the label mapping in your prquantifier.yaml context profile.
    • Only use the labels that matter to you, see context specification to customize your prquantifier.yaml context profile.
  • Change your engineering behaviors
    • For PRs that fall outside of the desired spectrum, review the details and check if:
      • Your PR could be split in smaller, self-contained PRs instead
      • Your PR only solves one particular issue. (For example, don't refactor and code new features in the same PR).

How to interpret the change counts in git diff output

  • One line was added: +1 -0
  • One line was deleted: +0 -1
  • One line was modified: +1 -1 (git diff doesn't know about modified, it will
    interpret that line like one addition plus one deletion)
  • Change percentiles: Change characteristics (addition, deletion, modification)
    of this PR in relation to all other PRs within the repository.


Was this comment helpful? 👍  :ok_hand:  :thumbsdown: (Email)
Customize PullRequestQuantifier for this repository.

@iSazonov

Copy link
Copy Markdown
Collaborator

/rebase

@iSazonov
Ilya (iSazonov) merged commit 0302b1f into PowerShell:master Jan 22, 2022
@iSazonov

Copy link
Copy Markdown
Collaborator

Brannen Hall (@BrannenGH) Thanks for your contribution!

@ghost

Copy link
Copy Markdown

🎉v7.3.0-preview.2 has been released which incorporates this pull request.:tada:

Handy links:

Thatgfsj (Thatgfsj) pushed a commit to Thatgfsj-contribs/PowerShell that referenced this pull request Aug 6, 2026
Add an -Options parameter to Invoke-Command and Start-PSSession to pass SSH options

Options parameter added to Invoke-Command
Options parameter added to Start-PSSession
Options parameter added to Enter-PSSession
Options parameter added to SSHConnection Hashtable
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

CL-General Indicates that a PR should be marked as a general cmdlet change in the Change Log Small

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Support passing options to SSH through cmdlets that allow remoting over SSH

6 participants