{Core} Fix: In Cloud Shell, cross-tenant authentication fails for user or Service Principal account #17805
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Description
In Cloud Shell, even if
az login
is run with user or Service Principal account, subsequent commands involving cross-tenant authentication fails:Cause
This bug was introduced by #16797 where only
in_cloud_console()
is checked:azure-cli/src/azure-cli-core/azure/cli/core/_profile.py
Lines 564 to 566 in 039fa21
In fact,
_CLOUD_SHELL_ID
(cloudShellID
) should also be checked so that the error is only raised for Cloud Shell's Managed Identity account, instead of user or Service Principal account.Testing guide
In Cloud Shell, run
az login # Replace `414af076-009b-4282-9a0a-acf75bcb037e` with your own subscription ID in another tenant az network vnet peering create --name myVnetAToMyVnetB --resource-group myResourceGroupA --vnet-name myVnetA --remote-vnet /subscriptions/414af076-009b-4282-9a0a-acf75bcb037e/resourceGroups/myResourceGroupB/providers/Microsoft.Network/VirtualNetworks/myVnetB --allow-vnet-access