Skip to content
Hands-on IT IT Drills

Appendix A: Cheat Sheet

Tested with bao v2.7.1 (the cluster is also on 2.7.1 from Day 12, chart 0.30.2). Paths and names match the lab; passwords are lab values.

Status and Login

# Set target and CA (Part B, via port forward)
export BAO_ADDR=https://127.0.0.1:8200 BAO_CACERT=~/bao-lab/tls/ca.crt
# Seal status, seal type, HA mode, Raft index; a single field (since 2.7)
bao status
bao status -field=version
# Log in with token, userpass, AppRole
bao login -method=token
bao login -method=userpass username=thomas
bao write auth/approle/login role_id=$RID secret_id=$SID
# Check your own token (policies, TTL, accessor); a single field (since 2.7)
bao token lookup
bao token lookup -field=policies
# Print the currently stored token
bao print token
# Log in without the token helper, print only the token
bao login -no-store -token-only -method=userpass username=thomas

KV v2

# Write, read, a single field
bao kv put -mount=secret webshop/config db_user=webshop db_pass=lab-pw
bao kv get -mount=secret webshop/config
bao kv get -mount=secret -field=db_pass webshop/config
# Change one field, keep the rest
bao kv patch -mount=secret webshop/config db_pass=lab-pw2
# Read an older version, list paths
bao kv get -mount=secret -version=1 webshop/config
bao kv list -mount=secret webshop
# Write only if the current version is 2 (check-and-set)
bao kv put -mount=secret -cas=2 webshop/config db_pass=lab-pw3
# Soft delete, restore, set an old version as the new one
bao kv delete -mount=secret webshop/config
bao kv undelete -mount=secret -versions=3 webshop/config
bao kv rollback -mount=secret -version=2 webshop/config
# Destroy permanently (one version or everything)
bao kv destroy -mount=secret -versions=1 webshop/config
bao kv metadata delete -mount=secret webshop/config
# Versions and retention
bao kv metadata get -mount=secret webshop/config
bao kv metadata put -mount=secret -max-versions=5 -delete-version-after=720h \
  webshop/config

Tokens

# Token with policy and TTL
bao token create -policy=webshop-read -ttl=1h
# Periodic token (renewable indefinitely), orphan, batch token
bao token create -policy=webshop-read -period=24h -orphan
bao token create -policy=webshop-read -type=batch -ttl=10m
# Look up and revoke someone else's token via accessor
bao token lookup -accessor $ACC
bao token revoke -accessor $ACC
# Renew, revoke your own token
bao token renew -increment=1h
bao token revoke -self
# Revoke all tokens of an auth method
bao token revoke -mode=path auth/approle/
# What may token X do on path Y?
bao token capabilities $TOKEN secret/data/webshop/config

Policies

# Write a policy (file or stdin), read, list, delete
bao policy write webshop-read webshop-read.hcl
bao policy read webshop-read
bao policy list
bao policy delete webshop-read
# Format HCL
bao policy fmt webshop-read.hcl
path "secret/data/webshop/*"     { capabilities = ["read"] }
path "secret/metadata/webshop/*" { capabilities = ["list"] }

Auth Methods

# Enable, list, tune TTLs
bao auth enable approle
bao auth list -detailed
bao auth tune -default-lease-ttl=1h -max-lease-ttl=24h approle/
# userpass
bao write auth/userpass/users/thomas password=lab-pw token_policies=webshop-read
# AppRole: role, RoleID, SecretID (wrapped)
bao write auth/approle/role/webshop token_policies=webshop-read token_ttl=1h
bao read -field=role_id auth/approle/role/webshop/role-id
bao write -wrap-ttl=60s -f auth/approle/role/webshop/secret-id
bao unwrap $WRAP_TOKEN
# List and destroy SecretIDs via accessor
bao list auth/approle/role/webshop/secret-id
bao write auth/approle/role/webshop/secret-id-accessor/destroy secret_id_accessor=$SACC
# Kubernetes auth (Day 11)
bao write auth/kubernetes/config kubernetes_host=https://kubernetes.default.svc:443
bao write auth/kubernetes/role/webshop bound_service_account_names=webshop \
  bound_service_account_namespaces=webshop audience=openbao \
  token_policies=webshop-read token_ttl=1h
