DefaultAzureCredentials and ChainedTokenCredential not working
See original GitHub issue- Package Name: azure-identity
- Package Version: 1.9.0
- Operating System: Linix
- Python Version: 3.6.8
Describe the bug AzureCliCredential works, but when DefaultAzureCredentials or ChainedTokenCredential are used subscription client is not able to list subscriptions
To Reproduce Azure CLI version 2.22.1 or 2.37.0
azure.identity==1.8.0 or 1.9.0
Steps to reproduce the behavior:
- Try with AzureCliCredential -
credentials = AzureCliCredential()
sub_client = SubscriptionClient(credentials,
base_url=azure_cloud.endpoints.resource_manager,
credential_scopes=[azure_cloud.endpoints.resource_manager + "/.default"])
for subscription in sub_client.subscriptions.list():
LOGGER.info("subscription: %s", subscription.display_name)
Returns subscription list.
- Try with DefaultAzureCredential as suggested by MS support -
credentials = DefaultAzureCredential(exclude_interactive_browser_credential=False)
Error seen -
EnvironmentCredential.get_token failed: EnvironmentCredential authentication unavailable. Environment variables are not fully configured.
- Try with only Azure CLI and managed identity to be included -
credentials = DefaultAzureCredential(
exclude_environment_credential=True,
exclude_managed_identity_credential=False,
exclude_visual_studio_code_credential=True,
exclude_cli_credential=False,
exclude_interactive_browser_credential=False
)
or
managed_identity = ManagedIdentityCredential()
azure_cli = AzureCliCredential()
credentials = ChainedTokenCredential(managed_identity, azure_cli)
Subscription list doesn’t return anything.
Expected behavior The following code should be able to list the subscriptions that the user or managed identity has access to.
managed_identity = ManagedIdentityCredential()
azure_cli = AzureCliCredential()
credentials = ChainedTokenCredential(managed_identity, azure_cli)
sub_client = SubscriptionClient(credentials,
base_url=azure_cloud.endpoints.resource_manager,
credential_scopes=[azure_cloud.endpoints.resource_manager + "/.default"])
for subscription in sub_client.subscriptions.list():
LOGGER.info("subscription: %s", subscription.display_name)
Issue Analytics
- State:
- Created a year ago
- Comments:7 (3 by maintainers)
Top Results From Across the Web
DefaultAzureCredential failed to retrieve a token
Solution. In order to solve this issue in a local machine: Add Active Directory app registration on Azure. Create access policy for this...
Read more >Azure Java SDK - ChainedTokenCredential not switching to ...
ChainedTokenCredential is not switching from System Assigned Managed Identity to ... DefaultAzureCredential defaultAzureCredential = new ...
Read more >DefaultAzureCredential failed to retrieve a token from the ...
this issue. ManagedIdentityCredential: ManagedIdentityCredential authentication unavailable. The requested identity has not been assigned to this resource.
Read more >Azure Identity 301 - ChainedTokenCredential - Jon Gallant
In Azure Identity 101, we learned about DefaultAzureCredential , which allows you to quickly add authentication to your application with a ...
Read more >Azure Identity client library for Python - NET
... refer to https://github.com/Azure/azure-sdk-for-python/issues/20691 ... DefaultAzureCredential and AzureCliCredential can authenticate as the user ...
Read more >Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start FreeTop Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
Top GitHub Comments
I think we will go with the workaround of using azure cli first. The workstation VM had a managed identity and I think that is what was causing the issues, since I wasn’t expecting any associated with the VM.
Hi @swathi-c, since you haven’t asked that we “
/unresolve
” the issue, we’ll close this out. If you believe further discussion is needed, please add a comment “/unresolve
” to reopen the issue.