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

Import-AzContext - Previously create Json file won't connect to Azure. #7554

Closed
MaximoTrinidad opened this issue Oct 14, 2018 · 5 comments
Closed

Comments

@MaximoTrinidad
Copy link

Description

I use the Import-AzContext to streamline my azure connection by using the Json file I create after using the Connect-AzAccount cmdlet.

Now, I've created a new Json file using the Save-AzContext, then realized that is not accepting the credential stored in the file

Script/Steps for Reproduction

Here's the steps reproduce:

Connect-AzAccount
Save-AzContext -Path "/mnt/c/Temp/lxMyAzureContextFile.json";
Import-AzContext -Path "/mnt/c/Temp/lxMyAzureContextFile.json";
## - It returns that it's fine but...

Get-AzLocation  ##-This failed displaying a credential error
Get-AzLocation : Your Azure credentials have not been set up or have expired, please run Connect-AzureRmAccount to set up your Azure credentials.
At line:1 char:1
+ Get-AzLocation | Select-Object Name | Format-Wide
+ ~~~~~~~~~~~~~~
+ CategoryInfo          : CloseError: (:) [Get-AzLocation], ArgumentException
+ FullyQualifiedErrorId : Microsoft.Azure.Commands.ResourceManager.Cmdlets.Implementation.GetAzureLocationCmdlet

azureimportcontext_01_2018-10-14_8-53-52

Module Version

PS [58] > get-module -ListAvailable Az* | Select-Object name, version

Name                      Version
----                      -------
Az.Aks                    0.3.0
Az.AnalysisServices       0.3.0
Az.ApiManagement          0.3.0
Az.ApplicationInsights    0.3.0
Az.Automation             0.3.0
Az.Batch                  0.3.0
Az.Billing                0.3.0
Az.Cdn                    0.3.0
Az.CognitiveServices      0.3.0
Az.Compute                0.3.0
Az.Consumption            0.3.0
Az.ContainerInstance      0.3.0
Az.ContainerRegistry      0.3.0
Az.DataLakeAnalytics      0.3.0
Az.DataLakeStore          0.3.0
Az.DevTestLabs            0.3.0
Az.Dns                    0.3.0
Az.EventGrid              0.3.0
Az.EventHub               0.3.0
Az.Insights               0.3.0
Az.IotHub                 0.3.0
Az.KeyVault               0.3.0
Az.LogicApp               0.3.0
Az.MachineLearning        0.3.0
Az.MachineLearningCompute 0.3.0
Az.MarketplaceOrdering    0.3.0
Az.Media                  0.3.0
Az.Network                0.3.0
Az.NotificationHubs       0.3.0
Az.OperationalInsights    0.3.0
Az.PolicyInsights         0.3.0
Az.PowerBIEmbedded        0.3.0
Az.Profile                0.3.0
Az.RedisCache             0.3.0
Az.Relay                  0.3.0
Az.Resources              0.3.0
Az.ServiceBus             0.3.0
Az.ServiceFabric          0.3.0
Az.SignalR                0.3.0
Az.Sql                    0.3.0
Az.Storage                0.3.0
Az.StreamAnalytics        0.3.0
Az.Tags                   0.3.0
Az.TrafficManager         0.3.0
Az.UsageAggregates        0.3.0
Az.Websites               0.3.0


PS [110] >

Environment Data

PS /mnt/c/Oslo2018> $PSVersionTable

Name                           Value
----                           -----
PSVersion                      6.1.0
PSEdition                      Core
GitCommitId                    6.1.0
OS                             Linux 4.4.0-18252-Microsoft #1000-Microsoft Fri Sep 28 14:10:00 PST 2018
Platform                       Unix
PSCompatibleVersions           {1.0, 2.0, 3.0, 4.0...}
PSRemotingProtocolVersion      2.3
SerializationVersion           1.1.0.1
WSManStackVersion              3.0

Debug Output

Below is the information:

PS /mnt/c/Oslo2018> $DebugPreference='Continue'
PS /mnt/c/Oslo2018> $AzureEvent = "Oslo2018"
PS /mnt/c/Oslo2018> $AzRmInfo = Import-AzContext -Path "/mnt/c/$AzureEvent/lxPSC_AsubRMprofile.json" -Debug;

Confirm
Are you sure you want to perform this action?
Performing the operation "Set the target account, tenant, and subscription of cmdlets executed in this session to the
context stored in /mnt/c/Oslo2018/lxPSC_AsubRMprofile.json" on target "Current context".
[Y] Yes  [A] Yes to All  [N] No  [L] No to All  [S] Suspend  [?] Help (default is "Y"): A
DEBUG: 9:23:40 AM - Autosave setting from startup session: 'CurrentUser'

Confirm
Continue with this operation?
[Y] Yes  [A] Yes to All  [H] Halt Command  [S] Suspend  [?] Help (default is "Y"): A
DEBUG: 9:23:48 AM - No autosave setting detected in environment variable 'AzureRmContextAutoSave'.
DEBUG: 9:23:48 AM - Using Autosave scope 'CurrentUser'
DEBUG: 9:23:48 AM - ImportAzureRMContextCommand end processing.
DEBUG: 9:23:48 AM - ImportAzureRMContextCommand end processing.
PS /mnt/c/Oslo2018> $AzRmInfo.context | Select-Object Environment, Account;

Environment Account
----------- -------
AzureCloud  max_trinidad@hotmail.com


