terminal icon indicating copy to clipboard operation
terminal copied to clipboard

Azure Cloud Shell keeps resulting in "Key not found" error

Open ghost opened this issue 6 years ago • 24 comments

I keep seeing the following behavior:

Tenant 0: Default Directory (brillfoxyahoo.onmicrosoft.com)
Tenant 1: Microsoft (microsoft.onmicrosoft.com)
Please enter the desired tenant number.
Enter n to login with a new account
Enter r to remove the above saved connection settings.
> 1
Requesting a cloud shell instance...
Succeeded.
Key not found
[process exited with code 1]

This issue seems persistent.

ghost avatar Jul 24 '20 07:07 ghost

I have the same issue.

To sign in, use a web browser to open the page https://microsoft.com/devicelogin and enter the code XXXXXXXX to authenticate.
This code will expire in 15 minutes.
Authenticated.
Tenant 0: xxx (xxx.onmicrosoft.com)
Tenant 1: xxx (xxx.onmicrosoft.com)
Tenant 2: xxx (xxx.onmicrosoft.com)
Tenant 3: xxx (xxx.onmicrosoft.com)
Please enter the desired tenant number.
> 0
Do you want to save these connection settings for future logins? [y/n]
> n
Requesting a cloud shell instance...
Succeeded.
Key not found
[process exited with code 1]

Javanite avatar Jul 27 '20 20:07 Javanite

@Javanite I'm going to follow up with you offline, as I can furnish a debug build of the AzCS bridge :smile:

DHowett avatar Jul 27 '20 22:07 DHowett

I am also having same issue.

Tenant 0: name Please enter the desired tenant number. Enter n to login with a new account Enter r to remove the above saved connection settings.

help Please enter a valid number to access the stored connection settings, n to log in with a new account, or r to remove the saved connection settings. 0 Requesting a cloud shell instance... Succeeded. Key not found [process exited with code 1]

saugatadatta avatar Jul 30 '20 18:07 saugatadatta

Hey @DHowett ,

Just a heads up I will be out the whole month of August, so I might be hard to reach. You can try pinging me on teams and I will respond if I can.

Javanite avatar Jul 30 '20 19:07 Javanite

Likely due to the shell storage hasn't been setup yet. Login to your Azure Portal, select the Azure Shell on top to first initialize and setup the shell. Once the storage is completed, you should be able connect via Azure Cloud Shell.

yiigy avatar Jul 30 '20 22:07 yiigy

@yiigy thanks for the suggestion, unfortunately doesn't appear to work. I started up the cloud shell in the portal, even ran it in interactive mode, but I still get the same result as before when using the Windows Terminal.

Here's a screencap of me running a random command in the az portal cloud shell.

image

Attempting to connect afterwards: image

Javanite avatar Jul 30 '20 23:07 Javanite

Having the same issue. Terminal Version: 1.2.2381.0

image

If these values matter:

pwsh --version: PowerShell 7.0.2 $PSVersionTable:

Key Value
PSEdition Core
PSCompatibleVersions System.Version[]
Platform Win32NT
GitCommitId 7.0.2
OS Microsoft Windows 10.0.18363
PSVersion 7.0.2
PSRemotingProtocolVersion 2.3
SerializationVersion 1.1.0.1
WSManStackVersion 3.0

ASIAubrie avatar Sep 23 '20 14:09 ASIAubrie

I'm not sure if this is useful, but I was also seeing this issue until I deleted the saved connection settings (r) and re-authenticated. I then saw a much more useful message, which led me to the actual cause:

image

markashleybell avatar Oct 08 '20 11:10 markashleybell

I had the same problem. Going to https://shell.azure.com AND THEN changing from Bash to PowerShell. This seemed to set everything up so it now works when I log in via Windows Terminal.

jamesdecourcy avatar Oct 13 '20 14:10 jamesdecourcy

Wow! @jamesdecourcy That solved the issue for me!

This is a really bad error message with an even stranger fix (changing a preference in a web browser affects a terminal instance in Windows!?). What is the best resolution here?

  1. Make the error message better with clear instructions, or an aka.ms link on how to troubleshoot / fix?
  2. Prompt and allow the user to switch their preference via the terminal from Bash to PowerShell?
  3. Something else?

ASIAubrie avatar Oct 13 '20 15:10 ASIAubrie

Likely due to the shell storage hasn't been setup yet. Login to your Azure Portal, select the Azure Shell on top to first initialize and setup the shell. Once the storage is completed, you should be able connect via Azure Cloud Shell.

