Movatterモバイル変換


[0]ホーム

URL:


Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

fix(cli/ssh): prevent reads/writes to stdin/stdout in stdio mode#12045

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 ourterms of service andprivacy statement. We’ll occasionally send you account related emails.

Already on GitHub?Sign in to your account

Merged
mafredri merged 4 commits intomainfrommafredri/fix-cli-ssh-stdio-output
Feb 8, 2024

Conversation

mafredri
Copy link
Member

@mafredrimafredri commentedFeb 7, 2024
edited
Loading

This PR prevents writes to stdout in stdio mode (assuming no developer error that usesos.Stdout).

For absolute safety, we also swap stdin with an EOF reader that logs errors on attempts to read. We can't make reads panic (or similar) since there's a high chance that such an issue could slip unnoticed into a release and trigger at runtime.

Fixes#11530


The added test, without the fix, would catch the issue at two stages:

    ssh_test.go:400: monitorServerOutput: "Planning workspace..." (0x506c616e6e696e6720776f726b73706163652e2e2e)    ssh_test.go:409:        Error Trace:/home/coder/coder/cli/ssh_test.go:409                    /home/coder/coder/cli/ssh_test.go:1479                    /usr/local/go/src/runtime/asm_amd64.s:1650        Error:      Not equal:                    expected: "SSH-2.0-Go"                    actual  : "Planning workspace..."                    Diff:                    --- Expected                    +++ Actual                    @@ -1 +1 @@                    -SSH-2.0-Go                    +Planning workspace...        Test:       TestSSH/Stdio_StartStoppedWorkspace_NoStdinOrStdout        Messages:   invalid header    ssh_test.go:400: monitorServerOutput: "==> ⧗ Queued" (0x3d3d3e20e2a79720517565756564)    [...]    ssh_test.go:463:        Error Trace:/home/coder/coder/cli/ssh_test.go:463        Error:      Received unexpected error:                    ssh: handshake failed: ssh: overflow reading version string        Test:       TestSSH/Stdio_StartStoppedWorkspace_NoStdinOrStdout

@mafredrimafredriforce-pushed themafredri/fix-cli-ssh-stdio-output branch from3793256 to3be345dCompareFebruary 7, 2024 12:10
@mafredrimafredri marked this pull request as ready for reviewFebruary 7, 2024 12:18
@mafredrimafredri changed the titlefix(cli/ssh): prevent stdin/stdout reads/writes in stdio modefix(cli/ssh): prevent reads/writes to stdin/stdout in stdio modeFeb 7, 2024
@mafredrimafredriforce-pushed themafredri/fix-cli-ssh-stdio-output branch from3be345d todd1f7c4CompareFebruary 7, 2024 12:32
Copy link
Contributor

@spikecurtisspikecurtis left a comment

Choose a reason for hiding this comment

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

I think the commentary and naming could be improved with some inline suggestions, but LGTM.


clientOutput, clientInput := io.Pipe()
serverOutput, serverInput := io.Pipe()
monitorServerOutput, monitorServerInput := io.Pipe()
Copy link
Contributor

Choose a reason for hiding this comment

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

it's pretty confusing what's happening with these 3 pipes, so I think an ASCII diagram would go a long way.

Copy link
MemberAuthor

@mafredrimafredriFeb 7, 2024
edited
Loading

Choose a reason for hiding this comment

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

I neither know mermaid or how to turn it into ascii, so I pasted it in there 😅

flowchart LRA[ProxyCommand] --> B[captureProxyCommandStdoutW]B --> C[captureProxyCommandStdoutR]C --> VA[Validate output]C --> D[proxyCommandStdoutW]D --> E[proxyCommandStdoutR]E --> F[SSH Client]
Loading

})

// Here we start a monitor for the input going to the server
// (i.e. client stdout) to ensure that the output is clean.
Copy link
Contributor

Choose a reason for hiding this comment

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

I think this comment is incorrect. This doesn't monitor data being sent to the server (to monitor that we'd need to be in the tailnet network path and we are not), but rather data being sent to the stdio client.

Underscores a need for a diagram about the pipes.

Copy link
MemberAuthor

@mafredrimafredriFeb 7, 2024
edited
Loading

Choose a reason for hiding this comment

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

The stdio client is a representation of a raw network connection, so I don't consider the statement incorrect. Lossy, perhaps.

Addendum: By "client stdout" I'm referring to the SSH command. Using "client" terminology for "stdio client" would cause more confusion IMO. Hence I prefer referring to the "stdio client" as "the connection" instead.

Yeah so after I rewrote the comment I realized what you meant, and you're right, it was incorrect, mb. 😄

// Ideally we would do further verification, but that would
// involve parsing the SSH protocol to look for output that
// doesn't belong. This at least ensures that no garbage is
// being sent to the server before trying to connect.
Copy link
Contributor

Choose a reason for hiding this comment

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

Suggested change
// being sent to theserver before trying to connect.
// being sent to theclient before trying to connect.

@mafredrimafredri merged commite659957 intomainFeb 8, 2024
@mafredrimafredri deleted the mafredri/fix-cli-ssh-stdio-output branchFebruary 8, 2024 11:09
@github-actionsgithub-actionsbot locked and limited conversation to collaboratorsFeb 8, 2024
Sign up for freeto subscribe to this conversation on GitHub. Already have an account?Sign in.
Reviewers

@spikecurtisspikecurtisspikecurtis approved these changes

@johnstcnjohnstcnjohnstcn approved these changes

Assignees

@mafredrimafredri

Labels
None yet
Projects
None yet
Milestone
No milestone
Development

Successfully merging this pull request may close these issues.

SSH failed:kex_exchange_identification: banner line contains invalid characters
3 participants
@mafredri@johnstcn@spikecurtis

[8]ページ先頭

©2009-2025 Movatter.jp