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

Fix TokenCache initialization when importing a context #7456

Closed
1 of 2 tasks
markcowl opened this issue Oct 3, 2018 · 13 comments
Closed
1 of 2 tasks

Fix TokenCache initialization when importing a context #7456

markcowl opened this issue Oct 3, 2018 · 13 comments
Assignees
Milestone

Comments

@markcowl
Copy link
Member

markcowl commented Oct 3, 2018

Description

When importing a saved context container with multiple contexts, the existing token cache should be overwritten with the token cache for the default context.

Instead, the token cache is cleared and the user must log in again.

  • Fix import logic to always overwrite token cache for the default context, if it is non-null
  • Add regression tests to ensure that non-empty context is always overwritten on import, with check s for null and empty contexts

Cost: 6

@pixelicous
Copy link

Hi, I am experiencing this issue and the workaround at #7110 is not helping me.. why solve such a critical issue on december?? all our scripts fail now!!

@MaximoTrinidad
Copy link

@markcowl

This issue need to be reopen. There's no indication it has been fix, nor which version will contain the fix.

The issue still exist with Az Module 0.5.0.

For now, the only workaround is to use the Enable-AzContextAutoSave cmdlet.

azimportcontextissue_01_2018-11-13_18-35-15

PS /home/maxt> Get-Module -ListAvailable Az*


    Directory: /usr/local/share/powershell/Modules


