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

KubernetesClientConfiguration.IsInCluster() not working when automountServiceAccountToken=false #1576

Open
zhiweiv opened this issue Aug 19, 2024 · 4 comments

Comments

@zhiweiv
Copy link
Contributor

zhiweiv commented Aug 19, 2024

In KubernetesClientConfiguration.IsInCluster, it uses service account token file as one check condition.

 var tokenPath = Path.Combine(ServiceAccountPath, ServiceAccountTokenKeyFileName);
 if (!FileSystem.Current.Exists(tokenPath))
 {
     return false;
 }

When set automountServiceAccountToken false(https://kubernetes.io/docs/tasks/configure-pod-container/configure-service-account/#opt-out-of-api-credential-automounting), there is no token file injected to container, KubernetesClientConfiguration.IsInCluster doesn't work correctly.

@tg123
Copy link
Member

tg123 commented Aug 19, 2024

any alternative way to know if the app is running inside k8s?
this is designed to use incluster auth

@zhiweiv
Copy link
Contributor Author

zhiweiv commented Aug 19, 2024

In client-go, seems there is no public IsInCluster method, it suggests checking return value of InClusterConfig(https://github.com/kubernetes/client-go/blob/master/examples/in-cluster-client-configuration/main.go#L42).

We used IsInCluster beyond auth purpose, plan to remove them.

@tg123
Copy link
Member

tg123 commented Aug 19, 2024

i believe the ask is
reband IsInCluster -> HasInClusterToken ?

@brendandburns
Copy link
Contributor

I don't think that IsInCluster is intended to test whether or not the container is running inside a cluster. We could make that name change to make it more clear, but honestly I'm not sure if it's worth it.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants