Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[BUG] No way to set IsChainedCredential when constructing ChainedTokenCredential with token sources #47140

Open
dggsax opened this issue Nov 13, 2024 · 4 comments
Assignees
Labels
Azure.Identity Client This issue points to a problem in the data-plane of the library. customer-reported Issues that are reported by GitHub users external to the Azure organization. needs-team-attention Workflow: This issue needs attention from Azure service team or SDK team question The issue doesn't require a change to the product in order to be resolved. Most issues start as that

Comments

@dggsax
Copy link

dggsax commented Nov 13, 2024

Library name and version

Azure.Identity 1.10.4

Describe the bug

When using credential sources like AzurePowerShellCredential with a ChainedTokenCredential we are unable to leverage the exception handling logic of the Chained credential that allows it to work through the available credential sources, such as inside the AzurePowerShellCredential which throws a CredentialUnavailableException instead of whatever exception was thrown.

catch (Exception e)
{
throw scope.FailWrapAndThrow(e, isCredentialUnavailable: _isChainedCredential);
}
}
catch (Exception e)
{
throw scope.FailWrapAndThrow(e, isCredentialUnavailable: _isChainedCredential);
}

This is because the IsChainedCredential property on TokenCredentialOptions (which classes like AzurePowerShellCredentialOptions extend from) is internal (this property gets translated into the _isChainedCredential field on the credential sources which feed into the chained throwing logic)

/// <summary>
/// Gets or sets whether this credential is part of a chained credential.
/// </summary>
internal bool IsChainedCredential { get; set; }

Expected behavior

As a consumer of the ChainedTokenCredential we should be able to set that our credential sources are for chaining so that if one fails the others can be tried

Actual behavior

We are unable to set this variable by hand (what I am doing instead in the meantime is to use System.Reflection to set the _isChainedCredential field on my Token Sources, if they have the field, before I provide them to my ChainedTokenCredential instance)

Reproduction Steps

n/a

Environment

Runtime Environment:
OS Name: Mac OS X
OS Version: 14.7
OS Platform: Darwin
RID: osx-arm64
Base Path: /usr/local/share/dotnet/sdk/8.0.300/

@github-actions github-actions bot added Azure.Identity Client This issue points to a problem in the data-plane of the library. customer-reported Issues that are reported by GitHub users external to the Azure organization. needs-team-attention Workflow: This issue needs attention from Azure service team or SDK team question The issue doesn't require a change to the product in order to be resolved. Most issues start as that labels Nov 13, 2024
Copy link

Thank you for your feedback. Tagging and routing to the team member best able to assist.

@dggsax
Copy link
Author

dggsax commented Nov 13, 2024

I'm now trying to run with the latest version of Azure.Identity at 1.13.1 and it looks like even with _isChainedCredential set to true on my AzurePowerShellCredential instance using System.Reflection the timeout is still getting thrown as a AuthenticationFailedException and not a CredentialUnavailableException as expected.

if (exception is OperationCanceledException || exception is AuthenticationFailedException)
{
return false;
}

Is it expected that if the exception received by TryWrapException is already an AuthenticationFailedException that it shouldn't try to wrap it even with isCredentialUnavailable parameter set to true?

@christothes
Copy link
Member

Is it expected that if the exception received by TryWrapException is already an AuthenticationFailedException that it shouldn't try to wrap it even with isCredentialUnavailable parameter set to true?

I'm surprised if you are seeing different behavior across versions in that this specific code path hasn't changed.

Looking at the code though, I'd agree that this should be treated as a bug.

I think the reason for the logic initially was to treat these exceptions differently because they may indicate that the credential was intended to succeed but failed due to timeout of permissions issues. So, the question is whether the chain should proceed no matter what until we successfully fetch a token or exhaust the chain. Looking back at the original intent of the feature, I believe this "proceed no matter what" should have been the behavior.

@dggsax
Copy link
Author

dggsax commented Nov 13, 2024

I'm surprised if you are seeing different behavior across versions in that this specific code path hasn't changed.

Ah! Sorry, should clarify, manually setting _isChainedCredential with reflection was also not working with 1.10.4 which is the version I was originally using. I updated to double check that that wasn't the reason.

For our purposes, increasinging the timeout and telling our customers to prefer Azure PowerShell will work for us in the meantime.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Azure.Identity Client This issue points to a problem in the data-plane of the library. customer-reported Issues that are reported by GitHub users external to the Azure organization. needs-team-attention Workflow: This issue needs attention from Azure service team or SDK team question The issue doesn't require a change to the product in order to be resolved. Most issues start as that
Projects
Status: Untriaged
Development

No branches or pull requests

2 participants