Azure / kubelogin

A Kubernetes credential (exec) plugin implementing azure authentication
https://azure.github.io/kubelogin/
MIT License
489 stars 92 forks source link

AzureCLICredential: exec: "C:\\WINDOWS\\cmd.exe": file does not exist #129

Open DaleyKD opened 2 years ago

DaleyKD commented 2 years ago

Windows 10 21H2 PowerShell 7.2.6

Installed Azure\kubelogin by exec az aks install-cli. It's currently version 0.0.20.

PS C:\> $env:PATH.split(";") | Sort-Object
C:\Program Files (x86)\Intel\Intel(R) Management Engine Components\DAL
C:\Program Files (x86)\Microsoft SDKs\Azure\CLI2\wbin
C:\Program Files (x86)\Microsoft SQL Server\150\DTS\Binn\
C:\Program Files (x86)\NVIDIA Corporation\PhysX\Common
C:\Program Files\Azure Data Studio\bin
C:\Program Files\Docker\Docker\resources\bin
C:\Program Files\dotnet\
C:\Program Files\Git\cmd
C:\Program Files\Intel\Intel(R) Management Engine Components\DAL
C:\Program Files\Intel\Intel(R) Memory and Storage Tool\
C:\Program Files\Microsoft SQL Server\130\Tools\Binn\
C:\Program Files\Microsoft SQL Server\150\Tools\Binn\
C:\Program Files\Microsoft SQL Server\Client SDK\ODBC\170\Tools\Binn\
C:\Program Files\nodejs
C:\Program Files\NVIDIA Corporation\NVIDIA NvDLISR
C:\Program Files\OpenSSL\bin
C:\Program Files\PowerShell\7
C:\Program Files\PowerShell\7\
C:\Program Files\Solidigm\Solidigm(TM) Storage Tool\
C:\ProgramData\chocolatey\bin
C:\ProgramData\DockerDesktop\version-bin
C:\Python310\
C:\Python310\Scripts\
C:\Python39\
C:\Python39\Scripts\
C:\Users\kdaley\.azure-kubelogin
C:\Users\kdaley\.dotnet\tools
C:\Users\kdaley\AppData\Local\GitHubDesktop\bin
C:\Users\kdaley\AppData\Local\Microsoft\WindowsApps
C:\Users\kdaley\AppData\Local\Programs\Fiddler
C:\Users\kdaley\AppData\Local\Programs\Microsoft VS Code\bin
C:\Users\kdaley\AppData\Roaming\nvm
C:\WINDOWS
C:\WINDOWS\system32
C:\WINDOWS\System32\OpenSSH\
C:\WINDOWS\System32\Wbem
C:\WINDOWS\System32\WindowsPowerShell\v1.0\

This is how I prepared everything.

PS C:\> az login
PS C:\> az account set -s={SUB_ID}
PS C:\> az aks get-credentials -g cluster-resources -n my-aks-cluster
A different object named clusterUser_cluster-resources_my-aks-cluster already exists in your kubeconfig file.
Overwrite? (y/n): y
Merged "my-aks-cluster" as current context in C:\Users\kdaley\.kube\config
PS C:\> kubelogin convert-kubeconfig -l azurecli

Finally, I just want kubectl to get me a version number.

PS C:\> kubectl version
Error: failed to get token: expected an empty error but received: AzureCLICredential: exec: "C:\\WINDOWS\\cmd.exe": file does not exist
WARNING: This version information is deprecated and will be replaced with the output from kubectl version --short.  Use --output=yaml|json to get the full version.
Client Version: version.Info{Major:"1", Minor:"25", GitVersion:"v1.25.0", GitCommit:"a866cbe2e5bbaa01cfd5e969aa3e033f3282a8a2", GitTreeState:"clean", BuildDate:"2022-08-23T17:44:59Z", GoVersion:"go1.19", Compiler:"gc", Platform:"windows/amd64"}
Kustomize Version: v4.5.7
Unable to connect to the server: getting credentials: exec: executable kubelogin failed with exit code 1

Not sure why it's looking for cmd.exe in the root of Windows?

(Omitted some for brevity, such as C:\Windows\servicing\LCU\Package_for_RollupFix~31bf3856ad364e35~amd64~~19041.1826.1.8 and C:\Windows\WinSxS\amd64_microsoft-windows-commandprompt_31bf3856ad364e35_10.0.19041.746_none_...)

PS C:\Windows\System32> Get-ChildItem -Path C:\Windows -Filter cmd.exe -Recurse -ErrorAction SilentlyContinue -Force
    Directory: C:\Windows\System32

Mode                 LastWriteTime         Length Name
----                 -------------         ------ ----
-a---            4/9/2021  8:48 AM         289792 cmd.exe

    Directory: C:\Windows\SysWOW64

Mode                 LastWriteTime         Length Name
----                 -------------         ------ ----
-a---            4/9/2021  8:49 AM         236544 cmd.exe
DaleyKD commented 2 years ago

I copied cmd.exe to my WINDOWS directory and it worked... but I'm only going to keep it there temporarily.

weinong commented 2 years ago

@DaleyKD from this code it's using the cmd.exe to invoke the az cli. I'm guessing for some reason cmd.exe isn't available in your search path? does typing cmd.exe work?

DaleyKD commented 2 years ago

@weinong : That code also shows that it's getting the %SYSTEMROOT% directory. That resolves to C:\WINDOWS on all of my machines. That is NOT where cmd.exe lives. I would think it should be %WINDIR%\system32 or %COMSPEC% (which is the full path to cmd.exe).

But to answer your question, yes, cmd.exe was in my search path (%PATH%). It is in C:\windows\system32 which is in my %PATH% environment variable. And when I type cmd.exe, it opens right up.

EDIT: In fact, if you look at my OP, you'll see that I showed all of the directories in my search path (%PATH%).