Skip to content

feat(cli) Pass token via cli - #7230

Merged
bacongobbler merged 2 commits into
helm:masterfrom
waveywaves:update/token
Mar 2, 2020
Merged

bacongobbler merged 2 commits into
helm:masterfrom
waveywaves:update/token

Conversation

@waveywaves

@waveywaves waveywaves commented Dec 14, 2019 •

Copy link
Copy Markdown
Contributor

Signed-off-by: Vibhav Bobade [email protected]

  • Add the ability to pass the token via a cli

fixes #7292

@helm-bot helm-bot added the size/XS Denotes a PR that changes 0-9 lines, ignoring generated files. label Dec 14, 2019
@marckhouzam

Copy link
Copy Markdown
Member

This is not my area, but I was trying to figure out if this new global flag may need to be handled in the completion logic.

@waveywaves Could you describe in which use case a user would specify this flag? Am I right to assume it is to authenticate with kube cluster?

@sbose78

sbose78 commented Dec 15, 2019 •

Copy link
Copy Markdown
Contributor

I would find this useful. Thank you!

How's the kube context / API Server specification going to work with this? I'm guessing that's picked up from the default kubeconfig context.

In addition, is it possible to support something similar to the following for helm commands as well:

oc get pods --token=rQ3BjjjjI --server=https://api.gamore.devcluster.openshift.com:6443

@waveywaves

Copy link
Copy Markdown
Contributor Author

@marckhouzam Yes it will be used to authenticate as well as allow helm to be used as middleware for executing commands via users tokens, without having to do multiple kubecontext changes (which is not possible in multi-tenant environments).

@marckhouzam

Copy link
Copy Markdown
Member

Thanks @waveywaves. So, I'm thinking about two aspects since this is a global flag:

  1. completion
  2. plugins

For completion since this flag will affect how to connect with the cluster, it needs to be added to the completion override flag list here:

__helm_override_flag_list=(--kubeconfig --kube-context --namespace -n)

For example, if you type

helm --token 12345 status <TAB>

the completion script will run a helm list to figure out which releases can be listed for helm status. However, to connect to the cluster helm list also needs the token. By adding it to the list mentioned above, all this will be done automatically.

About plugins, should the token be made available for plugins to use? All the other global flags have a corresponding environment variable which allows to pass the value of the flag to the plugin. See

"HELM_NAMESPACE": s.Namespace(),

namespace: os.Getenv("HELM_NAMESPACE"),

kvargs := []string{"--kube-context", "--namespace", "-n", "--kubeconfig", "--registry-config", "--repository-cache", "--repository-config"}

@sbose78

sbose78 commented Dec 16, 2019

Copy link
Copy Markdown
Contributor

Tested this out in a pod in an OpenShift cluster. Looks good.

Verification:
On doing a helm install ... --token=xyz --namespace=xyz , I could successfully create objects which the xyz token had privileges to, but the default service account didn't.

Comment thread pkg/kube/config.go Resolved
@helm-bot helm-bot added size/S Denotes a PR that changes 10-29 lines, ignoring generated files. and removed size/XS Denotes a PR that changes 0-9 lines, ignoring generated files. labels Dec 16, 2019
@waveywaves

Copy link
Copy Markdown
Contributor Author

@sbose78 Thank you for that, it does make more sense to have a --server option alongside token as well. Just added that to the PR as well.

@waveywaves
waveywaves force-pushed the update/token branch 3 times, most recently from b8920ec to 9669602 Compare December 16, 2019 08:14
@waveywaves

Copy link
Copy Markdown
Contributor Author

@marckhouzam I have added correspoding Env Vars for the token and server flags, so they can be consumed by the plugins as well. Let me know if I need to make any further changes

@waveywaves waveywaves changed the title Pass token via cli feat(cli) Pass token via cli Dec 16, 2019
Comment thread pkg/cli/environment.go Resolved
@marckhouzam

Copy link
Copy Markdown
Member

Nice patch.
No more comments from me.
I'll let another maintainer approve though. I'm still too green 😄

Comment thread pkg/cli/environment.go Resolved
Comment thread pkg/cli/environment.go Resolved
@waveywaves

Copy link
Copy Markdown
Contributor Author

@marckhouzam @bacongobbler I have made the necessary changes.

@bacongobbler

Copy link
Copy Markdown
Member

