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

Standalone Terminal / Terminal Locking For K8s on Different Teleport Clusters #7202

Closed
deusxanima opened this issue Jun 7, 2021 · 2 comments · Fixed by #7840
Closed

Standalone Terminal / Terminal Locking For K8s on Different Teleport Clusters #7202

deusxanima opened this issue Jun 7, 2021 · 2 comments · Fixed by #7840
Assignees
Labels
c-fw Internal Customer Reference c-q7j Internal Customer Reference feature-request Used for new features in Teleport, improvements to current should be #enhancements kubernetes-access tsh tsh - Teleport's command line tool for logging into nodes running Teleport.

Comments

@deusxanima
Copy link
Contributor

What

Ability to have each terminal tab/window be treated as a standalone environment from a kubernetes context perspective. Some customers require the ability to work in multiple, separate teleport clusters, each with their own kubernetes cluster, which is currently not possible as each new tsh login overrides the previous kube context even if eval $(tsh env) is used.

Why

Customer ask. Having the ability to treat each terminal tab/window as a standalone environment for kube contexts would also help prevent accidental context switching as devs/users could pin kube contexts to a single terminal tab/window without having to log in/out between contexts each time they switched clusters.

Workaround

n/a

@deusxanima deusxanima added feature-request Used for new features in Teleport, improvements to current should be #enhancements kubernetes-access tsh tsh - Teleport's command line tool for logging into nodes running Teleport. c-q7j Internal Customer Reference c-fw Internal Customer Reference labels Jun 7, 2021
@awly
Copy link
Contributor

awly commented Jun 8, 2021

One way to handle this with tsh env and without additional plumbing by users:

  • change tsh kube login to write a standalone kubeconfig file under ~/.tsh/keys/${PROXY}/${USER}-kube/${TELE_CLUSTER}/${KUBE_CLUSTER}-kubeconfig (right next to the k8s cert)
    • this is in addition to modifying ~/.kube/config
    • existing $KUBECONFIG should be handled carefully - if it points at a file under ~/.tsh/keys/..., we shouldn't treat it as the top-level ~/.kube/config
  • tsh env should output export KUBECONFIG=~/.tsh/... (same path as above)
  • that way, KUBECONFIG is fronzen per-terminal and points to a cluster-specific file

Workaround until we do that:

$ cat tsh_kube_login.sh
#!/bin/bash
set -euo pipefail
export KUBECONFIG=~/.kube/teleport-${1}
tsh kube login ${1} 1>&2
echo export KUBECONFIG=$KUBECONFIG

$ eval $(./tsh_kube_login.sh prod)

$ kubectl ... # runs on the prod cluster

# in another terminal
$ eval $(./tsh_kube_login.sh staging)

$ kubectl ... # runs on the staging cluster

@Joerger
Copy link
Contributor

Joerger commented Aug 6, 2021

  • existing $KUBECONFIG should be handled carefully - if it points at a file under ~/.tsh/keys/..., we shouldn't treat it as the top-level ~/.kube/config

What should be treated as the top-level ~/.kube/config in this case? It seems risky to default to ~/.kube/config, since the user would expect that the config set under $KUBECONFIG would be the only one touched.

I see two other options:

  1. skip procedures that are meant for top-level kubeconfigs, such as adding all kube clusters to the kubeconfig and changing contexts.
    - For example, if someone runs tsh kube login staging while $KUBECONFIG=~/.tsh/.../prod-kubeconfig, It would fail since there is no top-level kubeconfig to edit.
    • They would need to reset their $KUBECONFIG so that a non-profile kubeconfig can be used.
  2. allow users to set $KUBECONFIG as a list. the first one will be the top-level kubeconfig, and the second will be the profile specific kubeconfig.
    - tsh env will instead print export KUBECONFIG=$(KUBECONFIG),~/.tsh/....
    • Note that if $KUBECONFIG is unset, it will default to ~/.kube/config.

Edit: I went with the first option which should be much more simple to use and keep track of.

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

Successfully merging a pull request may close this issue.

3 participants