Azure / Azure/azure-powershell

Azure.CLI Authentication timeout

Open
#19,955 8 comments 1 reaction 1 assignee Claimed by @dingmeng-xue View on GitHub
Accounts bug customer-reported needs-team-attention
Dominant language
C#
Stars
4.8k
Forks
4.3k
Avg merge
2d 17h
Merged PRs (30d)
51

Description

### Description

When using Azure.Powershell > 7.5.0, downstream systems attempting to obtain a token from ManagedIdentityCredential sometimes times out.

In example using Azure.identity 1.7.0 from a c# program shows the following:

`Azure PowerShell authentication timed out.`

Downgrading to 7.5.0 seems to resolve the issue.

Follows from this issue:

https://github.com/Azure/azure-sdk-for-net/issues/31872

### Issue script & Debug output

```PowerShell
Working Example:

Starting: Run App
==============================================================================
Task : Azure PowerShell
Description : Run a PowerShell script within an Azure environment
Version : 5.209.0
Author : Microsoft Corporation
Help : https://aka.ms/azurepowershelltroubleshooting
==============================================================================
Generating script.
========================== Starting Command Output ===========================
"C:\Windows\System32\WindowsPowerShell\v1.0\powershell.exe" -NoLogo -NoProfile -NonInteractive -ExecutionPolicy Unrestricted -Command ". 'D:\a\_temp\f0f1c6c7-29b0-41e6-860e-bae07cf5d1aa.ps1'"
Added TLS 1.2 in session.
Import-Module -Name C:\Modules\az_7.5.0\Az.Accounts\2.9.1\Az.Accounts.psd1 -Global
WARNING: Both Az and AzureRM modules were detected on this machine. Az and AzureRM modules cannot be imported in the
same session or used in the same script or runbook. If you are running PowerShell in an environment you control you can
use the 'Uninstall-AzureRm' cmdlet to remove all AzureRm modules from your machine. If you are running in Azure
Automation, take care that none of your runbooks import both Az and AzureRM modules. More information can be found
here: https://aka.ms/azps-migration-guide
Clear-AzContext -Scope CurrentUser -Force -ErrorAction SilentlyContinue
Clear-AzContext -Scope Process
Connect-AzAccount -ServicePrincipal -Tenant TenantID -Credential System.Management.Automation.PSCredential -Environment AzureCloud @processScope
Set-AzContext -SubscriptionId SubscriptionID -TenantId TenantID

----------------------------------------------------------------------
Not Working Example (Using latest):

==============================================================================
Task : Azure PowerShell
Description : Run a PowerShell script within an Azure environment
Version : 5.209.0
Author : Microsoft Corporation
Help : https://aka.ms/azurepowershelltroubleshooting
==============================================================================
Az version 8.3.0 not avaiable locally on the agent. Downloading dynamically.

7-Zip [64] 16.00 : Copyright (c) 1999-2016 Igor Pavlov : 2016-05-10

Scanning the drive for archives:
1 file, 67255559 bytes (65 MiB)

Extracting archive: C:\Modules\az_8.3.0.zip
--
Path = C:\Modules\az_8.3.0.zip
Type = zip
Physical Size = 67255559

Everything is Ok

Folders: 81
Files: 1282
Size: 319427095
Compressed: 67255559
Generating script.
========================== Starting Command Output ===========================
"C:\Windows\System32\WindowsPowerShell\v1.0\powershell.exe" -NoLogo -NoProfile -NonInteractive -ExecutionPolicy Unrestricted -Command ". 'D:\a\_temp\4ad8c730-46e6-4eaf-8cee-5520d82506b8.ps1'"
Added TLS 1.2 in session.
Import-Module -Name C:\Modules\az_8.3.0\Az.Accounts\2.10.0\Az.Accounts.psd1 -Global
WARNING: Both Az and AzureRM modules were detected on this machine. Az and AzureRM modules cannot be imported in the
same session or used in the same script or runbook. If you are running PowerShell in an environment you control you can
use the 'Uninstall-AzureRm' cmdlet to remove all AzureRm modules from your machine. If you are running in Azure
Automation, take care that none of your runbooks import both Az and AzureRM modules. More information can be found
here: https://aka.ms/azps-migration-guide
Clear-AzContext -Scope CurrentUser -Force -ErrorAction SilentlyContinue
Clear-AzContext -Scope Process
Connect-AzAccount -ServicePrincipal -Tenant TenantID -Credential System.Management.Automation.PSCredential -Environment AzureCloud @processScope
Set-AzContext -SubscriptionId SubscriptionID -TenantId TenantID
--.Net App runs here, attempts to connect to a resource using the managed identity
Azure CLI authentication timed out.
```

### Environment data

```PowerShell
Using Azure Agents, windows-latest

https://github.com/actions/runner-images/blob/main/images/win/Windows2022-Readme.md
```

### Module versions

```PowerShell
Information is in the above windows image.
```

### Error output

```PowerShell
Error is internal to Azure.Identity.
```

Contributor guide

Open the contributing guide

Assessment

This issue has not been assessed yet.

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.