{Auth} Show raw MSAL error in debug log#31746
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 enhances the aad_error_handler by logging the raw MSAL error payload in debug mode, aiding troubleshooting in constrained environments (e.g., Cloud Shell).
- Adds a dynamic JSON import and a debug log call to dump the MSAL error.
- Enables visibility into error details when running with
--debug.
Comments suppressed due to low confidence (2)
src/azure-cli-core/azure/cli/core/auth/util.py:30
- [nitpick] Adding or updating the docstring for
aad_error_handlerto mention that it logs the raw MSAL error when debug is enabled would clarify its behavior for future maintainers.
# az account get-access-token --scope https://my-invalid-scope
src/azure-cli-core/azure/cli/core/auth/util.py:33
- It would be helpful to add or update tests to verify that the raw MSAL error is correctly logged when
--debugis enabled, ensuring this new behavior is covered.
logger.debug('MSAL error: %s', json.dumps(error))
| # To trigger this function for testing, simply provide an invalid scope: | ||
| # az account get-access-token --scope https://my-invalid-scope | ||
|
|
||
| import json |
There was a problem hiding this comment.
[nitpick] Consider moving import json to the top of the module with the other imports to follow standard Python import practices and avoid repeated dynamic imports.
Description
This change was part of #28954, but was postponed.
Showing the MSAL error in the debug log can be very helpful for troubleshooting, especially in a managed identity or Cloud Shell environment where changing the source code is difficult (#31743 (comment)).
As confirmed with MSAL team, the MSAL error will only contain PII but not any credentials. Azure CLI doesn't send debug log to telemetry, so it is safe to display the MSAL error in the debug log.
Testing Guide