joshcorr / SecretManagement.Hashicorp.Vault.KV

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

[BUG] Getting Exception: Cannot convert null to type "System.DateTime". #31

Closed MrZeeEs closed 1 year ago

MrZeeEs commented 2 years ago

On Windows 10 Pro is installed:

SecretManagement.Hashicorp.Vault.KV/2.0.0 Microsoft.PowerShell.SecretStore/1.0.5 Vault 1.9.2. PowerShell7

I have started Vault in DEV mode and only token authentication is set up.

Logging has revealed that there is a problem with System.DateTime conversion and Token's expiration datetime.

The whole debug report:

PS C:\Vault\SecretManagement.Hashicorp.Vault.KV> Test-SecretVault -VaultName secret -AdditionalParameters $additionalparameters -Verbose VERBOSE: Grabbing token for secret VERBOSE: Token Expired at 01/01/1600 00:00:00. Retieving a new token

PowerShell credential request Please Enter the token Password for user Token: **

VERBOSE: POST with 45-byte payload VERBOSE: received 461-byte response of content type application/json VERBOSE: Content encoding: utf-8 Exception: Cannot convert null to type "System.DateTime".

PS C:\Vault\SecretManagement.Hashicorp.Vault.KV> $error[0] | fl -force

Exception : System.Management.Automation.ArgumentTransformationMetadataException: Cannot convert null to type "System.DateTime". ---> System.Management.Automation.PSInvalidCastException: Cannot convert null to type "System.DateTime". at System.Management.Automation.LanguagePrimitives.ThrowInvalidCastException(Object valueToConvert, Type resultType) at System.Management.Automation.LanguagePrimitives.ConvertNoConversion(Object valueToConvert, Type resultType, Boolean recurse, PSObject originalValueToConvert, IFormatProvider formatProvider, TypeTable backup Table) at System.Management.Automation.LanguagePrimitives.ConversionData1.Invoke(Object valueToConvert, Type resultType, Boolean recurse, PSObject originalValueToConvert, IFormatProvider formatProvider, TypeTable ba ckupTable) at System.Management.Automation.LanguagePrimitives.ConvertTo(Object valueToConvert, Type resultType, Boolean recursion, IFormatProvider formatProvider, TypeTable backupTypeTable) at System.Management.Automation.ArgumentTypeConverterAttribute.Transform(EngineIntrinsics engineIntrinsics, Object inputData, Boolean bindingParameters, Boolean bindingScriptCmdlet) --- End of inner exception stack trace --- at System.Management.Automation.ExceptionHandlingOps.CheckActionPreference(FunctionContext funcContext, Exception exception) at System.Management.Automation.Interpreter.ActionCallInstruction2.Run(InterpretedFrame frame) at System.Management.Automation.Interpreter.EnterTryCatchFinallyInstruction.Run(InterpretedFrame frame) at System.Management.Automation.Interpreter.EnterTryCatchFinallyInstruction.Run(InterpretedFrame frame) TargetObject : CategoryInfo : MetadataError: (:) [], ArgumentTransformationMetadataException FullyQualifiedErrorId : RuntimeException ErrorDetails : InvocationInfo : System.Management.Automation.InvocationInfo ScriptStackTrace : at Invoke-VaultToken, C:\Vault\SecretManagement.Hashicorp.Vault.KV\SecretManagement.Hashicorp.Vault.KV\SecretManagement.Hashicorp.Vault.KV.Extension\SecretManagement.Hashicorp.Vault.KV.Extension.psm1: line 270 at Test-SecretVault, C:\Vault\SecretManagement.Hashicorp.Vault.KV\SecretManagement.Hashicorp.Vault.KV\SecretManagement.Hashicorp.Vault.KV.Extension\SecretManagement.Hashicorp.Vault.KV.Extension.psm1: lin e 673 at , : line 1 PipelineIterationInfo : {} PSMessageDetails :

Expected behaviour: valid token is retrieved, no datime error happens

joshcorr commented 2 years ago

Thanks for submitting this @MrZeeEs. I believe that the issue here is that you are using the Root token and that does not have an expiration time stamp, which is causing this error. Should have a fix pushed out to the Gallery soon.

joshcorr commented 2 years ago

Please try pulling the latest preview version from the Gallery version 2.0.1-Preview

Install-Module -Name SecretManagement.Hashicorp.Vault.KV -AllowPrerelease

This should fix the issue you were facing.

joshcorr commented 2 years ago

@MrZeeEs did you have a chance to try the code in the Preview branch?

hawleyOSU commented 1 year ago

Tested today 2003-08-25 Vault 1.13.0 SecretManagement.Hashicorp.Vault.KV 2.0.1 Preview Powershell 7.2.13

Auth with root token still returns "System.Management.Automation.PSInvalidOperationException: Unable to run Test-SecretVault on vault"