# Log in with a ServiceAccount JWT (CLI since 2.6)
bao login -no-store -method=kubernetes role=webshop jwt="$JWT"

Leases

# List leases under a path
bao list sys/leases/lookup/database/creds/webshop-ro
# Look up, renew, revoke a lease
bao lease lookup $LEASE_ID
bao lease renew -increment=1h $LEASE_ID
bao lease revoke $LEASE_ID
# All leases under a prefix (including auth tokens)
bao lease revoke -prefix database/creds/webshop-ro
bao lease revoke -prefix auth/approle/
# If the backend is unreachable: remove them anyway
bao lease revoke -force -prefix database/creds/webshop-ro

Database Secrets

bao secrets enable database
bao write database/config/postgres plugin_name=postgresql-database-plugin \
  connection_url="postgresql://{{username}}:{{password}}@127.0.0.1:5432/postgres" \
  allowed_roles=webshop-ro username=postgres password=lab-pg-pw
bao write database/roles/webshop-ro db_name=postgres default_ttl=1h max_ttl=24h \
  [email protected]
# Fetch dynamic credentials
bao read database/creds/webshop-ro
# Rotate the root password (afterwards only OpenBao knows it)
bao write -f database/rotate-root/postgres

Transit

bao secrets enable transit
bao write -f transit/keys/webshop
# Encrypt (Base64 in), decrypt (Base64 out)
bao write -field=ciphertext transit/encrypt/webshop plaintext=$(echo -n hallo | base64)
bao write -field=plaintext transit/decrypt/webshop ciphertext=$CT | base64 -d
# Rotate the key, lift ciphertext to the latest version
bao write -f transit/keys/webshop/rotate
bao write -field=ciphertext transit/rewrap/webshop ciphertext=$CT
bao read transit/keys/webshop

PKI

bao secrets enable pki
bao secrets tune -max-lease-ttl=87600h pki
bao write -field=certificate pki/root/generate/internal common_name=lab-root ttl=87600h
bao write pki/roles/webshop allowed_domains=webshop.lab allow_subdomains=true max_ttl=72h
# Issue a certificate, list serial numbers, clean up
bao write pki/issue/webshop common_name=api.webshop.lab ttl=24h
bao list pki/certs
bao write pki/tidy tidy_cert_store=true safety_buffer=1h
# Check the expiration date
openssl x509 -in tls.crt -noout -enddate -checkend 0

Identity

# Create, look up, list an entity
bao write identity/entity name=thomas policies=webshop-read
bao read identity/entity/name/thomas
bao list identity/entity/name
# Alias: the userpass login belongs to the entity
bao write identity/entity-alias name=thomas canonical_id=$ENTITY_ID \
  mount_accessor=$(bao auth list -format=json | jq -r '."userpass/".accessor')
# Group with a member
bao write identity/group name=devs policies=webshop-read member_entity_ids=$ENTITY_ID

Audit

# Server configuration (declarative; via API: "cannot enable audit device via API")
audit "file" "file" {
  options {
    file_path = "/openbao/audit/audit.log"
  }
}
bao audit list -detailed
# HMAC a value to find it in the log (token, accessor)
bao write -field=hash sys/audit-hash/file input=$ACC
# Who did what when?
jq -c 'select(.type=="response") | {time, path: .request.path,
  op: .request.operation, ip: .request.remote_address}' audit.log
# Reopen the log after rotation
kubectl -n openbao exec openbao-0 -- sh -c 'kill -HUP $(pidof bao)'

Operator and Raft

