Skip to content

{Auth} Remove broker_error detection for re-authentication message#31743

Merged
jiasli merged 1 commit intoAzure:devfrom
jiasli:reauth
Jul 4, 2025
Merged

{Auth} Remove broker_error detection for re-authentication message#31743
jiasli merged 1 commit intoAzure:devfrom
jiasli:reauth

Conversation

@jiasli
Copy link
Member

@jiasli jiasli commented Jul 1, 2025

Related command
az login

Description
Previously, broker_error is dedicated to denote getting VM SSH certificate error in Cloud Shell (#22162) and the re-authentication message (error recommendation) is:

Please explicitly log in with:

This is because in Cloud Shell, Azure CLI is implicitly authenticated and no explicit az login --identity is required.

On a local machine, the re-authentication message for Entra errors is

Interactive authentication is needed. Please run:

After supporting Windows broker (#23828), an Entra error such as AADSTS50076 is also returned as broker_error in the error property of the MSAL result, making it impossible to tell if the error is from Cloud Shell or Entra. The re-authentication message for Entra errors is also

Please explicitly log in with:

which is inaccurate.

This PR drops the broker_error detection logic and unifies the re-authentication message.

As it has been years since Cloud Shell supported getting VM SSH certificate, the error is not likely to happen anymore.

Testing Guide

> az account get-access-token --tenant 54826b22-38d6-4fb2-bad9-b7b93a3e9c5a
SubError: basic_action V2Error: invalid_grant AADSTS50076: Due to a configuration change made by your administrator, or because you moved to a new location, you must use multi-factor authentication to access '797f4846-ba00-4fd7-ba43-dac1f8f63013'. Trace ID: 5e7a55fa-d403-4c80-be59-20df17111400 Correlation ID: 632c9066-f581-4a21-b44d-8484adafe70c Timestamp: 2025-07-01 08:52:40Z. Status: Response_Status.Status_InteractionRequired, Error code: 3399614476, Tag: 557973645
Interactive authentication is needed. Please run:
az login --scope https://management.core.windows.net//.default

@azure-client-tools-bot-prd
Copy link

azure-client-tools-bot-prd bot commented Jul 1, 2025

️✔️AzureCLI-FullTest
️✔️acr
️✔️latest
️✔️3.12
️✔️3.9
️✔️acs
️✔️latest
️✔️3.12
️✔️3.9
️✔️advisor
️✔️latest
️✔️3.12
️✔️3.9
️✔️ams
️✔️latest
️✔️3.12
️✔️3.9
️✔️apim
️✔️latest
️✔️3.12
️✔️3.9
️✔️appconfig
️✔️latest
️✔️3.12
️✔️3.9
️✔️appservice
️✔️latest
️✔️3.12
️✔️3.9
️✔️aro
️✔️latest
️✔️3.12
️✔️3.9
️✔️backup
️✔️latest
️✔️3.12
️✔️3.9
️✔️batch
️✔️latest
️✔️3.12
️✔️3.9
️✔️batchai
️✔️latest
️✔️3.12
️✔️3.9
️✔️billing
️✔️latest
️✔️3.12
️✔️3.9
️✔️botservice
️✔️latest
️✔️3.12
️✔️3.9
️✔️cdn
️✔️latest
️✔️3.12
️✔️3.9
️✔️cloud
️✔️latest
️✔️3.12
️✔️3.9
️✔️cognitiveservices
️✔️latest
️✔️3.12
️✔️3.9
️✔️compute_recommender
️✔️latest
️✔️3.12
️✔️3.9
️✔️computefleet
️✔️latest
️✔️3.12
️✔️3.9
️✔️config
️✔️latest
️✔️3.12
️✔️3.9
️✔️configure
️✔️latest
️✔️3.12
️✔️3.9
️✔️consumption
️✔️latest
️✔️3.12
️✔️3.9
️✔️container
️✔️latest
️✔️3.12
️✔️3.9
️✔️containerapp
️✔️latest
️✔️3.12
️✔️3.9
️✔️core
️✔️latest
️✔️3.12
️✔️3.9
️✔️cosmosdb
️✔️latest
️✔️3.12
️✔️3.9
️✔️databoxedge
️✔️latest
️✔️3.12
️✔️3.9
️✔️dls
️✔️latest
️✔️3.12
️✔️3.9
️✔️dms
️✔️latest
️✔️3.12
️✔️3.9
️✔️eventgrid
️✔️latest
️✔️3.12
️✔️3.9
️✔️eventhubs
️✔️latest
️✔️3.12
️✔️3.9
️✔️feedback
️✔️latest
️✔️3.12
️✔️3.9
️✔️find
️✔️latest
️✔️3.12
️✔️3.9
️✔️hdinsight
️✔️latest
️✔️3.12
️✔️3.9
️✔️identity
️✔️latest
️✔️3.12
️✔️3.9
️✔️iot
️✔️latest
️✔️3.12
️✔️3.9
️✔️keyvault
️✔️latest
️✔️3.12
️✔️3.9
️✔️lab
️✔️latest
️✔️3.12
️✔️3.9
️✔️managedservices
️✔️latest
️✔️3.12
️✔️3.9
️✔️maps
️✔️latest
️✔️3.12
️✔️3.9
️✔️marketplaceordering
️✔️latest
️✔️3.12
️✔️3.9
️✔️monitor
️✔️latest
️✔️3.12
️✔️3.9
️✔️mysql
️✔️latest
️✔️3.12
️✔️3.9
️✔️netappfiles
️✔️latest
️✔️3.12
️✔️3.9
️✔️network
️✔️latest
️✔️3.12
️✔️3.9
️✔️policyinsights
️✔️latest
️✔️3.12
️✔️3.9
️✔️privatedns
️✔️latest
️✔️3.12
️✔️3.9
️✔️profile
️✔️latest
️✔️3.12
️✔️3.9
️✔️rdbms
️✔️latest
️✔️3.12
️✔️3.9
️✔️redis
️✔️latest
️✔️3.12
️✔️3.9
️✔️relay
️✔️latest
️✔️3.12
️✔️3.9
️✔️resource
️✔️latest
️✔️3.12
️✔️3.9
️✔️role
️✔️latest
️✔️3.12
️✔️3.9
️✔️search
️✔️latest
️✔️3.12
️✔️3.9
️✔️security
️✔️latest
️✔️3.12
️✔️3.9
️✔️servicebus
️✔️latest
️✔️3.12
️✔️3.9
️✔️serviceconnector
️✔️latest
️✔️3.12
️✔️3.9
️✔️servicefabric
️✔️latest
️✔️3.12
️✔️3.9
️✔️signalr
️✔️latest
️✔️3.12
️✔️3.9
️✔️sql
️✔️latest
️✔️3.12
️✔️3.9
️✔️sqlvm
️✔️latest
️✔️3.12
️✔️3.9
️✔️storage
️✔️latest
️✔️3.12
️✔️3.9
️✔️synapse
️✔️latest
️✔️3.12
️✔️3.9
️✔️telemetry
️✔️latest
️✔️3.12
️✔️3.9
️✔️util
️✔️latest
️✔️3.12
️✔️3.9
️✔️vm
️✔️latest
️✔️3.12
️✔️3.9

@azure-client-tools-bot-prd
Copy link

azure-client-tools-bot-prd bot commented Jul 1, 2025

️✔️AzureCLI-BreakingChangeTest
️✔️Non Breaking Changes

@yonzhan
Copy link
Collaborator

yonzhan commented Jul 1, 2025

Update re-authentication message

@github-actions
Copy link

github-actions bot commented Jul 1, 2025

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).
After that please run the following commands to enable git hooks:

pip install azdev --upgrade
azdev setup -c <your azure-cli repo path> -r <your azure-cli-extensions repo path>

@microsoft-github-policy-service microsoft-github-policy-service bot added the Auto-Assign Auto assign by bot label Jul 1, 2025
@microsoft-github-policy-service microsoft-github-policy-service bot added the ARM az resource/group/lock/tag/deployment/policy/managementapp/account management-group label Jul 1, 2025
@microsoft-github-policy-service microsoft-github-policy-service bot added the Account az login/account label Jul 1, 2025
recommendation = (
# Cloud Shell uses IMDS-like interface for implicit login. If getting token/cert failed,
# we let the user explicitly log in to AAD with MSAL.
"Please explicitly log in with:\n{}" if error.get('error') == 'broker_error'
Copy link
Member Author

@jiasli jiasli Jul 1, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

In Cloud Shell, az account get-access-token --scope non-existing triggers a {'error': 'AudienceNotSupported', 'error_description': 'Audience non-existing is not a supported MSI token audience.'}.

error.get('error') == 'broker_error' does not match this error.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I agree with this PR. Here comes more context about the "broker_error", for posterity.

  1. In MSAL's underlying implementation, the {"error": "broker_error", ...} was a necessary placeholder to normalize Cloud Shell's potential "deceivingly successful token response containing a mismatching token type" situation. It happened that the "broker_error" value was chosen (rather than inventing a "cloud_shell_error").

  2. Now looking back, if this error handling snippet in Azure CLI was meant to pinpoint that corner case, it should have used a more precise condition, something like this:

    recommendation = (
        """You are using Cloud Shell and it does not yet support this token type request.
            Please explicitly log in with: {}"""  # But I don't quite remember whether an "az login --identity" would make a difference here
        if in_cloud_console() and error.get('error') == 'broker_error'
        else "Interactive authentication is needed. Please run:\n{}"
        ).format(login_command)
  3. Now that the differentiation in #2 is no longer needed, yes let's simplify the implementation here to remove that "A if condition else B" usage. This change feels right because, even though an interactive login will NOT address all errors (certainly not the --scope NON-EXIST wrong usage), but at least the end user shall get a better error UI when interacting with Entra ID web pages.

Copy link
Member Author

@jiasli jiasli Jul 4, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

if this error handling snippet in Azure CLI was meant to pinpoint that corner case

Yes. The error handing is indeed to pinpoint Cloud Shell's potential "deceivingly successful token response containing a mismatching token type" situation, so we can use if in_cloud_console() and error.get('error') == 'broker_error to still handle this error.

In the latest Cloud Shell, this error is no longer reproducible:

cli.azure.cli.core.auth.credential_adaptor: CredentialAdaptor.get_token: scopes=('https://pas.windows.net/CheckMyAccess/Linux/.default',), kwargs={'data': {'token_type': 'ssh-cert', ...
cli.azure.cli.core.auth.msal_credentials: CloudShellCredential.acquire_token: scopes=['https://pas.windows.net/CheckMyAccess/Linux/.default'], kwargs={'data': {'token_type': 'ssh-cert', ...
urllib3.connectionpool: Starting new HTTP connection (1): localhost:50342
urllib3.connectionpool: http://localhost:50342 "POST /oauth2/token HTTP/1.1" 200 2085
msal.token_cache: event={
    "authority_type": "CLOUDSHELL",
    "client_id": "04b07795-8ddb-461a-bbee-02f9e1bf7b46",
    "data": {
        ...
        "token_type": "ssh-cert"
    },
    "response": {
        ...
        "token_type": "ssh-cert"
    },
    "scope": [
        "https://pas.windows.net/CheckMyAccess/Linux/.default"
    ],
    "token_endpoint": "https://login.microsoftonline.com/common/oauth2/v2.0/token"
}
cli.azext_ssh.custom: Generating certificate /tmp/aadsshcertddj67t98/id_rsa.pub-aadcert.pub

The token_type in the response does match the token_type in the request, so there is no need to keep this error handing logic.

# we let the user explicitly log in to AAD with MSAL.
"Please explicitly log in with:\n{}" if error.get('error') == 'broker_error'
else "Interactive authentication is needed. Please run:\n{}").format(login_command)
recommendation = ("Interactive authentication is needed. "
Copy link
Member Author

@jiasli jiasli Jul 2, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Without broker, the raw MSAL error (retrieved with #31746) in az account get-access-token --tenant 54826b22-38d6-4fb2-bad9-b7b93a3e9c5a --debug is

{
    "error": "invalid_grant",
    "error_description": "AADSTS50076: Due to a configuration change made by your administrator, or because you moved to a new location, you must use multi-factor authentication to access '797f4846-ba00-4fd7-ba43-dac1f8f63013'. Trace ID: 660478d8-34f9-4df6-ad18-d944abab5100 Correlation ID: 6a3b809c-592f-4dd4-8a2f-30e7fe643309 Timestamp: 2025-07-02 09:02:58Z",
    "error_codes": [50076],
    "timestamp": "2025-07-02 09:02:58Z",
    "trace_id": "660478d8-34f9-4df6-ad18-d944abab5100",
    "correlation_id": "6a3b809c-592f-4dd4-8a2f-30e7fe643309",
    "error_uri": "https://login.microsoftonline.com/error?code=50076",
    "suberror": "basic_action",
    "classification": "basic_action",
}

With WAM, the raw MSAL error in az account get-access-token --tenant 54826b22-38d6-4fb2-bad9-b7b93a3e9c5a --debug is

{
    "error": "broker_error",
    "error_description": "SubError: basic_action V2Error: invalid_grant AADSTS50076: Due to a configuration change made by your administrator, or because you moved to a new location, you must use multi-factor authentication to access '797f4846-ba00-4fd7-ba43-dac1f8f63013'. Trace ID: 2cabc6ba-9c4d-403c-8341-ce0d629a0000 Correlation ID: 23cddf21-bd93-4b5d-96f1-7b5bb91fbba8 Timestamp: 2025-07-02 09:16:06Z. Status: Response_Status.Status_InteractionRequired, Error code: 3399614476, Tag: 557973645",
    "msal_telemetry": '{"msalruntime_telemetry":{"DATA LIMITED":"Full MSALRuntime telemetry not yet implemented","api_error_context":"Error context redacted, value may be written to log.","api_name":"AcquireTokenSilently","api_status_code":"StatusInternal::InteractionRequired","broker_app_used":"true","client_id":"04b07795-8ddb-461a-bbee-02f9e1bf7b46","correlation_id":"23cddf21-bd93-4b5d-96f1-7b5bb91fbba8","is_successful":"false","msal_version":"1.1.0+local","msalruntime_version":"0.18.1"},"msal_python_telemetry":null}',
}

Response_Status.Status_InteractionRequired is only mentioned in the WAM flow, so we have no way to tell if interaction is required.

@jiasli jiasli changed the title {Auth} Update re-authentication message {Auth} Remove broker_error detection for re-authentication message Jul 3, 2025
@jiasli jiasli marked this pull request as ready for review July 3, 2025 09:16
@jiasli jiasli requested review from bebound and evelyn-ys as code owners July 3, 2025 09:16
@jiasli jiasli requested a review from rayluo July 3, 2025 09:16
@jiasli jiasli merged commit bb2b31a into Azure:dev Jul 4, 2025
48 checks passed
@jiasli jiasli deleted the reauth branch July 4, 2025 09:51
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Account az login/account ARM az resource/group/lock/tag/deployment/policy/managementapp/account management-group Auto-Assign Auto assign by bot

Projects

None yet

Development

Successfully merging this pull request may close these issues.

7 participants