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

fix(cli): session.Run is sensitive to quoting on Windows host #289

Conversation

mloskot
Copy link
Contributor

@mloskot mloskot commented Jan 19, 2024

There is a strange issue with SSH executor via session.Run
on Windows host (i.e. Windows SSH client) which seems to be
prone to failure depending on particular arrangements of quote,
double-quotes, etc. in PowerShell command.

For example, this fails

output, err := r.run(`Enable-NetFirewallRule -DisplayGroup "Remote Desktop"`)

while this succeeds

output, err := r.run(`Enable-NetFirewallRule -DisplayGroup 'Remote Desktop'`)

Wrapping the command with { and } also seems to solve this problem, effectively session.Run executing this with success

powershell -nologo -noprofile -c { Enable-NetFirewallRule -DisplayGroup "Remote Desktop" }

Interestingly, this issue seems not reproducible Linux host.

@k8s-ci-robot
Copy link
Contributor

[APPROVALNOTIFIER] This PR is APPROVED

This pull-request has been approved by: mloskot

The full list of commands accepted by this bot can be found here.

The pull request process is described here

Needs approval from an approver in each of these files:

Approvers can indicate their approval by writing /approve in a comment
Approvers can cancel approval by writing /approve cancel in a comment

@k8s-ci-robot k8s-ci-robot added the cncf-cla: yes Indicates the PR's author has signed the CNCF CLA. label Jan 19, 2024
@k8s-ci-robot k8s-ci-robot added approved Indicates a PR has been approved by an approver from all required OWNERS files. size/XS Denotes a PR that changes 0-9 lines, ignoring generated files. labels Jan 19, 2024
@mloskot
Copy link
Contributor Author

mloskot commented Jan 19, 2024

/cc @knabben

This fixes the issue that I was verbosely discussing on Slack.

@k8s-ci-robot k8s-ci-robot requested a review from knabben January 19, 2024 22:08
There is a strange issue with SSH executor via session.Run
on Windows host (i.e. Windows SSH client) which seems to be
prone to failure depending on particular arrangements of quote,
double-quotes, etc. in PowerShell command.

For example, this fails

  output, err := r.run(`Enable-NetFirewallRule -DisplayGroup "Remote Desktop"`)

while this succeeds

  output, err := r.run(`Enable-NetFirewallRule -DisplayGroup 'Remote Desktop'`)

Wrapping the command with { and } also seems to solve
this problem.

Interestingly, this issue seems not reproducible Linux host.
@mloskot mloskot force-pushed the ml/swdt-cli-fix-fragile-ssh-run-on-windows branch from 49b59af to 2d48619 Compare January 19, 2024 22:10
@knabben
Copy link
Member

knabben commented Jan 19, 2024

/lgtm

@k8s-ci-robot k8s-ci-robot added the lgtm "Looks good to me", indicates that a PR is ready to be merged. label Jan 19, 2024
@k8s-ci-robot k8s-ci-robot merged commit 990b7ba into kubernetes-sigs:master Jan 19, 2024
4 checks passed
@mloskot mloskot deleted the ml/swdt-cli-fix-fragile-ssh-run-on-windows branch January 20, 2024 19:03
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
approved Indicates a PR has been approved by an approver from all required OWNERS files. cncf-cla: yes Indicates the PR's author has signed the CNCF CLA. lgtm "Looks good to me", indicates that a PR is ready to be merged. size/XS Denotes a PR that changes 0-9 lines, ignoring generated files.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants