Skip to content

[ssh-gateway] fix missing output when running simple command #18366

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

Merged
merged 4 commits into from
Jul 31, 2023

Conversation

iQQBot
Copy link
Contributor

@iQQBot iQQBot commented Jul 27, 2023

Description

This PR fixes missing output in SSH gateway when running a simple command, and also upgrade golang crypto library

Summary generated by Copilot

🤖 Generated by Copilot at e9c1f91

Fixed security and compatibility issues in ws-proxy component. Refactored SSH proxy forwarding code to prevent crashes and handle errors better.

Related Issue(s)

Fixes EXP-246

How to test

  1. start a workspace in preview environment
  2. get ssh connection string via access token
  3. run watch -n 0.1 ssh -T 'workspaceID#[email protected]' 'date +%s%N' test for 1minute
  4. also run this command in gitpod.io workspace, and compare output.

Documentation

Preview status

Gitpod was successfully deployed to your preview environment.

Build Options

Build
  • /werft with-werft
    Run the build with werft instead of GHA
  • leeway-no-cache
  • /werft no-test
    Run Leeway with --dont-test
Publish
  • /werft publish-to-npm
  • /werft publish-to-jb-marketplace
Installer
  • analytics=segment
  • with-dedicated-emulation
  • workspace-feature-flags
    Add desired feature flags to the end of the line above, space separated
Preview Environment
  • /werft with-local-preview
    If enabled this will build install/preview
  • /werft with-preview
  • /werft with-large-vm
  • /werft with-gce-vm
    If enabled this will create the environment on GCE infra
  • with-integration-tests=ssh
    Valid options are all, workspace, webapp, ide, jetbrains, vscode, ssh
  • with-monitoring

/hold

@iQQBot iQQBot changed the title [DO NOT MERGE] SSH output debug [ssh-gateway] fix missing output when running simple command Jul 27, 2023
@roboquat roboquat added size/M and removed size/S labels Jul 27, 2023
@iQQBot iQQBot marked this pull request as ready for review July 28, 2023 07:41
@iQQBot iQQBot requested a review from a team as a code owner July 28, 2023 07:41
@akosyakov
Copy link
Member

@iQQBot there is the actual fix? in the library?

@iQQBot
Copy link
Contributor Author

iQQBot commented Jul 28, 2023

@iQQBot there is the actual fix? in the library?

image

Move close to another place, it's because golang routine competition, we need send all date before we call close.

@iQQBot
Copy link
Contributor Author

iQQBot commented Jul 28, 2023

/hold

maybe we should wait all of stdout, stderr, request then call close

@akosyakov
Copy link
Member

akosyakov commented Jul 28, 2023

ok, I tried with VS Code Desktop and Local SSH over direct SSH, it does not help there, it now fails differently though, it seems it can tunnel, but then interrupts, before could not forward at all.

[09:55:56.820] Remote server is listening on 36127
[09:55:56.820] Parsed server configuration: {"serverConfiguration":{"remoteListeningOn":{"port":36127},"osReleaseId":"ubuntu","arch":"x86_64","webUiAccessToken":"","sshAuthSock":"","display":"","tmpDir":"/tmp","platform":"linux","connectionToken":"1a1aa111-a1aa-111a-1111-aa1a1a1a111a"},"extInstallTime":239,"installUnpackCode":""}
[09:55:56.821] Persisting server connection details to /Users/[user]/Library/Application Support/Code/User/globalStorage/ms-vscode-remote.remote-ssh/vscode-ssh-host-0fdc06be-660393deaaa6d1996740ff4880f1bad43768c814-0.102.0/data.json
[09:55:56.826] Starting forwarding server. localPort 64392 -> socksPort 64384 -> remotePort 36127
[09:55:56.827] Forwarding server listening on 64392
[09:55:56.827] Waiting for ssh tunnel to be ready
[09:55:56.828] [Forwarding server 64392] Got connection 0
[09:55:56.829] Tunneled 36127 to local port 64392
[09:55:56.829] Resolved "ssh-remote+7b22686f73744e616d65223a22616b6f7379616b6f762d70617263656c64656d6f2d373476766964317a3762702e7673732e70642d7373682d6f75747075742e707265766965772e676974706f642d6465762e636f6d222c2275736572223a22616b6f7379616b6f762d70617263656c64656d6f2d373476766964317a376270227d" to "127.0.0.1:64392"
[09:55:56.837] ------




[09:55:56.866] [Forwarding server 64392] Got connection 1
[09:55:56.961] > local-server-2> ssh child died, shutting down
[09:55:56.961] Failed to set up socket for dynamic port forward to remote port 36127: Socket closed. Is the remote port correct?
[09:55:56.962] Failed to set up socket for dynamic port forward to remote port 36127: Socket closed. Is the remote port correct?
[09:55:56.966] Local server exit: 0

@iQQBot
Copy link
Contributor Author

iQQBot commented Jul 28, 2023

ok, I tried with VS Code Desktop and Local SSH over direct SSH, it does not help there, it now fails differently though, it seems it can tunnel, but then interrupts, before could not forward at all.

