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

Improve tsh profile support. #3089

Open
benarent opened this issue Oct 18, 2019 · 8 comments
Open

Improve tsh profile support. #3089

benarent opened this issue Oct 18, 2019 · 8 comments
Labels
c-dmr Internal Customer Reference feature-request Used for new features in Teleport, improvements to current should be #enhancements tsh tsh - Teleport's command line tool for logging into nodes running Teleport. ux

Comments

@benarent
Copy link
Contributor

What happened:
If a customer has multiple Teleport proxies, customers use ➜ $ tsh login --proxy=work.example.com to login.

If you are working with multiple Teleport proxies you need to switch each time with, and tsh sets the profile to the last one it logged in.

Examples of apps with different profile systems.

What you expected to happen

  • tsh user should know what their default profile is.
  • tsh can set a default profile.
  • tsh users easily list all known profiles, and output current certificate status ( e.g. time left before reauthorisation )
  • tsh users can login to an account using a profile alais vs full URL
  • tsh users can remove accounts.
@benarent benarent added feature-request Used for new features in Teleport, improvements to current should be #enhancements tsh tsh - Teleport's command line tool for logging into nodes running Teleport. labels Oct 18, 2019
@russjones russjones added this to the 5.1 "San Diego" milestone Jun 24, 2020
@klizhentas
Copy link
Contributor

klizhentas commented Nov 3, 2020

I think user profile should be more like ini profile that never gets overwritten and our default ~/.tsh/profile.yaml should be treated like internal state database file.

So devs can write things like this:

# cluster name
[staging]
k8s-cluster=
user=alice

[prod]
...

I was also thinking about using elisp as prfofile engine:

(setq cluster 'staging)

(defun select-cluster ()
  (mapc (lambda (K) 
	      (let* ((key (car K)) (fun (cdr K)))
           (define-key cluster-map (parse-cluster key) fun)))
	    '(("<right>" . cluster-next-match)
	      ("<left>"  . cluster-prev-match)
	      ("<up>"    . ignore             )
	      ("<down>"  . ignore             ))))
(add-hook 'select-cluster 'select-cluster-hook-local-keys)

...

Just kidding about lisp one :)

@webvictim
Copy link
Contributor

Would also be nice to let devs add port forwarding, agent forwarding etc to their profile files:

[staginghost21839]
login=staginguser
agent_forwarding=yes
port_forwarding=54321:localhost:12345,3434:localhost:3434

Then tsh ssh staginghost21839 would automatically do the same as tsh ssh -A -L 54321:localhost:12345,3434:localhost:3434 -l staginguser staginghost21839

@webvictim webvictim removed their assignment Nov 14, 2020
@russjones russjones added the ux label Nov 20, 2020
@wreed4
Copy link
Contributor

wreed4 commented Feb 23, 2021

For what it's worth I found a work around here for easily switching between two teleport instances:

alias t_one="echo teleport.one.url.without.port.io > ~/.tsh/current-profile"
alias t_two="echo teleport.two.url.without.port.io > ~/.tsh/current-profile"

Obviously replace the url with the real one.

@webvictim
Copy link
Contributor

We merged this recently: #5395 - it basically allows you to 'pin' a terminal to a given cluster by running eval $(tsh env) after logging in.

@et304383
Copy link

et304383 commented Feb 3, 2022

For what it's worth I found a work around here for easily switching between two teleport instances:

alias t_one="echo teleport.one.url.without.port.io > ~/.tsh/current-profile"
alias t_two="echo teleport.two.url.without.port.io > ~/.tsh/current-profile"

Obviously replace the url with the real one.

I can't believe this is the way to deal with multiple profiles. At th very least, tsh login should factor in that you're already logged in and just switch the current profile over.

@alwaysastudent
Copy link

The easiest way to solve this is to expose an environment variable that can pick up the current profile. Then we can toggle that env variable on-demand to the profile we want.

@zmb3
Copy link
Collaborator

zmb3 commented Oct 18, 2022

See also #2972

@nivasomu nivasomu added the c-dmr Internal Customer Reference label Nov 13, 2024
@ravicious
Copy link
Member

ravicious commented Nov 14, 2024

I don't know what the state of tsh was in 2019, but at this point the issue likely represents different problems for different people.

  • tsh user should know what their default profile is.
  • tsh can set a default profile.

tsh has no notion of a default profile. It works more like kubectl where there's a current profile that, in theory, can be changed globally, but tsh doesn't expose an easy way of changing it yet.

  • tsh users easily list all known profiles, and output current certificate status ( e.g. time left before reauthorisation )

tsh status does that now.

  • tsh users can login to an account using a profile alias vs full URL

I'm not sure what an alias for a profile would be. We could probably let users set custom profile aliases through ~/.tsh/config/config.yaml, which today is used for setting command aliases.

  • tsh users can remove accounts.

This is in theory supported by tsh logout --proxy example.com --user alice, but it's a bit weird because it behaves differently than tsh logout. tsh logout just wipes everything so that if you execute tsh status afterwards, you see nothing. Providing the flags for the proxy and the user causes tsh to overwrite the cert but keep the profile, which means that tsh status still shows it.

It also forces you to provide both the proxy and the user flags. The user flag is in theory unnecessary, as tsh doesn't support multiple users per proxy.


The way I understand the issue as of today is that tsh lacks subcommands for switching the current profile and removing a specific profile.

Another issue that's present in the current codebase is that there's a bunch of cases where under specific circumstances a tsh call might override the current profile without the user knowing that. IIRC, lib/client.RetryWithRelogin does that by default. So if someone is switched to a different profile with eval $(tsh env), that function is going to change the current profile. This also affects #25806.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
c-dmr Internal Customer Reference feature-request Used for new features in Teleport, improvements to current should be #enhancements tsh tsh - Teleport's command line tool for logging into nodes running Teleport. ux
Projects
None yet
Development

No branches or pull requests

10 participants