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 · 5 comments
Labels
lifecycle/stale Denotes an issue or PR has remained open with no activity and has become stale.

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.

@k8s-triage-robot
Copy link

The Kubernetes project currently lacks enough contributors to adequately respond to all issues.

This bot triages un-triaged issues according to the following rules:

  • After 90d of inactivity, lifecycle/stale is applied
  • After 30d of inactivity since lifecycle/stale was applied, lifecycle/rotten is applied
  • After 30d of inactivity since lifecycle/rotten was applied, the issue is closed

You can:

  • Mark this issue as fresh with /remove-lifecycle stale
  • Close this issue with /close
  • Offer to help out with Issue Triage

Please send feedback to sig-contributor-experience at kubernetes/community.

/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 Nov 21, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
lifecycle/stale Denotes an issue or PR has remained open with no activity and has become stale.
Projects
None yet
Development

No branches or pull requests

5 participants