Help us shape the future of Go! Take the 2026 Go Developer Survey

vaultpkcs11

package module
v0.0.0-...-2fd882a Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Sep 30, 2020 License: MPL-2.0 Imports: 14 Imported by: 0

README

What this is

This is a plugin for HashiCorp Vault that implements storing data objects into HSM devices using PKCS#11

It support multiple devices and uses a tree like structure to store objects.

At this stage its considered a MVP for storing data objects on a HSM.

Installation

  1. Download the plugin binary or compile it by using the Makefile
  2. Copy the binary to your plugins directory.
  3. Enable the plugin globaly
$ vault write sys/plugins/catalog/database/pkcs11 \
    sha256=<expected SHA256 Hex value of the plugin binary> \
    command="myplugin"
  1. Mount the secrent engine
$ vault secrets enable pkcs11
Success! Enabled the pkcs11 secrets engine at: pkcs11/
  1. Configure the HSM device
$ vault write pkcs11/devices/my-device lib_path="/usr/lib/pkcs11/libsofthsm2.so" slot=229915468 pin="1234"   
$ vault read pkcs11/devices/my-device
Key         Value
---         -----
lib_path    /usr/lib/pkcs11/libsofthsm2.so
pin         1234
slot        229915468

  1. Read/Write data to your HSM device
$ vault write pkcs11/devices/my-device/foo3 bar=foo
Success! Data written to: pkcs11/devices/my-device/foo3
$vault read  pkcs11/devices/my-device/foo3 -format=json
{
  "request_id": "3f2371a1-a0e5-b137-2edc-5cab18ee59c6",
  "lease_id": "",
  "lease_duration": 0,
  "renewable": false,
  "data": {
    "data": {
      "bar": "foo"
    }
  },
  "warnings": null
}

Verification

$ pkcs11-tool --module /usr/lib/softhsm/libsofthsm2.so --slot 229915468 --login --pin 1234 -O
Data object 2
  label:          'vault_path=my-device/foo3'
  application:    'HashiCorp Vault pkcs11 secret'
  app_id:         <empty>
  flags:           modifiable private

$ pkcs11-tool --module /usr/lib/softhsm/libsofthsm2.so --slot 229915468 --login --pin 1234 -r --label 'vault_path=my-device/foo3' --type data
{"bar":"foo"}⏎

TODO

  • Add Leases to data objects
  • Add other types of objects
  • Add full testing coverage
  • Add write/destroy-only objects

License

Mozilla Public License Version 2.0

Documentation

Index

Constants

This section is empty.

Variables

View Source
var (
	ErrdeviceNotFound = errors.New("Error: encryption device not found")
)

Functions

func Backend

func Backend() *backend

Backend returns a configured instance of the backend.

func Factory

Factory returns a configured instance of the backend.

Types

type Device

type Device struct {
	// Name is the name of the device in Vault.
	Name string `json:"name"`

	LibPath string `json:"lib_path"`
	Slot    int    `json:slot`
	Pin     string `json:pin`
	ObjID   uint   `json:obj_id`
}

Device represents a device configuration from the storage backend.

Directories

Path Synopsis
cmd

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL