PowerShell / SecretManagement

PowerShell module to consistent usage of secrets through different extension vaults
MIT License
335 stars 47 forks source link

The absence of the 'secretmanagement' directory seems to modify the behavior of the Unregister-SecretVault cmdlet #119

Open LaurentDardenne opened 3 years ago

LaurentDardenne commented 3 years ago

Expected use : image Get-SecretVault return nothing.

Now I delete the 'secretmanagement' directory image

$PSVersionTable

Name                           Value
----                           -----
PSVersion                      5.1.19041.610
PSEdition                      Desktop
PSCompatibleVersions           {1.0, 2.0, 3.0, 4.0, 5.0, 5.1.19041.610}
BuildVersion                   10.0.19041.610
CLRVersion                     4.0.30319.42000
WSManStackVersion              3.0
PSRemotingProtocolVersion      2.3
SerializationVersion           1.1.0.1

Repro:

get-module

import-module Microsoft.PowerShell.SecretManagement
import-module Microsoft.PowerShell.SecretStore
#first installation
Register-SecretVault -Name SecretStore -ModuleName Microsoft.PowerShell.SecretStore -DefaultVault
Get-SecretVault
# Name        ModuleName                       IsDefaultVault
# ----        ----------                       --------------
# SecretStore Microsoft.PowerShell.SecretStore True

Get-SecretVault|Unregister-SecretVault
Get-SecretVault
#nothing
dir $env:USERPROFILE\AppData\Local\Microsoft\PowerShell

Register-SecretVault -Name SecretStore -ModuleName Microsoft.PowerShell.SecretStore -DefaultVault
del $env:USERPROFILE\AppData\Local\Microsoft\PowerShel\secretmanagement\
Get-SecretVault|Unregister-SecretVault
Get-SecretVault
# Name        ModuleName                       IsDefaultVault
# ----        ----------                       --------------
# SecretStore Microsoft.PowerShell.SecretStore True

Register-SecretVault -Name SecretStore -ModuleName Microsoft.PowerShell.SecretStore -DefaultVault
#Errror  : Register-SecretVault : Provided Name for vault is already being used.

When a close the current session and open a new session, Get-SecretVault return nothing.

It's not really a bug but a special case I think.

PaulHigin commented 3 years ago

This behavior is by design. The vault registry information is cached in memory and only updated when file contents change. But I agree the missing directory behavior should be better. I am thinking SecretManagement should try to re-create the directory/registry file, which it does anyway after PowerShell is restarted.