Azure / azure-powershell

Microsoft Azure PowerShell
Other
4.21k stars 3.82k forks source link

Azure credentials have not been set up or have expired #16037

Open TheOnlyWei opened 2 years ago

TheOnlyWei commented 2 years ago

Description

I am running Azure Stack Hub. After logging in and calling Get-AzResourceGroup

Getting this error: Get-AzResourceGroup: Your Azure credentials have not been set up or have expired, please run Connect-AzAccount to set up your Azure credentials.

The solution is to call: Clear-AzContext -Scope CurrentUser -Force Clear-AzContext -Scope Process -Force

Steps to reproduce

Have many contexts in get-azcontext -ListAvailable. I was using an environment where I had 3 contexts for 3 different accounts, there were also many many contexts for other azure stack environments as well as azure cloud. We think the root cause might be that MSAL might be confusing different contexts with each other. The debug error contains this:

Exception: Azure.Identity.CredentialUnavailableException (0x80131500): SharedTokenCacheCredential authentication unavailable. Multiple accounts matching the specified username: CloudAdmin@azs-long05-int.selfhost.corp.microsoft.com tenantId: adfs were found in the cache

This seems to indicate that something thinks there are multiple CloudAdmin@azs-long05-int.selfhost.corp.microsoft.com accounts, but there is only one. Log into said account and call Get-AzResourceGroup and get the error below:

Get-AzResourceGroup: Your Azure credentials have not been set up or have expired, please run Connect-AzAccount to set up your Azure credentials.

Environment data

PS C:\Users\weshi1> $PSVersionTable

Name                           Value
----                           -----
PSVersion                      7.1.4
PSEdition                      Core
GitCommitId                    7.1.4
OS                             Microsoft Windows 10.0.19043
Platform                       Win32NT
PSCompatibleVersions           {1.0, 2.0, 3.0, 4.0…}
PSRemotingProtocolVersion      2.3
SerializationVersion           1.1.0.1
WSManStackVersion              3.0

Module versions

PS C:\Users\weshi1> Get-Module  -ListAvailable

    Directory: C:\Users\weshi1\Documents\PowerShell\Modules

ModuleType Version    PreRelease Name                                PSEdition ExportedCommands
---------- -------    ---------- ----                                --------- ----------------
Script     1.10.0                Az                                  Core,Desk
Script     2.2.8                 Az.Accounts                         Core,Desk {Disable-AzDataCollection, Disable-AzContex…
Script     0.11.0                Az.Billing                          Core,Desk Get-UsageAggregates
Script     1.0.1                 Az.BootStrapper                     Core,Desk {Update-AzProfile, Uninstall-AzProfile, Ins…
Script     3.3.0                 Az.Compute                          Core,Desk {Remove-AzAvailabilitySet, Get-AzAvailabili…
Script     1.1.0                 Az.DataBoxEdge                      Core,Desk {Get-AzDataBoxEdgeJob, Get-AzDataBoxEdgeDev…
Script     0.11.0                Az.Dns                              Core,Desk {Get-AzDnsRecordSet, New-AzDnsRecordConfig,…
Script     1.4.3                 Az.EventHub                         Core,Desk {New-AzEventHubNamespace, Get-AzEventHubNam…
Script     0.11.0                Az.IotHub                           Core,Desk {Add-AzIotHubKey, Get-AzIotHubEventHubConsu…
Script     0.11.0                Az.KeyVault                         Core,Desk {Add-AzKeyVaultCertificate, Set-AzKeyVaultC…
Script     1.6.0                 Az.Monitor                          Core,Desk {Get-AzMetricDefinition, Get-AzMetric, Remo…
Script     1.2.2                 Az.Network                          Core,Desk {Add-AzApplicationGatewayAuthenticationCert…
Script     0.11.0                Az.Resources                        Core,Desk {Get-AzProviderOperation, Remove-AzRoleAssi…
Script     2.6.2                 Az.Storage                          Core,Desk {Get-AzStorageAccount, Get-AzStorageAccount…
Script     0.11.0                Az.Websites                         Core,Desk {Get-AzAppServicePlan, Set-AzAppServicePlan…
Script     1.0.1                 Azs.Azurebridge.Admin               Core,Desk {Get-AzsAzureBridgeActivation, Get-AzsAzure…
Script     1.0.1                 Azs.Backup.Admin                    Core,Desk {Get-AzsBackup, Get-AzsBackupConfiguration,…
Script     1.0.1                 Azs.Commerce.Admin                  Core,Desk Get-AzsSubscriberUsage
Script     1.0.1                 Azs.Compute.Admin                   Core,Desk {Add-AzsPlatformImage, Add-AzsVMExtension, …
Script     1.0.0                 Azs.Deployment.Admin                Core,Desk {Get-AzsFileContainer, Get-AzsProductDeploy…
Script     1.0.1                 Azs.Fabric.Admin                    Core,Desk {Add-AzsScaleUnitNode, Disable-AzsScaleUnit…
Script     1.0.1                 Azs.Gallery.Admin                   Core,Desk {Add-AzsGalleryItem, Get-AzsGalleryItem, Re…
Script     1.0.1                 Azs.Infrastructureinsights.Admin    Core,Desk {Close-AzsAlert, Get-AzsAlert, Get-AzsRegio…
Script     1.0.1                 Azs.Keyvault.Admin                  Core,Desk Get-AzsKeyvaultQuota
Script     1.0.1                 Azs.Network.Admin                   Core,Desk {Get-AzsLoadBalancer, Get-AzsNetworkAdminOv…
Script     1.0.1                 Azs.Storage.Admin                   Core,Desk {Get-AzsStorageAccount, Get-AzsStorageAcqui…
Script     1.0.1                 Azs.Subscriptions                   Core,Desk {Get-AzsDelegatedProviderOffer, Get-AzsOffe…
Script     1.0.1                 Azs.Subscriptions.Admin             Core,Desk {Add-AzsPlanToOffer, Get-AzsAcquiredPlan, G…
Manifest   0.1.157               Azs.Syndication.Admin               Desk      {Select-AzsMarketplaceItem, Export-AzsMarke…
Script     1.0.1                 Azs.Update.Admin                    Core,Desk {Get-AzsUpdate, Get-AzsUpdateLocation, Get-…
Manifest   2.1.1                 AzureStack                          Core,Desk
Script     1.0.0.8               DockerMsftProvider                  Desk
Manifest   1.2005.12… preview    Microsoft.AzureStack.ReadinessChec… Desk      {Invoke-AzsGraphValidation, Invoke-AzsADFSV…
Script     4.6.0                 Pester                              Desk      {Describe, Context, It, Should…}
Script     0.14.1                platyPS                             Desk      {New-MarkdownHelp, Get-MarkdownMetadata, Ne…

    Directory: C:\program files\powershell\7\Modules

ModuleType Version    PreRelease Name                                PSEdition ExportedCommands
---------- -------    ---------- ----                                --------- ----------------
Manifest   7.0.0.0               CimCmdlets                          Core      {Get-CimAssociatedInstance, Get-CimClass, G…
Manifest   1.2.5                 Microsoft.PowerShell.Archive        Desk      {Compress-Archive, Expand-Archive}
Manifest   7.0.0.0               Microsoft.PowerShell.Diagnostics    Core      {Get-WinEvent, New-WinEvent, Get-Counter}
Manifest   7.0.0.0               Microsoft.PowerShell.Host           Core      {Start-Transcript, Stop-Transcript}
Manifest   7.0.0.0               Microsoft.PowerShell.Management     Core      {Add-Content, Clear-Content, Get-Clipboard,…
Manifest   7.0.0.0               Microsoft.PowerShell.Security       Core      {Get-Acl, Set-Acl, Get-PfxCertificate, Get-…
Manifest   7.0.0.0               Microsoft.PowerShell.Utility        Core      {Export-Alias, Get-Alias, Import-Alias, New…
Manifest   7.0.0.0               Microsoft.WSMan.Management          Core      {Disable-WSManCredSSP, Enable-WSManCredSSP,…
Script     1.4.7                 PackageManagement                   Desk      {Find-Package, Get-Package, Get-PackageProv…
Script     2.2.5                 PowerShellGet                       Desk      {Find-Command, Find-DSCResource, Find-Modul…
Script     2.0.5                 PSDesiredStateConfiguration         Core      {Configuration, New-DscChecksum, Get-DscRes…
Script     7.0.0.0               PSDiagnostics                       Core      {Disable-PSTrace, Disable-PSWSManCombinedTr…
Script     2.1.0                 PSReadLine                          Desk      {Get-PSReadLineKeyHandler, Set-PSReadLineKe…
Binary     2.0.3                 ThreadJob                           Desk      Start-ThreadJob

    Directory: C:\Program Files\WindowsPowerShell\Modules

ModuleType Version    PreRelease Name                                PSEdition ExportedCommands
---------- -------    ---------- ----                                --------- ----------------
Script     0.1.0      preview    Az.BootStrapper                     Core,Desk {Update-AzProfile, Uninstall-AzProfile, Ins…
Script     1.0.1                 Microsoft.PowerShell.Operation.Val… Desk      {Get-OperationValidation, Invoke-OperationV…
Script     1.4.6                 PackageManagement                   Desk      {Find-Package, Get-Package, Get-PackageProv…
Binary     1.0.0.1               PackageManagement                   Desk      {Find-Package, Get-Package, Get-PackageProv…
Script     3.4.0                 Pester                              Desk      {Describe, Context, It, Should…}
Script     2.2.1                 PowerShellGet                       Desk      {Find-Command, Find-DSCResource, Find-Modul…
Script     1.0.0.1               PowerShellGet                       Desk      {Install-Module, Find-Module, Save-Module, …
Script     2.0.0      beta2      PSReadline                          Desk      {Get-PSReadLineKeyHandler, Set-PSReadLineKe…

    Directory: C:\WINDOWS\system32\WindowsPowerShell\v1.0\Modules

ModuleType Version    PreRelease Name                                PSEdition ExportedCommands
---------- -------    ---------- ----                                --------- ----------------
Manifest   1.0.0.0               AppBackgroundTask                   Core,Desk {Disable-AppBackgroundTaskDiagnosticLog, En…
Manifest   2.0.1.0               Appx                                Core,Desk {Add-AppxPackage, Get-AppxPackage, Get-Appx…
Script     1.0.0.0               AssignedAccess                      Core,Desk {Clear-AssignedAccess, Get-AssignedAccess, …
Manifest   1.0.0.0               BitLocker                           Core,Desk {Unlock-BitLocker, Suspend-BitLocker, Resum…
Manifest   2.0.0.0               BitsTransfer                        Core,Desk {Add-BitsFile, Complete-BitsTransfer, Get-B…
Manifest   1.0.0.0               BranchCache                         Core,Desk {Add-BCDataCacheExtension, Clear-BCCache, D…
Manifest   1.0                   Defender                            Core,Desk {Get-MpPreference, Set-MpPreference, Add-Mp…
Manifest   1.0.2.0               DeliveryOptimization                Core,Desk {Delete-DeliveryOptimizationCache, Set-Deli…
Manifest   1.0.0.0               DirectAccessClientComponents        Core,Desk {Disable-DAManualEntryPointSelection, Enabl…
Script     3.0                   Dism                                Core,Desk {Add-AppxProvisionedPackage, Add-WindowsDri…
Manifest   1.0.0.0               DnsClient                           Core,Desk {Resolve-DnsName, Clear-DnsClientCache, Get…
Manifest   1.0.0.0               EventTracingManagement              Core,Desk {Start-EtwTraceSession, New-EtwTraceSession…
Manifest   1.0.0.0               HgsClient                           Core,Desk {Get-HgsAttestationBaselinePolicy, Get-HgsC…
Manifest   1.0.0.0               HgsDiagnostics                      Core,Desk {New-HgsTraceTarget, Get-HgsTrace, Get-HgsT…
Binary     2.0.0.0               Hyper-V                             Core,Desk {Add-VMAssignableDevice, Add-VMDvdDrive, Ad…
Binary     1.1                   Hyper-V                             Core,Desk {Add-VMDvdDrive, Add-VMFibreChannelHba, Add…
Manifest   2.0.0.0               International                       Core,Desk {Get-WinDefaultInputMethodOverride, Set-Win…
Manifest   1.0.0.0               Kds                                 Core,Desk {Add-KdsRootKey, Get-KdsRootKey, Test-KdsRo…
Manifest   3.0.0.0               Microsoft.PowerShell.Diagnostics    Core,Desk {Get-WinEvent, Get-Counter, Import-Counter,…
Manifest   1.0.0.0               Microsoft.PowerShell.LocalAccounts  Core,Desk {Add-LocalGroupMember, Disable-LocalUser, E…
Manifest   3.1.0.0               Microsoft.PowerShell.Management     Core,Desk {Add-Content, Clear-Content, Clear-ItemProp…
Manifest   1.0                   MMAgent                             Core,Desk {Disable-MMAgent, Enable-MMAgent, Set-MMAge…
Manifest   2.0.0.0               NetAdapter                          Core,Desk {Disable-NetAdapter, Disable-NetAdapterBind…
Manifest   1.0.0.0               NetConnection                       Core,Desk {Get-NetConnectionProfile, Set-NetConnectio…
Manifest   1.0.0.0               NetEventPacketCapture               Core,Desk {New-NetEventSession, Remove-NetEventSessio…
Manifest   2.0.0.0               NetLbfo                             Core,Desk {Add-NetLbfoTeamMember, Add-NetLbfoTeamNic,…
Manifest   1.0.0.0               NetNat                              Core,Desk {Get-NetNat, Get-NetNatExternalAddress, Get…
Manifest   2.0.0.0               NetQos                              Core,Desk {Get-NetQosPolicy, Set-NetQosPolicy, Remove…
Manifest   2.0.0.0               NetSecurity                         Core,Desk {Get-DAPolicyChange, New-NetIPsecAuthPropos…
Manifest   1.0.0.0               NetSwitchTeam                       Core,Desk {New-NetSwitchTeam, Remove-NetSwitchTeam, G…
Manifest   1.0.0.0               NetTCPIP                            Core,Desk {Get-NetIPAddress, Get-NetIPInterface, Get-…
Manifest   1.0.0.0               NetworkConnectivityStatus           Core,Desk {Get-DAConnectionStatus, Get-NCSIPolicyConf…
Manifest   1.0.0.0               NetworkSwitchManager                Core,Desk {Disable-NetworkSwitchEthernetPort, Enable-…
Manifest   1.0.0.0               NetworkTransition                   Core,Desk {Add-NetIPHttpsCertBinding, Disable-NetDnsT…
Manifest   1.0.0.0               PcsvDevice                          Core,Desk {Get-PcsvDevice, Start-PcsvDevice, Stop-Pcs…
Manifest   1.0.0.0               PKI                                 Core,Desk {Add-CertificateEnrollmentPolicyServer, Exp…
Manifest   1.0.0.0               PnpDevice                           Core,Desk {Get-PnpDevice, Get-PnpDeviceProperty, Enab…
Manifest   1.1                   PrintManagement                     Core,Desk {Add-Printer, Add-PrinterDriver, Add-Printe…
Binary     1.0.12                ProcessMitigations                  Core,Desk {Get-ProcessMitigation, Set-ProcessMitigati…
Script     3.0                   Provisioning                        Core,Desk {Install-ProvisioningPackage, Export-Provis…
Manifest   1.0.0.0               ScheduledTasks                      Core,Desk {Get-ScheduledTask, Set-ScheduledTask, Regi…
Manifest   2.0.0.0               SecureBoot                          Core,Desk {Confirm-SecureBootUEFI, Set-SecureBootUEFI…
Manifest   2.0.0.0               SmbShare                            Core,Desk {Get-SmbShare, Remove-SmbShare, Set-SmbShar…
Manifest   2.0.0.0               SmbWitness                          Core,Desk {Get-SmbWitnessClient, Move-SmbWitnessClien…
Manifest   1.0.0.1               StartLayout                         Core,Desk {Export-StartLayout, Import-StartLayout, Ex…
Manifest   2.0.0.0               Storage                             Core,Desk {Add-InitiatorIdToMaskingSet, Add-Partition…
Manifest   2.0.0.0               TLS                                 Core,Desk {New-TlsSessionTicketKey, Enable-TlsSession…
Manifest   1.0.0.0               TroubleshootingPack                 Core,Desk {Get-TroubleshootingPack, Invoke-Troublesho…
Manifest   2.0.0.0               TrustedPlatformModule               Core,Desk {Get-Tpm, Initialize-Tpm, Clear-Tpm, Unbloc…
Binary     2.1.639.0             UEV                                 Core,Desk
Manifest   2.0.0.0               VpnClient                           Core,Desk {Add-VpnConnection, Set-VpnConnection, Remo…
Manifest   1.0.0.0               Wdac                                Core,Desk {Get-OdbcDriver, Set-OdbcDriver, Get-OdbcDs…
Manifest   2.0.0.0               Whea                                Core,Desk {Get-WheaMemoryPolicy, Set-WheaMemoryPolicy}
Manifest   1.0.0.0               WindowsDeveloperLicense             Core,Desk {Get-WindowsDeveloperLicense, Unregister-Wi…
Script     1.0                   WindowsErrorReporting               Core,Desk {Enable-WindowsErrorReporting, Disable-Wind…
Manifest   1.0.0.0               WindowsSearch                       Core,Desk {Get-WindowsSearchSetting, Set-WindowsSearc…
Manifest   1.0.0.0               WindowsUpdate                       Core,Desk Get-WindowsUpdateLog
Manifest   1.0.0.2               WindowsUpdateProvider               Core,Desk {Get-WUAVersion, Get-WULastInstallationDate…

    Directory: C:\Program Files (x86)\Microsoft Azure Information Protection\Powershell

ModuleType Version    PreRelease Name                                PSEdition ExportedCommands
---------- -------    ---------- ----                                --------- ----------------
Binary     2.6.111.0             AzureInformationProtection          Desk

Debug output

PS C:\Users\weshi1\.Azure> Connect-AzAccount -EnvironmentName "longhaul5" -TenantId "3a38509d-79d8-4516-9282-df14fc0adf15" -SubscriptionId "6cf9e4d3-0c29-4dfc-8c70-cc37b94de146"
DEBUG: 5:16:34 PM - ConnectAzureRmAccountCommand begin processing with ParameterSet 'UserWithSubscriptionId'.
DEBUG: 5:16:34 PM - Autosave setting from startup session: 'CurrentUser'
DEBUG: 5:16:34 PM - No autosave setting detected in environment variable 'AzContextAutoSave'.
DEBUG: 5:16:34 PM - Using Autosave scope 'CurrentUser'
DEBUG: 5:16:34 PM - Autosave setting from startup session: 'CurrentUser'
DEBUG: 5:16:34 PM - No autosave setting detected in environment variable 'AzContextAutoSave'.
DEBUG: 5:16:34 PM - Using Autosave scope 'CurrentUser'
DEBUG: 5:16:34 PM - [InteractiveUserAuthenticator] Calling InteractiveBrowserCredential.AuthenticateAsync with TenantId:'adfs', Scopes:'https://adminmanagement.adfs.azs-long05-int.selfhost.corp.microsoft.com/3a38509d-79d8-4516-9282-df14fc0adf15/openid', AuthorityHost:'https://adfs.northwest.azs-longhaul-05.selfhost.corp.microsoft.com/adfs/', RedirectUri:'http://localhost:8405/'
DEBUG: InteractiveBrowserCredential.Authenticate invoked. Scopes: [ https://adminmanagement.adfs.azs-long05-int.selfhost.corp.microsoft.com/3a38509d-79d8-4516-9282-df14fc0adf15/openid ] ParentRequestId:
DEBUG: Request [7e4f6af2-6778-4198-a4ad-cc441a38b7e0] POST https://adfs.northwest.azs-longhaul-05.selfhost.corp.microsoft.com/adfs/oauth2/token
x-client-SKU:REDACTED
x-client-Ver:REDACTED
x-client-OS:REDACTED
x-client-current-telemetry:REDACTED
x-client-last-telemetry:REDACTED
x-ms-PKeyAuth:REDACTED
x-ms-lib-capability:REDACTED
client-request-id:REDACTED
return-client-request-id:REDACTED
x-app-name:REDACTED
x-app-ver:REDACTED
x-ms-client-request-id:7e4f6af2-6778-4198-a4ad-cc441a38b7e0
x-ms-return-client-request-id:true
User-Agent:azsdk-net-Identity/1.4.0-beta.3,(.NET 5.0.9; Microsoft Windows 10.0.19043)
Content-Type:application/x-www-form-urlencoded
client assembly: Azure.Identity
DEBUG: Response [7e4f6af2-6778-4198-a4ad-cc441a38b7e0] 200 OK (00.1s)
Cache-Control:no-store
Pragma:no-cache
Server:Microsoft-HTTPAPI/2.0
client-request-id:REDACTED
Date:Thu, 07 Oct 2021 00:16:35 GMT
Content-Length:8424
Content-Type:application/json; charset=UTF-8

DEBUG: InteractiveBrowserCredential.Authenticate succeeded. Scopes: [ https://adminmanagement.adfs.azs-long05-int.selfhost.corp.microsoft.com/3a38509d-79d8-4516-9282-df14fc0adf15/openid ] ParentRequestId:  ExpiresOn: 2021-10-07T01:16:35.0000000+00:00
DEBUG: 5:16:35 PM - [MsalAccessToken] Calling InteractiveBrowserCredential.GetTokenAsync - Scopes:'https://adminmanagement.adfs.azs-long05-int.selfhost.corp.microsoft.com/3a38509d-79d8-4516-9282-df14fc0adf15/openid'
DEBUG: InteractiveBrowserCredential.GetToken invoked. Scopes: [ https://adminmanagement.adfs.azs-long05-int.selfhost.corp.microsoft.com/3a38509d-79d8-4516-9282-df14fc0adf15/openid ] ParentRequestId:
DEBUG: InteractiveBrowserCredential.GetToken succeeded. Scopes: [ https://adminmanagement.adfs.azs-long05-int.selfhost.corp.microsoft.com/3a38509d-79d8-4516-9282-df14fc0adf15/openid ] ParentRequestId:  ExpiresOn: 2021-10-07T01:16:35.0000000+00:00
DEBUG: ============================ HTTP REQUEST ============================

HTTP Method:
GET

Absolute Uri:
https://adminmanagement.northwest.azs-longhaul-05.selfhost.corp.microsoft.com/subscriptions/6cf9e4d3-0c29-4dfc-8c70-cc37b94de146?api-version=2019-06-01

Headers:
x-ms-client-request-id        : 2976fa38-e320-46a4-abdc-6e22de85c7b1
Accept-Language               : en-US

Body:

DEBUG: ============================ HTTP RESPONSE ============================

Status Code:
OK

Headers:
Cache-Control                 : no-cache
Pragma                        : no-cache
x-ms-ratelimit-remaining-tenant-reads: 14999
x-ms-request-id               : 35f95ee6-90d4-4541-a2e1-1cb487d64555
x-ms-correlation-request-id   : 35f95ee6-90d4-4541-a2e1-1cb487d64555
x-ms-routing-request-id       : NORTHWEST:20211007T001635Z:35f95ee6-90d4-4541-a2e1-1cb487d64555
Strict-Transport-Security     : max-age=31536000; includeSubDomains
X-Content-Type-Options        : nosniff
Date                          : Thu, 07 Oct 2021 00:16:35 GMT

Body:
{
  "offerId": "/delegatedProviders/default/offers/System",
  "id": "/subscriptions/6cf9e4d3-0c29-4dfc-8c70-cc37b94de146",
  "subscriptionId": "6cf9e4d3-0c29-4dfc-8c70-cc37b94de146",
  "tenantId": "3a38509d-79d8-4516-9282-df14fc0adf15",
  "displayName": "Default Provider Subscription",
  "state": "Enabled",
  "subscriptionPolicies": {
    "locationPlacementId": "AzureStack"
  }
}

DEBUG: AzureQoSEvent: CommandName - Connect-AzAccount; IsSuccess - True; Duration - 00:00:01.1947696
DEBUG: Finish sending metric.
DEBUG: 5:16:36 PM - ConnectAzureRmAccountCommand end processing.
Account                                               SubscriptionName              TenantId                             Environment
-------                                               ----------------              --------                             -----------
CloudAdmin@azs-long05-int.selfhost.corp.microsoft.com Default Provider Subscription 3a38509d-79d8-4516-9282-df14fc0adf15 longhaul5

PS C:\Users\weshi1\.Azure> Get-AzResourceGroup
DEBUG: 5:16:40 PM - GetAzureResourceGroupCmdlet begin processing with ParameterSet 'GetByResourceGroupName'.
DEBUG: 5:16:40 PM - using account id 'CloudAdmin@azs-long05-int.selfhost.corp.microsoft.com'...
DEBUG: [Common.Authentication]: Authenticating using Account: 'CloudAdmin@azs-long05-int.selfhost.corp.microsoft.com', environment: 'longhaul5', tenant: '3a38509d-79d8-4516-9282-df14fc0adf15'
DEBUG: 5:16:40 PM - [SilentAuthenticator] Calling SharedTokenCacheCredential.GetTokenAsync - TenantId:'adfs', Scopes:'https://adminmanagement.adfs.azs-long05-int.selfhost.corp.microsoft.com/3a38509d-79d8-4516-9282-df14fc0adf15/openid', AuthorityHost:'https://adfs.northwest.azs-longhaul-05.selfhost.corp.microsoft.com/adfs/', UserId:'CloudAdmin@azs-long05-int.selfhost.corp.microsoft.com'
DEBUG: SharedTokenCacheCredential.GetToken invoked. Scopes: [ https://adminmanagement.adfs.azs-long05-int.selfhost.corp.microsoft.com/3a38509d-79d8-4516-9282-df14fc0adf15/openid ] ParentRequestId:
DEBUG: SharedTokenCacheCredential.GetToken was unable to retrieve an access token. Scopes: [ https://adminmanagement.adfs.azs-long05-int.selfhost.corp.microsoft.com/3a38509d-79d8-4516-9282-df14fc0adf15/openid ] ParentRequestId:  Exception: Azure.Identity.CredentialUnavailableException (0x80131500): SharedTokenCacheCredential authentication unavailable. Multiple accounts matching the specified username: CloudAdmin@azs-long05-int.selfhost.corp.microsoft.com tenantId: adfs were found in the cache.
DEBUG: [Common.Authentication]: Received exception SharedTokenCacheCredential authentication unavailable. Multiple accounts matching the specified username: CloudAdmin@azs-long05-int.selfhost.corp.microsoft.com tenantId: adfs were found in the cache., while authenticating.
Get-AzResourceGroup: Your Azure credentials have not been set up or have expired, please run Connect-AzAccount to set up your Azure credentials.
DEBUG: AzureQoSEvent: CommandName - Get-AzResourceGroup; IsSuccess - False; Duration - 00:00:00.0851813; Exception - Your Azure credentials have not been set up or have expired, please run Connect-AzAccount to set up your Azure credentials.;
DEBUG: Finish sending metric.
DEBUG: 5:16:41 PM - GetAzureResourceGroupCmdlet end processing.

Error output

Unfortunately, I do not know how to reproduce this error to get resolve-azerror output.

dingmeng-xue commented 2 years ago

Hi Wei, Can you reproduce this issue in your environment? Can you share your environment to us?

TheOnlyWei commented 2 years ago

@dingmeng-xue No, we don't have a consistent reproduction of this issue after I applied the fix. This is not a per environment bug, but one where if you have multiple environments/accounts, it causes weird behavior when trying to use commands like Get-AzResourceGroup. It seems like accounts are being mixed up.

I have backed up the .Azure and .IdentityService folders created during when the bug could be reproduced consistently, but I don't know where are the sensitive informations to redact, so I did not upload it.

dingmeng-xue commented 2 years ago

Hi Wei, you need to filter out all secret values from context file. Then it should be safe. In addition, we will add more debug information into Az.Accounts. Please try it when new Az.Accounts is released.