Read secrets from your app
Applications read and write secret values over the Vault API (OpenBao, KV version 2) at your workspace’s address. Any Vault-compatible client works: the bao or vault CLI, bao agent, a Vault SDK such as hvac for Python, or plain HTTP. Every client needs three things: the address, the namespace, and a token from an app credential login.
The three values
The address uses a publicly trusted certificate over HTTPS (TLS 1.2 or 1.3), so you don’t need a CA file. Send the namespace as a header, not in the path.
Sign in
Logins aren’t billed, but they’re limited to 5 per second per IP address: sign in once and reuse the token.
The bao and vault CLI
The OpenBao CLI bao (download) and HashiCorp’s vault take the same commands. Choose the store with -mount=secret (yours) or -mount=ibee-managed (read only).
key=@file reads the value from a file, which keeps it out of your shell history. kv put replaces all keys of a secret; use kv patch to change one.
Each bao kv or vault kv command first checks the store’s settings with a separate request. That check isn’t billed, but it counts toward the 10-requests-per-second limit for writes and listing in your namespace. For a busy application, read over HTTP or an SDK instead of running the CLI in a loop.
Keep a token fresh with bao agent
bao agent runs next to your application, signs in with the app credential, renews the token, and can write secrets into a file your app reads. This is the simplest choice for a long-running service on a VM.
Put the Role ID and Secret ID in the two files, readable only by the agent’s user.
Set namespace inside method "approle". A namespace set only in the vault {} block isn’t used for the login, and the agent gets 403 at the root namespace.
Python (hvac)
Node.js
Node.js 18 or later has fetch built in.
HTTP (curl)
Every request carries X-Vault-Namespace, and every request after login carries X-Vault-Token.
A read answers:
Which Vault API paths you can use
Anything else, such as sys/ or the OpenBao web UI, isn’t available and answers 404. Your token’s permissions still apply on top: a read only credential can’t write, and no app credential can destroy versions.
Any other Vault SDK (for example Go’s vault/api or Spring Cloud Vault) works the same way: set the address, the namespace and AppRole login, and use the KV version 2 methods with the mount secret.
Good practice for applications
- Read once, then cache. Read secrets at startup and keep them in memory. Re-read when you know a value changed, or every few minutes at most. Every read is a billed operation (₹4 per 10,000) and counts toward rate limits.
- Renew, then sign in again. Renew the token before its hour is up; after 24 hours, sign in again.
bao agentdoes both for you. - Retry with backoff. A
429means a rate limit; wait at least a second and retry, with a limit on attempts. A503“OpenBao leader is changing; retry the request” is safe to retry. The service doesn’t retry for you, and each request times out after 30 seconds. - Use check-and-set for writes, so two writers can’t overwrite each other.
- Never log tokens, Secret IDs or values.
Rate limits
See Limits.
Troubleshooting
More in Troubleshooting.
