Skip to content
This repository was archived by the owner on Dec 8, 2021. It is now read-only.
This repository was archived by the owner on Dec 8, 2021. It is now read-only.

[SecretManagement] Get-Secret / Set-Secret hooks support #94

Open
@itfranck

Description

@itfranck

Additional optional vault parameters to support hooks :

  • After a secret is received, before it is returned to the user
  • Before a secret is set and sent to the keyvault.

The Flow of operations would be :

  • Get-Secret is called

  • AfterGet scriptblock is invoked (if present in vault registration)

  • Secret is returned

  • Set-Secret is called

  • BeforeSet scriptblock is invoked (if present in vault registration)

  • Secret is set in the SecretVault

The idea is to overhaul existing providers with additional features without creating a custom implementation and / or having to use a second function to pre-process / post-process a secret before using the Get/Set secret.

Some potential uses

  • Double encryption before sending a credential into an external vault (eg: ProtectTo-Cms)
  • Managing incomplete implementation (eg: Az.Keyvault support only SecureString. You could use a hook on the BeforeSet to convert the other supported types (hashtable, pscredential, etc) to secure string and the AfterGet to convert it back )
  • Accepting custom secret classes (by using BeforeSet to convert the unsupported type to something else and back again to the class in the AfterGet)

Main advantage
The main benefit of having those options as scriptblock defined in the vault registration is that it is would be embedded into that vault, meaning if you want to use Protect-CMS before sending your secret into the vault, you'd have to do it manually and every time. Furthermore, you'd have to to the reverse operation every time after getting your secret back.

The idea of hook streamline that process by embedding further capabilities directly into Get-Secret / Set-Secret managed directly and transparently through the vault registration.

Example 1 : Double encryption

$Params = @{
    'AffterGet' = { $_ | Unprotect-CmsMessage "*youralias@emailaddress.com*" }
    'BeforeSet' = { $_ | Protect-CmsMessage -To "*youralias@emailaddress.com*" }
}

Register-SecretVault -Name 'DoubleEncryptionVault' -VaultParameters $params

Example 2 :
I opened these issues regarding Az.Keyvault implementation, which only support SecureString.
With hooks, I could easily had registered my vault with Scriptblock to manage conversion from other supported type to SecureString before Set-Secret set the actual secret in the vault and back from the SecureString to the desired type. It would have allowed me to workaround the Az.Keyvault limitation, which might or might not be fixed anytime soon.

#93
Azure/azure-powershell#12190

Example 3:
This ultimately will fail.
PSCustomObject and classes are not supported.
However, with hooks, I could manage the conversion of the unknown object to something manageable by the Set-Secret accepted type and even enforce specific types.

$CustomObject = [PSCustomObject]@{
    'Hello' = 'World'
    'Foo' = 'Bar'
}


$CustomObject.GetType()

Set-Secret -Vault BuiltInLocalVault -Name test -Secret $CustomObject

Metadata

Metadata

Assignees

No one assigned

    Labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions