Azure / Azure/azure-powershell
Connect-AzAccount - VSCode Remote-SSH - pwsh
- Dominant language
- C#
- Stars
- 4.8k
- Forks
- 4.3k
- Avg merge
- 2d 17h
- Merged PRs (30d)
- 51
Description
### Description
When using `Connect-AzAccount` the following is produced:
```
WARNING: Interactive authentication is not supported in this session, please run cmdlet 'Connect-AzAccount -UseDeviceAuthentication'.
```
My setup is the following:
- Local Machine
- OS: Windows 11
- VSCode Remote-SSH
- Remote Machine
- OS: RHEL 9
- VSCode Server via VSCode Remote-SSH
VSCode Remote-SSH will open `xdg-open` from the remote machine to my local machine browser
I was able to track down the issue to this function which would return false in my case because there is no DISPLAY, this is a SSH connection.
https://github.com/Azure/azure-powershell/blob/784c5e04022795d7c70b2e3a23bb2e57caf21c8f/src/Accounts/Accounts/Account/ConnectAzureRmAccount.cs#L510-L514
https://github.com/Azure/azure-powershell/blob/784c5e04022795d7c70b2e3a23bb2e57caf21c8f/src/Accounts/Authentication/Utilities/CommonUtilities.cs#L28-L36
I think these common utilities check could be remove and rely on Microsoft.Identity.Client exception throwing if its unable to open interactively.
https://github.com/AzureAD/microsoft-authentication-library-for-dotnet/blob/f9253a67e69d4c34f30d26063006d6f788d71591/src/client/Microsoft.Identity.Client/Platforms/netcore/NetCorePlatformProxy.cs#L189-L228
A workaround is as simple as setting `$env:DISPLAY = ":0.0"` before running `Connect-AzAccount`. I just set this up in `~/.config/powershell/profile.ps1` so it is always loaded.
### Issue script & Debug output
```PowerShell
Connect-AzAccount
DEBUG: 1:59:29 PM - [ConfigManager] Got nothing from [DisplaySecretsWarning], Module = [], Cmdlet = []. Returning default value [False].
DEBUG: 1:59:29 PM - ConnectAzureRmAccountCommand begin processing with ParameterSet 'UserWithSubscriptionId'.
DEBUG: 1:59:29 PM - [ConfigManager] Got nothing from [DisplayBreakingChangeWarning], Module = [], Cmdlet = []. Returning default value [True].
DEBUG: 1:59:29 PM - [ConfigManager] Got nothing from [DefaultSubscriptionForLogin], Module = [], Cmdlet = []. Returning default value [].
WARNING: Interactive authentication is not supported in this session, please run cmdlet 'Connect-AzAccount -UseDeviceAuthentication'.
DEBUG: 1:59:29 PM - [ConfigManager] Got nothing from [DisplayRegionIdentified], Module = [], Cmdlet = []. Returning default value [True].
DEBUG: 1:59:29 PM - [ConfigManager] Got nothing from [CheckForUpgrade], Module = [], Cmdlet = []. Returning default value [True].
DEBUG: AzureQoSEvent: Module: Az.Accounts:2.19.0; CommandName: Connect-AzAccount; PSVersion: 7.4.2; IsSuccess: True; Duration: 00:00:00.0037181
DEBUG: 1:59:29 PM - [ConfigManager] Got nothing from [EnableDataCollection], Module = [], Cmdlet = []. Returning default value [True].
DEBUG: 1:59:29 PM - ConnectAzureRmAccountCommand end processing.
```
### Environment data
```PowerShell
Name Value
---- -----
PSVersion 7.4.2
PSEdition Core
GitCommitId 7.4.2
OS Red Hat Enterprise Linux 9.2 (Plow)
Platform Unix
PSCompatibleVersions {1.0, 2.0, 3.0, 4.0…}
PSRemotingProtocolVersion 2.3
SerializationVersion 1.1.0.1
WSManStackVersion 3.0
```
### Module versions
```PowerShell
ModuleType Version PreRelease Name ExportedCommands
---------- ------- ---------- ---- ----------------
Script 2.19.0 Az.Accounts {Add-AzEnvironment, Clear-AzConfig, Clear-AzContext, Clear-AzDefault…}
```
### Error output
```PowerShell
Technically no error was produced, just a warning and exits.
```
Contributor guide
Assessment
This issue has not been assessed yet.