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

Add Escape Sequences to Shell Sessions #96

Open
wants to merge 3 commits into
base: mainline
Choose a base branch
from

Conversation

neilramsay
Copy link

Issue

Description of changes:
Add a SSH-like escape sequence to shell sessions.

As a start, the only functionality is terminating the session.
This allows an operator to terminate their session if the remote target becomes unresponsive.

Warning

Please note that session termination does not current work for AWS SSO / Identity Center authentication credentials.
This is due to a bug in session-manager-plugin, which interferes with refreshing SSO tokens.
(I'll raise a separate PR for that issue).


By submitting this pull request, I confirm that you can use, modify, copy, and redistribute this contribution, under the terms of your choice.

Add a struct for tracking the state of a possible
escape sequence.

We're using the same escape sequence as SSH, which is a newline
followed by tilde (~). See https://linux.die.net/man/1/ssh.

To do this we need to track keypresses over multiple iterations of the
Unix and Windows handleKeyboardInput function loops.
In particular we need to half trigger on newline, and then fully
trigger on tilde (~).
Implement a function to process key presses
looking for the escape sequence, and storing the
state in the Shell Session Escape Sequence tracking struct.

We do not want to send the tilde (~), or the command to the target.
To do this we need to indicate to the Unix and Windows
handleKeyboardInput functions whether to send the keypress to the
target of this session, or skip the loop iteration.

As a start, the following commands have been implemented:
- ~? help
- ~~ send ~ to the connected session
- ~- disable escape sequences for the rest of this session
- ~. disconnect and terminate the session
Add the handleEscapeSequence function to both the
Unix and Windows handleKeyboardInput functions.
@neilramsay
Copy link
Author

Some extra details:

  • I've tested this on both Ubuntu Linux (WSL2) and Windows 11 (Windows Sandbox) connecting to a Amazon Linux EC2 Instance.
  • I haven't written tests, and would welcome assistance if tests are required.

@neilramsay neilramsay marked this pull request as ready for review July 5, 2024 01:59
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

1 participant