java: GCP authentication does not support refreshing tokens
This relates to #143.
GCPAuthenticator does not implement the refresh() method. How can the client be used without manually refreshing the access token if it is expired?
for reference, initializing the client (i.e. running the example) with an expired token will result in:
Caused by: java.lang.IllegalStateException: Unimplemented at io.kubernetes.client.util.authenticators.GCPAuthenticator.refresh(GCPAuthenticator.java:49) at io.kubernetes.client.util.KubeConfig.getAccessToken(KubeConfig.java:188) at io.kubernetes.client.util.credentials.KubeconfigAuthentication.<init>(KubeconfigAuthentication.java:33) at io.kubernetes.client.util.ClientBuilder.kubeconfig(ClientBuilder.java:165) at io.kubernetes.client.util.ClientBuilder.standard(ClientBuilder.java:80) at io.kubernetes.client.util.Config.defaultClient(Config.java:104) at serivces.KubernetesService.<clinit>(KubernetesService.groovy:23) ... 2 more
About this issue
- Original URL
- State: open
- Created 6 years ago
- Reactions: 24
- Comments: 32 (10 by maintainers)
I am using it like this.
Running in.
/remove-lifecycle stale
What an annoying bot. Please stop closing issues that are still open, and affect many users!
I would suggest that #238 be the way forward. Although Google Cloud does not yet advertise it, you can authenticate to GKE from
kubectlwithout using any vendor-specific plugin:One design issue with this, at least as of 52b65f8, is that the io.kubernetes.client.util.credentials.Authentication interface is only asked to provide authentication for an ApiClient at construction time - when ClientBuilder is first constructing the ApiClient.
To support tokens that change during the lifetime of an ApiClient instance (as with a GCP token that needs to be refreshed periodically), it seems like the design would have to change to have ApiClient periodically ask the Authentication (or some other interface) for a new or current token.
Would a patch to implement such a change be welcomed?
FYI: for out-of-cluster refresh token to work,
kubectlregisters a plugin to thegolangclient, that in return calls agcloudinternal command: https://github.com/kubernetes/kubernetes/blob/master/staging/src/k8s.io/client-go/plugin/pkg/client/auth/gcp/gcp.gothe command with args is kept in the
kubeconfig:I was trying to figure out it doesn’t work with and out-of-cluster setup:
@jhbae200 how do you think about sending the patch as a PR in the repo?
@haugene we use
GoogleCredentials.getApplicationDefault()to get a token for the service account of the GCE instance where this code is running. The code callscredentials.refreshIfExpired()on each of the loops before callingapiClient.setApiKey(..).