Hi @waveywaves, it’s the holiday season right now. Probably won’t get to reviewing this until the second week of January. Thanks for your patience.

@waveywaves

Copy link
Copy Markdown
Contributor Author

@bacongobbler No worries. Have a good one :)

@bacongobbler

Copy link
Copy Markdown
Member

closes #5159

@waveywaves

waveywaves commented Jan 7, 2020 •

Copy link
Copy Markdown
Contributor Author

@bacongobbler can you check this out ? Do I need to make any other changes ?

Comment thread cmd/helm/root.go Resolved
Comment thread cmd/helm/root.go Resolved
Comment thread pkg/cli/environment.go Resolved
@marckhouzam

Copy link
Copy Markdown
Member

@waveywaves you should be able to run make test-acceptance to run some regression tests which include completion tests. Or to focus on completion make test-acceptance-completion

@marckhouzam

Copy link
Copy Markdown
Member

Hi @waveywaves . Good news. With the merging of #7323 , you no longer need to make modifications for completion in this PR. Everything should be handled automatically for completion. Therefore, you just need to remove your completion changes and rebase on master.

Thanks.

@waveywaves

Copy link
Copy Markdown
Contributor Author

@marckhouzam That's good news. I will do the same.

@waveywaves
waveywaves force-pushed the update/token branch 4 times, most recently from 89e85da to 0c14df0 Compare February 12, 2020 22:36
@bacongobbler

bacongobbler commented Feb 12, 2020 •

Copy link
Copy Markdown
Member

This is looking great!

I want to make sure that passing an empty string (&"" instead of nil) for clientConfig.BearerToken and clientConfig.ApiServer won't accidentally pass along some extra headers, tricking certain Kubernetes api server implementations.

Marking this for 3.2 for review

@bacongobbler bacongobbler added this to the 3.2.0 milestone Feb 12, 2020
@01mcgrady01

Copy link
Copy Markdown

I tried
helm install happy-panda stable/mariadb --kube-token xxx --kube-apiserver xxx
but got error
unknown flag: --kube-apiserver, --kube-token
Is that right way to specify k8s cluster token and api server address?

@bacongobbler

Copy link
Copy Markdown
Member

yes. Are you sure you're using a version of helm built using this PR?

@01mcgrady01

01mcgrady01 commented Feb 19, 2020 •

Copy link
Copy Markdown

yes. Are you sure you're using a version of helm built using this PR?

I build helm from source code of https://github.com/waveywaves/helm/tree/update/token
I checked code and found I used wrong branch, I will build again, thanks

Comment thread pkg/cli/environment.go Resolved
Comment thread pkg/cli/environment.go
s.configOnce.Do(func() {
s.config = kube.GetConfig(s.KubeConfig, s.KubeContext, s.namespace)
clientConfig := kube.GetConfig(s.KubeConfig, s.KubeContext, s.namespace)
if len(s.KubeToken) > 0 {

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

generally speaking, if s.KubeToken != "" is the more idiomatic approach. This looks good though, and we can address it in a follow-up PR.

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

@bacongobbler
bacongobbler merged commit 3dbc4dd into helm:master Mar 2, 2020
@bacongobbler

Copy link
Copy Markdown
Member

thanks!

@kkorada

kkorada commented Jun 29, 2020 •

Copy link
Copy Markdown

I am unable to use server and token with helm cli
e.g.
helm install happy-panda stable/mariadb --kube-token xxx --kube-apiserver xxx

it is giving error Unable to connect to the server: x509: certificate signed by unknown authority

Same data if set in kubeconfig file, it is working. Am I missing some parameter here ? Please help

@chancejin

chancejin commented Jul 16, 2020 •

Copy link
Copy Markdown

Same issue with kkorada.

I tried to use helm command in my local.

  1. helm list --kubeconfig {kubeconfigFilePath} --kube-context {contextName}
    -> It works fine.

  2. helm list --kube-apiserver https://{API server IP}:{API server Port} --kube-token {Kubetoken}
    -> It shows error like below

Error: Kubernetes cluster unreachable: Get https://10.251.205.11:6443/version?timeout=32s: x509: certificate signed by unknown authority"

Is there necessary data do I have to add to use "--kube-apiserver" without "--kubeconfig"?

@bacongobbler

Copy link
Copy Markdown
Member

Please open a new ticket.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

size/S Denotes a PR that changes 10-29 lines, ignoring generated files.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Support passing token and api server to the cli

8 participants