OpenBao Transit and plugins
Encryption as a service: the key stays in the vault and only the operations come out.
Where we come from
In EXP-001, on secure enclaves, the question was how to protect a key even from whoever controls the machine. Before getting to hardware there is a much simpler and much more common step, one most systems have not taken yet: getting the key out of the application.
The problem
The usual way to encrypt sensitive data is to put the key in an environment variable and encrypt in your own code. It works, but now the key lives everywhere the code runs: the API service, the worker, the backup script, the .env on a developer's laptop. Every copy is one more way to leak it.
What OpenBao is
OpenBao is an open source secrets vault, born as a community fork of HashiCorp Vault when Vault changed its license. It is maintained under the Linux Foundation, licensed MPL 2.0, and still compatible with almost everything written for Vault: the CLI is called bao, but the API, the policies and the plugins have the same shape.
Everything in it is an HTTP API. Every request goes through the same line: who are you, what are you allowed to do, and which part of the vault answers for that path. Those parts are called secrets engines and they are mounted on paths, like folders: kv/ stores secrets, pki/ issues certificates, transit/ does cryptography.
When OpenBao starts it is sealed: the storage is there, but the barrier key is not in memory and nothing opens. To unseal, either a few people combine pieces of a key (Shamir), or a cloud KMS does it on its own (auto-unseal). It is the same idea as sealing in an enclave, only guarded by software and people instead of by the chip.
Transit does not store your data
This is the detail that surprises people most. Transit stores only the keys. The data comes in, goes out encrypted, and your application stores the result in your own database. That is why it handles any volume: OpenBao does not grow with the number of records, only with the number of keys.
What you can ask for
| Path | Does what |
|---|---|
encrypt / decrypt | Encrypts and decrypts a value with the named key. |
rewrap | Re-encrypts an old value with the newest key version, without returning the plaintext. |
datakey | Generates a fresh key so you can encrypt something large on your side (envelope). |
sign / verify | Signs and verifies signatures with asymmetric keys. |
hmac | Computes an HMAC, useful to compare or index values without storing them. |
random / hash | Random bytes and hashes, so you don't depend on the client machine. |
Key types
| Type | Used for |
|---|---|
aes256-gcm96 (default), aes128-gcm96, chacha20-poly1305 | Encrypt and decrypt |
ed25519 | Sign (fast, small key) |
ecdsa-p256, ecdsa-p384, ecdsa-p521 | Sign with NIST curves |
rsa-2048, rsa-3072, rsa-4096 | Sign and encrypt |
hmac | HMAC only |
Notice what is not on the list: secp256k1, the curve used by Bitcoin and Ethereum. Keep that in mind for part three.
Keys that don't leave
By default a Transit key is created with exportable=false and allow_plaintext_backup=false. There is no API path that returns the key material. You can turn export on, but it is a one-way door: once on, it cannot be turned off. In practice, whoever needs export is almost always trying to use Transit as a KV store, and that is not its job.
Versions and rotation
Each Transit key is really a list of versions. Rotating creates a new version, which encrypts everything from then on. The old ones keep decrypting. The ciphertext says which version it used, right in the prefix: vault:v2:… (OpenBao kept Vault's prefix for compatibility).
Quick glossary
- Secrets engine
- An OpenBao module mounted on a path, answering the requests for that path.
- Policy
- A rule that says which paths a token may call and with which capabilities.
- Barrier
- The layer that encrypts everything before it goes to storage.
- Sealed / unsealed
- Without the barrier key in memory, OpenBao opens nothing. Unsealing puts it there.
- Rewrap
- Re-encrypting a value with the current key version without the plaintext leaving OpenBao.
The scenario
A sign-up app stores each customer's tax id (in the examples, a Brazilian CPF). The database is backed up every day, read replicas go to other teams and, every now and then, someone restores a dump on their machine to chase a bug. The goal: the tax id is never in plaintext in any of those places, and the app holds no key.
Turn it on, create the key, encrypt
# turn the engine on and create a key that never leaves OpenBao
bao secrets enable transit
bao write -f transit/keys/customers type=aes256-gcm96
# encrypt: the plaintext always travels as base64
bao write transit/encrypt/customers \
plaintext=$(printf '123.456.789-09' | base64)
# ciphertext vault:v1:8SDd3WHDOjf7mq69CyCqYjBXAiQQAVZRkFM13ok481zo
# decrypt: the answer comes back as base64 too
bao write transit/decrypt/customers \
ciphertext=vault:v1:8SDd3WHDOjf7mq69CyCqYjBXAiQQAVZRkFM13ok481zo
# plaintext MTIzLjQ1Ni43ODktMDk=The plaintext travels as base64 because Transit treats everything as bytes. A tax id, a photo or a JSON document all take the same path.
The app's policy
The app's token may only call the two paths it needs, and only for this key:
# the app encrypts and decrypts with this one key, and nothing else
path "transit/encrypt/customers" {
capabilities = ["update"]
}
path "transit/decrypt/customers" {
capabilities = ["update"]
}POST, and POST maps to the update capability, not create. Even creating a key (POST transit/keys/name) counts as update. That is why the app's token should have no capability at all on transit/keys/*: managing keys is another role.The life of a tax id
vault:v1:….Large files: envelope
Sending a 40 MB PDF to OpenBao on every upload is a waste. For large data Transit hands you a data key and steps out of the way:
- The app calls
transit/datakey/plaintext/customersand gets two things back: a fresh key in plaintext and the same key encrypted by the Transit key. - The app encrypts the file locally with the plaintext key.
- The plaintext key is thrown away. Only its encrypted copy is stored next to the file.
- To read, the app sends the encrypted key to
decrypt, gets the plaintext key back and decrypts the file.
OpenBao sees a few bytes per file, and the main key still never leaves it. Cloud KMS products use the same pattern under the hood.
Sign and verify
With an asymmetric key, Transit signs instead of encrypting. Example: receipts that a partner must be able to verify without talking to your vault.
bao write transit/keys/receipts type=ed25519
bao write transit/sign/receipts input=$(printf 'receipt 0042: 150.00' | base64)
# signature vault:v1:3q2+7wAAqL…
bao write transit/verify/receipts \
input=$(printf 'receipt 0042: 150.00' | base64) signature=vault:v1:3q2+7wAAqL…
# valid true
# the public key is readable: anyone can verify offline, without OpenBao
bao read transit/keys/receiptsThe private key stays in OpenBao. The public one can go into a file, an endpoint or the partner's README.
Rotation, for real
# new version v2: new data is encrypted with it, v1 still decrypts
bao write -f transit/keys/customers/rotate
# re-encrypt an old value with the latest version, without the plaintext leaving
bao write transit/rewrap/customers ciphertext=vault:v1:8SDd3WHD…
# ciphertext vault:v2:Xk0q9Lrb…
# once everything is rewrapped, v1 stops opening anything
bao write transit/keys/customers/config min_decryption_version=2
# or let OpenBao rotate on its own, every 30 days
bao write transit/keys/customers/config auto_rotate_period=720hA job sweeps the table now and then, rewraps whatever is still on old versions and, once nothing is left, raises min_decryption_version. No tax id goes through that job in plaintext.
One key per customer, without creating a thousand keys
With derived=true, the key accepts a context on each call and derives a subkey from it. Using the customer id as context, one customer's ciphertext does not open with another customer's context, even though it is the same key in OpenBao. That helps in multi-tenant systems: a bug that mixes up the id when reading returns an error, not someone else's data.
What Transit guarantees
- The key is not in the app. A memory dump of the app, a leaked
.envor a database backup do not give away the key. - One place to audit. Every encrypt and decrypt goes through OpenBao's audit log, with the token that asked.
- Revoking is fast. Removing a policy or revoking a token cuts access immediately, without changing any key.
- Rotation without downtime. Old versions keep opening until you decide they don't.
What is still on you
- A stolen token is an oracle. Whoever holds the app's token can decrypt everything the app decrypts. Short-lived tokens, AppRole with an expiring
secret_idand alerts on the audit log shrink the window. - OpenBao becomes a dependency. If it goes down, nobody reads a tax id. It needs high availability like a database does.
- Latency per call. Each operation is a network round trip. The paths accept
batch_inputto encrypt many values in one call. - Whoever runs the OpenBao server can still see the key. It is encrypted on disk, but in plaintext in the process memory. That is exactly the problem the enclave solves.
Where Transit stops
Transit has a closed set of operations and key types. Two situations show up early:
- An algorithm is missing. You need to sign with
secp256k1, or with a signature scheme Transit does not know. - A rule about the content is missing. Transit signs anything an authorized token sends. The policy decides who may call
sign, never what may be signed.
How a plugin runs
A plugin is a secrets engine you write, in a separate binary. OpenBao starts that binary as a child process and talks to it over gRPC, with mutual TLS between the two. To the rest of the world it is just another mounted path, like transit/.
If the plugin crashes, OpenBao starts it again. If someone swaps the binary on disk, the hash does not match the catalog and it does not start. Recent OpenBao versions can also declare plugins in the server config file, which keeps the hash versioned together with the infrastructure.
An example: signing releases
An open source project publishes signed binaries. Whoever downloads them checks the signature against the project's public key. Today the private key sits in a CI secret: any job, from any branch, can sign anything. We want a release-signer that only signs when:
require ci-manifest:
the build manifest is signed by the CI key and came from the main branch
require known-artifact:
the artifact hash is on the manifest's list
require version-goes-up:
the version is greater than the last signed version
default: denyThe ed25519 key is generated inside the plugin on first use and kept in its storage. Nobody ever has to copy it anywhere. Only the public key has a read path.
Register, mount, call
# the binary sits in the plugin_directory set in the server config
sha256sum /etc/openbao/plugins/release-signer
# the catalog pins name + hash: a different binary will not start
bao plugin register -sha256=4f1c…9a secret release-signer
bao secrets enable -path=releases release-signer
# from the CI pipeline
bao write releases/sign artifact_sha256=9f2c…e1 version=2.4.0 manifest=@manifest.jsonThe path of each request
Pick a request to see how far it gets:
No request picked: the flowchart shows every path.
The code, simplified
A secrets engine plugin is a Go program using the OpenBao SDK: it declares paths, the fields of each one and which function answers. The heart of release-signer fits on one screen:
package main
// Simplified: a secrets engine with one path, "sign".
// The key, the rules and the counter all live in the plugin's own storage.
func main() {
err := plugin.Serve(&plugin.ServeOpts{BackendFactoryFunc: Factory})
if err != nil {
os.Exit(1)
}
}
func (b *backend) pathSign() *framework.Path {
return &framework.Path{
Pattern: "sign",
Fields: map[string]*framework.FieldSchema{
"artifact_sha256": {Type: framework.TypeString, Required: true},
"version": {Type: framework.TypeString, Required: true},
"manifest": {Type: framework.TypeString, Required: true},
},
Operations: map[logical.Operation]framework.OperationHandler{
logical.UpdateOperation: &framework.PathOperation{Callback: b.sign},
},
}
}
func (b *backend) sign(ctx context.Context, req *logical.Request, d *framework.FieldData) (*logical.Response, error) {
// one signature at a time, so two calls never read the same counter
b.mu.Lock()
defer b.mu.Unlock()
r := releaseFrom(d)
// the rules sit next to the key: nothing is signed before they pass
if err := b.check(ctx, req.Storage, r); err != nil {
return logical.ErrorResponse("denied: %s", err), nil
}
key, err := b.loadKey(ctx, req.Storage) // ed25519, created here, never exported
if err != nil {
return nil, err
}
sig := ed25519.Sign(key, r.Digest())
// the counter only goes up: an older version can never be signed again
if err := b.saveLastVersion(ctx, req.Storage, r.Version); err != nil {
return nil, err
}
return &logical.Response{Data: map[string]any{
"signature": base64.StdEncoding.EncodeToString(sig),
}}, nil
}Notice what does not exist: no path returns the private key. In Transit, "not exportable" is a flag. Here, it is the absence of code.
From Transit to the enclave
This plugin is the same piece as the policy engine in part two of EXP-001: someone asks, a rule decides, and only a good decision becomes a signature. The difference is where it runs and whom you have to trust.
What the plugin does not solve
- Whoever administers OpenBao can register another binary. The catalog stops a silent swap on disk, but an admin can register a new hash. That shows up in the audit log; alert on every catalog change.
- Restoring a snapshot rolls the counter back. If someone restores a backup from before v2.4.0, the plugin will happily sign v2.3.9 again. It is the same rollback attack as in the enclave, and the defense is the same: verifiers also reject versions lower than the last one they saw.
- A bug in the plugin is a bug holding the key. The code must stay small, with tests for every rule and every denial.
- Availability. If the plugin doesn't start, nothing gets signed. At least it fails on the safe side.
When to use what
| Option | Where the key lives | Rule about the content |
|---|---|---|
| Key in the app | In every copy of the app and its config | Whatever the app wants, including none |
| Cloud KMS | At the provider, often in an HSM | No: IAM decides who calls |
| OpenBao Transit | In your OpenBao, encrypted by the barrier | No: the policy only sees the path |
| OpenBao + plugin | In the plugin's storage, encrypted by the barrier | Yes, in the same process that signs |
| Plugin in an enclave | Sealed in the enclave | Yes, and attested to whoever verifies |
Glossary for this part
- Secrets engine plugin
- An engine you write, in a separate binary, that OpenBao mounts like any other path.
- Plugin catalog
- The list of plugins OpenBao will start, each one pinned to the SHA-256 of its binary.
- Mount
- An engine enabled on a path. The same plugin can be mounted on several paths, each with its own storage.
- Monotonic counter
- A value that only goes up. Here, the last signed version, which prevents re-signing an old one.
