Improve Error Handling for 'az login --identity; with Multiple Assigned Identities#31012
Improve Error Handling for 'az login --identity; with Multiple Assigned Identities#31012
Conversation
|
Validation for Azure CLI Full Test Starting...
Thanks for your contribution! |
|
Validation for Breaking Change Starting...
Thanks for your contribution! |
|
Thank you for your contribution! We will review the pull request and get back to you soon. |
|
The git hooks are available for azure-cli and azure-cli-extensions repos. They could help you run required checks before creating the PR. Please sync the latest code with latest dev branch (for azure-cli) or main branch (for azure-cli-extensions). pip install azdev --upgrade
azdev setup -c <your azure-cli repo path> -r <your azure-cli-extensions repo path>
|
|
Thanks for the contribution.
For user-assigned managed identity, we explicitly added Meanwhile, we are migrating managed identity authentication from |
Related command
az login --identity
Description
This PR improves login error handling for situations where multiple identities are assigned to a resource by surfacing the error_description returned by ARM in the HTTPError response body. The current CLI logic for
az login --identityreturns a 400 Bad Request error without surfacing the actual error, making it unactionable for the user.Services like AKS make use of this, where the enablement of certain features creates a secondary identity. Doing so will cause AKS nodes and pods to no longer be authenticate to Azure resources simply by running
az login --identity, returning a generic 'Failed to connect to MSI' error message.During tests, I noticed the error object returned from the MSRestAzure library does not include the response body. Adding stream=True to the request mitigated, but this library has been deprecated and is read-only. Because of this, I've added the logic to replay the request and extract the error_description in the adal_authentication file.
Testing Guide
az aks create --resource-group <rgName>--name <cluster_name> --kubernetes-version 1.31.5 --enable-cluster-autoscaler --min-count 1 --max-count 30 --auto-upgrade-channel stable --node-count 1 --node-vm-size Standard_E4bs_v5 --network-plugin kubenet --vnet-subnet-id $SUBNET_ID --node-osdisk-size 128 --enable-managed-identity --enable-addons monitoring --max-pods 250 --enable-node-public-ip --generate-ssh-keys --tier Standardaz login --identityto observe it's working.az aks update -g <rgName> -n <cluster_name> --enable-cost-analysisaz login --identityand observe the 400 Bad Request error.az login --identityagain and observe the error message now includes additional error details:ERROR: Failed to connect to MSI. Please make sure MSI is configured correctly. Get Token request returned http error: 400, reason: Bad Request, details: Multiple user assigned identities exist, please specify the clientId / resourceId of the identity in the token requestHistory Notes
[Azure CLI] Append HTTPError response body to error message for
az login --identitycommand when multiple identities are present.