Prepare for public release #5

Merged
benvin merged 4 commits from benvin/public-release-docs into main 2026-11-17 23:12:37 +11:00
13 changed files with 328 additions and 72 deletions
+21
View File
@@ -0,0 +1,21 @@
MIT License
Copyright (c) 2026 IUCLabs
Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
in the Software without restriction, including without limitation the rights
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
copies of the Software, and to permit persons to whom the Software is
furnished to do so, subject to the following conditions:
The above copyright notice and this permission notice shall be included in all
copies or substantial portions of the Software.
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
SOFTWARE.
+66 -63
View File
@@ -1,57 +1,62 @@
# vault-plugin-secrets-gpg
A HashiCorp Vault / OpenBao secrets engine that manages **GPG / OpenPGP keys**
and performs **signing, verification, encryption and decryption** with them —
the transit engine, but the key material is OpenPGP.
A secrets engine for HashiCorp Vault and OpenBao that manages OpenPGP (GPG)
keys and signs, verifies, encrypts and decrypts with them. Think of it as the
transit engine, but the keys are OpenPGP keys.
Keys are generated and stored inside Vault's own barrier storage (seal-wrapped
under `key/`) and the private key never leaves Vault unless a key is explicitly
marked `exportable`. Each named key is **versioned**: rotating adds a new
OpenPGP entity, while older versions are retained so archived signatures still
verify and old ciphertext still decrypts.
### Why use this plugin?
The armored public key the engine hands back is a standard, importable OpenPGP
key, so `gpg`, [`pass`](https://www.passwordstore.org/) and friends can encrypt
to it while the private key stays in Vault and decryption is delegated back to
`decrypt/<name>`.
Private keys are generated and stored in Vault's barrier storage. They never
leave Vault unless you mark a key `exportable`. The engine hands out a
standard armored public key, so `gpg`, [`pass`](https://www.passwordstore.org/)
and other OpenPGP tools can encrypt to the key. Decryption goes back through
Vault. Keys are versioned: when you rotate a key, older versions stay
available, so old signatures still verify and old ciphertext still decrypts.
```
gpg / pass ──encrypt to public key──▶ binary .gpg
│ │
│ import public key │ decrypt/<name>
▼ ▼
export/public-key/<name> ◀── Vault ──▶ private key (never leaves the barrier)
To manage the engine's mounts and keys from Terraform or OpenTofu, use
[terraform-provider-vault-secrets-gpg](https://github.com/IUCLabs/terraform-provider-vault-secrets-gpg).
## Requirements
- HashiCorp Vault or OpenBao. The same binary works on both. The end-to-end
tests run against Vault 1.18 and the latest OpenBao release.
- Go 1.25+ (only if you build from source)
## Installation
Download a binary from the
[releases page](https://github.com/IUCLabs/vault-plugin-secrets-gpg/releases),
or build one:
```sh
make build # -> dist/vault-plugin-secrets-gpg
```
## Paths
Copy the binary into the server's `plugin_directory`, then register it in the
plugin catalog and enable the engine. On OpenBao, run the same commands with
`bao` in place of `vault`.
The example assumes `plugin_directory = "/etc/vault/plugins"`; use the
directory set in your server config.
| Path | Purpose |
|------|---------|
| `keys/<name>` (write/read/delete, list `keys/`) | generate a key (`rsa-2048`, `rsa-3072`, `rsa-4096`, `ed25519`); read metadata + armored public key |
| `keys/<name>/config` | set `min_decryption_version`, `deletion_allowed`, `exportable` |
| `keys/<name>/rotate` | add a new version (older versions kept for decrypt/verify) |
| `keys/<name>/import` | import an existing armored private key |
| `export/<public-key\|private-key>/<name>[/<version>]` | export armored key material |
| `sign/<name>` / `verify/<name>` | detached OpenPGP signature over base64 input |
| `encrypt/<name>` / `decrypt/<name>` | OpenPGP encrypt to / decrypt with the key |
Creating a key is **idempotent** — writing `keys/<name>` again returns the
existing key rather than regenerating it. Deletion is refused unless
`deletion_allowed=true` is set via `keys/<name>/config`.
```sh
SHA256=$(sha256sum /etc/vault/plugins/vault-plugin-secrets-gpg | cut -d' ' -f1)
vault plugin register -sha256="$SHA256" secret vault-plugin-secrets-gpg
vault secrets enable -path=gpg vault-plugin-secrets-gpg
```
## Usage
The engine has no mount-level configuration. Each key holds its own settings
(see [keys](docs/keys.md)).
All binary input and output is base64-encoded.
```sh
# register + enable (the plugin_directory must contain the binary)
sha=$(sha256sum /opt/vault-plugins/vault-plugin-secrets-gpg | cut -d' ' -f1)
vault plugin register -sha256=$sha secret vault-plugin-secrets-gpg
vault secrets enable -path=gpg vault-plugin-secrets-gpg
# create a key (repeating the write returns the existing key)
vault write gpg/keys/app algorithm=rsa-4096 identity="App <app@example.com>"
vault read gpg/keys/app
# generate a key
vault write gpg/keys/app algorithm=rsa-4096 identity="App <app@unkin.net>"
vault read gpg/keys/app # metadata + armored public key
# sign / verify (input and output are base64 / armored)
# sign / verify
sig=$(vault write -field=signature gpg/sign/app input=$(base64 <<<"ship it"))
vault write -field=valid gpg/verify/app input=$(base64 <<<"ship it") signature="$sig"
@@ -59,42 +64,40 @@ vault write -field=valid gpg/verify/app input=$(base64 <<<"ship it") signature="
ct=$(vault write -field=ciphertext gpg/encrypt/app plaintext=$(base64 <<<"secret"))
vault write -field=plaintext gpg/decrypt/app ciphertext="$ct" | base64 -d
# rotate; old ciphertext still decrypts
# rotate; ciphertext from older versions still decrypts
vault write gpg/keys/app/rotate
```
## Using it with `pass`
### With `pass`
The engine holds the private key; `pass`/`gpg` only need the **public** key to
encrypt, and delegate decryption back to Vault.
`pass` needs only the public key to encrypt. Decryption goes through Vault.
```sh
# import the engine's public key into your gpg keyring
vault read -field=public_key gpg/keys/app | gpg --import
fpr=$(vault read -field=fingerprint gpg/keys/app)
pass init "$(vault read -field=fingerprint gpg/keys/app)"
pass insert email/example
# initialise a password store against it
pass init "$fpr"
pass insert email/example # writes ~/.password-store/email/example.gpg (binary OpenPGP)
# decrypt an entry through Vault (decrypt accepts binary ciphertext directly)
vault write -field=plaintext gpg/decrypt/app \
ciphertext=$(base64 -w0 ~/.password-store/email/example.gpg) | base64 -d
```
`decrypt/<name>` auto-detects ASCII-armored vs raw-binary input, so the binary
`.gpg` files `pass` writes work without conversion. A thin `gpg`/`pass`
wrapper that routes decryption to Vault automatically can be layered on top.
## Documentation
## Build
Full path reference:
- [Keys](docs/keys.md): `keys/`, `keys/:name`, `keys/:name/config`, `keys/:name/rotate`, `keys/:name/import`
- [Export](docs/export.md): `export/:type/:name(/:version)`
- [Sign and verify](docs/sign-verify.md): `sign/:name`, `verify/:name`
- [Encrypt and decrypt](docs/encrypt-decrypt.md): `encrypt/:name`, `decrypt/:name`
## Development
```sh
make build # -> dist/vault-plugin-secrets-gpg
make test lint # go test -race / go vet
make e2e # full lifecycle against Vault + OpenBao in Docker
make rpm # vault + openbao RPM flavours
make test # unit tests, including gpg/pass interop when those binaries exist
make lint
make e2e # full lifecycle against Vault and OpenBao in Docker
```
CI (Woodpecker) runs pre-commit/build/lint/test on PRs and builds+publishes the
RPMs on a `v*` tag. The unit tests include real-`gpg` and real-`pass` interop
checks (skipped automatically when those binaries are absent).
## License
[MIT](LICENSE)
+2 -2
View File
@@ -41,7 +41,7 @@ func createKey(t *testing.T, b logical.Backend, s logical.Storage, name, algorit
t.Helper()
return do(t, b, s, logical.CreateOperation, "keys/"+name, map[string]interface{}{
"algorithm": algorithm,
"identity": "Test Key <test@unkin.net>",
"identity": "Test Key <test@example.com>",
})
}
@@ -169,7 +169,7 @@ func TestExportImportRoundtrip(t *testing.T) {
do(t, b, s, logical.CreateOperation, "keys/src", map[string]interface{}{
"algorithm": "ed25519",
"identity": "Exportable <e@unkin.net>",
"identity": "Exportable <e@example.com>",
"exportable": true,
})
+1 -1
View File
@@ -7,7 +7,7 @@ import (
"github.com/hashicorp/vault/api"
"github.com/hashicorp/vault/sdk/plugin"
gpg "git.unkin.net/unkin/vault-plugin-secrets-gpg"
gpg "github.com/IUCLabs/vault-plugin-secrets-gpg"
)
func main() {
+43
View File
@@ -0,0 +1,43 @@
# Encrypt and decrypt
Messages are standard OpenPGP messages. Anything encrypted to the key's public
key, whether by this engine, `gpg` or `pass`, can be decrypted here.
## Encrypt
`POST /gpg/encrypt/:name`
Encrypts to the latest key version.
| Parameter | Type | Default | Description |
|-----------|------|---------|-------------|
| `plaintext` | string | required | Base64-encoded plaintext. |
| `format` | string | `base64` | `base64` (base64-encoded binary OpenPGP), or `ascii-armor`. |
The response has `ciphertext` and `key_version`.
```sh
vault write -field=ciphertext gpg/encrypt/app plaintext=$(base64 <<<"secret")
vault write -field=ciphertext gpg/encrypt/app plaintext=$(base64 <<<"secret") format=ascii-armor
```
## Decrypt
`POST /gpg/decrypt/:name`
Tries every key version at or above `min_decryption_version`. The engine
detects whether the input is armored or binary.
| Parameter | Type | Description |
|-----------|------|-------------|
| `ciphertext` | string | ASCII-armored message, or base64-encoded binary (the format `gpg`/`pass` write by default). |
The response has `plaintext` (base64).
```sh
vault write -field=plaintext gpg/decrypt/app ciphertext="$ct" | base64 -d
# decrypt a file written by gpg or pass
vault write -field=plaintext gpg/decrypt/app \
ciphertext=$(base64 -w0 ~/.password-store/email/example.gpg) | base64 -d
```
+28
View File
@@ -0,0 +1,28 @@
# Export
`GET /gpg/export/:type/:name(/:version)`
Returns armored key material. `public-key` can always be exported, and is what
`gpg` or `pass` imports to encrypt to the key. `private-key` works only if the
key is `exportable`.
| Parameter | Type | Description |
|-----------|------|-------------|
| `type` | string | `public-key` or `private-key`. |
| `name` | string | Name of the key. |
| `version` | int | Version to export. `0` means the latest version. Leave it out to export every version. |
The response has `name`, `type` and `keys`. `keys` maps each version number to
its armored key.
```sh
# all public versions
vault read gpg/export/public-key/app
# latest public key, ready for gpg
vault read -format=json gpg/export/public-key/app/0 \
| jq -r '.data.keys | to_entries[0].value' | gpg --import
# private key of version 1 (key must be exportable)
vault read gpg/export/private-key/app/1
```
+118
View File
@@ -0,0 +1,118 @@
# Keys
These paths create, read, configure, rotate, import, list and delete named
OpenPGP keys. All examples assume the engine is mounted at `gpg/`.
Every key is versioned. Each version is a separate OpenPGP entity with its own
fingerprint. Private keys are stored seal-wrapped.
## Create key
`POST /gpg/keys/:name`
Generates a new key. Creating a key is idempotent: if the key already exists,
the request returns it unchanged and does not regenerate it.
| Parameter | Type | Default | Description |
|-----------|------|---------|-------------|
| `name` | string | required | Name of the key (in the URL). |
| `algorithm` | string | `rsa-3072` | One of `rsa-2048`, `rsa-3072`, `rsa-4096`, `ed25519`. |
| `identity` | string | key name | OpenPGP User ID, e.g. `Jane Doe <jane@example.com>`. |
| `exportable` | bool | `false` | Allow the private key to be exported. Once enabled, this cannot be disabled. |
```sh
vault write gpg/keys/app algorithm=ed25519 identity="App <app@example.com>"
```
## Read key
`GET /gpg/keys/:name`
Returns key metadata and the armored public key of every version.
```sh
vault read gpg/keys/app
```
| Field | Description |
|-------|-------------|
| `name`, `algorithm`, `identity` | As set at creation. |
| `latest_version` | Highest key version. |
| `min_decryption_version` | Lowest version used for decryption. |
| `deletion_allowed`, `exportable` | Key policy. |
| `imported` | `true` if the key was imported, not generated. |
| `creation_time` | RFC 3339 timestamp. |
| `fingerprint`, `public_key` | Fingerprint and armored public key of the latest version. |
| `keys` | Map of version to `creation_time`, `fingerprint`, `key_id`, `public_key`. |
The create, config, rotate and import endpoints return the same response.
## List keys
`LIST /gpg/keys`
```sh
vault list gpg/keys
```
## Delete key
`DELETE /gpg/keys/:name`
Deletes the key and all of its versions. This fails unless `deletion_allowed`
has been set to `true` through the config endpoint.
```sh
vault write gpg/keys/app/config deletion_allowed=true
vault delete gpg/keys/app
```
## Configure key
`POST /gpg/keys/:name/config`
Changes key policy. The key material is not touched. Only the parameters you
send are changed.
| Parameter | Type | Description |
|-----------|------|-------------|
| `min_decryption_version` | int | Lowest version usable for decryption. Must be between 1 and `latest_version`. |
| `deletion_allowed` | bool | Whether the key may be deleted. |
| `exportable` | bool | Allow private key export. Once enabled, this cannot be disabled. |
```sh
vault write gpg/keys/app/config min_decryption_version=2
```
## Rotate key
`POST /gpg/keys/:name/rotate`
Generates a new version with the same algorithm and identity, and makes it the
latest version. Older versions are kept, so older ciphertext still decrypts and
older signatures still verify. Decryption is limited to versions at or above
`min_decryption_version`.
Imported keys cannot be rotated; the request fails with
`cannot rotate an imported key`.
```sh
vault write -field=latest_version gpg/keys/app/rotate
```
## Import key
`POST /gpg/keys/:name/import`
Imports an existing armored OpenPGP private key as version 1 of a new key.
This fails if the name is already in use.
| Parameter | Type | Default | Description |
|-----------|------|---------|-------------|
| `private_key` | string | required | ASCII-armored private key. It must not be passphrase-protected. |
| `exportable` | bool | `false` | Allow the private key to be exported again later. |
```sh
gpg --export-secret-keys --armor app@example.com > app.asc
vault write gpg/keys/app/import private_key=@app.asc
```
+43
View File
@@ -0,0 +1,43 @@
# Sign and verify
These paths create and check detached OpenPGP signatures. The input message is
always base64-encoded.
## Sign
`POST /gpg/sign/:name`
| Parameter | Type | Default | Description |
|-----------|------|---------|-------------|
| `input` | string | required | Base64-encoded message to sign. |
| `key_version` | int | `0` (latest) | Key version to sign with. |
| `format` | string | `ascii-armor` | `ascii-armor`, or `base64` for a raw binary signature. |
The response has `signature`.
```sh
vault write -field=signature gpg/sign/app input=$(base64 -w0 release.tar.gz) > release.tar.gz.asc
# check it with gpg, using the exported public key
vault read -field=public_key gpg/keys/app | gpg --import
gpg --verify release.tar.gz.asc release.tar.gz
```
## Verify
`POST /gpg/verify/:name`
Checks the signature against every key version.
| Parameter | Type | Description |
|-----------|------|-------------|
| `input` | string | Base64-encoded message that was signed. |
| `signature` | string | Detached signature, either ASCII-armored or base64-encoded binary. |
The response has `valid` (`true` or `false`). A malformed signature returns
`valid=false`, not an error.
```sh
vault write -field=valid gpg/verify/app \
input=$(base64 -w0 release.tar.gz) signature=@release.tar.gz.asc
```
+1 -1
View File
@@ -1,4 +1,4 @@
module git.unkin.net/unkin/vault-plugin-secrets-gpg
module github.com/IUCLabs/vault-plugin-secrets-gpg
go 1.25.0
+1 -1
View File
@@ -22,7 +22,7 @@ func pathKeyConfig(b *gpgBackend) *framework.Path {
},
"min_decryption_version": {
Type: framework.TypeInt,
Description: "Minimum key version usable for decryption and verification. Versions below this can no longer open data.",
Description: "Minimum key version usable for decryption. Versions below this can no longer open data.",
},
"deletion_allowed": {
Type: framework.TypeBool,
+1 -1
View File
@@ -29,7 +29,7 @@ func pathKeys(b *gpgBackend) *framework.Path {
},
"identity": {
Type: framework.TypeString,
Description: `OpenPGP User ID for the key, e.g. "Ben Vincent <ben@unkin.net>". Defaults to the key name.`,
Description: `OpenPGP User ID for the key, e.g. "Jane Doe <jane@example.com>". Defaults to the key name.`,
},
"exportable": {
Type: framework.TypeBool,
+2 -2
View File
@@ -24,8 +24,8 @@ export PACKAGE_RELEASE="1"
export PACKAGE_ARCH="amd64"
export PACKAGE_PLATFORM="linux"
export PACKAGE_DESCRIPTION="Vault/OpenBao secrets engine for GPG/OpenPGP keys (sign/verify/encrypt/decrypt)"
export PACKAGE_MAINTAINER="Ben Vincent <ben@unkin.net>"
export PACKAGE_HOMEPAGE="https://git.unkin.net/unkin/vault-plugin-secrets-gpg"
export PACKAGE_MAINTAINER="IUCLabs"
export PACKAGE_HOMEPAGE="https://github.com/IUCLabs/vault-plugin-secrets-gpg"
export PACKAGE_LICENSE="MIT"
build_flavor() {
+1 -1
View File
@@ -53,7 +53,7 @@ run_engine() {
# --- generate a key ---
local pub
pub="$(ex write -field=public_key "${MOUNT}/keys/app" algorithm=rsa-2048 identity='App <app@unkin.net>')"
pub="$(ex write -field=public_key "${MOUNT}/keys/app" algorithm=rsa-2048 identity='App <app@example.com>')"
printf '%s' "${pub}" | grep -q 'BEGIN PGP PUBLIC KEY BLOCK' || fail "[${engine}] no armored public key returned"
green "[${engine}] key generated; public key exported"