Skip to content
New issue

Have a question about this project? # for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “#”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? # to your account

AzureCLICredential Error on kubelogin v0.0.19 #123

Closed
cezapata opened this issue Aug 9, 2022 · 3 comments
Closed

AzureCLICredential Error on kubelogin v0.0.19 #123

cezapata opened this issue Aug 9, 2022 · 3 comments

Comments

@cezapata
Copy link

cezapata commented Aug 9, 2022

I have an Azaure Devops pipeline that uses an AAD managed identity to work alongside kubelogin's AzureCLI non interactive token login option.

An excerpt of how it is configured is:

        steps:
        - task: CmdLine@2
          displayName: 'Installs aks cli alongside kubelogin'
          inputs:
            script: 'az login --identity -u $(identity)'

        - task: CmdLine@2
          displayName: 'Installs aks cli alongside kubelogin'
          inputs:
            script: 'az aks install-cli'

        - task: CmdLine@2
          displayName: 'Gets AKS credentials and sets the k8s context'
          inputs:
            script: 'az aks get-credentials --name $(aksClusterName) --resource-group $(resourceGroupName) --overwrite-existing'

        - task: CmdLine@2
          displayName: 'Sets kubeconfig configuration'
          inputs:
            script: |
              export KUBECONFIG=~/.kube/config
              kubelogin convert-kubeconfig -l azurecli
              kubectl get no

Since version 0.0.19 came out, we have been getting an error: AzureCLICredential: ERROR: Tenant shouldn't be specified for managed identity account

2022-08-09T05:08:01.5080612Z ##[section]Starting: Sets kubeconfig configuration
2022-08-09T05:08:01.5090446Z ==============================================================================
2022-08-09T05:08:01.5090832Z Task         : Command line
2022-08-09T05:08:01.5091185Z Description  : Run a command line script using Bash on Linux and macOS and cmd.exe on Windows
2022-08-09T05:08:01.5091528Z Version      : 2.201.1
2022-08-09T05:08:01.5091767Z Author       : Microsoft Corporation
2022-08-09T05:08:01.5092149Z Help         : https://docs.microsoft.com/azure/devops/pipelines/tasks/utility/command-line
2022-08-09T05:08:01.5092575Z ==============================================================================
2022-08-09T05:08:01.6777152Z Generating script.
2022-08-09T05:08:01.6816023Z ========================== Starting Command Output ===========================
2022-08-09T05:08:01.6833737Z [command]/usr/bin/bash --noprofile --norc /opt/azure-agent/_work/_temp/da2d9e71-87c6-4505-826a-43fc7118c2c1.sh
2022-08-09T05:08:02.3995748Z Error: failed to get token: expected an empty error but received: AzureCLICredential: ERROR: Tenant shouldn't be specified for managed identity account
2022-08-09T05:08:02.3996606Z 
2022-08-09T05:08:03.0337879Z Error: failed to get token: expected an empty error but received: AzureCLICredential: ERROR: Tenant shouldn't be specified for managed identity account
2022-08-09T05:08:03.0341832Z 
2022-08-09T05:08:03.5797207Z Error: failed to get token: expected an empty error but received: AzureCLICredential: ERROR: Tenant shouldn't be specified for managed identity account
2022-08-09T05:08:03.5798207Z 
2022-08-09T05:08:04.1139856Z Error: failed to get token: expected an empty error but received: AzureCLICredential: ERROR: Tenant shouldn't be specified for managed identity account
2022-08-09T05:08:04.1140417Z 
2022-08-09T05:08:04.7296711Z Error: failed to get token: expected an empty error but received: AzureCLICredential: ERROR: Tenant shouldn't be specified for managed identity account
2022-08-09T05:08:04.7324192Z 
2022-08-09T05:08:04.7325102Z Unable to connect to the server: getting credentials: exec: executable kubelogin failed with exit code 1
2022-08-09T05:08:04.7466262Z ##[error]Bash exited with code '1'.
2022-08-09T05:08:04.7594393Z ##[section]Finishing: Sets kubeconfig configuration

Because of the timing and the nature of the change, I suspect that this changed based on this PR: #122

To temporarily fix this, I have mended the az aks install-cli command, and I am fixing the version to the last working one for us: --kubelogin-version v0.0.18.

I would like to ask for help, a sample that could help me figure out how to get the login mechanism to work on latest. Thank you so much for your help!

@weinong
Copy link
Contributor

weinong commented Aug 9, 2022

Since kubelogin has no knowledge how azure cli is logged in with, i think the solution is simply disregard the tenant ID from input kubeconfig during the conversion. If overriding the tenant ID for different tenant is desired, add --tenant-id in conversion. For example,

az aks get-credentials -g ${RG} -n ${AKS} && kubelogin convert-kubeconfig -l azurecli --tenant-id ${TENANT_ID}

cc: @pearj about this change

@pearj
Copy link

pearj commented Aug 10, 2022

@weinong thanks for the heads up.
I guess a limitation of this new approach is that you need to run convert-kubeconfig
after every az aks get-credentials, because if you run it at the end it will use the same tenantid for all clusters. I suppose an alternate solution could be a flag that just says to use the tenant id that is in kubeconfig. But this solution is fairly useable, so probably not worth the effort.

@weinong
Copy link
Contributor

weinong commented Aug 10, 2022

fixed in v0.0.20

@weinong weinong closed this as completed Aug 10, 2022
bingosummer pushed a commit to bingosummer/kubelogin that referenced this issue Oct 3, 2022
…ure#124)

The change in v0.0.19 introduced passing the tenantID from input kubeconfig to azurecli. This resulted in error in azurecli when it's logged in using MSI as MSI login does not support tenant ID. (Azure#123)

The change in this PR will disregard the tenant ID from input kubeconfig when convert to azurecli. If overriding tenant ID in azurecli mode is desired, add `--tenant-id` explicitly during conversion. For instance,
```sh
az aks get-credentials -g ${RG} -n ${AKS} && kubelogin convert-kubeconfig -l azurecli --tenant-id ${TENANT_ID}
```
# for free to join this conversation on GitHub. Already have an account? # to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants