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

Config::infer can return in-cluster config outside cluster with rustls feature #623

Closed
webern opened this issue Aug 23, 2021 · 12 comments
Closed
Labels
rustls rustls-tls related

Comments

@webern
Copy link

webern commented Aug 23, 2021

I think there is a problem with this code branch:
https://github.com/kube-rs/kube-rs/blob/master/kube/src/config/mod.rs#L94...L97

This takes us to:
https://github.com/kube-rs/kube-rs/blob/b7fe7485a5661bdec398377109801e675db8aaee/kube/src/config/incluster_config.rs#L22...L29

Where we always return an on-cluster URL even if we are not running on a cluster.

So the issue is, if I want to use a KUBECONFIG, off-cluster with Rustls, I never make it to the KUBECONFIG code branches.

One simple fix would be to check for the absence of KUBECONFIG at https://github.com/kube-rs/kube-rs/blob/master/kube/src/config/mod.rs#L94 but that might be a slightly different behavior than advertised in the documentation.

@webern
Copy link
Author

webern commented Aug 23, 2021

Ugh, I did a workaround but found that my kubeconfig file has the server address as https://127.0.0.1[...]. This was created by kind for local development. Anyway, when I workaround the problem described above to use my kubconfig file, Rustls still errors due to the "invalid dns name" rustls/hyper-rustls#84

@kazk
Copy link
Member

kazk commented Aug 23, 2021

Closing as duplicate of #153. We keep track of rustls issues with a label https://github.com/kube-rs/kube-rs/labels/rustls

@kazk kazk closed this as completed Aug 23, 2021
@kazk kazk added the duplicate This issue or pull request already exists label Aug 23, 2021
@kazk
Copy link
Member

kazk commented Aug 23, 2021

Where we always return an on-cluster URL even if we are not running on a cluster.

Well, this might be a new issue.

@kazk kazk reopened this Aug 23, 2021
@kazk kazk added the rustls rustls-tls related label Aug 23, 2021
@webern
Copy link
Author

webern commented Aug 23, 2021

OK, but are you aware that the rustls workaround linked to in this issue prevents a KUBECONFIG from ever being used. So, if my KUBECONFIG specifies https://somekubernetes.com, the bug I've mention exists where the KUBECONFIG will never be read. In this case the rustls "invalid DNS" is not the problem.

Edit: just saw you re-opened this. Thank you.

@kazk kazk changed the title cannot use kubeconfig with rustls Config::infer always returns in-cluster with rustls feature Aug 23, 2021
@kazk kazk added bug Something isn't working and removed duplicate This issue or pull request already exists labels Aug 23, 2021
@kazk
Copy link
Member

kazk commented Aug 23, 2021

Looks like it was overlooked because it should fall back to KUBECONFIG as long as the following files doesn't exist:

  • /var/run/secrets/kubernetes.io/serviceaccount/token
  • /var/run/secrets/kubernetes.io/serviceaccount/ca.crt
  • /var/run/secrets/kubernetes.io/serviceaccount/namespace

Failing to find these files should fall back to KUBECONFIG.

@kazk kazk changed the title Config::infer always returns in-cluster with rustls feature Config::infer can return in-cluster config outside cluster with rustls feature Aug 23, 2021
@kazk
Copy link
Member

kazk commented Aug 23, 2021

@webern Do you have the files listed above when you're outside the cluster?

@webern
Copy link
Author

webern commented Aug 23, 2021

No I don't have those files outside of the cluster. Outside of the cluster I'm running on a mac. I think the check for rustls happens too early in the code... before the check for those files.

$ ls /var/run/secrets/kubernetes.io/
ls: /var/run/secrets/kubernetes.io/: No such file or directory

@kazk
Copy link
Member

kazk commented Aug 23, 2021

Hmm, then it should fall back to KUBECONFIG because from_cluster_env should fail without those files.

https://github.com/kube-rs/kube-rs/blob/b7fe7485a5661bdec398377109801e675db8aaee/kube/src/config/mod.rs#L70-L75

I'm assuming you're using Config::infer or Client::try_default which uses Config::infer.

@webern
Copy link
Author

webern commented Aug 23, 2021

Client::try_default correct.

from_cluster_env succeeds returning the hardcoded workaround url irrespective of whether we are in cluster or not:
https://github.com/kube-rs/kube-rs/blob/master/kube/src/config/mod.rs#L94...L97

@kazk
Copy link
Member

kazk commented Aug 23, 2021

You're correct about cluster_url, but from_cluster_env will fail when reading those files just below.

https://github.com/kube-rs/kube-rs/blob/b7fe7485a5661bdec398377109801e675db8aaee/kube/src/config/mod.rs#L107-L115

@webern
Copy link
Author

webern commented Aug 23, 2021

Oh I see. This issue might be in error. I'll double check through my breakpoints again.

@kazk kazk removed the bug Something isn't working label Aug 23, 2021
@webern
Copy link
Author

webern commented Aug 23, 2021

I think I was wrong about the failure mode. Perhaps it was getting my kubeconfig and failing because it had the server address 127.0.0.1. Closing.

@webern webern closed this as completed Aug 23, 2021
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
rustls rustls-tls related
Projects
None yet
Development

No branches or pull requests

2 participants