Day 5: Transit and PKI
Goal: Have data encrypted without seeing the keys, and run a two-tier CA · Duration: approx. 120 min · Prerequisite: Day 2
Briefing
- Transit = encryption as a service: the app sends data and gets ciphertext back. The key never leaves OpenBao.
- Ciphertext carries the key version (
vault:v2:...) – rotation without being forced to re-encrypt. - PKI = your own CA: the root in
pki/, the intermediate inpki_int/issues short-lived certificates.
pki/ Root CA (10 yrs) --signs--> pki_int/ Intermediate (5 yrs)
|
roles/webshop --issue--> api.webshop.lab (24 h)
Drill 1: Lab and Transit Key
Terminal 1:
bao server -dev -dev-root-token-id=rootTerminal 2:
mkdir -p ~/bao-lab/tag05 && cd ~/bao-lab/tag05
export BAO_ADDR=http://127.0.0.1:8200 BAO_TOKEN=root
bao secrets enable transit
bao write -f transit/keys/webshopExpected (abridged):
Success! Enabled the transit secrets engine at: transit/
Key Value
--- -----
deletion_allowed false
exportable false
keys map[1:1791442702]
latest_version 1
min_decryption_version 1
supports_encryption true
type aes256-gcm96
Save your progress? Sign up for free
Drill 2: Encrypt and Decrypt
Transit always expects plaintext base64-encoded.
CT=$(bao write -field=ciphertext transit/encrypt/webshop \
plaintext=$(echo -n "4111-1111-1111-1111" | base64))
echo "$CT"
bao write -field=plaintext transit/decrypt/webshop ciphertext="$CT" | base64 -d; echoExpected:
vault:v1:IUDSBoxEgTXXEZuDk2GyQP18X93vIy/bOlfgPVd2oSCXv1QHpUHnN6UZMRhW+U4=
4111-1111-1111-1111
Why vault:? The prefix has stayed for compatibility
reasons; v1 is the key version.
Save your progress? Sign up for free
Drill 3: Rotate, Rewrap, min_decryption_version
bao write -f transit/keys/webshop/rotate | grep -E 'latest_version|keys '
bao write transit/encrypt/webshop plaintext=$(echo -n "neu" | base64)Expected (abridged):
keys map[1:1791442702 2:1791442708]
latest_version 2
ciphertext vault:v2:xhgL7lQ+wTAdux7S+W2ZSgq3Pr2UCzKla+gLzvE=
key_version 2
Lift old data to the new version without seeing the plaintext:
CT2=$(bao write -field=ciphertext transit/rewrap/webshop ciphertext="$CT")
echo "$CT2"Expected:
vault:v2:d7Ifgva7m99eJ5fpjKaHxLve3TMpwsUY+kpYQr2FVNbQ3f6Hvc9l2ThUmyGIT40=
Then lock out v1:
bao write transit/keys/webshop/config min_decryption_version=2 | grep min_dec
bao write transit/decrypt/webshop ciphertext="$CT"
bao write -field=plaintext transit/decrypt/webshop ciphertext="$CT2" | base64 -d; echoExpected (abridged):
min_decryption_version 2
Code: 400. Errors:
* ciphertext or signature version is disallowed by policy (too old)
4111-1111-1111-1111
Warning: Rewrap all records first, then raise
min_decryption_version– otherwise old data can no longer be read.
Save your progress? Sign up for free
Drill 4: Datakey (Envelope Encryption)
For large files: OpenBao generates a data key, and you encrypt locally.
bao write -f transit/datakey/plaintext/webshop
bao write -f transit/datakey/wrapped/webshopExpected (abridged):
Key Value
--- -----
ciphertext vault:v2:UE2bAO9UwGK/LW/Q8vqjrz1ET9mxdOeHPneil2P1JWtVU1x5...
key_version 2
plaintext +innBfLQ2vB0gIpyWOlZmcZeBHNJi5tbBPCIT8/GPVQ=
Key Value
--- -----
ciphertext vault:v2:4+boJqiYRuC00vrTuCkpQMgT7vtv4griptB00hBVQOq7cCWALckh...
key_version 2
Why? You use plaintext immediately (AES-256) and discard
it; you store ciphertext next to the file and later have it
decrypted via transit/decrypt. wrapped returns
only the ciphertext – for systems that decrypt later.
Save your progress? Sign up for free
Drill 5: HMAC, Sign and Verify
HMAC (e.g. for pseudonymized search indexes):
IN=$(echo -n "[email protected]" | base64)
H=$(bao write -field=hmac transit/hmac/webshop input="$IN")
echo "$H"
bao write transit/verify/webshop input="$IN" hmac="$H"Expected:
vault:v2:gF1nI5MRYrhjfJqJqT4YyGIZ0snC8P12ht4HSh5vXZU=
Key Value
--- -----
valid true
Signing needs an asymmetric key:
bao write transit/keys/webshop-sign type=ecdsa-p256 | grep -E '^type|supports_signing'
MSG=$(echo -n "Bestellung 4711: 99.90 EUR" | base64)
SIG=$(bao write -field=signature transit/sign/webshop-sign input="$MSG")
bao write transit/verify/webshop-sign input="$MSG" signature="$SIG"
FAKE=$(echo -n "Bestellung 4711: 0.01 EUR" | base64)
bao write transit/verify/webshop-sign input="$FAKE" signature="$SIG"Expected (abridged):
supports_signing true
type ecdsa-p256
valid true
valid false
Third parties may have the public key:
bao read -format=json transit/keys/webshop-sign | jq -r '.data.keys."1".public_key'Expected:
-----BEGIN PUBLIC KEY-----
MFkwEwYHKoZIzj0CAQYIKoZIzj0DAQcDQgAEbxDKoRIXpSXVmCn+4e7vZ29CzpH5
...
-----END PUBLIC KEY-----
Save your progress? Sign up for free
Drill 6: exportable=false
bao read transit/export/encryption-key/webshopExpected (abridged):
Code: 400. Errors:
* private key material is not exportable
Why? The default is exportable=false: nobody – not even
root – can read out the key material. exportable=true can
be set via transit/keys/<name>/config, but
can never be reverted. Use it only for justified cases
(e.g. migration).
Save your progress? Sign up for free
Drill 7: Root CA
bao secrets enable pki
bao secrets tune -max-lease-ttl=87600h pki
bao write -field=certificate pki/root/generate/internal \
common_name="Bao Lab Root CA" issuer_name=root-2026 ttl=87600h > root_ca.crt
openssl x509 -in root_ca.crt -noout -subject -issuer -datesExpected (abridged):
Success! Enabled the pki secrets engine at: pki/
Success! Tuned the secrets engine at: pki/
WARNING! The following warnings were returned from OpenBao:
* This mount hasn't configured any authority information access (AIA)
fields; this may make it harder for systems to find missing certificates
...
subject=CN=Bao Lab Root CA
issuer=CN=Bao Lab Root CA
notBefore=Oct 8 06:58:11 2026 GMT
notAfter=Oct 5 06:58:41 2036 GMT
Why tune? The mount’s max_lease_ttl
(default 32 days) limits every certificate, including the CA itself. The
AIA warning goes to stderr; since v2.7.0, -field no longer
suppresses warnings. You set the URLs next.
bao write pki/config/urls \
issuing_certificates="$BAO_ADDR/v1/pki/ca" \
crl_distribution_points="$BAO_ADDR/v1/pki/crl"Expected (abridged):
crl_distribution_points [http://127.0.0.1:8200/v1/pki/crl]
issuing_certificates [http://127.0.0.1:8200/v1/pki/ca]
Save your progress? Sign up for free
Drill 8: Intermediate CA
bao secrets enable -path=pki_int pki
bao secrets tune -max-lease-ttl=43800h pki_int
bao write pki_int/config/urls \
issuing_certificates="$BAO_ADDR/v1/pki_int/ca" \
crl_distribution_points="$BAO_ADDR/v1/pki_int/crl"
# 1. Generate the CSR in the intermediate (the key stays in pki_int/)
bao write -field=csr pki_int/intermediate/generate/internal \
common_name="Bao Lab Intermediate CA" > pki_int.csr
# 2. The root signs the CSR
bao write -field=certificate pki/root/sign-intermediate \
issuer_ref=root-2026 csr=@pki_int.csr ttl=43800h > int.crt
openssl x509 -in int.crt -noout -subject -issuer
# 3. Signed certificate back into the intermediate
bao write pki_int/intermediate/set-signed [email protected]Expected (abridged):
subject=CN=Bao Lab Intermediate CA
issuer=CN=Bao Lab Root CA
Key Value
--- -----
imported_issuers [ce891cf4-62d6-829e-7a93-cb8375da1afa]
imported_keys <nil>
Tip: Set the URLs before
set-signed, otherwise OpenBao warns about missing AIA fields.
Save your progress? Sign up for free
Drill 9: Role and Certificate
bao write pki_int/roles/webshop \
allowed_domains=webshop.lab allow_subdomains=true max_ttl=72h
bao write -format=json pki_int/issue/webshop \
common_name=api.webshop.lab ttl=24h > cert.json
jq -r '.data | keys[]' cert.json
jq -r .data.certificate cert.json > api.crt
jq -r .data.private_key cert.json > api.keyExpected:
ca_chain
certificate
expiration
issuing_ca
not_before
private_key
private_key_type
serial_number
openssl verify -CAfile root_ca.crt -untrusted int.crt api.crt
openssl x509 -in api.crt -noout -subject -issuer -enddate -ext subjectAltNameExpected:
api.crt: OK
subject=CN=api.webshop.lab
issuer=CN=Bao Lab Intermediate CA
notAfter=Oct 9 06:58:51 2026 GMT
X509v3 Subject Alternative Name:
DNS:api.webshop.lab
Cross-check:
bao write pki_int/issue/webshop common_name=evil.example.comExpected (abridged):
* common name evil.example.com not allowed by this role
Security: The private key is delivered only once and is not stored in OpenBao.
cert.jsonandapi.keyare lab files – in production never leave them on disk.
Save your progress? Sign up for free
Drill 10: Revoke, CRL and Tidy
SER=$(jq -r .data.serial_number cert.json)
bao write pki_int/revoke serial_number="$SER"
bao list pki_int/certs/revoked
curl -s "$BAO_ADDR/v1/pki_int/crl/pem" \
| openssl crl -noout -text | grep -A1 "Serial Number"Expected (abridged):
revocation_time_rfc3339 2026-10-08T06:58:56.468904Z
state revoked
Keys
----
15:53:13:bb:bf:54:6a:0e:89:75:9e:6c:3a:24:5e:47:d0:32:c4:1e
Serial Number: 155313BBBF546A0E89759E6C3A245E47D032C41E
Revocation Date: Oct 8 06:58:56 2026 GMT
Clean expired certificates out of storage:
bao write pki_int/tidy tidy_cert_store=true tidy_revoked_certs=true safety_buffer=1s
bao read pki_int/tidy-status | grep -E '^state|deleted_count'Expected (abridged):
* Tidy operation successfully started. Any information from the operation
will be printed to OpenBao's server logs.
cert_store_deleted_count 0
revoked_cert_deleted_count 0
state Finished
Why 0? Tidy only deletes certificates that expired more than
safety_buffer ago – our certificate is still valid for 24
h.
Save your progress? Sign up for free
Drill 11: ACME (Briefly)
OpenBao speaks ACME (RFC 8555) – certbot, cert-manager or Caddy fetch certificates directly.
bao write pki_int/config/cluster \
path="$BAO_ADDR/v1/pki_int" aia_path="$BAO_ADDR/v1/pki_int"
bao secrets tune \
-passthrough-request-headers=If-Modified-Since \
-allowed-response-headers=Last-Modified \
-allowed-response-headers=Location \
-allowed-response-headers=Replay-Nonce \
-allowed-response-headers=Link \
pki_int
bao write pki_int/config/acme enabled=true | grep enabled
curl -s "$BAO_ADDR/v1/pki_int/acme/directory" | jq .Expected (abridged):
enabled true
{
"keyChange": "http://127.0.0.1:8200/v1/pki_int/acme/key-change",
"meta": {
"externalAccountRequired": false
},
"newAccount": "http://127.0.0.1:8200/v1/pki_int/acme/new-account",
"newNonce": "http://127.0.0.1:8200/v1/pki_int/acme/new-nonce",
"newOrder": "http://127.0.0.1:8200/v1/pki_int/acme/new-order",
"revokeCert": "http://127.0.0.1:8200/v1/pki_int/acme/revoke-cert"
}
A real issuance needs a client and reachable challenges (HTTP-01/DNS-01) – that is not part of this lab.
Save your progress? Sign up for free
Checkpoint
#!/usr/bin/env bash
cd ~/bao-lab/tag05
check() { if eval "$2" >/dev/null 2>&1; then echo "✔ $1"; else echo "✘ $1"; fi; }
check "Transit-Key webshop" "bao read transit/keys/webshop"
RT=$(bao write -field=ciphertext transit/encrypt/webshop \
plaintext=$(echo -n ok | base64))
check "Encrypt/Decrypt Roundtrip" \
"bao write -field=plaintext transit/decrypt/webshop ciphertext=$RT \
| base64 -d | grep -qx ok"
check "Signing-Key ecdsa" \
"bao read -field=type transit/keys/webshop-sign | grep -q ecdsa-p256"
check "Root-CA" "bao read pki/cert/ca"
check "Kette gültig" "openssl verify -CAfile root_ca.crt -untrusted int.crt api.crt"
check "Rolle webshop" "bao read pki_int/roles/webshop"
check "ACME-Directory" "curl -sf $BAO_ADDR/v1/pki_int/acme/directory"Challenge
Create a policy webshop-encrypt that lets a token
encrypt but not decrypt, and prove both.
Hint: Transit operations are update on
the respective path.
Solution
bao policy write webshop-encrypt - <<'EOF'
path "transit/encrypt/webshop" {
capabilities = ["update"]
}
EOF
T=$(bao token create -policy=webshop-encrypt -field=token)
CT=$(BAO_TOKEN=$T bao write -field=ciphertext transit/encrypt/webshop \
plaintext=$(echo -n geheim | base64))
echo "$CT"
BAO_TOKEN=$T bao write transit/decrypt/webshop ciphertext="$CT"Expected (abridged):
vault:v2:+TxsTcVYofyggN4t5B2b8GvsSrolm9gTpkP309Lnf3gCNA==
...
* permission denied
Save your progress? Sign up for free
Enterprise Note
- Transit: set
auto_rotate_periodand run batch rewraps regularly;deletion_allowedstaysfalse. - Split encrypt and decrypt permissions across different identities (writing service vs. reading service).
- Do not run the root CA in the same cluster as the intermediate, or seal it off after signing; long root TTL, short leaf TTL (hours to days).
- Automate
tidyviaconfig/auto-tidy, make the CRL/OCSP endpoints reachable for clients. - Open ACME only with
eab_policy(External Account Binding) and restrictedallowed_roles.