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

Created on 24 Jul 2020  路  15Comments  路  Source: microsoft/terminal

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.

Area-AzureShell Issue-Bug Needs-Tag-Fix Product-Terminal

Most helpful comment

@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:

All 15 comments

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 I'm going to follow up with you offline, as I can furnish a debug build of the AzCS bridge :smile:

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]

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.

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 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

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 |

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

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.

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?

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 - 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:

@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 - 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"}

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

Handy links:

Was this page helpful?
0 / 5 - 0 ratings