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

Connect-AzAccount: The term 'Connect-AzAccount' is not recognized as a name of a cmdlet #18928

Closed
Davidh-claranet opened this issue Jul 13, 2022 · 9 comments
Assignees
Labels
Accounts Issues in Az.Accounts except authentication related bug This issue requires a change to an existing behavior in the product in order to be resolved. customer-reported needs-team-attention This issue needs attention from Azure service team or SDK team

Comments

@Davidh-claranet
Copy link

Description

Hello
The Connect-AzAccount is correctly recognized :

PS /> [root@server user]# docker run  -it mcr.microsoft.com/azure-powershell
PowerShell 7.2.4
Copyright (c) Microsoft Corporation.

https://aka.ms/powershell
Type 'help' to get help.

PS /> Connect-AzAccount
WARNING: Interactive authentication is not supported in this session, please run cmdlet 'Connect-AzAccount -UseDeviceAuthentication'.
PS />

But when using http_proxy, https_proxy, HTTP_PROXY and HTTPS_PROXY environment variables, the Connect-AzAccount is no more recognized :

PS /> [root@server Z98D8008export HTTPS_PROXY=http://my_proxy:3128
[root@server user]# export HTTPS_PROXY=http://my_proxy:3128
[root@server user]# export HTTP_PROXY=http://my_proxy:3128
[root@server user]# export http_proxy=http://my_proxy:3128
[root@server user]# export https_proxy=http://my_proxy:3128
[root@server user]# docker run  -e http_proxy  -e https_proxy -e HTTP_PROXY -e HTTPS_PROXY -it mcr.microsoft.com/azure-powershe
ll
PowerShell 7.2.4
Copyright (c) Microsoft Corporation.

https://aka.ms/powershell
Type 'help' to get help.

PS /> Connect-AzAccount                 
Connect-AzAccount: The term 'Connect-AzAccount' is not recognized as a name of a cmdlet, function, script file, or executable program.
Check the spelling of the name, or if a path was included, verify that the path is correct and try again.

The Az.accounts module does not export commands :

PS /> get-module

ModuleType Version    PreRelease Name                                ExportedCommands
---------- -------    ---------- ----                                ----------------
Script     2.8.0                 Az.Accounts
Manifest   7.0.0.0               Microsoft.PowerShell.Management     {Add-Content, Clear-Content, Clear-Item, Clear-ItemProperty…}
Manifest   7.0.0.0               Microsoft.PowerShell.Utility        {Add-Member, Add-Type, Clear-Variable, Compare-Object…}      
Script     2.1.0                 PSReadLine                          {Get-PSReadLineKeyHandler, Get-PSReadLineOption, Remove-PSReadLineKeyHandler, Set-PSReadLineKeyHandler…}

Issue script & Debug output

PS /> $DebugPreference='Continue' 
PS /> import-module -name Az.Accounts
DEBUG: Registering Az shared AssemblyLoadContext for path: '/usr/local/share/powershell/Modules/Az.Accounts/2.8.0/StartupScripts/../AzSharedAlcAssemblies'.
DEBUG: AssemblyLoadContext registered.
Import-Module: An item with the same key has already been added. Key: https_proxy

Environment data

PS /> $PSVersionTable

Name                           Value
----                           -----
PSVersion                      7.2.4
PSEdition                      Core
GitCommitId                    7.2.4
OS                             Linux 4.18.0-372.9.1.el8.x86_64 #1 SMP Fri Apr 15 22:12:19 EDT 2022
Platform                       Unix
PSCompatibleVersions           {1.0, 2.0, 3.0, 4.0…}
PSRemotingProtocolVersion      2.3
SerializationVersion           1.1.0.1
WSManStackVersion              3.0

Module versions

PS /> Get-Module Az*

ModuleType Version    PreRelease Name                                ExportedCommands
---------- -------    ---------- ----                                ----------------
Script     2.8.0                 Az.Accounts

Error output

PS /> Resolve-AzError
Resolve-AzError: The term 'Resolve-AzError' is not recognized as a name of a cmdlet, function, script file, or executable program.
Check the spelling of the name, or if a path was included, verify that the path is correct and try again.
@Davidh-claranet Davidh-claranet added bug This issue requires a change to an existing behavior in the product in order to be resolved. needs-triage This is a new issue that needs to be triaged to the appropriate team. labels Jul 13, 2022
@ghost ghost added customer-reported and removed needs-triage This is a new issue that needs to be triaged to the appropriate team. labels Jul 13, 2022
@dingmeng-xue
Copy link
Member

dingmeng-xue commented Jul 14, 2022

Thanks for reporting. @Davidh-claranet , Could you check the output of $Error[0].Exception | fl -f * after you tried to import module Import-Module Az.Accounts? It will share the detailed error message. Resolve-AzError cannot work because module is not imported.

@dingmeng-xue dingmeng-xue added needs-author-feedback More information is needed from author to address the issue. Accounts Issues in Az.Accounts except authentication related labels Jul 14, 2022
@Davidh-claranet
Copy link
Author

PS /> Import-Module Az.Accounts                         
Import-Module: An item with the same key has already been added. Key: HTTP_PROXY

PS /> $Error[0].Exception | fl -f *

Message        : An item with the same key has already been added. Key: HTTP_PROXY
ParamName      : 
TargetSite     : Void ThrowAddingDuplicateWithKeyArgumentException[T](T)
Data           : {}
InnerException : 
HelpLink       : 
Source         : System.Private.CoreLib
HResult        : -2147024809
StackTrace     :    at System.Collections.Generic.Dictionary`2.TryInsert(TKey key, TValue value, InsertionBehavior behavior)
                    at System.Collections.Generic.Dictionary`2.Add(TKey key, TValue value)
                    at System.Linq.Enumerable.ToDictionary[TSource,TKey,TElement](IEnumerable`1 source, Func`2 keySelector, Func`2 elementSelector, IEqualityComparer`1 comparer)
                    at Microsoft.Azure.Commands.Common.Authentication.Config.DefaultEnvironmentVariableProvider.List(EnvironmentVariableTarget target)
                    at Microsoft.Azure.Commands.Common.Authentication.Config.Internal.Providers.EnvironmentVariablesConfigurationProvider.Load()
                    at Microsoft.Azure.Commands.Common.Authentication.Config.Internal.ConfigurationRoot..ctor(IList`1 providers)
                    at Microsoft.Azure.Commands.Common.Authentication.Config.Internal.ConfigurationBuilder.Build()
                    at Microsoft.Azure.Commands.Common.Authentication.Config.ConfigManager.BuildConfig()
                    at Microsoft.Azure.Commands.Common.Authentication.Config.ConfigInitializer.InitializeForAzureSession(AzureSession session)
                    at Microsoft.Azure.Commands.Common.Authentication.AzureSessionInitializer.InitializeConfigs(AzureSession session, String profilePath)
                    at Microsoft.Azure.Commands.Common.Authentication.AzureSessionInitializer.CreateInstance(IDataStore dataStore)
                    at Microsoft.Azure.Commands.Common.Authentication.AzureSessionInitializer.<>c.<InitializeAzureSession>b__2_0()
                    at Microsoft.Azure.Commands.Common.Authentication.AzureSession.Initialize(Func`1 instanceCreator, Boolean overwrite)
                    at Microsoft.Azure.Commands.Common.Authentication.AzureSession.Initialize(Func`1 instanceCreator)
                    at Microsoft.Azure.Commands.Common.Authentication.AzureSessionInitializer.InitializeAzureSession()
                    at Microsoft.Azure.Commands.Profile.ConnectAzureRmAccountCommand.OnImport()
                    at System.Management.Automation.Runspaces.PSSnapInHelpers.ExecuteModuleInitializer(Assembly assembly, IEnumerable`1 assemblyTypes)
                    at System.Management.Automation.Runspaces.PSSnapInHelpers.AnalyzeModuleAssemblyWithReflection(Assembly assembly, String name, PSSnapInInfo psSnapInInfo, PSModuleInfo moduleInfo, String helpFile, 
                 Dictionary`2& cmdlets, Dictionary`2& aliases, Dictionary`2& providers)
                    at System.Management.Automation.Runspaces.PSSnapInHelpers.AnalyzePSSnapInAssembly(Assembly assembly, String name, PSSnapInInfo psSnapInInfo, PSModuleInfo moduleInfo, Dictionary`2& cmdlets, Dictionary`2&       
                 aliases, Dictionary`2& providers, String& helpFile)
                    at System.Management.Automation.Runspaces.InitialSessionState.ImportCmdletsFromAssembly(Assembly assembly, PSModuleInfo module)
                    at Microsoft.PowerShell.Commands.ModuleCmdletBase.LoadBinaryModule(PSModuleInfo parentModule, String moduleName, String fileName, Assembly assemblyToLoad, String moduleBase, SessionState ss,
                 ImportModuleOptions options, ManifestProcessingFlags manifestProcessingFlags, String prefix, Boolean loadTypes, Boolean loadFormats, Boolean& found, String shortModuleName, Boolean disableFormatUpdates)
                    at Microsoft.PowerShell.Commands.ModuleCmdletBase.LoadBinaryModule(String moduleName, String fileName, Assembly assemblyToLoad, String moduleBase, SessionState ss, ImportModuleOptions options,
                 ManifestProcessingFlags manifestProcessingFlags, String prefix, Boolean loadTypes, Boolean loadFormats, Boolean& found)
                    at Microsoft.PowerShell.Commands.ModuleCmdletBase.LoadModule(PSModuleInfo parentModule, String fileName, String moduleBase, String prefix, SessionState ss, Object privateData, ImportModuleOptions& options,    
                 ManifestProcessingFlags manifestProcessingFlags, Boolean& found, Boolean& moduleFileFound)
                    at Microsoft.PowerShell.Commands.ModuleCmdletBase.LoadModule(String fileName, String moduleBase, String prefix, SessionState ss, ImportModuleOptions& options, ManifestProcessingFlags manifestProcessingFlags,  
                 Boolean& found)
                    at Microsoft.PowerShell.Commands.ImportModuleCommand.ImportModule_LocallyViaName(ImportModuleOptions importModuleOptions, String name)
                    at Microsoft.PowerShell.Commands.ImportModuleCommand.ImportModule_LocallyViaName_WithTelemetry(ImportModuleOptions importModuleOptions, String name)
                    at Microsoft.PowerShell.Commands.ImportModuleCommand.ProcessRecord()
                    at System.Management.Automation.Cmdlet.DoProcessRecord()
                    at System.Management.Automation.CommandProcessor.ProcessRecord()

@ghost ghost added needs-team-attention This issue needs attention from Azure service team or SDK team and removed needs-author-feedback More information is needed from author to address the issue. labels Jul 15, 2022
@RickBankers
Copy link

This may be related to #18424.

We set proxy environment variables as well however if we just pull the image from mcr without setting proxy vars it fails outright. Everything worked properly in 2.7.6.

@dingmeng-xue
Copy link
Member

@Davidh-claranet , @RickBankers , it seems relate to issue #18312. This issue has been fixed in the latest version of Az.Accounts 2.9.0. Could you update the version and try again?

@dingmeng-xue dingmeng-xue added needs-author-feedback More information is needed from author to address the issue. and removed needs-team-attention This issue needs attention from Azure service team or SDK team labels Jul 21, 2022
@RickBankers
Copy link

Still doesn't seem to be fixed. The alpine-3.14 image seems to work fine.

Ubuntu Image

`docker pull mcr.microsoft.com/azure-powershell
Using default tag: latest
Trying to pull repository mcr.microsoft.com/azure-powershell ...
latest: Pulling from mcr.microsoft.com/azure-powershell
d5fd17ec1767: Pull complete
acf5110a340e: Pull complete
de27e63c182a: Pull complete
fa3568af4d57: Pull complete
f5fb4bd701e8: Pull complete
9776292961b8: Pull complete
Digest: sha256:163586739f74a02282a4c2b7f12805b596d6ada983a0ff729196af18ec8c823a
Status: Downloaded newer image for mcr.microsoft.com/azure-powershell:latest
mcr.microsoft.com/azure-powershell:latest

docker run -it mcr.microsoft.com/azure-powershell pwsh
PowerShell 7.2.4
Copyright (c) Microsoft Corporation.

https://aka.ms/powershell
Type 'help' to get help.

PS /> connect-azaccount
connect-azaccount: The term 'connect-azaccount' is not recognized as a name of a cmdlet, function, script file, or executable program.
Check the spelling of the name, or if a path was included, verify that the path is correct and try again.
exit`

Alpine Image

`docker pull mcr.microsoft.com/azure-powershell:alpine-3.14
docker run -it mcr.microsoft.com/azure-powershell:alpine-3.14 pwsh
PowerShell 7.2.5
Copyright (c) Microsoft Corporation.

https://aka.ms/powershell
Type 'help' to get help.

PS /> connect-azaccount
WARNING: Interactive authentication is not supported in this session, please run cmdlet 'Connect-AzAccount -UseDeviceAuthentication'.
PS /> exit
`

@Davidh-claranet
Copy link
Author

Hello
I use the lastest version of the mcr.microsoft.com/azure-powershell image

It still provides Az.Accounts 2.8.0, and not 2.9.0.

PS /> get-module         
ModuleType Version    PreRelease Name                                ExportedCommands
---------- -------    ---------- ----                                ----------------
Script     2.8.0                 Az.Accounts
[...]

I tried to force the version :

PS /> Import-Module -Name Az.Accounts -MinimumVersion 2.9.0           
Import-Module: The specified module 'Az.Accounts' with version '2.9.0' was not loaded because no valid module file was found in any module directory.

I don't know how import Az.Accounts 2.9.0

@ghost ghost added needs-team-attention This issue needs attention from Azure service team or SDK team and removed needs-author-feedback More information is needed from author to address the issue. labels Jul 21, 2022
@ElvenSpellmaker
Copy link

I've got a very similar issue currently regarding Azure DevOps builds which don't run as a root user.

The module location has moved from /usr/local/share/powershell/Modules to /root/.local/share/powershell/Modules in a recent build of the image.

This means any user running as non-root no longer has access to this module as they can't read /root/...

SHAs of a build that works and doesn't work:
✔️ : sha256:163586739f74a02282a4c2b7f12805b596d6ada983a0ff729196af18ec8c823a
❌ : sha256:d7da797d627a135b31acb15329c8a949f06caa963e7c99fc04e63b70d839df75

@Nickcandy
Copy link
Contributor

Nickcandy commented Oct 11, 2022 via email

@Davidh-claranet
Copy link
Author

Hello
I confirm the fix.
Thank you !

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Accounts Issues in Az.Accounts except authentication related bug This issue requires a change to an existing behavior in the product in order to be resolved. customer-reported needs-team-attention This issue needs attention from Azure service team or SDK team
Projects
None yet
Development

No branches or pull requests

5 participants