Skip to content

[Identity] Improve WorkloadIdentityCredential/DAC diagnosability - #42346

Merged
pvaneck merged 2 commits into
Azure:mainfrom
pvaneck:identity-workload-identity
Aug 5, 2025
Merged

[Identity] Improve WorkloadIdentityCredential/DAC diagnosability#42346
pvaneck merged 2 commits into
Azure:mainfrom
pvaneck:identity-workload-identity

Conversation

@pvaneck

@pvaneck pvaneck commented Aug 4, 2025

Copy link
Copy Markdown
Member

The goal here is to have WorkloadIdentityCredential be reported in the final error message as an attempted credential.

A substitute credential for credentials that fail to construct has been added and used in the WorkloadIdentityCredential case. This will allow the reason WorkloadIdentityCredential can't be used to be propagated to the user.

An error message like the following will now be printed with the reason WorkloadIdentityCredential was not attempted.

Attempted credentials:
        EnvironmentCredential: EnvironmentCredential authentication unavailable. Environment variables are not fully configured.
Visit https://aka.ms/azsdk/python/identity/environmentcredential/troubleshoot to troubleshoot this issue.
        WorkloadIdentityCredential: WorkloadIdentityCredential authentication unavailable. The workload options are not fully configured. See the troubleshooting guide for more information: https://aka.ms/azsdk/python/identity/workloadidentitycredential. Missing required arguments: 'tenant_id', 'client_id', 'token_file_path'.
        ManagedIdentityCredential: ManagedIdentityCredential authentication unavailable. The requested identity has not been assigned to this resource. Error: Unexpected response "{'error': 'invalid_request', 'error_description': 'Identity not found'}"
        SharedTokenCacheCredential: SharedTokenCacheCredential authentication unavailable. No accounts were found in the cache.
...
To mitigate this issue, please refer to the troubleshooting guidelines here at https://aka.ms/azsdk/python/identity/defaultazurecredential/troubleshoot.

Closes: #42075

@pvaneck
pvaneck force-pushed the identity-workload-identity branch from ff21cfe to a812205 Compare August 4, 2025 23:26
@pvaneck pvaneck changed the title [Identity] Improve WorkloadIdentityCredentia/DAC diagnosability [Identity] Improve WorkloadIdentityCredential/DAC diagnosability Aug 4, 2025
@pvaneck
pvaneck force-pushed the identity-workload-identity branch from a812205 to 420d0b8 Compare August 4, 2025 23:29
@pvaneck
pvaneck marked this pull request as ready for review August 4, 2025 23:56
Copilot AI review requested due to automatic review settings August 4, 2025 23:56
@pvaneck
pvaneck requested review from a team and xiangyan99 as code owners August 4, 2025 23:56

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

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 improves error diagnostics for the WorkloadIdentityCredential within the DefaultAzureCredential chain by introducing a substitute credential mechanism that captures initialization errors and reports them in the final error message when credential acquisition fails.

  • Introduces FailedDACCredential and AsyncFailedDACCredential classes to capture and report initialization errors
  • Updates error message generation logic to use custom credential names from failed credential instances
  • Modifies WorkloadIdentityCredential error handling to provide more informative error messages with troubleshooting guidance

Reviewed Changes

Copilot reviewed 8 out of 8 changed files in this pull request and generated 2 comments.

Show a summary per file
File Description
azure/identity/_credentials/default.py Adds FailedDACCredential class and error handling for WorkloadIdentityCredential initialization
azure/identity/aio/_credentials/default.py Adds async version AsyncFailedDACCredential and corresponding error handling
azure/identity/_credentials/workload_identity.py Updates error messages to use standardized format with troubleshooting guidance
azure/identity/aio/_credentials/workload_identity.py Updates async version with same standardized error messages
azure/identity/_credentials/chained.py Modifies error message generation to support custom credential names
tests/test_default.py Adds comprehensive tests for the new failed credential functionality
tests/test_default_async.py Adds async tests for the new failed credential functionality
CHANGELOG.md Documents the improvement in diagnostics

Comment thread sdk/identity/azure-identity/azure/identity/_credentials/default.py Outdated
Comment thread sdk/identity/azure-identity/azure/identity/aio/_credentials/default.py Outdated
pvaneck and others added 2 commits August 5, 2025 17:33
The goal here is to have WorkloadIdentityCredential be reported in the
the final error message as an attempted credential.

A substitute credential for credentials that fail to construct has been
added and used in the WorkloadIdentityCredential case. This will allow
the reason WorkloadIdentityCredential can't be used to be propagated to
the user.

Signed-off-by: Paul Van Eck <paulvaneck@microsoft.com>
Co-authored-by: Copilot <175728472+Copilot@users.noreply.github.com>
@pvaneck
pvaneck force-pushed the identity-workload-identity branch from 086953f to 6aab953 Compare August 5, 2025 17:34
@pvaneck
pvaneck requested a review from xiangyan99 August 5, 2025 18:13
@github-project-automation github-project-automation Bot moved this from Untriaged to In Progress in Azure Identity SDK Improvements Aug 5, 2025
@pvaneck
pvaneck merged commit 992c402 into Azure:main Aug 5, 2025
21 checks passed
@github-project-automation github-project-automation Bot moved this from In Progress to Done in Azure Identity SDK Improvements Aug 5, 2025
@pvaneck
pvaneck deleted the identity-workload-identity branch August 5, 2025 18:33
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

Development

Successfully merging this pull request may close these issues.

Include information about the workload identity credential in the DAC, even if it is unavailable.

3 participants