From 53227f9126f00f4b1e925a3d42920dc32765c7e9 Mon Sep 17 00:00:00 2001 From: unkin-agent Date: Tue, 17 Nov 2026 23:12:37 +1100 Subject: [PATCH] Prepare for public release (#5) The engine is being published as github.com/IUCLabs/vault-plugin-secrets-gpg, so the module path, docs and examples must stand alone without private infrastructure references. - move the Go module to github.com/IUCLabs/vault-plugin-secrets-gpg - replace private identities in examples and tests with example.com - add MIT LICENSE - rewrite README: overview, install for Vault and OpenBao, usage, link to terraform-provider-vault-secrets-gpg - add per-path reference docs under docs/ - correct min_decryption_version description (decryption only) Reviewed-on: https://git.unkin.net/unkin/vault-plugin-secrets-gpg/pulls/5 Co-authored-by: unkin-agent Co-committed-by: unkin-agent --- LICENSE | 21 +++++ README.md | 129 ++++++++++++++------------- backend_test.go | 4 +- cmd/vault-plugin-secrets-gpg/main.go | 2 +- docs/encrypt-decrypt.md | 43 +++++++++ docs/export.md | 28 ++++++ docs/keys.md | 118 ++++++++++++++++++++++++ docs/sign-verify.md | 43 +++++++++ go.mod | 2 +- path_config.go | 2 +- path_keys.go | 2 +- scripts/build-rpm.sh | 4 +- scripts/e2e.sh | 2 +- 13 files changed, 328 insertions(+), 72 deletions(-) create mode 100644 LICENSE create mode 100644 docs/encrypt-decrypt.md create mode 100644 docs/export.md create mode 100644 docs/keys.md create mode 100644 docs/sign-verify.md diff --git a/LICENSE b/LICENSE new file mode 100644 index 0000000..83ee371 --- /dev/null +++ b/LICENSE @@ -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. diff --git a/README.md b/README.md index ad0f9a0..64ea465 100644 --- a/README.md +++ b/README.md @@ -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/`. +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/ - ▼ ▼ -export/public-key/ ◀── 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/` (write/read/delete, list `keys/`) | generate a key (`rsa-2048`, `rsa-3072`, `rsa-4096`, `ed25519`); read metadata + armored public key | -| `keys//config` | set `min_decryption_version`, `deletion_allowed`, `exportable` | -| `keys//rotate` | add a new version (older versions kept for decrypt/verify) | -| `keys//import` | import an existing armored private key | -| `export//[/]` | export armored key material | -| `sign/` / `verify/` | detached OpenPGP signature over base64 input | -| `encrypt/` / `decrypt/` | OpenPGP encrypt to / decrypt with the key | - -Creating a key is **idempotent** — writing `keys/` again returns the -existing key rather than regenerating it. Deletion is refused unless -`deletion_allowed=true` is set via `keys//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 " +vault read gpg/keys/app -# generate a key -vault write gpg/keys/app algorithm=rsa-4096 identity="App " -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/` 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) diff --git a/backend_test.go b/backend_test.go index 4f1ec41..cf5bb57 100644 --- a/backend_test.go +++ b/backend_test.go @@ -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 ", + "identity": "Test Key ", }) } @@ -169,7 +169,7 @@ func TestExportImportRoundtrip(t *testing.T) { do(t, b, s, logical.CreateOperation, "keys/src", map[string]interface{}{ "algorithm": "ed25519", - "identity": "Exportable ", + "identity": "Exportable ", "exportable": true, }) diff --git a/cmd/vault-plugin-secrets-gpg/main.go b/cmd/vault-plugin-secrets-gpg/main.go index 9e4acda..b3445c1 100644 --- a/cmd/vault-plugin-secrets-gpg/main.go +++ b/cmd/vault-plugin-secrets-gpg/main.go @@ -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() { diff --git a/docs/encrypt-decrypt.md b/docs/encrypt-decrypt.md new file mode 100644 index 0000000..dda0413 --- /dev/null +++ b/docs/encrypt-decrypt.md @@ -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 +``` diff --git a/docs/export.md b/docs/export.md new file mode 100644 index 0000000..78b1a6e --- /dev/null +++ b/docs/export.md @@ -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 +``` diff --git a/docs/keys.md b/docs/keys.md new file mode 100644 index 0000000..8ea1bf0 --- /dev/null +++ b/docs/keys.md @@ -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 `. | +| `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 " +``` + +## 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 +``` diff --git a/docs/sign-verify.md b/docs/sign-verify.md new file mode 100644 index 0000000..5a3118f --- /dev/null +++ b/docs/sign-verify.md @@ -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 +``` diff --git a/go.mod b/go.mod index 98b88ab..60d2869 100644 --- a/go.mod +++ b/go.mod @@ -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 diff --git a/path_config.go b/path_config.go index 2b52293..f44c64f 100644 --- a/path_config.go +++ b/path_config.go @@ -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, diff --git a/path_keys.go b/path_keys.go index a77b30b..a1de57d 100644 --- a/path_keys.go +++ b/path_keys.go @@ -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 ". Defaults to the key name.`, + Description: `OpenPGP User ID for the key, e.g. "Jane Doe ". Defaults to the key name.`, }, "exportable": { Type: framework.TypeBool, diff --git a/scripts/build-rpm.sh b/scripts/build-rpm.sh index 63c3538..d59afd2 100755 --- a/scripts/build-rpm.sh +++ b/scripts/build-rpm.sh @@ -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 " -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() { diff --git a/scripts/e2e.sh b/scripts/e2e.sh index 33c8fe5..cc48a84 100755 --- a/scripts/e2e.sh +++ b/scripts/e2e.sh @@ -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 ')" + pub="$(ex write -field=public_key "${MOUNT}/keys/app" algorithm=rsa-2048 identity='App ')" printf '%s' "${pub}" | grep -q 'BEGIN PGP PUBLIC KEY BLOCK' || fail "[${engine}] no armored public key returned" green "[${engine}] key generated; public key exported"