Skip to content

{Auth} Do not show re-authentication message for service principal and managed identity#31745

Open
jiasli wants to merge 1 commit intoAzure:devfrom
jiasli:reauth-sp
Open

{Auth} Do not show re-authentication message for service principal and managed identity#31745
jiasli wants to merge 1 commit intoAzure:devfrom
jiasli:reauth-sp

Conversation

@jiasli
Copy link
Copy Markdown
Member

@jiasli jiasli commented Jul 1, 2025

Description
Currently, the re-authentication message is also shown for service principals:

> az login --service-principal --username aaa --password bbb --tenant 54826b22-38d6-4fb2-bad9-b7b93a3e9c5a
AADSTS700016: Application with identifier 'aaa' was not found in the directory 'AzureSDKTeam'. This can happen if the application has not been installed by the administrator of the tenant or consented to by any user in the tenant. You may have sent your authentication request to the wrong tenant. Trace ID: 7314ce0e-cf06-46cd-a37d-ec0549841f00 Correlation ID: b279ed29-07ef-4bce-907a-40ae377e50a4 Timestamp: 2025-07-01 09:47:03Z
Interactive authentication is needed. Please run:
az login

and managed identity:

> az login --identity --client-id xxx
Identity not found
Interactive authentication is needed. Please run:
az login

This is incorrect and meaningless.

This PR changes behavior so that the re-authentication message with a bare az login is not shown for service principal:

> az login --service-principal --username aaa --password bbb --tenant 54826b22-38d6-4fb2-bad9-b7b93a3e9c5a
AADSTS700016: Application with identifier 'aaa' was not found in the directory 'AzureSDKTeam'. This can happen if the application has not been installed by the administrator of the tenant or consented to by any user in the tenant. You may have sent your authentication request to the wrong tenant. Trace ID: dc386116-460c-4e36-8235-a12e5a762900 Correlation ID: cc78e339-9d82-4c18-9af8-d47802edab6b Timestamp: 2025-07-01 09:50:11Z

or managed identity:

> az login --identity --client-id xxx
Identity not found

For Cloud Shell, we still show the re-authentication message as a fallback (explicit login) in case of failure:

check_result(result, scopes=scopes)

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

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
Copy Markdown

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

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

@yonzhan
Copy link
Copy Markdown
Collaborator

yonzhan commented Jul 1, 2025

Thank you for your contribution! We will review the pull request and get back to you soon.

@github-actions
Copy link
Copy Markdown

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 Account az login/account label Jul 1, 2025
@jiasli jiasli marked this pull request as ready for review July 7, 2025 06:44
Copilot AI review requested due to automatic review settings July 7, 2025 06:44
@jiasli jiasli requested review from bebound and evelyn-ys as code owners July 7, 2025 06:44
Copy link
Copy Markdown
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

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

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 recommendation to None by default
  • Change the else branch to elif kwargs so 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_handler when called with no kwargs to verify that recommendation remains None for service principal and managed identity error paths.
    recommendation = None

if error_codes and 7000215 in error_codes:
recommendation = PASSWORD_CERTIFICATE_WARNING
else:
elif kwargs:
Copy link

Copilot AI Jul 7, 2025

Choose a reason for hiding this comment

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

[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.

Suggested change
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:

Copilot uses AI. Check for mistakes.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Account az login/account act-identity-squad Auto-Assign Auto assign by bot

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants