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

Fix infinite recursion loop with kube login #107

Merged
merged 3 commits into from
Aug 29, 2024

Conversation

tjamet
Copy link
Contributor

@tjamet tjamet commented Aug 14, 2024

Problem

As raised in #37 and in rancher-sandbox/rancher-desktop#1308, When using kubelogin or any other credentials benefiting from kubectl plugins, an infinite recursion loop happens.

kuberlr is designed to be a built-in replacement for kubectl and hence replaces the kubectl command in the PATH.

Using kubectl exec plugin configured as below,
the Kubernetes version client will systematically
execute kubectl to obtain credentials to the cluster.

This will result calling kuberlr which will try to get the version again.

  - name: schip-oidc
    user:
      exec:
        apiVersion: client.authentication.k8s.io/v1beta1
        args:
          - oidc-login
          - get-token
          - --oidc-issuer-url=https://auth.example.com
          - --oidc-client-id=kubelogin
        command: kubectl

To prevent this infinite loop, mark the execution of KubectlVersionToUse in an environment variable.

This way, when kuberlr is executed again to authenticate to Kubernetes so it can retrieve the Kubernetes version, it will systematically use the latest stable Kubectl version and avoid the infinite recursion loop.

fixes: #37
fixes: rancher-sandbox/rancher-desktop#1308

tjamet and others added 2 commits August 14, 2024 09:49
Problem
---

As raised in flavio#37 and in rancher-sandbox/rancher-desktop#1308,
When using kubelogin or any other credentials benefiting from kubectl
plugins, an infinite recursion loop happens.

kuberlr is designed to be a built-in replacement for `kubectl` and hence
replaces the `kubectl` command in the `PATH`.

Using kubectl exec plugin configured as below,
the Kubernetes version client will systematically
execute kubectl to obtain credentials to the cluster.

This will result calling `kuberlr` which will try to get the version
again.

```yaml
  - name: schip-oidc
    user:
      exec:
        apiVersion: client.authentication.k8s.io/v1beta1
        args:
          - oidc-login
          - get-token
          - --oidc-issuer-url=https://auth.example.com
          - --oidc-client-id=kubelogin
        command: kubectl
```

To prevent this infinite loop, mark the execution of `KubectlVersionToUse`
in an environment variable.

This way, when `kuberlr` is executed again to authenticate to Kubernetes
so it can retrieve the Kubernetes version, it will systematically use
the latest stable Kubectl version and avoid the infinite recursion loop.

fixes: flavio#37
fixes: rancher-sandbox/rancher-desktop#1308
Signed-off-by: Flavio Castelli <[email protected]>
@flavio
Copy link
Owner

flavio commented Aug 14, 2024

@tjamet thanks for the fix! I've done a small refactor, can you double test it please? I don't have a suitable environment

@tjamet
Copy link
Contributor Author

tjamet commented Aug 14, 2024

@tjamet thanks for the fix! I've done a small refactor, can you double test it please? I don't have a suitable environment

I just tested and it worked for me.
I have also added some unit tests to ensure it keeps working over time

@tjamet
Copy link
Contributor Author

tjamet commented Aug 22, 2024

Hi @flavio would you need anything else from me to be able to move this forward?
Thanks a lot!

@flavio
Copy link
Owner

flavio commented Aug 22, 2024

@tjamet I’m currently on vacation. I’ll look into that next week

@flavio
Copy link
Owner

flavio commented Aug 29, 2024

Thanks for having added the unit tests. There's a risk of the two tests influencing each other when the tests are run in parallel, but this is not going to happen since we don't have parallelism enabled.

Before going on vacation I was looking into the unit tests of the project and I realized I could do some cleanups.

I'm going to merge this PR, do the cleanups in the next days and then tag a new release.

Thanks again for this fix!

@flavio flavio merged commit d8c6882 into flavio:master Aug 29, 2024
4 checks passed
@tjamet tjamet deleted the fix/kube-login branch September 27, 2024 13:06
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

Successfully merging this pull request may close these issues.

Does not work with kubelogin OIDC Login Support
2 participants