aws / aws-tools-for-powershell

The AWS Tools for PowerShell lets developers and administrators manage their AWS services from the PowerShell scripting environment.
Apache License 2.0
235 stars 77 forks source link

Error using Install-AWSToolsModule for AWS.Tools.SecretsManager #226

Closed macfarmw closed 2 years ago

macfarmw commented 3 years ago

Description

I am unable to install AWS.Tools.SecretsManager with the Install-AWSToolsModule command. It ends up trying to load a .nupkg file from a temp file location after the temp file has been deleted.

Reproduction Steps

  1. Start Windows PowerShell 5.1 as administrator
  2. Install-Module AWS.Tools.Installer -Force -Repository PSGallery -Scope AllUsers
  3. Install-AWSToolsModule AWS.Tools.SecretsManager -RequiredVersion 4.1.13 -Scope AllUsers -CleanUp -Verbose -AllowClobber

Results

PS C:\Users\mmacfarland> Install-AWSToolsModule AWS.Tools.SecretsManager -RequiredVersion 4.1.13 -Scope AllUsers -CleanU
p -Verbose -AllowClobber
VERBOSE: [Install-AWSToolsModule] ConfirmPreference=High WhatIfPreference=False VerbosePreference=Continue Force=False
Name=(AWS.Tools.SecretsManager) RequiredVersion=4.1.13.0 SkipUpdate=False CleanUp=True
VERBOSE: [Find-AWSToolsModule] ConfirmPreference=High WhatIfPreference=False VerbosePreference=Continue
Name=(AWS.Tools.SecretsManager)
VERBOSE: [Find-AWSToolsModule] End
VERBOSE: [Install-AWSToolsModule] Installing AWS Tools version 4.1.13.0
VERBOSE: [Install-AWSToolsModule] Searching installed modules
VERBOSE: [Install-AWSToolsModule] Removing already installed modules from the. Final list of modules to install:
(AWS.Tools.SecretsManager)

Confirm
Are you sure you want to perform this action?
Performing the operation "Install-AWSToolsModule" on target "AWS Tools version 4.1.13.0".
[Y] Yes  [A] Yes to All  [N] No  [L] No to All  [S] Suspend  [?] Help (default is "Y"): A
VERBOSE: [Install-AWSToolsModule] Create folder for temporary repository
C:\Users\mmacfarland\AppData\Local\Temp\9\2u5nzoz1.g0m
VERBOSE: [Install-AWSToolsModule] Registering temporary repository AWSToolsTemp
Package Source with Name: AWSToolsTemp added successfully.
VERBOSE: [Install-AWSToolsModule] Downloading modules to temporary repository
VERBOSE: [Install-AWSToolsModule] Downloading modules (AWS.Tools.SecretsManager)
VERBOSE: [Install-AWSToolsModule] Downloading module AWS.Tools.SecretsManager to
C:\Users\mmacfarland\AppData\Local\Temp\9\2u5nzoz1.g0m
VERBOSE: [Get-AWSToolsModuleDependenciesAndValidate] ConfirmPreference=None WhatIfPreference=False
VerbosePreference=Continue Name=AWS.Tools.SecretsManager
Path=C:\Users\mmacfarland\AppData\Local\Temp\9\2u5nzoz1.g0m\AWS.Tools.SecretsManager.4.1.13.0.nupkg
VERBOSE: [Install-AWSToolsModule] Unregistering temporary repository AWSToolsTemp
Package source with Name: AWSToolsTemp removed successfully.
VERBOSE: [Install-AWSToolsModule] Delete repository folder C:\Users\mmacfarland\AppData\Local\Temp\9\2u5nzoz1.g0m
Get-AWSToolsModuleDependenciesAndValidate : Exception calling "OpenRead" with "1" argument(s): "Could not find file
'C:\Users\mmacfarland\AppData\Local\Temp\9\2u5nzoz1.g0m\AWS.Tools.SecretsManager.4.1.13.0.nupkg'."
At C:\Program Files\WindowsPowerShell\Modules\AWS.Tools.Installer\1.0.2.1\AWS.Tools.Installer.psm1:605 char:54
+ ... ndencies += Get-AWSToolsModuleDependenciesAndValidate -Path $task.Pat ...
+                 ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
    + CategoryInfo          : NotSpecified: (:) [Get-AWSToolsMod...ciesAndValidate], MethodInvocationException
    + FullyQualifiedErrorId : FileNotFoundException,Get-AWSToolsModuleDependenciesAndValidate

Logs

Environment

Resolution

According the VERBOSE output the installer deletes the folder C:\Users\mmacfarland\AppData\Local\Temp\9\2u5nzoz1.g0m but it also tries to load C:\Users\mmacfarland\AppData\Local\Temp\9\2u5nzoz1.g0m\AWS.Tools.SecretsManager.4.1.13.0.nupkg from that same folder. It appears from this output that the delete is happening too soon.


This is a :bug: bug-report

macfarmw commented 3 years ago

I reviewed the source code for the installer. The VERBOSE message about deleting the temp folder happens in a finally block after the error. It's not clear if the installer is deleting the files before they are read or if the files were never downloaded. I ran the installer again and I could see that it created a new temp folder. The folder was present for a couple of seconds so I could open it, but when I did it was empty. I'm not certain if the files were downloaded and deleted before I could see them or if they were just never downloaded at all.

I repeated this test a few times and even if I open the folder very quickly after it appears the .nupkg file never appears. It looks like the file is not being downloaded at all. I'm checking with our infrastructure team to see of one of the security tools is blocking the download.

ashishdhingra commented 3 years ago

Hi @macfarmw,

Good morning.

Thanks for reporting the issue. Based on your comment, please check with your infrastructure team if security tools is blocking the download. Also noticed that you already launched Windows PowerShell as Administrator. I have tried using Install-AWSToolsModule several times and have not seen this kind of error (though there are weird errors with Windows PowerShell, not seen on PowerShell 7.x).

Thanks, Ashish

macfarmw commented 3 years ago

Hi @ashishdhingra

We disabled the security software but that did not make any difference. Yesterday I tried running this same installation with PowerShell 7 and it works fine on this same server. The scripts running under 5.1 can't load the modules installed under PS 7 by default so I abandoned that approach. We're not ready to move our modules over the PS 7 quite yet.

Since there does not appear to be a simple way to fix this we will abandon attempts to use AWS.Tools.* for now and try calling the AWS CLI from our scripts. It's not ideal but we have move on with the project.

ashishdhingra commented 3 years ago

Hi @macfarmw,

Thanks for your response. I have seen issues with Windows PowerShell 5.1 which subsequently self resolve by itself. Not sure the root cause, may be Windows PowerShell rebuilds it's cache and could not load modules due to incorrect directory naming initially. Unfortunately, these issues with Windows PowerShell is beyond control of AWS PowerShell tools installer. Does using Install-Module directly works?

Thanks, Ashish

macfarmw commented 3 years ago

It seemed to work better with Install-Module but then the Get-SECSecretValue function fails with an HttpResponse error. I was hoping that if I could install the modules with Install-AWSToolsModule that it would fix that issue. I also tried downloading the zip file and copying AWS.Tools.Common and AWS.Tools.SecretsManager into the Modules folder. With that method I had to go into the folder and unblock the dlls so that could use Import-Module. Even then Get-SECSecretValue still fails. I'm hoping that with the CLI it will work better. I'll be trying that later today.

ashishdhingra commented 2 years ago

@macfarmw Closing this issue since we cannot reproduce it at our end. Feel free to open a new issue in case of any issue.

github-actions[bot] commented 2 years ago

⚠️COMMENT VISIBILITY WARNING⚠️

Comments on closed issues are hard for our team to see. If you need more assistance, please either tag a team member or open a new issue that references this one. If you wish to keep having a conversation with other community members under this issue feel free to do so.

jameskirsop commented 2 years ago

FWIW, @ashishdhingra I'm able to reproduce this issue when trying to install AWS-Tools-S3.

Running Install-Module does not help resolve the lack of installation issue, either.