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.

Without TransitWith TransitAPI servicehas the keyWorkerhas the keyConfig backuphas the keyDev laptop (.env)has the keyAPI serviceonly a tokenWorkeronly a tokenConfig backupnothing to leakOpenBao (Transit)the only copy
A stolen token is still bad, but it expires and can be revoked. A copied key is good forever.
The idea in one sentence: Transit is encryption as a service. The application sends the data, OpenBao sends it back encrypted (or signed), and the key never leaves.

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.

ClientAuthenticationtoken, AppRole, OIDCPolicymay call this path?Routerkv/pki/transit/releases/a plugin of yoursBarrierencrypts everything that goes to disk, Transit keys includedStorage (Raft, on disk)only encrypted bytesSealShamir or KMS
The policy only looks at the path. What happens to the content is up to the engine mounted there.

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

PathDoes what
encrypt / decryptEncrypts and decrypts a value with the named key.
rewrapRe-encrypts an old value with the newest key version, without returning the plaintext.
datakeyGenerates a fresh key so you can encrypt something large on your side (envelope).
sign / verifySigns and verifies signatures with asymmetric keys.
hmacComputes an HMAC, useful to compare or index values without storing them.
random / hashRandom bytes and hashes, so you don't depend on the client machine.

Key types

TypeUsed for
aes256-gcm96 (default), aes128-gcm96, chacha20-poly1305Encrypt and decrypt
ed25519Sign (fast, small key)
ecdsa-p256, ecdsa-p384, ecdsa-p521Sign with NIST curves
rsa-2048, rsa-3072, rsa-4096Sign and encrypt
hmacHMAC 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).

versions of key customersv1no longer opensv2decrypt onlyv3 (current)encrypt and decryptmin_decryption_version = 2vault:v1:…vault:v2:…vault:v3:…rewrap: decrypts and re-encrypts inside
Rotating does not force a migration right away. Rewrap brings old data to the new version over time, and only then is the old version switched off.

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.

Next part: using Transit in a real app →

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"]
}
Gotcha: in Transit every operation is a 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

AppOpenBaoDatabasewrite1. encrypt(tax id)2. encrypts with v13. vault:v1:8SDd…4. stores only the ciphertextread5. vault:v1:8SDd…6. decrypt7. plaintext tax idBackup, replica,local dumponly read vault:v1:…
The tax id only exists in plaintext in the app's memory, during the request. On disk, anywhere, it is 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:

  1. The app calls transit/datakey/plaintext/customers and gets two things back: a fresh key in plaintext and the same key encrypted by the Transit key.
  2. The app encrypts the file locally with the plaintext key.
  3. The plaintext key is thrown away. Only its encrypted copy is stored next to the file.
  4. 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/receipts

The 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=720h

A 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

What is still on you

Next part: when Transit is not enough →

Where Transit stops

Transit has a closed set of operations and key types. Two situations show up early:

The key point: an OpenBao policy answers "may this token call this path?". It does not answer "should this content be signed?". For that second question, the rule has to live next to the key, in the same process. That is what a plugin gives you.

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/.

OpenBao processRouterroutes releases/* thereBarrier + storageencrypts plugin writesplugin process (another binary)release-signersigning rulesed25519 keyversion counterno path to exportgRPC + mTLSmount storagePlugin catalog: name + SHA-256 of the binarya different binary won't start
The plugin never sees the seal key. What it writes goes through the same barrier that protects Transit, and each plugin mount only sees its own slice of storage.

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: deny

The 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.json

The path of each request

Pick a request to see how far it gets:

No request picked: the flowchart shows every path.

outside the plugin: OpenBaoinside the pluginPOST releases/signToken policy allowsreleases/sign?no403: plugin never sees ityesManifest signed by CIand from main?noDeny: bad manifestyesArtifact hash ison the manifest?noDeny: unknown artifactyesVersion greater thanthe last signed one?noDeny: old versionyesSigns with the plugin's ed25519 keyRaises the counter to 2.4.0Returns the signature
The first question belongs to OpenBao and only looks at the path. All the others belong to the plugin and look at the content, next to the key.

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.

1. Transitkey out of the apprule: path onlythe OpenBao hostsees the memory2. Pluginrule next to the keycontent is checkedthe admin can stillswap the binary3. Plugin in enclavesame code, attestedthe operator can't reador change the ruletrust in the chipmanufacturer
Each step removes someone from the list of who must be trusted. Writing the rule and the signing as a small core that doesn't depend on OpenBao makes the last step cheap.

What the plugin does not solve

When to use what

OptionWhere the key livesRule about the content
Key in the appIn every copy of the app and its configWhatever the app wants, including none
Cloud KMSAt the provider, often in an HSMNo: IAM decides who calls
OpenBao TransitIn your OpenBao, encrypted by the barrierNo: the policy only sees the path
OpenBao + pluginIn the plugin's storage, encrypted by the barrierYes, in the same process that signs
Plugin in an enclaveSealed in the enclaveYes, 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.

← Back to the concept