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

Unable to connect GCP GKE cluster using client-go with GCP service account key #668

Closed
mickymics opened this issue Sep 2, 2019 · 7 comments
Labels
lifecycle/rotten Denotes an issue or PR that has aged beyond stale and will be auto-closed.

Comments

@mickymics
Copy link

I want to connect GCP GKE cluster without setting GOOGLE_APPLICATION_CREDENTIALS, gcloud and kubeconfig.

When I use the basic authentication using username and password, I am able to connect. But when I am using GCP IAMservice account key, it always reporting error: cannot construct google default token source: google: could not find default credentials.

I am creating the GKE cluster on a fly using GKE APIs but GKE do not have support on cluster level and that's why I am using client-go sdk. But all the docs, github posts and blogs are saying to set ADC credentials. But without setting that and even without gcloud and kubectl how can I create kubernetes client with GCP IAM service account credential.

@mickymics mickymics changed the title Unable to connect GCP GKE cluster using client-go Unable to connect GCP GKE cluster using client-go with GCP service account key Sep 2, 2019
@mickymics
Copy link
Author

@cjcullen can you provide me some idea of how to achieve the same

@ahmetb
Copy link
Member

ahmetb commented Sep 3, 2019

client-go auth/gcp plugin will just use GOOGLE_APPLICATION_CREDENTIALS.

If you want to authorize differently you should:

  1. https://godoc.org/golang.org/x/oauth2/google package to get a oauth2.TokenSource, for example:
  1. Then use the oauth2.TokenSource to create an http.Client, via oauth2.NewClient https://godoc.org/golang.org/x/oauth2/google#DefaultTokenSource

  2. Configure client-go and set its HTTP client with this http.Client, without using gcp auth plugin because you're now authenticating manually with this http.Client.

@csandanov
Copy link

@ahmetb as I understand you suggest something like:

restClient, _ := rest.RESTClientFor(restConfig)
restClient.Client = oauth2HTTPClient
clientSet := kubernetes.New(restClient)

the problem with this approach is that you have one config for all api groups, unlike when you use kubernetes.NewForConfig(restConfig) where each api group has its own http client with specific ContentConfig.GroupVersion which is required to have it working. So, in other words, you'll have to create a clientSet each time you want to work with another api group and that's completely unusable. I honestly don't understand why this New even exists.

@fejta-bot
Copy link

Issues go stale after 90d of inactivity.
Mark the issue as fresh with /remove-lifecycle stale.
Stale issues rot after an additional 30d of inactivity and eventually close.

If this issue is safe to close now please do so with /close.

Send feedback to sig-testing, kubernetes/test-infra and/or fejta.
/lifecycle stale

@k8s-ci-robot k8s-ci-robot added the lifecycle/stale Denotes an issue or PR has remained open with no activity and has become stale. label Dec 11, 2019
@fejta-bot
Copy link

Stale issues rot after 30d of inactivity.
Mark the issue as fresh with /remove-lifecycle rotten.
Rotten issues close after an additional 30d of inactivity.

If this issue is safe to close now please do so with /close.

Send feedback to sig-testing, kubernetes/test-infra and/or fejta.
/lifecycle rotten

@k8s-ci-robot k8s-ci-robot added lifecycle/rotten Denotes an issue or PR that has aged beyond stale and will be auto-closed. and removed lifecycle/stale Denotes an issue or PR has remained open with no activity and has become stale. labels Jan 10, 2020
@fejta-bot
Copy link

Rotten issues close after 30d of inactivity.
Reopen the issue with /reopen.
Mark the issue as fresh with /remove-lifecycle rotten.

Send feedback to sig-testing, kubernetes/test-infra and/or fejta.
/close

@k8s-ci-robot
Copy link
Contributor

@fejta-bot: Closing this issue.

In response to this:

Rotten issues close after 30d of inactivity.
Reopen the issue with /reopen.
Mark the issue as fresh with /remove-lifecycle rotten.

Send feedback to sig-testing, kubernetes/test-infra and/or fejta.
/close

Instructions for interacting with me using PR comments are available here. If you have questions or suggestions related to my behavior, please file an issue against the kubernetes/test-infra repository.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
lifecycle/rotten Denotes an issue or PR that has aged beyond stale and will be auto-closed.
Projects
None yet
Development

No branches or pull requests

5 participants