Yeah, It's another problem, not related this PR

@akosyakov
Copy link
Member

not related this PR

What interesting though that before it won't ever reach [Forwarding server 64392] Got connection 1 so this PR did fix initiation of the forwarding somehow.

@akosyakov
Copy link
Member

@iQQBot Good to retest?

defer wg.Done()
_, _ = io.Copy(targetChan, originChan)
targetChannelWg.Done()
targetChannelWg.Wait()
Copy link
Member

Choose a reason for hiding this comment

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

I wonder should not we wait for stderr/stdout in both directions? won't close on one end trigger close on another

Copy link
Contributor Author

Choose a reason for hiding this comment

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

In fact, they are closed together. It's just that due to the nature of go routines, it is possible that the last few bytes may not be guaranteed to be sent completely, so we need to wait for all of them to be sent before sending a close signal.

Copy link
Member

Choose a reason for hiding this comment

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

yeah, I meant there we can simplify with one wg, which waits for both directions, but like that is fine as well 👍

@akosyakov
Copy link
Member

@iQQBot preview envs are down?

@iQQBot
Copy link
Contributor Author

iQQBot commented Jul 31, 2023

@iQQBot preview envs are down?

Rerun

@mustard-mh
Copy link
Contributor

ok, I tried with VS Code Desktop and Local SSH over direct SSH, it does not help there, it now fails differently though, it seems it can tunnel, but then interrupts, before could not forward at all.

[09:55:56.820] Remote server is listening on 36127
[09:55:56.820] Parsed server configuration: {"serverConfiguration":{"remoteListeningOn":{"port":36127},"osReleaseId":"ubuntu","arch":"x86_64","webUiAccessToken":"","sshAuthSock":"","display":"","tmpDir":"/tmp","platform":"linux","connectionToken":"1a1aa111-a1aa-111a-1111-aa1a1a1a111a"},"extInstallTime":239,"installUnpackCode":""}
[09:55:56.821] Persisting server connection details to /Users/[user]/Library/Application Support/Code/User/globalStorage/ms-vscode-remote.remote-ssh/vscode-ssh-host-0fdc06be-660393deaaa6d1996740ff4880f1bad43768c814-0.102.0/data.json
[09:55:56.826] Starting forwarding server. localPort 64392 -> socksPort 64384 -> remotePort 36127
[09:55:56.827] Forwarding server listening on 64392
[09:55:56.827] Waiting for ssh tunnel to be ready
[09:55:56.828] [Forwarding server 64392] Got connection 0
[09:55:56.829] Tunneled 36127 to local port 64392
[09:55:56.829] Resolved "ssh-remote+7b22686f73744e616d65223a22616b6f7379616b6f762d70617263656c64656d6f2d373476766964317a3762702e7673732e70642d7373682d6f75747075742e707265766965772e676974706f642d6465762e636f6d222c2275736572223a22616b6f7379616b6f762d70617263656c64656d6f2d373476766964317a376270227d" to "127.0.0.1:64392"
[09:55:56.837] ------




[09:55:56.866] [Forwarding server 64392] Got connection 1
[09:55:56.961] > local-server-2> ssh child died, shutting down
[09:55:56.961] Failed to set up socket for dynamic port forward to remote port 36127: Socket closed. Is the remote port correct?
[09:55:56.962] Failed to set up socket for dynamic port forward to remote port 36127: Socket closed. Is the remote port correct?
[09:55:56.966] Local server exit: 0

@akosyakov Found bug in https://github.com/microsoft/dev-tunnels-ssh that it omit SSH_MSG_CHANNEL_EXTENDED_DATA and throw error, will create a fix PR later today.

Which should make local-ssh x gateway works

@akosyakov
Copy link
Member

@akosyakov Found bug in https://github.com/microsoft/dev-tunnels-ssh that it omit SSH_MSG_CHANNEL_EXTENDED_DATA and throw error, will create a fix PR later today.

@mustard-mh I checked it is the same with the tunnel but it works. I wonder whether maybe it works with all changes together now. Although if we resolved localhost hanging then exploring direct SSH is not a priority.

@mustard-mh
Copy link
Contributor

mustard-mh commented Jul 31, 2023

@mustard-mh I checked it is the same with the tunnel but it works. I wonder whether maybe it works with all changes together now. Although if we resolved localhost hanging then exploring direct SSH is not a priority.

@akosyakov It's because golang lib doesn't ignore SSH_MSG_UNIMPLEMENTED as rfc said https://github.com/gitpod-io/golang-crypto/blob/master/ssh/messages.go#L844

When we use local-ssh x gateway, dev-tunnel will send SSH_MSG_UNIMPLEMENTED since it doesn't resolve SSH_MSG_CHANNEL_EXTENDED_DATA.

So we can fix it in golang-crypto or dev-tunnel

@iQQBot
Copy link
Contributor Author

iQQBot commented Jul 31, 2023

/unhold

@roboquat roboquat merged commit 2e2833a into main Jul 31, 2023
@roboquat roboquat deleted the pd/ssh-output branch July 31, 2023 19:21
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

5 participants