Yes, I know this helps. But why we cannot do this in Windows Terminal or give us a more clear message.

wbpluto avatar Nov 08 '20 07:11 wbpluto

@wbpluto - I have implemented a fix but was able to test it only once. Since I fixed the issue in azure portal by selecting a shell, I cannot reproduce the issue anymore. Even if I remove the user settings with an API or for new subscriptions.

My guess is that the problem happens only for "old" cloud shells, i.e., for those configured by an old versions of cloud console API (with API version lower than 2018-10-1). In such case, settings lack a "preferredShellType" field, that Terminal expects. As a result for such shells, Terminal succeeds to fetch the configuration, but then crashes trying to read this missing field.

I have added a code that prevents a crash and instead suggests to login in the browser and to set the shell. I will try to push the code and let's see if the team likes it :blush:

Don-Vito avatar Nov 08 '20 15:11 Don-Vito

@wbpluto - I have implemented a fix but was able to test it only once. Since I fixed the issue in azure portal by selecting a shell, I cannot reproduce the issue anymore. Even if I remove the user settings with an API or for new subscriptions.

My guess is that the problem happens only for "old" cloud shells, i.e., for those configured by an old versions of cloud console API (with API version lower than 2018-10-1). In such case, settings lack a "preferredShellType" field, that Terminal expects. As a result for such shells, Terminal succeeds to fetch the configuration, but then crashes trying to read this missing field.

I have added a code that prevents a crash and instead suggests to login in the browser and to set the shell. I will try to push the code and let's see if the team likes it 😊

Thanks, so clear! Can you tell me how can I delete of get the Cloud Shell user setting with API or CLI?

wbpluto avatar Nov 10 '20 15:11 wbpluto

@wbpluto - after some work with the team, what we pushed was to fallback to powershell if "preferredShell" cannot be loaded.

The settings can be retrieved this way:

$token= ((Invoke-WebRequest -Uri "$env:MSI_ENDPOINT`?resource=https://management.core.windows.net/" -Headers @{Metadata='true'}).content |  ConvertFrom-Json).access_token
((Invoke-WebRequest -Uri https://management.azure.com/providers/Microsoft.Portal/usersettings/cloudconsole?api-version=2018-10-01 -Headers @{Authorization = "Bearer $token"}).Content | ConvertFrom-Json).properties | Format-List

and deleted this way:

$token= ((Invoke-WebRequest -Uri "$env:MSI_ENDPOINT`?resource=https://management.core.windows.net/" -Headers @{Metadata='true'}).content |  ConvertFrom-Json).access_token
Invoke-WebRequest -Method Delete -Uri https://management.azure.com/providers/Microsoft.Portal/usersettings/cloudconsole?api-version=2018-10-01 -Headers @{Authorization = "Bearer $token"}

Don-Vito avatar Nov 10 '20 16:11 Don-Vito

:tada:This issue was addressed in #8197, which has now been successfully released as Windows Terminal Preview v1.5.3142.0.:tada:

Handy links:

ghost avatar Nov 11 '20 18:11 ghost

I had the same problem. Going to shell.azure.com AND THEN changing from Bash to PowerShell. This seemed to set everything up so it now works when I log in via Windows Terminal.

image

I had the same problem as well (obscure error message) and went to the same URL and was alerted that I needed to setup a storage account. After doing so (it was automatically handled by the site - just needed to specify which subscription) I was presented with the option to switch between Bash or PS.

Before selecting the option, I tried the cloud shell again and received a useful message:

You have not set up your cloud shell account yet. Please go to https://shell.azure.com to set it up.

After selecting Powershell in the browser, I tried again in Terminal and it's working as expected.

ChadLevy avatar Dec 07 '20 20:12 ChadLevy

@ChadLevy - what version of the terminal are you using? We don't expect this error in the new builds.

Don-Vito avatar Dec 07 '20 20:12 Don-Vito

@Don-Vito

1.4.3243.0

ChadLevy avatar Dec 07 '20 20:12 ChadLevy

@Don-Vito

1.4.3243.0

@ChadLevy - Thanks! I was worried for a moment. The fix was introduced in 1.5.3142.0 (which is still in preview) and it will fallback to powershell without a need to go to shell.azure.com.

Don-Vito avatar Dec 07 '20 20:12 Don-Vito

I reproduced this error on 1.16.2642.0 has the fix been reverted?

homotechsual avatar Nov 04 '22 12:11 homotechsual