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

Initial implementation of a builtin SSH connection support #1323

Merged
merged 3 commits into from Nov 8, 2023

Conversation

christianparpart
Copy link
Member

@christianparpart christianparpart commented Oct 29, 2023

Main motivation of implementing this is to bypass local PTY (ConPTY) on Windows. But there may be more use to it than that on other platforms maybe as well, so we make it available on all platforms, if possible.

Closes #1319, #1064.

Implement builtin SSH support. While being not THAT useful on Linux desktop or MacOS, it turns out to be a game changer on Windows platform, as we can fully bypass ConPTY with a builtin SSH client in case would simply SSH away only anyways.

Maybe this would also bypass ConPTY on Windows when using to get into WSL / WSL2 (I do not know yet).

Checklist

  • build: make sure it builds on MacOS/X (CI) (currently has linker errors, can't find lib)
  • build: make sure it builds on Windows (CI)
  • build: make sure it builds on Linux (CI)
  • SSH backend (using libssh2, bridging to C++ API: SshClient)
  • vtpty::Pty implementation: SshSession
  • frontend: configuration for login shell over SSH (how could the YAML config look like?)
  • frontend: support SSH session configuration for SSH-agent based authentication
  • frontend: support SSH session configuration for SSH key pair based authentication with password (to be prompted!) (needs code to interactively ask for password within the TE grid)
  • frontend: support username/password based auth
  • configuration additions documented
  • DNS resolution of hostname to IP via getaddr (API matches on UNIX + Win32, yay)
  • support TCP/IPv4
  • support TCP/IPv6
  • properly propagate login shell's exit code
  • server host key verification
  • configurable SSH agent forwarding (current problem: upon ssh-add -l the session terminates - ref)

Postponed post-merge and maybe post-0.4.0-release

Notes

this feature is only built if libssh2 is installed (its development package).

@christianparpart christianparpart added the frontend Contour Terminal Emulator (GUI frontend) label Oct 29, 2023
@christianparpart christianparpart marked this pull request as draft October 29, 2023 18:15
@github-actions github-actions bot added VT: Backend Virtual Terminal Backend (libterminal API) and removed frontend Contour Terminal Emulator (GUI frontend) labels Oct 29, 2023
@christianparpart christianparpart force-pushed the feature/ssh-client branch 2 times, most recently from f3f325d to 5a3abf1 Compare October 29, 2023 19:50
@github-actions github-actions bot added the CI GitHub Actions & CI label Oct 29, 2023
@christianparpart christianparpart force-pushed the feature/ssh-client branch 3 times, most recently from 93ff06d to 82bcf9a Compare October 29, 2023 21:02
@christianparpart christianparpart changed the title [vtpty] Initial implementation of a builtin SSH login session Pty implementation Initial implementation of a builtin SSH login session Pty implementation Oct 29, 2023
@github-actions github-actions bot added documentation Improvements or additions to documentation frontend Contour Terminal Emulator (GUI frontend) labels Oct 30, 2023
@christianparpart christianparpart force-pushed the feature/ssh-client branch 6 times, most recently from 3e158ec to 498f618 Compare October 30, 2023 22:01
@christianparpart christianparpart changed the title Initial implementation of a builtin SSH login session Pty implementation Initial implementation of a builtin SSH login PTY session Oct 31, 2023
@christianparpart christianparpart force-pushed the feature/ssh-client branch 8 times, most recently from 977a89a to b64d840 Compare October 31, 2023 15:52
@christianparpart christianparpart force-pushed the feature/ssh-client branch 2 times, most recently from 7667d3b to 9ad7a29 Compare November 6, 2023 07:00
whisperity

This comment was marked as outdated.

@christianparpart
Copy link
Member Author

Right off the bat, here is something weird. When using the build from https://github.com/contour-terminal/contour/actions/runs/6763840917, I immediately get a complete failure when just starting Contour if I let contour create its default configuration:

nice catch. the instant failure is because it tries to connect to SSH (localhost here) via IPv6. apparently that's not working (either not possible or i need to fix IPv6 support, will check).

On the other hand, SSH should not be used when using default config. i'll address that asap. (it's because ssh.hostname defaults to "localhost" and makes the frontend think that it should connect to SSH rather than spawn a local process.

@christianparpart christianparpart force-pushed the feature/ssh-client branch 4 times, most recently from 7492123 to ae99510 Compare November 6, 2023 20:05
@christianparpart
Copy link
Member Author

@whisperity I cannot repro what you described. my earlier comment was based on an old state of this PR. :(

I've found some other minor issue though. the default user name on windows was not properly inferred. it was set to "unknown" as fallback. I've just fixed that.

@whisperity
Copy link
Member

I cannot repro what you described. my earlier comment was based on an old state of this PR. :(

I linked exactly the build I was using... 😦 Although, yeah, it does not point to a commit.

I will try the latest build of the branch tomorrow!

@whisperity
Copy link
Member

Using this build, I can confirm that Contour auto-starts PowerShell on Windows using the default configuration.

Copy link
Member

@Yaraslaut Yaraslaut left a comment

Choose a reason for hiding this comment

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

contour failed to spawn ssh sessions for me because i dont have .ssh/config file

src/vtpty/SshSession.cpp Outdated Show resolved Hide resolved
Yaraslaut

This comment was marked as resolved.

Signed-off-by: Christian Parpart <christian@parpart.family>
…itCode

Signed-off-by: Christian Parpart <christian@parpart.family>
Copy link
Member

@Yaraslaut Yaraslaut left a comment

Choose a reason for hiding this comment

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

Now it asks password for three times, but if i insert correct password second time it does not work
here is output log for two different runs

~/r/contour feature/ssh-client 20.2s ❱ ./build/src/contour/contour
QML debugging is enabled. Only use this in a safe environment.
Info: libpng warning: iCCP: known incorrect sRGB profile ((null):0, (null))
[2023-11-08 14:52:05.116606663.116606] [ssh] (contour) Resizing PTY to 80x24.
[2023-11-08 14:52:05.116649454.116649] [ssh] Starting SSH session to host: user@192.168.50.20
[2023-11-08 14:52:05.116654083.116654] [ssh] (contour) State transition from Initial to Started.
[2023-11-08 14:52:05.116656448.116656] [ssh] (contour) State transition from Started to Connect.
[2023-11-08 14:52:05.117152308.117152] [ssh] Connected to 192.168.50.20
[2023-11-08 14:52:05.117156336.117156] [ssh] (contour) State transition from Connect to Handshake.
[2023-11-08 14:52:05.255754371.255754] [ssh] (contour) State transition from Handshake to VerifyHostKey.
[2023-11-08 14:52:05.255812912.255812] [ssh] Host key verification succeeded (AAAAE2VjZHNhLXNoYTItbmlzdHAyNTYAAAAIbmlzdHAyNTYAAABBBCvNflTlLiqQTLfsiDJpdiZbqVov9zWXFfnw4EcEGr8WEeeH7UoIkwaQk8pwvs9LOXGDYAOpsDtMO/Aza3cx7oY=).
[2023-11-08 14:52:05.255818603.255818] [ssh] (contour) State transition from VerifyHostKey to AuthenticateAgent.
[error] Failed to connect to SSH agent. Bad use
[error] Failed to authenticate with SSH agent. No more identities available.
[2023-11-08 14:52:05.255828111.255828] [ssh] (contour) State transition from AuthenticateAgent to AuthenticatePasswordStart.
[2023-11-08 14:52:05.255830425.255830] [ssh] (contour) State transition from AuthenticatePasswordStart to AuthenticatePasswordWaitForInput.
[2023-11-08 14:52:05.268786526.268786] [ssh] (contour) Resizing PTY to 80x23.
[2023-11-08 14:52:05.420128299.420128] [ssh] (QSGRenderThread) Resizing PTY to 80x24.
[2023-11-08 14:52:05.469879871.469879] [ssh] (contour) Resizing PTY to 162x24.
[2023-11-08 14:52:05.470018193.470018] [ssh] (contour) Resizing PTY to 162x43.
[2023-11-08 14:52:05.471272903.471272] [ssh] (contour) Resizing PTY to 162x43.
[2023-11-08 14:52:05.471277902.471277] [ssh] (contour) Resizing PTY to 162x43.
[2023-11-08 14:52:05.913383187.913383] [ssh] (contour) Handling pre-authentication input: "s"
[2023-11-08 14:52:06.120066394.120066] [ssh] (contour) Handling pre-authentication input: "t"
[2023-11-08 14:52:06.297095622.297095] [ssh] (contour) Handling pre-authentication input: "a"
[2023-11-08 14:52:06.456843719.456843] [ssh] (contour) Handling pre-authentication input: "r"
[2023-11-08 14:52:06.903854537.903854] [ssh] (contour) Handling pre-authentication input: "f"
[2023-11-08 14:52:07.003769011.003768] [ssh] (contour) Handling pre-authentication input: "i"
[2023-11-08 14:52:07.138722175.138722] [ssh] (contour) Handling pre-authentication input: "v"
[2023-11-08 14:52:07.226831010.226830] [ssh] (contour) Handling pre-authentication input: "e"
[2023-11-08 14:52:07.382814777.382814] [ssh] (contour) Handling pre-authentication input: "\r"
[2023-11-08 14:52:07.382837070.382837] [ssh] (contour) State transition from AuthenticatePasswordWaitForInput to AuthenticatePassword.
[2023-11-08 14:52:07.763370245.763370] [ssh] Successfully authenticated with password.
[2023-11-08 14:52:07.763397417.763397] [ssh] (contour) State transition from AuthenticatePassword to OpenChannel.
[2023-11-08 14:52:09.521277450.521277] [ssh] (contour) State transition from OpenChannel to RequestAuthAgent.
[2023-11-08 14:52:09.521298640.521298] [ssh] (contour) State transition from RequestAuthAgent to RequestPty.
[2023-11-08 14:52:09.535460839.535460] [ssh] (contour) State transition from RequestPty to SetEnv.
[error] Failed to set SSH environment variable "COLORTERM". Request denied
[error] Failed to set SSH environment variable "TERMINAL_NAME". Request denied
[error] Failed to set SSH environment variable "TERMINAL_VERSION_STRING". Request denied
[error] Failed to set SSH environment variable "TERMINAL_VERSION_TRIPLE". Request denied
[2023-11-08 14:52:09.537095809.537095] [ssh] (contour) State transition from SetEnv to StartShell.
[2023-11-08 14:52:09.538545749.538545] [ssh] (contour) State transition from StartShell to Operational.
[2023-11-08 14:52:11.648588210.648588] [ssh] (Terminal.Loop) State transition from Operational to Closed.
Debug[qml]: Client process terminated. Closing the window. (file:///home/yaraslau/repo/contour/src/contour/ui/Terminal.qml:205, expression for onTerminated)
~/r/contour feature/ssh-client 6.7s ❱ ./build/src/contour/contour
QML debugging is enabled. Only use this in a safe environment.
Info: libpng warning: iCCP: known incorrect sRGB profile ((null):0, (null))
[2023-11-08 14:52:16.257187556.257187] [ssh] (contour) Resizing PTY to 80x24.
[2023-11-08 14:52:16.257235167.257235] [ssh] Starting SSH session to host: user@192.168.50.20
[2023-11-08 14:52:16.257240276.257240] [ssh] (contour) State transition from Initial to Started.
[2023-11-08 14:52:16.257242711.257242] [ssh] (contour) State transition from Started to Connect.
[2023-11-08 14:52:16.257757607.257757] [ssh] Connected to 192.168.50.20
[2023-11-08 14:52:16.257761916.257761] [ssh] (contour) State transition from Connect to Handshake.
[2023-11-08 14:52:16.409017837.409017] [ssh] (contour) State transition from Handshake to VerifyHostKey.
[2023-11-08 14:52:16.409078292.409078] [ssh] Host key verification succeeded (AAAAE2VjZHNhLXNoYTItbmlzdHAyNTYAAAAIbmlzdHAyNTYAAABBBCvNflTlLiqQTLfsiDJpdiZbqVov9zWXFfnw4EcEGr8WEeeH7UoIkwaQk8pwvs9LOXGDYAOpsDtMO/Aza3cx7oY=).
[2023-11-08 14:52:16.409085085.409085] [ssh] (contour) State transition from VerifyHostKey to AuthenticateAgent.
[error] Failed to connect to SSH agent. Bad use
[error] Failed to authenticate with SSH agent. No more identities available.
[2023-11-08 14:52:16.409096647.409096] [ssh] (contour) State transition from AuthenticateAgent to AuthenticatePasswordStart.
[2023-11-08 14:52:16.409099613.409099] [ssh] (contour) State transition from AuthenticatePasswordStart to AuthenticatePasswordWaitForInput.
[2023-11-08 14:52:16.422029935.422029] [ssh] (contour) Resizing PTY to 80x23.
[2023-11-08 14:52:16.497921300.497921] [ssh] (QSGRenderThread) Resizing PTY to 80x24.
[2023-11-08 14:52:16.545855757.545855] [ssh] (contour) Resizing PTY to 162x24.
[2023-11-08 14:52:16.545968671.545968] [ssh] (contour) Resizing PTY to 162x43.
[2023-11-08 14:52:16.547079417.547079] [ssh] (contour) Resizing PTY to 162x43.
[2023-11-08 14:52:16.547085208.547085] [ssh] (contour) Resizing PTY to 162x43.
[2023-11-08 14:52:17.405177073.405177] [ssh] (contour) Handling pre-authentication input: "a"
[2023-11-08 14:52:17.797939193.797939] [ssh] (contour) Handling pre-authentication input: "\r"
[2023-11-08 14:52:17.797957808.797957] [ssh] (contour) State transition from AuthenticatePasswordWaitForInput to AuthenticatePassword.
[error] Authentication failed. Authentication failed
[2023-11-08 14:52:20.657258732.657258] [ssh] (contour) State transition from AuthenticatePassword to AuthenticatePasswordStart.
[2023-11-08 14:52:20.657267468.657267] [ssh] (contour) State transition from AuthenticatePasswordStart to AuthenticatePasswordWaitForInput.
[2023-11-08 14:52:21.703121413.703121] [ssh] (contour) Handling pre-authentication input: "s"
[2023-11-08 14:52:22.084141599.084141] [ssh] (contour) Handling pre-authentication input: "t"
[2023-11-08 14:52:22.478187858.478187] [ssh] (contour) Handling pre-authentication input: "a"
[2023-11-08 14:52:22.773196283.773196] [ssh] (contour) Handling pre-authentication input: "r"
[2023-11-08 14:52:23.172443805.172443] [ssh] (contour) Handling pre-authentication input: "f"
[2023-11-08 14:52:23.316162514.316162] [ssh] (contour) Handling pre-authentication input: "i"
[2023-11-08 14:52:23.407145251.407145] [ssh] (contour) Handling pre-authentication input: "v"
[2023-11-08 14:52:23.517153830.517153] [ssh] (contour) Handling pre-authentication input: "e"
[2023-11-08 14:52:23.891107564.891107] [ssh] (contour) Handling pre-authentication input: "\r"
[2023-11-08 14:52:23.891129065.891129] [ssh] (contour) State transition from AuthenticatePasswordWaitForInput to AuthenticatePassword.
[error] Authentication failed. Authentication failed
[2023-11-08 14:52:26.750514333.750514] [ssh] (contour) State transition from AuthenticatePassword to AuthenticatePasswordStart.
[2023-11-08 14:52:26.750523881.750523] [ssh] (contour) State transition from AuthenticatePasswordStart to AuthenticatePasswordWaitForInput.

…lementation

Signed-off-by: Christian Parpart <christian@parpart.family>
@christianparpart
Copy link
Member Author

Now it asks password for three times, but if i insert correct password second time it does not work here is output log for two different runs

we weren't clearing the input buffer on retry. I did not notice, because I only tried success and login failure excess. thx for pointing it out. fixed.

Copy link
Member

@Yaraslaut Yaraslaut left a comment

Choose a reason for hiding this comment

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

Tested that things are working

@christianparpart christianparpart merged commit 2ff337e into master Nov 8, 2023
49 of 55 checks passed
@christianparpart christianparpart deleted the feature/ssh-client branch November 8, 2023 15:50
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
CI GitHub Actions & CI CMake documentation Improvements or additions to documentation frontend Contour Terminal Emulator (GUI frontend) VT: Backend Virtual Terminal Backend (libterminal API)
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Bypass conpty when using ssh.
3 participants