Minikube: kubectl doesn't use provided token permissions

8/3/2020

Using minikube, when running the following command:

kubectl -v=11 --kubeconfig /dev/null --insecure-skip-tls-verify -s http://localhost:8001 --token "invalid" -n namespace get pods

I have an answer when I don't want one. And I don't know how it was authorized. Moreover, if I use a valid token with specific rights, these are not used.

https://stackoverflow.com/questions/60083889/kubectl-token-token-doesnt-run-with-the-permissions-of-the-token doesn't answer my question as I specified to used /dev/null as a config file.

Any idea ?

-- Neok
kubectl
kubernetes
minikube

1 Answer

8/5/2020

I will try to summarize the answer I provided in the comments.

The question was: Why does running kubectl -s http://localhost:8001 --kubeconfig /dev/null --token <invalid_token> (where :8001 is a port opened by kubectl proxy) repoonds as if I was authorized, when it shouldn't beacause I set all possible authorization options to null or incorrect values?

The answer is that kubectl proxy opens a port and handles all authorization for you so you dont have to. Now to access REST api of kubernetes all you need to do is to use curl localhost:8001/.... No tokens and certificates.

Because you are already authorized with kubectl proxy, using kubectl and pointing it to localhost:8001 is causing that it won't need to authorize and you won't need any tokens to access k8s.


As an alternative you can check what happens when you run the same but instead of connecting through kubectl proxy you use kubernetes port directly.

You mentioned that you are using minikube so by default that would be port 8443

$ kubectl --kubeconfig /dev/null -s https://$(minikube ip):8443 --token "invalid" --insecure-skip-tls-verify get pods

error: You must be logged in to the server (Unauthorized)

As you see now it works as expected.

-- Matt
Source: StackOverflow