PS /mnt/c/Oslo2018>
PS /mnt/c/Oslo2018> Get-AzLocation -Debug;
DEBUG: 9:24:12 AM - GetAzureLocationCmdlet begin processing with ParameterSet '__AllParameterSets'.

Confirm
Continue with this operation?
[Y] Yes  [A] Yes to All  [H] Halt Command  [S] Suspend  [?] Help (default is "Y"): A
DEBUG: 9:24:15 AM - using account id 'max_trinidad@hotmail.com'...
DEBUG: [Common.Authentication]: Authenticating using Account: 'max_trinidad@hotmail.com', environment: 'AzureCloud', tenant: '04b51827-7e6c-4caa-9f59-f599c5f59a00'
DEBUG: [Common.Authentication]: Received exception Authentication error while acquiring token: '{0}'., while authenticating.
Get-AzLocation : Your Azure credentials have not been set up or have expired, please run Connect-AzureRmAccount to set up your Azure credentials.
At line:1 char:1
+ Get-AzLocation -Debug;
+ ~~~~~~~~~~~~~~~~~~~~~
+ CategoryInfo          : CloseError: (:) [Get-AzLocation], ArgumentException
+ FullyQualifiedErrorId : Microsoft.Azure.Commands.ResourceManager.Cmdlets.Implementation.GetAzureLocationCmdlet

DEBUG: AzureQoSEvent: CommandName - Get-AzLocation; IsSuccess - False; Duration - 00:00:03.7764936; Exception - System.ArgumentException: Your Azure credentials have not been set up or have expired, please run Connect-AzureRmAccount to set up your Azure credentials. ---> Microsoft.Rest.Azure.Authentication.AuthenticationException: Authentication error while acquiring token: '{0}'. ---> Microsoft.IdentityModel.Clients.ActiveDirectory.AdalSilentTokenAcquisitionException: Failed to acquire token silently as no token was found in the cache. Call method AcquireToken
   at Microsoft.IdentityModel.Clients.ActiveDirectory.Internal.Flows.AcquireTokenSilentHandler.SendTokenRequestAsync()
   at Microsoft.IdentityModel.Clients.ActiveDirectory.Internal.Flows.AcquireTokenHandlerBase.CheckAndAcquireTokenUsingBrokerAsync()
   at Microsoft.IdentityModel.Clients.ActiveDirectory.Internal.Flows.AcquireTokenHandlerBase.RunAsync()
   at Microsoft.IdentityModel.Clients.ActiveDirectory.AuthenticationContext.AcquireTokenSilentCommonAsync(String resource, ClientKey clientKey, UserIdentifier userId, IPlatformParameters parameters)
   at Microsoft.IdentityModel.Clients.ActiveDirectory.AuthenticationContext.AcquireTokenSilentAsync(String resource, String clientId, UserIdentifier userId)
   at Microsoft.Rest.Azure.Authentication.UserTokenProvider.CreateCredentialsFromCache(String clientId, String domain, String username, ActiveDirectoryServiceSettings serviceSettings, TokenCache cache)
   --- End of inner exception stack trace ---
   at Microsoft.Rest.Azure.Authentication.UserTokenProvider.CreateCredentialsFromCache(String clientId, String domain, String username, ActiveDirectoryServiceSettings serviceSettings, TokenCache cache)
   at Microsoft.Azure.Commands.Common.Authentication.Factories.AuthenticationFactory.GetServiceClientCredentials(IAzureContext context, String targetEndpoint)
   --- End of inner exception stack trace ---
   at Microsoft.Azure.Commands.Common.Authentication.Factories.AuthenticationFactory.GetServiceClientCredentials(IAzureContext context, String targetEndpoint)
   at Microsoft.Azure.Commands.Common.Authentication.Factories.ClientFactory.CreateArmClient[TClient](IAzureContext context, String endpoint)
   at Microsoft.Azure.Commands.ResourceManager.Cmdlets.SdkClient.SubscriptionSdkClient..ctor(IAzureContext context)
   at Microsoft.Azure.Commands.ResourceManager.Cmdlets.Implementation.ResourceManagerCmdletBase.get_SubscriptionSdkClient()
   at Microsoft.Azure.Commands.ResourceManager.Cmdlets.Implementation.GetAzureLocationCmdlet.ExecuteCmdlet()
   at Microsoft.WindowsAzure.Commands.Utilities.Common.AzurePSCmdlet.ProcessRecord();
DEBUG: Finish sending metric.
DEBUG: 9:24:17 AM - GetAzureLocationCmdlet end processing.
DEBUG: 9:24:18 AM - GetAzureLocationCmdlet end processing.
PS /mnt/c/Oslo2018>

Observation

Just an FYI
I'm saying that's the issue is with the Import-AzContext because I can use the "Connect-AzAccount" to connect to Azure and the continue working without any issues.

@MaximoTrinidad
Copy link
Author

Hum!! I was polishing some demos when I came up with this issue.

Thinking more... What about if the issue more with the Save-AzContext? As it's the file was newly created with that cmdlet.

:)

@markcowl
Copy link
Member

The issue is here: #7456

We will fix it, but out of curiosity, whey are you uaing save/import context rather than the context autosave feature. If you just turn on context autosave, your contexts are automatically saved and are available every time you open a new session

@markcowl
Copy link
Member

Closing as duplicate of #7456

@MaximoTrinidad
Copy link
Author

Hi @markcowl,

Hum!! Autosave! I'll try that one.

Thanks,
Max

@MaximoTrinidad
Copy link
Author

Hi @markcowl, The AutoSave works!

Thanks,
:)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants