2017-08-08 16:39:19 +00:00
|
|
|
---
|
2020-01-18 00:18:09 +00:00
|
|
|
layout: guides
|
|
|
|
page_title: Plugin Backends - Guides
|
|
|
|
sidebar_title: Building Plugin Backends
|
|
|
|
description: 'Learn how to build, register, and mount a custom plugin backend.'
|
2017-08-08 16:39:19 +00:00
|
|
|
---
|
|
|
|
|
|
|
|
# Introduction
|
|
|
|
|
2018-02-01 17:50:59 +00:00
|
|
|
Plugin backends utilize the [plugin system][plugin-system] to enable third-party
|
|
|
|
secrets engines and auth methods.
|
2017-08-08 16:39:19 +00:00
|
|
|
|
2017-09-20 20:05:00 +00:00
|
|
|
It is worth noting that even though [database secrets engines][database-backend]
|
2017-08-09 14:28:13 +00:00
|
|
|
operate under the same underlying plugin mechanism, they are slightly different
|
2018-02-01 17:50:59 +00:00
|
|
|
in design than plugin backends demonstrated in this guide. The database secrets
|
|
|
|
engine manages multiple plugins under the same backend mount point, whereas
|
|
|
|
plugin backends are kv backends that function as either secret or auth methods.
|
2017-08-08 16:39:19 +00:00
|
|
|
|
|
|
|
This guide provides steps to build, register, and mount non-database external
|
|
|
|
plugin backends.
|
|
|
|
|
2017-09-21 20:56:29 +00:00
|
|
|
## Setup Vault
|
2017-08-08 16:39:19 +00:00
|
|
|
|
|
|
|
Set `plugin_directory` to the desired path in the Vault configuration file.
|
|
|
|
The path should exist and have proper lockdown on access permissions.
|
|
|
|
|
2017-09-21 20:56:29 +00:00
|
|
|
```hcl
|
|
|
|
# /etc/vault/config.d/plugins.hcl
|
|
|
|
plugin_directory = "/etc/vault/vault_plugins"
|
2017-08-08 16:39:19 +00:00
|
|
|
```
|
|
|
|
|
2017-09-21 20:56:29 +00:00
|
|
|
If the Vault server is already running, you will need to tell it to reload its
|
|
|
|
configuration by sending SIGHUP. If you stop and start the Vault server, you
|
|
|
|
will need to unseal it again.
|
|
|
|
|
|
|
|
## Compile Plugin
|
2017-08-08 16:39:19 +00:00
|
|
|
|
2018-02-01 17:50:59 +00:00
|
|
|
Build the custom binary, and move it inside the `plugin_directory` path
|
|
|
|
configured above. This guide uses `mock-plugin` that comes from Vault's
|
|
|
|
[`logical/plugin/mock`](https://github.com/hashicorp/vault/tree/master/logical/plugin/mock/mock-plugin) package.
|
2017-08-08 16:39:19 +00:00
|
|
|
|
2017-09-21 20:56:29 +00:00
|
|
|
Download the source (you would probably use your own plugin):
|
|
|
|
|
2020-05-21 17:18:17 +00:00
|
|
|
```shell-session
|
2017-09-21 20:56:29 +00:00
|
|
|
$ go get -f -u -d github.com/hashicorp/vault
|
|
|
|
# ...
|
2019-04-12 21:54:35 +00:00
|
|
|
$ cd $GOPATH/src/github.com/hashicorp/vault/sdk/plugin/mock/mock-plugin
|
2017-08-08 16:39:19 +00:00
|
|
|
```
|
|
|
|
|
2017-09-21 20:56:29 +00:00
|
|
|
Compile the plugin:
|
2017-08-08 16:39:19 +00:00
|
|
|
|
2020-05-21 17:18:17 +00:00
|
|
|
```shell-session
|
2017-09-21 20:56:29 +00:00
|
|
|
$ go build -o my-mock-plugin
|
|
|
|
```
|
2017-08-08 16:39:19 +00:00
|
|
|
|
2017-09-21 20:56:29 +00:00
|
|
|
Put the plugin in the directory:
|
|
|
|
|
2020-05-21 17:18:17 +00:00
|
|
|
```shell-session
|
2017-09-21 20:56:29 +00:00
|
|
|
$ mv my-mock-plugin /etc/vault/vault_plugins
|
2017-08-08 16:39:19 +00:00
|
|
|
```
|
|
|
|
|
2018-11-14 17:17:12 +00:00
|
|
|
Alternatively, if you wanted a custom version of a plugin built into Vault, such as AppRole:
|
|
|
|
|
2020-05-21 17:18:17 +00:00
|
|
|
```shell-session
|
2018-11-14 17:17:12 +00:00
|
|
|
$ cd $GOPATH/src/github.com/hashicorp/vault/builtin/credential/approle/cmd/approle
|
|
|
|
$ go build
|
|
|
|
$ mv approle /etc/vault/vault_plugins
|
|
|
|
```
|
|
|
|
|
2017-09-21 20:56:29 +00:00
|
|
|
## Register in Plugin Catalog
|
2017-08-08 16:39:19 +00:00
|
|
|
|
2017-09-21 20:56:29 +00:00
|
|
|
Calculate the SHA256 sum of the compiled plugin binary, and use that to register
|
|
|
|
the plugin into Vault's plugin catalog:
|
2017-08-08 16:39:19 +00:00
|
|
|
|
2020-05-21 17:18:17 +00:00
|
|
|
```shell-session
|
2017-09-21 20:56:29 +00:00
|
|
|
$ shasum -a 256 /etc/vault/vault_plugins/my-mock-plugin
|
|
|
|
2c071aafa1b30897e60b79643e77592cb9d1e8f803025d44a7f9bbfa4779d615 /etc/vault/vault_plugins/my-mock-plugin
|
2017-08-08 16:39:19 +00:00
|
|
|
|
2018-11-14 17:17:12 +00:00
|
|
|
$ vault write sys/plugins/catalog/secret/my-mock-plugin \
|
2018-10-04 16:51:54 +00:00
|
|
|
sha256=2c071aafa1b30897e60b79643e77592cb9d1e8f803025d44a7f9bbfa4779d615 \
|
2017-09-21 20:56:29 +00:00
|
|
|
command=my-mock-plugin
|
2018-11-14 17:17:12 +00:00
|
|
|
Success! Data written to: sys/plugins/catalog/secret/my-mock-plugin
|
2017-08-08 16:39:19 +00:00
|
|
|
```
|
|
|
|
|
2017-09-21 20:56:29 +00:00
|
|
|
## Enable Plugin
|
2017-08-08 16:39:19 +00:00
|
|
|
|
2017-09-21 20:56:29 +00:00
|
|
|
Enabling the plugin varies depending on if it's a secrets engine or auth method:
|
|
|
|
|
2020-05-21 17:18:17 +00:00
|
|
|
```shell-session
|
2018-11-14 17:17:12 +00:00
|
|
|
$ vault secrets enable -path=my-secrets-plugin my-mock-plugin
|
2017-09-21 20:56:29 +00:00
|
|
|
Success! Enabled the my-mock-plugin plugin at: my-secrets-plugin/
|
2017-08-08 16:39:19 +00:00
|
|
|
```
|
|
|
|
|
2017-09-21 20:56:29 +00:00
|
|
|
If you try to mount this particular plugin as an auth method instead of a
|
|
|
|
secrets engine, you will get an error:
|
2017-08-08 16:39:19 +00:00
|
|
|
|
2020-05-21 17:18:17 +00:00
|
|
|
```shell-session
|
2018-11-14 17:17:12 +00:00
|
|
|
$ vault auth enable -path=my-auth-plugin my-mock-plugin
|
2017-09-21 20:56:29 +00:00
|
|
|
# ...
|
|
|
|
* cannot mount 'my-mock-plugin' of type 'secret' as an auth method
|
2017-08-08 16:39:19 +00:00
|
|
|
```
|
|
|
|
|
2017-09-21 20:56:29 +00:00
|
|
|
## Perform Operations
|
|
|
|
|
|
|
|
Each plugin responds to read, write, list, and delete as its own behavior.
|
2017-08-08 16:39:19 +00:00
|
|
|
|
2020-05-21 17:18:17 +00:00
|
|
|
```shell-session
|
2017-09-21 20:56:29 +00:00
|
|
|
$ vault write my-secrets-plugin/kv/foo value=bar
|
|
|
|
Key Value
|
|
|
|
--- -----
|
|
|
|
value bar
|
2017-08-08 16:39:19 +00:00
|
|
|
```
|
2017-09-21 20:56:29 +00:00
|
|
|
|
|
|
|
## Disable Plugin
|
|
|
|
|
|
|
|
When you are done using the plugin, disable it.
|
|
|
|
|
2020-05-21 17:18:17 +00:00
|
|
|
```shell-session
|
2017-09-21 20:56:29 +00:00
|
|
|
$ vault secrets disable my-secrets-plugin
|
|
|
|
Success! Disabled the secrets engine (if it existed) at: my-secrets-plugin/
|
2017-08-08 16:39:19 +00:00
|
|
|
```
|
|
|
|
|
2020-01-22 20:05:41 +00:00
|
|
|
[plugin-system]: /docs/internals/plugins
|
|
|
|
[database-backend]: /docs/secrets/databases
|