int128 / kubelogin

kubectl plugin for Kubernetes OpenID Connect authentication (kubectl oidc-login)
Apache License 2.0
1.75k stars 195 forks source link

MFA Login with plugin without Browser #950

Open dhorstmann opened 1 year ago

dhorstmann commented 1 year ago

Describe the question

When setting --username in kubeconfig, there is no Browser opening keycloak for asking username and password, just asking in terminale directly. Thats very nice. When the user has mfa configured in keycloak, he has to login with otp. But then the login with the username option in kubeconfig does not work anymore (error see next line). Is there an option, so that the otp will be asked on bash?
error: {"error":"invalid_grant","error_description":"Invalid user credentials"}

To reproduce

Your environment

igurleen911 commented 1 year ago

@dhorstmann were you able to resolve this issue?

dhorstmann commented 1 year ago

@dhorstmann were you able to resolve this issue?

Nope.

jsalatiel commented 2 weeks ago

I have forked this and added support to asking for OTP.

Just add this to your .kube/config

users:
    - name: kubernetes-admin
      user:
        exec:
            apiVersion: client.authentication.k8s.io/v1beta1
            args:
                - oidc-login
                - get-token
                - --oidc-issuer-url=https://keycloak/auth/realms/master
                - --oidc-client-id=yourclientid
                - --grant-type=password
            command: kubectl
            env: null
            interactiveMode: IfAvailable
            provideClusterInfo: false

and you will get something like this:

image

Just clone from my fork and build it if you want.