tsh: Implement puttyconfig command to add saved PuTTY sessions to Windows registry#19316
tsh: Implement puttyconfig command to add saved PuTTY sessions to Windows registry#19316
Conversation
077da09 to
c441e91
Compare
1a5ebcc to
5a65ba9
Compare
|
@zmb3 @timothyb89 This should be ready for review now. Please feel free to add other reviewers or suggest improvements :) |
|
Thanks for the initial review @zmb3. I would like to try and find a way to test the registry methods without requiring the code to run on a Windows box or actually writing to the registry. My best guess is that I could move all the related code to a Any suggestions gratefully received. |
zmb3
left a comment
There was a problem hiding this comment.
A few stylistic comments, nothing major.
|
Note: this currently contains @rosstimothy's commit 59c5570 which fixes the broken Windows builds. I'll rebase to remove that when #28357 is merged. Depends on #28357 Edit: Now rebased |
| return outputHostList | ||
| } | ||
|
|
||
| var hostnameRegexp = regexp.MustCompile("^(([a-zA-Z0-9]|[a-zA-Z0-9][a-zA-Z0-9-]*[a-zA-Z0-9]).)*([A-Za-z0-9]|[A-Za-z0-9][A-Za-z0-9-]*[A-Za-z0-9])$") |
There was a problem hiding this comment.
I was just curious, but the answer was quite educating: https://chat.openai.com/share/0898d082-ba3a-489e-a71c-83e84cbd3657
There was a problem hiding this comment.
This was actually really interesting; I'd never thought of using ChatGPT to explain or validate regex. It also gave me ideas for a few more test cases.
Unfortunately...
panic: regexp: Compile(`^(?:(?:(?:[a-zA-Z0-9](?:[a-zA-Z0-9\-]{0,61}[a-zA-Z0-9])?)\.){1,126}(?:[a-zA-Z0-9](?:[a-zA-Z0-9\-]{0,61}[a-zA-Z0-9])?))$`): error parsing regexp: invalid repeat count: `{1,126}`
Maybe being naive is a good thing?!
Also moved registry/hostname functions into external packages
Co-authored-by: Zac Bergquist <zac.bergquist@goteleport.com>
…dows registry (#19316) * tsh: Implement puttyconfig command to add saved PuTTY sessions to Windows registry * Addressed comments from code review * Add support for leaf clusters * Refactoring from code review Also moved registry/hostname functions into external packages * Address more feedback from code review * Rebase following tsh/common changes * Fix up putty_config_windows * Reorder command * Remove surplus comment * Use a separate list instead of overloading the 'extra' key * Address Tim's code review comments * Address some of Zac's comments * Refactor formatLocalCommandString to use text/template * Refactor non-Windows logic into puttyhosts * Fix subcommand name * Fix test structure * Add some more hostnames test cases * Apply suggestions from code review Co-authored-by: Zac Bergquist <zac.bergquist@goteleport.com> * Fix up --------- Co-authored-by: Zac Bergquist <zac.bergquist@goteleport.com>
This is an implementation of support for a
tsh puttyconfig [user@]hostcommand which will automatically add saved PuTTY sessions to the local Windows registry to make it easy to connect to a named Teleport host.The added session runs
tsh proxy sshlocally to get an authenticated tunnel to the proxy which means PuTTY can neatlly handle auto-relogin and TLS routing etc. The session is configured to authenticate using the ephemeral.ppkfile which has been automatically generated and stored in the user's.tshdirectory when runningtsh loginon Windows hosts since v10.0.1.Every host also has its public host key configured in the registry based on the proxy's hostname, using wildcards when an FQDN is provided or individual hostnames otherwise.
I've tested this on three different clusters (one self-hosted using separate ports, one self-hosted using TLS routing, one Teleport cloud) with a combination of various different users and hostnames and found it to work well in all cases.
tsh proxy sshis doing most of the heavy lifting - this is PR mostly just registry wrangling.Benefits:
HKEY_CURRENT_USER, so no admin access should be neededfor HOST in host1 host2 host; do tsh puttyconfig user@$HOST; done)Caveats:
Leaf clusters aren't currently supportedLeaf clusters are now supported.I don't think they're prohibitively difficult to add, but this PR has taken far too long to write alreadytsh puttyconfigcommand will overwrite any changes to any of the ~10 values the command touchestsh config --putty [user@]host, but unfortunately our fork of Kingpin is too old to allow default arguments/commands, this seems like the next best wayThere are no tests at the moment, as I'm really not sure where to start...There's no tests for the Windows registry stuff, but the PuTTY hostname/CA logic is tested.Login and setup:

Session list:

Connected session:

Active session in Teleport:

Registry values added:

Host key settings:

All comments and feedback welcome. I'm curious about what/how I should test and any better ways to handle the registry abstractions.