ModuleType Version    Name                                PSEdition ExportedCommands
---------- -------    ----                                --------- ----------------
Script     0.5.0      Az.Aks                              Core,Desk {Get-AzAks, New-AzAks, Remove-AzAks, Import-AzAk...
Script     0.5.0      Az.AnalysisServices                 Core,Desk {Resume-AzAnalysisServicesServer, Suspend-AzAnal...
Script     0.5.0      Az.ApiManagement                    Core,Desk {Add-AzApiManagementRegion, Get-AzApiManagementS...
Script     0.5.0      Az.ApplicationInsights              Core,Desk {Get-AzApplicationInsights, New-AzApplicationIns...
Script     0.5.0      Az.Automation                       Core,Desk {Get-AzAutomationHybridWorkerGroup, Get-AzAutoma...
Script     0.5.0      Az.Batch                            Core,Desk {Remove-AzBatchAccount, Get-AzBatchAccount, Get-...
Script     0.5.0      Az.Billing                          Core,Desk {Get-AzBillingInvoice, Get-AzBillingPeriod, Get-...
Script     0.5.0      Az.Cdn                              Core,Desk {Get-AzCdnProfile, Get-AzCdnProfileSsoUrl, New-A...
Script     0.5.0      Az.CognitiveServices                Core,Desk {Get-AzCognitiveServicesAccount, Get-AzCognitive...
Script     0.5.0      Az.Compute                          Core,Desk {Remove-AzAvailabilitySet, Get-AzAvailabilitySet...
Script     0.5.0      Az.Consumption                      Core,Desk {Get-AzConsumptionBudget, Get-AzConsumptionMarke...
Script     0.5.0      Az.ContainerInstance                Core,Desk {New-AzContainerGroup, Get-AzContainerGroup, Rem...
Script     0.5.0      Az.ContainerRegistry                Core,Desk {New-AzContainerRegistry, Get-AzContainerRegistr...
Script     0.5.0      Az.DataLakeAnalytics                Core,Desk {Get-AzDataLakeAnalyticsDataSource, New-AzDataLa...
Script     0.5.0      Az.DataLakeStore                    Core,Desk {Get-AzDataLakeStoreTrustedIdProvider, Remove-Az...
Script     0.5.0      Az.DevTestLabs                      Core,Desk {Get-AzDtlAllowedVMSizesPolicy, Get-AzDtlAutoShu...
Script     0.5.0      Az.Dns                              Core,Desk {Get-AzDnsRecordSet, New-AzDnsRecordConfig, Remo...
Script     0.5.0      Az.EventGrid                        Core,Desk {New-AzEventGridTopic, Get-AzEventGridTopic, Set...
Script     0.5.0      Az.EventHub                         Core,Desk {New-AzEventHubNamespace, Get-AzEventHubNamespac...
Script     0.5.0      Az.Insights                         Core,Desk {Get-AzMetricDefinition, Get-AzMetric, Remove-Az...
Script     0.5.0      Az.IotHub                           Core,Desk {Add-AzIotHubKey, Get-AzIotHubEventHubConsumerGr...
Script     0.5.0      Az.KeyVault                         Core,Desk {Add-AzKeyVaultCertificate, Update-AzKeyVaultCer...
Script     0.5.0      Az.LogicApp                         Core,Desk {Get-AzIntegrationAccountAgreement, Get-AzIntegr...
Script     0.5.0      Az.MachineLearning                  Core,Desk {Move-AzMlCommitmentAssociation, Get-AzMlCommitm...
Script     0.5.0      Az.MachineLearningCompute           Core,Desk {Get-AzMlOpCluster, Get-AzMlOpClusterKey, Test-A...
Script     0.5.0      Az.MarketplaceOrdering              Core,Desk {Get-AzMarketplaceTerms, Set-AzMarketplaceTerms}
Script     0.5.0      Az.Media                            Core,Desk {Sync-AzMediaServiceStorageKeys, Set-AzMediaServ...
Script     0.5.0      Az.Network                          Core,Desk {Add-AzApplicationGatewayAuthenticationCertifica...
Script     0.5.0      Az.NotificationHubs                 Core,Desk {Get-AzNotificationHub, Get-AzNotificationHubAut...
Script     0.5.0      Az.OperationalInsights              Core,Desk {New-AzOperationalInsightsAzureActivityLogDataSo...
Script     0.5.0      Az.PolicyInsights                   Core,Desk {Get-AzPolicyEvent, Get-AzPolicyState, Get-AzPol...
Script     0.5.0      Az.PowerBIEmbedded                  Core,Desk {Remove-AzPowerBIWorkspaceCollection, Get-AzPowe...
Script     0.5.0      Az.Profile                          Core,Desk {Disable-AzDataCollection, Disable-AzContextAuto...
Script     0.5.0      Az.RecoveryServices                 Core,Desk {Get-AzRecoveryServicesBackupProperty, Get-AzRec...
Script     0.5.0      Az.RedisCache                       Core,Desk {Remove-AzRedisCachePatchSchedule, New-AzRedisCa...
Script     0.5.0      Az.Relay                            Core,Desk {New-AzRelayNamespace, Get-AzRelayNamespace, Set...
Script     0.5.0      Az.Resources                        Core,Desk {Get-AzProviderOperation, Remove-AzRoleAssignmen...
Script     0.5.0      Az.ServiceBus                       Core,Desk {New-AzServiceBusNamespace, Get-AzServiceBusName...
Script     0.5.0      Az.ServiceFabric                    Core,Desk {Add-AzServiceFabricApplicationCertificate, Add-...
Script     0.5.0      Az.SignalR                          Core,Desk {New-AzSignalR, Get-AzSignalR, Get-AzSignalRKey,...
Script     0.5.1      Az.Sql                              Core,Desk {Get-AzSqlDatabaseTransparentDataEncryption, Get...
Script     0.5.0      Az.Storage                          Core,Desk {Get-AzStorageAccount, Get-AzStorageAccountKey, ...
Script     0.5.0      Az.StreamAnalytics                  Core,Desk {Get-AzStreamAnalyticsFunction, Get-AzStreamAnal...
Script     0.5.0      Az.Tags                             Core,Desk {Remove-AzTag, Get-AzTag, New-AzTag}
Script     0.5.0      Az.TrafficManager                   Core,Desk {Add-AzTrafficManagerCustomHeaderToEndpoint, Rem...
Script     0.5.0      Az.UsageAggregates                  Core,Desk Get-UsageAggregates
Script     0.5.0      Az.Websites                         Core,Desk {Get-AzAppServicePlan, Set-AzAppServicePlan, New...

PS /home/maxt> $PSVersionTable

Name                           Value
----                           -----
PSVersion                      6.1.1
PSEdition                      Core
GitCommitId                    6.1.1
OS                             Linux 4.4.0-18277-Microsoft #1000-Microsoft Fri Nov 02 14:46: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

PS /home/maxt>

@markcowl markcowl self-assigned this Nov 14, 2018
@markcowl
Copy link
Member Author

@MaximoTrinidad This is the issue that tracks a fix for this - the referenced issue was closed as a duplkicate, to make tracking the fix easier.

Meanwhile, if you are using PowerShell interactively, consider using context autosave instead of importing and exporting contexts. Context autosave automatically saves your available contexts in between sessions, making it unnecessary to improt and export contextts.

If you are mainly running scripts in PowerShell, here is some advice:

(1) Turn off context autosave, as this will make all authentication occur in memory, and isolate each session from the context changes in other sessions (Disable-AzureRContextAutosave -Scope Process). If you are not also executing interactive cmdlets, then you can turn context autosave off for all sessions (Disable-AzureRMContextAutosave -Scope CurrentUser)
(2) Authenticate at the beginning of your script, rather than relying on previous / imported contexts - Azure Automation provides default service principal authentication that should be easy to use at the beginning of scripts
(3) Use service principal authentication, as this allows granular control over authorization

@MaximoTrinidad
Copy link

Hi @markcowl!! Thanks for the advice!
Greatly Appreciated!
:)

@markcowl
Copy link
Member Author

Candidate fix for this issue is here: #7949

This was referenced Nov 29, 2018
@markcowl
Copy link
Member Author

markcowl commented Dec 1, 2018

Fix is checked in. will be in 12/18 release.

@markcowl markcowl closed this as completed Dec 1, 2018
@MaximoTrinidad
Copy link

@markcowl

That's Awesome!! Looking forward to it.
Thanks again

@MaximoTrinidad
Copy link

MaximoTrinidad commented Dec 13, 2018

@markcowl,

I know there's an urgency in closing resolving open issues, but I would recommend to re-open this issue as it hasn't been release yet and tested by users.

For example, issues closed #7954 and #7956 on module version 0.6.1 shows closed but remains broken in module version 0.7.0.

This issue is causing people to go back and install the old AzureRM modules so their scripts won't break.

Is just my opinion!

:)

@pixelicous
Copy link

@MaximoTrinidad totally agree, cannot rely on these modules anymore, every update is just scary, you have no idea when and where you will need to work hours to understand what MS has broken -_-

@MaximoTrinidad
Copy link

Although, this has been close for awhile... I just want to say... This is finally working on Az Module Version 1.0 released on December 18th.

Woohoo!!

@pixelicous
Copy link

@MaximoTrinidad this is not fully resolved.

@MaximoTrinidad
Copy link

@pixelicous

If you feel it isn't working. I suggest to open a new incident so it can be track down. This will create visibility. The issues I was having seems all gone.

:)

@pixelicous
Copy link

@MaximoTrinidad Not enough time in the day to open an issue on this 😆

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

No branches or pull requests

4 participants