joshcorr / SecretManagement.Hashicorp.Vault.KV

A PowerShell SecretManagement extension for Hashicorp Vault Key Value Engine
MIT License
30 stars 10 forks source link

[Feature] Support Windows PowerShell #26

Closed b-dasass closed 2 years ago

b-dasass commented 2 years ago

Is your feature request related to a problem? Please describe. Nope

Describe the solution you'd like I'd like to use this module with Windows PowerShell

Describe alternatives you've considered I considered using PowerShell 7, but I cannot do that.

Additional context n/a

joshcorr commented 2 years ago

@b-dasass thanks for submitting this issue.

I will look at revising the decision to remove 5.1 support. Originally I thought that I would not be able to support Windows PowerShell in the 2.0.0+ version. As a quick fix for Windows Powershell I have tested the following versions and found them to be working:

Install-Module -Name Microsoft.PowerShell.SecretManagement  -RequiredVersion 1.1.1
Install-Module -Name SecretManagement.Hashicorp.Vault.KV  -RequiredVersion 1.1.1-preview -AllowPrerelease

A more lengthy explanation: In the 1.1.1 version of SecretManagment the Constrained Language Mode (CLM) was causing issues with using the Extension from Terminal [#22], as well as supporting the Unlock-SecretVault function [#24] [#21]. The original design of the extension used a custom PowerShell class to store the session information (not supported in CLM). I removed this and aggressively tried to remove any code that wouldn't load in a CLM session. Hashicorp Vault uses a custom HTTP method for listing metadata on it's api (Which is used in Get-SecretInfo). In PS 6.0+ this is not a problem because Invoke-RestMethod supports custom methods, but for 5.1 I wrote Invoke-CustomRestMethod to support calling non standard HTTP methods. When testing for CLM this did not appear to work correctly (or at least I assumed it wouldn't because I was adding types, and there are a limited set of supported types).

Some initial tests seem to point out that I should be able to add this function back for 5.1 support, but I still need to do some testing. Will release a preview branch in the next day or so for you to test..

joshcorr commented 2 years ago

So here is what I have done, and I think this should work moving forward. I've back ported all of the important changes made in 2.x.x to a branch called 1.x. I added back the function Invoke-CustomWebRequest to support the custom HTTP method. As long as you do not need Constrained Language Mode you should be able to install and download the 1.x.x version from the PowerShell Gallery on any 5.1+ version of PowerShell with the following...

Install-Module -Name SecretManagement.Hashicorp.Vault.KV  -MaximumVersion 1.99.99
Update-Module -name secretmanagement.hashicorp.vault.KV -MaximumVersion 1.99.99 

Please give that version a spin and please submit an issue if you run into any problems. 🙂

sassdawe commented 2 years ago

I'll try my best, and if I find something I'll let you know ASAP 😉