Skip to content

Commit eeba3c2

Browse files
authored
Merge pull request #33 from joshcorr/development
Release 2.0.1 Preview
2 parents 9a6726e + 154747b commit eeba3c2

File tree

8 files changed

+54
-31
lines changed

8 files changed

+54
-31
lines changed

.github/workflows/test.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,7 @@ jobs:
1919
# Full git history is needed to get a proper list of changed files within `super-linter`
2020
fetch-depth: 0
2121
- name: Lint Code Base
22-
uses: github/super-linter@v3
22+
uses: github/super-linter@v4
2323
env:
2424
VALIDATE_ALL_CODEBASE: true
2525
VALIDATE_JSON: false

CHANGELOG.md

Lines changed: 11 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,16 @@
1-
# Change Log
1+
# Changelog
22

33
All notable changes to this project will be documented in this file.
44

55
The format is based on [Keep a Changelog](http://keepachangelog.com/)
66
and this project adheres to [Semantic Versioning](http://semver.org/).
77

8+
## [2.0.1] - 2022-01-13
9+
10+
Support skipping certificate varification [#29](https://github.com/joshcorr/SecretManagement.Hashicorp.Vault.KV/issues/29) thanks to [@ryancbutler](https://github.com/ryancbutler)
11+
bugfix for DateTime conversion when useing root token [#31](https://github.com/joshcorr/SecretManagement.Hashicorp.Vault.KV/issues/31)
12+
bugfix Linter
13+
814
## [1.3.0] - 2021-11-14
915

1016
Reintroduced PowerShell 5.1 support [#26](https://github.com/joshcorr/SecretManagement.Hashicorp.Vault.KV/issues/26)
@@ -15,7 +21,7 @@ Backported changes from main branch
1521
*Powershell 5.1 is no longer a supported version for this extension.
1622
version 1.1.1-Preview is the last 5.1 compatible version*
1723

18-
Major re-write of the token management to make it compatible with [Constrained Language Mode](https://docs.microsoft.com/en-us/powershell/module/microsoft.powershell.core/about/about_language_modes?view=powershell-7.1#constrained-language-constrained-language)
24+
Major rewrite of the token management to make it compatible with [Constrained Language Mode](https://docs.microsoft.com/en-us/powershell/module/microsoft.powershell.core/about/about_language_modes?view=powershell-7.1#constrained-language-constrained-language)
1925
Fixes issues with `Unlock-SecretVault` [#24](https://github.com/joshcorr/SecretManagement.Hashicorp.Vault.KV/issues/24)
2026
Fixes issue using extension from Terminal [#22](https://github.com/joshcorr/SecretManagement.Hashicorp.Vault.KV/issues/22)
2127
Updated documentation
@@ -52,7 +58,7 @@ Update About; remove Preview Tag
5258

5359
## [0.0.11] - 2021-03-16
5460

55-
More Bug fixes
61+
More bugfixes
5662

5763
## [0.0.10] - 2021-03-16
5864

@@ -80,11 +86,11 @@ Version Bump
8086

8187
## [0.0.4] - 2021-03-08
8288

83-
More Github Actions changes
89+
More GitHub Actions changes
8490

8591
## [0.0.3] - 2021-03-08
8692

87-
Github Actions changes
93+
GitHub Actions changes
8894

8995
## [0.0.2] - 2021-03-08
9096

CONTRIBUTING.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,7 @@ If this is your first time contributing to an opensource project, welcome! Here
2727

2828
- Look for items marked as "good first issue" (these usually only require a few easy changes)
2929
- Comment on this issue to let us know you want to work on it
30-
- Fork the module into your own repo
30+
- Fork the module into your own repository
3131
- Create a feature branch off of the development branch
3232
Call it something like `fix-bad-example-issue43`
3333
- If you get stuck reach out for help

README.md

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@
44
[![PSGallery][]][PSGalleryLink]
55
[![SupportBadge][]][SupportBadge]
66

7-
A PowerShell SecretManagement extension for Hashicorp Vault Key Value (KV) Engine. This supports version 1, version2, and cubbyhole (similar to v1). It does not currently support all of the version 2 features like versioned secrets.
7+
A PowerShell SecretManagement extension for Hashicorp Vault key- value (KV) Engine. This supports version 1, version2, and cubbyhole (similar to v1). It does not currently support all of the version 2 features like versioned secrets.
88

99
| Extension Version | 6.0+ | 5.1 | Constrained Language Mode |
1010
| ----------------- | ---- | --- | ------------------------- |
@@ -23,6 +23,12 @@ When registering a vault you need to provide at least these options:
2323
Register-SecretVault -ModuleName SecretManagement.Hashicorp.Vault.KV -Name PowerShellTest -VaultParameters @{ VaultServer = 'http://vault.domain.local:8200'; VaultAuthType = 'Token'}
2424
```
2525

26+
To disable HTTPS certificate checks (e.g. self-signed certs) use the `VaultSkipVerify` parameter
27+
28+
```PowerShell
29+
Register-SecretVault -ModuleName SecretManagement.Hashicorp.Vault.KV -Name PowerShellTest -VaultParameters @{ VaultServer = 'https://vault.domain.local:8200'; VaultAuthType = 'Token'; VaultSkipVerify = $true}
30+
```
31+
2632
The vault name should match exactly, as Hashicorp vault is case sensitive. If no VaultParameters are provided the functions will prompt you on the first execution in your session. Additionally you may provide which version of KV you are using when registering. It defaults to version 2 of KV.
2733

2834
```PowerShell
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
@{
2-
ModuleVersion = '2.0.0'
2+
ModuleVersion = '2.0.1'
33
RootModule = 'SecretManagement.Hashicorp.Vault.KV.Extension.psm1'
44
FunctionsToExport = @('Set-Secret', 'Get-Secret', 'Remove-Secret', 'Get-SecretInfo', 'Test-SecretVault', 'Unlock-SecretVault', 'Unregister-SecretVault')
55
}

SecretManagement.Hashicorp.Vault.KV/SecretManagement.Hashicorp.Vault.KV.Extension/SecretManagement.Hashicorp.Vault.KV.Extension.psm1

Lines changed: 30 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -2,8 +2,8 @@
22
using namespace System.Collections.ObjectModel
33
using namespace System.Collections.Generic
44
# enum and Variables setup for use
5-
$script:HashicorpVaultConfigValues = @('VaultServer', 'VaultAuthType', 'VaultToken', 'VaultAPIVersion', 'KVVersion', 'OutputType', 'Verbose')
6-
$script:AllVariables = @('VaultServer', 'VaultAuthType', 'VaultToken', 'VaultAPIVersion', 'KVVersion', 'OutputType', 'TokenRenewable', 'TokenLifespan', 'TokenType', 'TokenExpireTime', 'Verbose')
5+
$script:HashicorpVaultConfigValues = @('VaultServer', 'VaultAuthType', 'VaultToken', 'VaultAPIVersion', 'VaultSkipVerify', 'KVVersion', 'OutputType', 'Verbose')
6+
$script:AllVariables = @('VaultServer', 'VaultAuthType', 'VaultToken', 'VaultAPIVersion', 'VaultSkipVerify', 'KVVersion', 'OutputType', 'TokenRenewable', 'TokenLifespan', 'TokenType', 'TokenExpireTime', 'Verbose')
77

88
enum HashicorpVaultAuthTypes {
99
None
@@ -21,7 +21,9 @@ $script:HashicorpAuthTypes = @('None', 'AppRole', 'LDAP', 'userpass', 'Token')
2121
[string]$script:VaultAPIVersion = 'v1'
2222
[string]$script:KVVersion = 'v2'
2323
[string]$script:OutputType = 'Hashtable'
24+
[bool]$script:VaultSkipVerify = $false
2425
# Internally used
26+
[bool]$script:RootToken = $false
2527
[bool]$script:TokenRenewable
2628
[double]$script:TokenLifespan
2729
[string]$script:TokenType
@@ -119,9 +121,10 @@ function Invoke-VaultAPIQuery {
119121
}
120122

121123
$VaultSplat = @{
122-
URI = $uri
123-
Method = $Method
124-
Headers = New-VaultAPIHeader
124+
URI = $uri
125+
Method = $Method
126+
Headers = New-VaultAPIHeader
127+
SkipCertificateCheck = $script:VaultSkipVerify
125128
}
126129
if ($null -ne $body) { $VaultSplat['Body'] = $body }
127130

@@ -169,7 +172,7 @@ function Invoke-VaultToken {
169172
Write-Verbose "Retrieving a Token for authenticating to Vault"
170173
$RenewToken = $false
171174
#continue
172-
} elseif ($Null -ne $script:VaultToken -and $script:TokenExpireTime -lt (Get-date)) {
175+
} elseif ($Null -ne $script:VaultToken -and $script:TokenExpireTime -lt (Get-date) -and -not $script:RootToken) {
173176
# Retrieve a new token if expired
174177
Write-Verbose "Token Expired at $($script:TokenExpireTime). Retieving a new token"
175178
$script:VaultToken = $null
@@ -248,11 +251,11 @@ function Invoke-VaultToken {
248251
}
249252
try {
250253
if ($script:VaultAuthType -notin @('Token', 'RenewToken')) {
251-
$auth = (Invoke-RestMethod -Method POST -Uri $UserLogin -Body $UserPassword -ErrorVariable RestError)
254+
$auth = (Invoke-RestMethod -Method POST -Uri $UserLogin -Body $UserPassword -ErrorVariable RestError -SkipCertificateCheck:$script:VaultSkipVerify)
252255
$auth_info = $auth.auth
253256
$script:VaultToken = $auth_info.client_token | ConvertTo-SecureString -AsPlainText -Force
254257
} elseif ($script:VaultAuthType -eq 'RenewToken') {
255-
$auth = (Invoke-RestMethod -Method POST -Uri $UserLogin -Headers $headers -ErrorVariable RestError)
258+
$auth = (Invoke-RestMethod -Method POST -Uri $UserLogin -Headers $headers -ErrorVariable RestError -SkipCertificateCheck:$script:VaultSkipVerify)
256259
$auth_info = $auth.auth
257260
$script:VaultToken = $auth_info.client_token | ConvertTo-SecureString -AsPlainText -Force
258261
}
@@ -261,13 +264,18 @@ function Invoke-VaultToken {
261264
$token_uri = "$($script:VaultServer)/$($script:VaultAPIVersion)/auth/token/lookup"
262265
$token_body = @{'token' = $([PSCredential]::new("token", $($script:VaultToken)).GetNetworkCredential().Password) } | ConvertTo-Json
263266
$Headers = New-VaultAPIHeader
264-
$token_info = (Invoke-RestMethod -Method POST -Uri $token_uri -Body $token_body -Headers $headers -ErrorVariable RestError)
267+
$token_info = (Invoke-RestMethod -Method POST -Uri $token_uri -Body $token_body -Headers $headers -ErrorVariable RestError -SkipCertificateCheck:$script:VaultSkipVerify)
265268

266269
# Storing the information for checking before future calls.
270+
if ($token_info.data.policies -contains 'root') {
271+
$script:RootToken = $true
272+
}
267273
$script:TokenRenewable = $token_info.data.renewable
268274
$script:TokenType = $token_info.data.type
269275
$script:TokenLifespan = $token_info.data.ttl
270-
$script:TokenExpireTime = $token_info.data.expire_time
276+
if (-not $script:RootToken) {
277+
$script:TokenExpireTime = $token_info.data.expire_time
278+
}
271279
} catch {
272280
if ($null -ne $RestError.message) {
273281
throw "Received an error: $($RestError.message)"
@@ -303,9 +311,10 @@ function New-Vault {
303311
$version = '2'
304312
}
305313
$VaultSplat = @{
306-
URI = $serverURI
307-
Method = 'POST'
308-
Headers = New-VaultAPIHeader
314+
URI = $serverURI
315+
Method = 'POST'
316+
Headers = New-VaultAPIHeader
317+
SkipCertificateCheck = $script:VaultSkipVerify
309318
}
310319
$VaultOptions = @{
311320
type = 'kv'
@@ -398,9 +407,10 @@ function Remove-Vault {
398407
$serverURI = $($script:VaultServer), $($script:VaultAPIVersion), 'sys/mounts', $VaultName -join '/'
399408
Write-Verbose "Removing $VaultName. $AdditionalParameters['Description']"
400409
$VaultSplat = @{
401-
URI = $serverURI
402-
Method = 'DELETE'
403-
Headers = New-VaultAPIHeader
410+
URI = $serverURI
411+
Method = 'DELETE'
412+
Headers = New-VaultAPIHeader
413+
SkipCertificateCheck = $script:VaultSkipVerify
404414
}
405415

406416
Invoke-RestMethod @VaultSplat
@@ -476,7 +486,7 @@ function Get-Secret {
476486
[hashtable] $AdditionalParameters
477487
)
478488
process {
479-
$VerboseSplat = @{Verbose = $AdditionalParameters['Verbose']}
489+
$VerboseSplat = @{Verbose = $AdditionalParameters['Verbose'] }
480490
$null = Test-SecretVault -VaultName $VaultName -AdditionalParameters $AdditionalParameters
481491
if ($Name -match '/') {
482492
$SecretName = $($Name -split '/')[-1]
@@ -549,7 +559,7 @@ function Get-SecretInfo {
549559
[hashtable] $AdditionalParameters
550560
)
551561
process {
552-
$VerboseSplat = @{Verbose = $AdditionalParameters['Verbose']}
562+
$VerboseSplat = @{Verbose = $AdditionalParameters['Verbose'] }
553563
$null = Test-SecretVault -VaultName $VaultName -AdditionalParameters $AdditionalParameters
554564
$Filter = "*$Filter"
555565
$VaultSecrets = Resolve-VaultSecretPath -VaultName $VaultName @VerboseSplat
@@ -583,7 +593,7 @@ function Remove-Secret {
583593
[hashtable] $AdditionalParameters
584594
)
585595
process {
586-
$VerboseSplat = @{Verbose = $AdditionalParameters['Verbose']}
596+
$VerboseSplat = @{Verbose = $AdditionalParameters['Verbose'] }
587597
$null = Test-SecretVault -VaultName $VaultName -AdditionalParameters $AdditionalParameters
588598
$SecretData = Invoke-VaultAPIQuery -VaultName $VaultName -SecretName $Name @VerboseSplat
589599

@@ -609,7 +619,7 @@ function Set-Secret {
609619
[hashtable] $Metadata
610620
)
611621
process {
612-
$VerboseSplat = @{Verbose = $AdditionalParameters['Verbose']}
622+
$VerboseSplat = @{Verbose = $AdditionalParameters['Verbose'] }
613623
$null = Test-SecretVault -VaultName $VaultName -AdditionalParameters $AdditionalParameters
614624
$type = $Secret.GetType()
615625
switch ($Secret.GetType()) {

SecretManagement.Hashicorp.Vault.KV/SecretManagement.Hashicorp.Vault.KV.psd1

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
@{
2-
ModuleVersion = '2.0.0'
2+
ModuleVersion = '2.0.1'
33
CompatiblePSEditions = @('Core')
44
GUID = '5dbf943d-d9c0-4db5-88a2-1995043a6305'
55
Author = 'Josh Corrick'
@@ -15,7 +15,7 @@
1515

1616
PSData = @{
1717
# Prerelease string of this module
18-
# Prerelease = 'Preview'
18+
Prerelease = 'Preview'
1919
Tags = 'SecretManagement', 'HashiCorp', 'Secret', 'Vault', 'MacOS', 'Linux', 'Windows'
2020
ExternalModuleDependencies = @('Microsoft.PowerShell.SecretManagement')
2121
LicenseUri = 'https://raw.githubusercontent.com/joshcorr/SecretManagement.Hashicorp.Vault.KV/main/LICENSE'

SecretManagement.Hashicorp.Vault.KV/en-us/about_SecretManagement.Hashicorp.Vault.KV.Extension.Help.txt

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -42,6 +42,7 @@ REGISTRATION PARAMETERS
4242
VaultAuthType - The type of auth you will use to retrieve a token
4343
VaultToken - The Vault Token you are using. This must be input as ConvertFrom-SecureString output.
4444
VaultAPIVersion - Defaults to v1
45+
VaultSkipVerify - To disable HTTPS certificate checks (e.g. self-signed certs). Defaults as $false
4546
KVVersion - Defaults to v2
4647
OutputType - Defaults to Hashtable
4748
Verbose - Supported by SecretManagement

0 commit comments

Comments
 (0)