{Auth} Do not show re-authentication message for service principal and managed identity#31745
{Auth} Do not show re-authentication message for service principal and managed identity#31745
Conversation
️✔️AzureCLI-FullTest
|
️✔️AzureCLI-BreakingChangeTest
|
|
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>
|
There was a problem hiding this comment.
Pull Request Overview
This PR updates the authentication error handler so that the interactive login recommendation is only shown when context arguments are provided (e.g., Cloud Shell) and is suppressed for service principal and managed identity failures.
- Initialize
recommendationtoNoneby default - Change the
elsebranch toelif kwargsso that the interactive login prompt only appears when kwargs are present
Comments suppressed due to low confidence (1)
src/azure-cli-core/azure/cli/core/auth/util.py:44
- Add a unit test for
aad_error_handlerwhen called with no kwargs to verify thatrecommendationremainsNonefor service principal and managed identity error paths.
recommendation = None
| if error_codes and 7000215 in error_codes: | ||
| recommendation = PASSWORD_CERTIFICATE_WARNING | ||
| else: | ||
| elif kwargs: |
There was a problem hiding this comment.
[nitpick] The elif kwargs condition may be unclear about which scenarios trigger the interactive prompt. Consider adding a comment or using explicit checks (e.g., if is_cloud_shell:) to clarify intent.
| elif kwargs: | |
| # If additional context (e.g., tenant or scopes) is provided in kwargs, suggest interactive authentication. | |
| elif 'tenant' in kwargs or 'scopes' in kwargs or 'claims_challenge' in kwargs: |
Description
Currently, the re-authentication message is also shown for service principals:
and managed identity:
This is incorrect and meaningless.
This PR changes behavior so that the re-authentication message with a bare
az loginis not shown for service principal:or managed identity:
For Cloud Shell, we still show the re-authentication message as a fallback (explicit login) in case of failure:
azure-cli/src/azure-cli-core/azure/cli/core/auth/msal_credentials.py
Line 132 in 4177017