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

Added support for additional OpenSSH compatibility flags. #46879

Merged
merged 1 commit into from
Oct 26, 2024

Conversation

russjones
Copy link
Contributor

@russjones russjones commented Sep 23, 2024

Added support for OpenSSH compatibility flags for interactivity (-t and -T) and version information (-V). This is for customers that alias ssh to tsh ssh.

changelog: Added support for -t, -T, and -V flags to tsh for OpenSSH compatibility.

@github-actions github-actions bot requested review from klizhentas and zmb3 September 23, 2024 21:29
@github-actions github-actions bot added size/md tsh tsh - Teleport's command line tool for logging into nodes running Teleport. labels Sep 23, 2024
tool/tsh/common/tsh.go Outdated Show resolved Hide resolved
tool/tsh/common/tsh.go Outdated Show resolved Hide resolved
tool/tsh/common/tsh.go Outdated Show resolved Hide resolved
@russjones russjones force-pushed the rjones/openssh-interactive-flags branch from 696bf61 to 6223db1 Compare September 27, 2024 22:08
@gravitational gravitational deleted a comment from github-actions bot Sep 27, 2024
@gravitational gravitational deleted a comment from github-actions bot Sep 27, 2024
@russjones russjones requested a review from zmb3 September 30, 2024 21:33
tool/tsh/common/tsh.go Outdated Show resolved Hide resolved
@rosstimothy rosstimothy requested a review from espadolini October 1, 2024 19:01
@russjones russjones removed the request for review from klizhentas October 1, 2024 20:03
tool/tsh/common/tsh.go Outdated Show resolved Hide resolved
@russjones
Copy link
Contributor Author

/excludeflake *

@russjones russjones force-pushed the rjones/openssh-interactive-flags branch 2 times, most recently from 77fb730 to 438c0f5 Compare October 23, 2024 18:50
@russjones russjones requested review from zmb3 and espadolini October 23, 2024 18:50
tool/tsh/common/tsh.go Show resolved Hide resolved
}

// If "tsh ssh" is invoked the user must specify some host to connect to.
if cf.UserHost == "" {
Copy link
Collaborator

Choose a reason for hiding this comment

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

I don't follow why we had to make the argument optional in kingpin and validate it here. Can we leave a comment explaining why this was necessary?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

It's to support tsh ssh -V which can run without any additional arguments. I'll update the comment to explain why I had to remove Required() from that Arg.

Copy link
Contributor

Choose a reason for hiding this comment

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

Does this affect the usage docs badly? I reckon that everyone would likely figure out that sshing into an unspecified destination is never going to work, but still...

Copy link
Contributor Author

@russjones russjones Oct 24, 2024

Choose a reason for hiding this comment

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

It does.

Adding Required() removes the square brackets from --help output.

Not ideal, but I can update the help text to indicate this is a required argument.

Output of tsh ssh --help before:

$ tsh ssh --help
usage: tsh ssh [<flags>] <[user@]host> [<command>...]

Run shell or execute a command on a remote SSH node.

Flags:
[...]

Args:
  <[user@]host>  Remote hostname and the login to use
  [<command>]    Command to execute on a remote host

Aliases:

Output of tsh ssh --help after this PR:

$ tsh ssh --help
usage: tsh ssh [<flags>] [<[user@]host>] [<command>...]

Run shell or execute a command on a remote SSH node.

Flags:
[...]

Args:
  [<[user@]host>]  Remote hostname and the login to use, this argument is required
  [<command>]      Command to execute on a remote host

Aliases:

What do you guys think?

}

// If "tsh ssh" is invoked the user must specify some host to connect to.
if cf.UserHost == "" {
Copy link
Contributor

Choose a reason for hiding this comment

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

Does this affect the usage docs badly? I reckon that everyone would likely figure out that sshing into an unspecified destination is never going to work, but still...

@russjones russjones force-pushed the rjones/openssh-interactive-flags branch 7 times, most recently from dcabbb5 to f75370e Compare October 25, 2024 16:51
Added support for OpenSSH compatibility flags for interactivity (-t and
-T) and version information (-V). This is for customers that alias "ssh"
to "tsh ssh".
@russjones russjones force-pushed the rjones/openssh-interactive-flags branch from f75370e to 50ea203 Compare October 25, 2024 16:52
@zmb3
Copy link
Collaborator

zmb3 commented Oct 25, 2024

/excludeflake *

@russjones russjones added this pull request to the merge queue Oct 26, 2024
Merged via the queue into master with commit 8cb7ee9 Oct 26, 2024
38 checks passed
@russjones russjones deleted the rjones/openssh-interactive-flags branch October 26, 2024 00:58
Comment on lines +3731 to +3734
// If "tsh ssh" is invoked with the "-t" or "-T" flag, manually validate
// "-t" and "-T" flags for "tsh ssh" due to the lack of inverse short flags
// in kingpin.
if cf.Interactive && cf.NonInteractive {
Copy link
Contributor

Choose a reason for hiding this comment

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

We already use a fork of kingpin, would it be worth investigating adding support in kingpin instead of all of the various workarounds that we've had to introduce in this PR to overcome its shortcomings?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

@rosstimothy That's what I originally did and even had a working implementation.

I don't remember all the details, but during testing I found that the way we hook kingpin for terminate (which I would have to use) is broken and the fact that tsh does not panic often is incidental. Fixing this would have been a fairly big undertaking because we hook termination from tsh.

This is what I have in my notes:

https://github.com/gravitational/kingpin/blob/master/app.go#L617

None of those `a.terminate(1)` will actually exit due to how we hook the terminate function
in Teleport, which means things will not be set downstream and panic when it flows through
the rest of kingpin code.

This FatalIfError is called all over the place in kingpin.

https://github.com/gravitational/kingpin/blob/master/app.go#L642C23-L642C35

russjones added a commit that referenced this pull request Oct 28, 2024
Added support for OpenSSH compatibility flags for interactivity (-t and
-T) and version information (-V). This is for customers that alias "ssh"
to "tsh ssh".
russjones added a commit that referenced this pull request Oct 28, 2024
Added support for OpenSSH compatibility flags for interactivity (-t and
-T) and version information (-V). This is for customers that alias "ssh"
to "tsh ssh".
russjones added a commit that referenced this pull request Oct 28, 2024
Added support for OpenSSH compatibility flags for interactivity (-t and
-T) and version information (-V). This is for customers that alias "ssh"
to "tsh ssh".
github-merge-queue bot pushed a commit that referenced this pull request Oct 29, 2024
Added support for OpenSSH compatibility flags for interactivity (-t and
-T) and version information (-V). This is for customers that alias "ssh"
to "tsh ssh".
github-merge-queue bot pushed a commit that referenced this pull request Oct 29, 2024
Added support for OpenSSH compatibility flags for interactivity (-t and
-T) and version information (-V). This is for customers that alias "ssh"
to "tsh ssh".
github-merge-queue bot pushed a commit that referenced this pull request Oct 29, 2024
Added support for OpenSSH compatibility flags for interactivity (-t and
-T) and version information (-V). This is for customers that alias "ssh"
to "tsh ssh".
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
size/md tsh tsh - Teleport's command line tool for logging into nodes running Teleport.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants