-
Notifications
You must be signed in to change notification settings - Fork 49
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
Help connecting to AKS cluster using exec #177
Comments
The https://github.com/kubernetes-client/c/blob/master/kubernetes/config/exec_provider.c should work. You need the https://github.com/Azure/kubelogin#web-browser-flow-default If you have a config that uses |
Thanks Brendan. I will pass the information on to the team and will update here after. |
There is an example using the Hope it helps |
Hello @ityuhui , Thank you for providing us a sample. We tried to use this approach but we have trouble figuring out how to retrieve token. get-token --environment AzurePublicCloud --server-id --client-id --tenant-id --login devicecode (we also tried interactive) Then we passed the generated token as the last argument to my_exec_provider. The result is as the following:
We also tried to use refresh-token from ~/.kube/config but we receive HTTP 401. Also, from my_exec_provider code, I see there is another option to use client private key and client certificate instead of token. May I ask how to retrieve the values for these two parameters? |
Hello @brendandburns , Thank you for the suggestion you made yesterday.
We tried to load it using this: load_kube_config(&basePath, &sslConfig, &apiKeys, NULL); The rest of the code is the same as the sample. This also result in HTTP 401. |
Does this Kubeconfig file work correctly when you use |
Yes, kubectl works fine. |
This is a defect. The reason is insufficient buffer memory. Please enlarge the value: https://github.com/kubernetes-client/c/blob/master/kubernetes/config/exec_provider.c#L8-L9 And take another try. BTW, |
@shayan-eftekhari can you try increasing the buffer size per @ityuhui 's suggestion and see if that works with the If that doesn't work, I will try to reproduce this locally and see what is happening. |
Thank you for your suggestions @brendandburns and @ityuhui. I increased the buffer size so I don't see the buffer size problem anymore when I use the generated token of kubelogin, yet I still get HTTP 401. I tried these two approaches:
|
For the first approach: Using my_exec_provider and the following config file curl -X GET $APISERVER/api --header "Authorization: Bearer $TOKEN" --insecure |
Hi Hui Yu,
The token looks fine. |
If the token works fine, the
|
Hi Hui Yu, Yes, I passed the custom kube config. Let me give you more update. In my previous setup, I created a conan package for kubernetes and I was trying to connect to AKS in my project. Now I am running a fresh Ubuntu 22.04 docker container. I increased buffer size to 4096 and I followed the instructions listed here: https://github.com/kubernetes-client/c to compile kubernetes and exec_provider example. Then I used the following command to generate the token: Then I modified the config_with_exec_provider like this:
Everything else is exactly the same as the sample. Here is the output:
|
Let's go back to the 2nd approach: Using default kube config in ~/.kube/config which is: Can you update the command with an absolute path in your ~/.kube/config command: /path/to/kubelogin And try to debug the token getting from kubelogin at c/kubernetes/config/exec_provider.c Line 90 in 859fc3f
You can enable debugging when buiding the c client library: mkdir build
cd build
cmake -DCMAKE_BUILD_TYPE=Debug -DCMAKE_INSTALL_PREFIX=/usr/local ..
make
sudo make install |
Hi Hui Yu, Thank you Hui Yu for your suggestion. We logged the token in exec_provider and it was fine. Then we followed the code logic until we found this function: https://github.com/kubernetes-client/c/blob/master/kubernetes/config/kube_config.c#L86 This function truncates the token because BEARER_TOKEN_BUFFER_SIZE is only 2048 bytes. We increased the buffer size here as well and the problem is solved. You may want to increase this buffer size as well as those two you mentioned earlier in the library. Thank you for all your help, |
Glad you got this fixed, we should update the code to have a larger buffer size (and we should probably also print better error messages if the token is too long :) |
Yes. the errors of insufficient buffer are caught and printed in the function |
We are trying to use the official C API for Kubernetes: https://github.com/kubernetes-client/c
What we want is to connect to an AKS cluster from a local workstation, and use the API to list pods in a cluster.
We have already installed kubectl/az/kubelogin/etc on this workstation, and listing pods via kubectl works just fine.
Our AKS is on version 1.24
We are following the example here.
However, after we load the K8s config and get the API client:
we receive a 401 error when we try to list pods:
Our Azure Infrastructure partner has suggested that this may be due to some authentication changes that were introduced recently.
Can you please send us a sample c/c++ code that would work with AKS clusters version 1.24 or higher or point us into the right direction.
Many Thanks
The text was updated successfully, but these errors were encountered: