SecretStore icon indicating copy to clipboard operation
SecretStore copied to clipboard

Unlock-SecretStore randomly fails after running Reset-SecretStore

Open wilddev65 opened this issue 2 years ago • 0 comments

Prerequisites

  • [X] Write a descriptive title.
  • [X] Make sure you are able to repro it on the latest released version
  • [X] Search the existing issues.

Steps to reproduce

I am writing a script for setting up a vault for automation. The initial run of the script and setup of the new vault runs well. I then tested doing Reset-SecretStore to see what would happen if someone wanted to start again if they didn't know the passwords. This of course resets everything to defaults and I then ran 'Set-SecretStoreConfiguration -Authentication 'Password' -PasswordTimeout 3600 -Interaction 'None' -Confirm:$false' to have a longer timeout and to not prompt. As this command appears to reset the password cached by Unlock-SecretStore, I ran it again immediately after to have it available for the rest of the script. The next part begins with Get-SecretInfo to discover if any users are in the vault, so they can be added if needed. This results in the following error: Get-Secretinfo : A valid password is required to access the Microsoft.PowerShell.SecretStore vault. Use the Unlock-SecretStore cmdlet to provide the required password to access the store.

I have attempted to put Unlock-SecretStore in different places in the script and even went to far as to run it before every command to get it to function as expected. There seems to be always a part where it randomly fails to supply the necessary password for the vault.

Expected behavior

Once Unlock-SecretStore is run, the password is cached and available to other commands being run by the script

Actual behavior

Random failure with an error to 'Use the Unlock-SecretStore cmdlet to provide the required password to access the store.'

Error details

Get-Secretinfo : A valid password is required to access the Microsoft.PowerShell.SecretStore vault.
Use the Unlock-SecretStore cmdlet to provide the required password to access the store.
At C:\GitLab\hpe-oneview-and-ilo-provisioning\HPiLO-Import.ps1:183 char:18
+ ...   $accounts = (Get-Secretinfo -Vault VenafiPS -ErrorAction Stop).Name
+                    ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
    + CategoryInfo          : InvalidOperation: (Microsoft.Power...cretInfoCommand:GetSecretInfoCommand) [Get-SecretInfo], PasswordRequiredException
    + FullyQualifiedErrorId : GetSecretInfoException,Microsoft.PowerShell.SecretManagement.GetSecretInfoCommand

Environment data

Name                           Value
----                           -----
PSVersion                      5.1.19041.1682
PSEdition                      Desktop
PSCompatibleVersions           {1.0, 2.0, 3.0, 4.0...}
BuildVersion                   10.0.19041.1682
CLRVersion                     4.0.30319.42000
WSManStackVersion              3.0
PSRemotingProtocolVersion      2.3
SerializationVersion           1.1.0.1

Version

Using VS Code on Windows 10

Visuals

No response

wilddev65 avatar Aug 15 '22 23:08 wilddev65