-
Notifications
You must be signed in to change notification settings - Fork 3.5k
Incompatibility between az ad and --subscription #29837
Copy link
Copy link
Open
Labels
Auto-AssignAuto assign by botAuto assign by botAzure CLI TeamThe command of the issue is owned by Azure CLI teamThe command of the issue is owned by Azure CLI teamGraph(doesn't work with label-triggered comments; use Graph.Microsoft instead) az ad(doesn't work with label-triggered comments; use Graph.Microsoft instead) az adKeyVaultaz keyvaultaz keyvaultact-identity-squadpotential-pruningquestionThe issue doesn't require a change to the product in order to be resolved. Most issues start as thatThe issue doesn't require a change to the product in order to be resolved. Most issues start as that
Milestone
Description
Activity
Metadata
Metadata
Labels
Auto-AssignAuto assign by botAuto assign by botAzure CLI TeamThe command of the issue is owned by Azure CLI teamThe command of the issue is owned by Azure CLI teamGraph(doesn't work with label-triggered comments; use Graph.Microsoft instead) az ad(doesn't work with label-triggered comments; use Graph.Microsoft instead) az adKeyVaultaz keyvaultaz keyvaultact-identity-squadpotential-pruningquestionThe issue doesn't require a change to the product in order to be resolved. Most issues start as thatThe issue doesn't require a change to the product in order to be resolved. Most issues start as that
az adand--subscription--subscription(_subscription) is explicitly ignored foraz adcommands asaz adcommands are tenant-level. They have nothing to do with subscription.azure-cli/src/azure-cli/azure/cli/command_modules/role/_params.py
Line 26 in e8efb79
However, since subscription ID is the primary key of Azure CLI's account, this gives
--subscriptionanother functionality - temporarily switching login context.send_raw_requestonly switches subscription when the subscription ID is in an ARM URL:azure-cli/src/azure-cli-core/azure/cli/core/util.py
Line 977 in a5198b5
As Graph API's URL is like
https://graph.microsoft.com/,send_raw_requestuses the current login context:azure-cli/src/azure-cli-core/azure/cli/core/util.py
Line 979 in a5198b5
So
--subscriptiondoesn't take effect in:Problem in doc
The in-tool help says
az adcommands don't support--subscriptionbut the online doc says they do, which is wrong (#21806, #23412): https://learn.microsoft.com/en-us/cli/azure/ad/app?view=azure-cli-latest#az-ad-app-show
Problem in
az keyvault createConsider
sub1is the current subscription+login context whilesub2is another one, andaz keyvault createis run with--subscription sub2Creating keyvault
As
subscriptioncan be read fromcmd.cli_ctx.data.get['subscription_id']:azure-cli/src/azure-cli/azure/cli/command_modules/keyvault/custom.py
Line 671 in 85d68d3
The keyvault is created with the identity of the
--subscription-specified account - (sub2, tenant2, user2)._get_current_user_object_idWhen granting permissions for the keyvault,
az keyvault createfirst calls_get_current_user_object_idazure-cli/src/azure-cli/azure/cli/command_modules/keyvault/custom.py
Line 736 in 85d68d3
_get_current_user_object_idinternally calls the/meAPI on Microsoft Graph with the current account's identity, so it grants permission to the identity of the current account - (N/A, tenant1, user1). This causes a mismatch._get_object_idIf
_get_current_user_object_idfails, it calls_get_object_id:azure-cli/src/azure-cli/azure/cli/command_modules/keyvault/custom.py
Line 738 in 85d68d3
which resolves the identity of the
--subscription-specified account, but in the current tenant - (N/A, tenant1, user2).Solution
The best solution is to implement a 3-layer structure (#15005).
More information
az role assignment list --subscriptionshows emptyprincipalName#15532