# Init (Shamir, or auto-unseal with recovery keys), unseal, seal
bao operator init -key-shares=5 -key-threshold=3 -format=json
bao operator init -recovery-shares=5 -recovery-threshold=3 -format=json
bao operator unseal
bao operator seal
# Raft peers, autopilot, members, hand over leadership
bao operator raft list-peers
bao operator raft autopilot state
bao operator members
bao operator step-down
# Let a node join / remove it
bao operator raft join https://openbao-0.openbao-internal:8200
bao operator raft remove-peer openbao-2
# Save a snapshot, restore it (foreign cluster: -force)
bao operator raft snapshot save bao.snap
bao operator raft snapshot restore bao.snap
bao operator raft snapshot restore -force bao.snap
# Regenerate unseal/recovery keys (replaces "operator rekey")
bao operator rotate-keys -init -key-shares=5 -key-threshold=3
bao operator rotate-keys -init -target=recovery -key-shares=5 -key-threshold=3
# New root token from key shares (since 2.6: requires a token with a policy on
# sys/generate-root-token/*, e.g. the break-glass user from Day 13)
bao operator generate-root -generate-otp
bao operator generate-root -init -otp=$OTP
bao operator generate-root -decode=$ENCODED -otp=$OTP
# Rotate the encryption key, status
bao operator rotate
bao operator key-status
# Namespaces
bao namespace create team-a
bao namespace list
bao secrets enable -namespace=team-a -path=secret kv-v2

Kubernetes and Helm

helm repo add openbao https://openbao.github.io/openbao-helm
helm search repo openbao/openbao --versions | head -3
# Always pin the chart version; upgrade = change server.image.tag, then roll
helm -n openbao upgrade openbao openbao/openbao --version 0.30.2 \
  -f ~/bao-lab/k8s/values.yaml
helm -n openbao get values openbao
# Pods with role and seal status
kubectl -n openbao get pods -o wide -L openbao-active,openbao-sealed
kubectl -n openbao exec -ti openbao-0 -- bao status
kubectl -n openbao logs openbao-0 --tail=50
# StatefulSet uses OnDelete: delete standbys, step-down, active last
kubectl -n openbao delete pod openbao-2
# Version per Raft node (upgrade check)
bao operator raft autopilot state -format=json | jq -r '.Servers[] | "\(.ID) \(.Version)"'
kubectl -n openbao port-forward svc/openbao-active 8200:8200
# Replace the TLS Secret
kubectl -n openbao create secret generic openbao-tls --from-file=tls.crt \
  --from-file=tls.key --from-file=ca.crt --dry-run=client -o yaml | kubectl apply -f -
# then SIGHUP each pod (or tls_auto_reload = true in the listener, since 2.7)
# ESO status and immediate sync
kubectl -n webshop get externalsecret,secretstore
kubectl -n webshop annotate externalsecret --all force-sync=$(date +%s) --overwrite

Troubleshooting with curl

# Health: 200 active, 429 standby, 501 not initialized, 503 sealed
curl -s --cacert $BAO_CACERT $BAO_ADDR/v1/sys/health | jq
curl -s -o /dev/null -w '%{http_code}\n' --cacert $BAO_CACERT \
  "$BAO_ADDR/v1/sys/health?standbyok=true"
curl -s --cacert $BAO_CACERT $BAO_ADDR/v1/sys/seal-status | jq '{sealed,type,t,n}'
curl -s --cacert $BAO_CACERT $BAO_ADDR/v1/sys/leader | jq
# With a token: Raft configuration, read KV, Prometheus metrics
H="X-Vault-Token: $BAO_TOKEN"
curl -s --cacert $BAO_CACERT -H "$H" $BAO_ADDR/v1/sys/storage/raft/configuration \
  | jq '.data.config.servers'
curl -s --cacert $BAO_CACERT -H "$H" $BAO_ADDR/v1/secret/data/webshop/config \
  | jq .data.data
curl -s --cacert $BAO_CACERT -H "$H" "$BAO_ADDR/v1/sys/metrics?format=prometheus" | head
# Print a CLI command as curl
bao kv get -output-curl-string -mount=secret webshop/config
# Check TLS
openssl s_client -connect 127.0.0.1:8200 -CAfile $BAO_CACERT </dev/null | grep Verify
# Diagnostic bundle for support
bao debug -duration=1m -interval=10s -output=bao-debug.tar.gz