Skip to navigation

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

ValueEnvironment variableHTTPWhere to find it
AddressVAULT_ADDR (or BAO_ADDR)The base URL, for example https://secrets.ibee.aiSecret Manager → Connect, or endpoint from GET /secret-manager/workspace
NamespaceVAULT_NAMESPACE (or BAO_NAMESPACE)X-Vault-Namespace: acme-payments header on every requestSecret Manager → Connect, or namespace from the same call
TokenVAULT_TOKEN (or BAO_TOKEN)X-Vault-Token: <token> headerAn app credential login (below), or a 60-second CLI session for people

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

WhoHowToken lifetime
An application, VM, CI job or clusterApp credential: auth/approle/login with the Role ID and Secret ID1 hour, renewable up to 24 hours
You, trying commandsSecret Manager → Connect → Get a 60-second CLI session60 seconds, not renewable
export VAULT_TOKEN=$(bao write -field=token auth/approle/login \
role_id="$ROLE_ID" secret_id="$SECRET_ID")

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

# Read
bao kv get -mount=secret payments/db # latest version
bao kv get -mount=secret -field=password payments/db # one value
bao kv get -mount=secret -version=2 payments/db # an older version
bao kv get -mount=secret -format=json payments/db | jq '.data.data'
bao kv list -mount=secret payments # names in a folder
# Write (needs a read & write credential, or a session as an editor)
bao kv put -mount=secret -cas=0 payments/stripe api_key=@./stripe-key.txt # create only
bao kv put -mount=secret -cas=3 payments/db username=app password=@./new-password.txt # replace version 3
bao kv patch -mount=secret payments/db port=5433 # change one key, keep the rest
# Versions
bao kv metadata get -mount=secret payments/db # versions and settings
bao kv rollback -mount=secret -version=2 payments/db # save version 2 as a new version
bao kv delete -mount=secret -versions=4 payments/db # delete (undo with undelete)
bao kv undelete -mount=secret -versions=4 payments/db

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.

/etc/bao-agent.hcl
vault {
address = "https://secrets.ibee.ai"
}
auto_auth {
method "approle" {
# The namespace goes on the login method; templates then read from it.
namespace = "acme-payments"
config = {
role_id_file_path = "/etc/bao-agent/role_id"
secret_id_file_path = "/etc/bao-agent/secret_id"
remove_secret_id_file_after_reading = false
}
}
}
template {
destination = "/etc/myapp/secrets.env"
contents = <<EOT
{{ with secret "secret/data/payments/db" }}DB_PASSWORD={{ .Data.data.password }}{{ end }}
EOT
}
bao agent -config=/etc/bao-agent.hcl

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)

pip install hvac
import os
import hvac
client = hvac.Client(url=os.environ["VAULT_ADDR"], namespace=os.environ["VAULT_NAMESPACE"])
client.auth.approle.login(role_id=os.environ["ROLE_ID"], secret_id=os.environ["SECRET_ID"])
# Read once at startup and keep the values: each read is a billed operation.
secret = client.secrets.kv.v2.read_secret_version(
path="payments/db", mount_point="secret", raise_on_deleted_version=True
)
values = secret["data"]["data"] # {"username": "app", "password": "..."}
version = secret["data"]["metadata"]["version"]
# Write a new version (read & write credential). cas = the version you are replacing.
client.secrets.kv.v2.create_or_update_secret(
path="payments/db", mount_point="secret",
secret={**values, "password": "new-password"}, cas=version,
)
# Renew the token before it expires (up to 24 hours), then log in again.
client.auth.token.renew_self()

Node.js

Node.js 18 or later has fetch built in.

const base = process.env.VAULT_ADDR;
const ns = process.env.VAULT_NAMESPACE;
// Sign in with the app credential.
const login = await fetch(`${base}/v1/auth/approle/login`, {
method: "POST",
headers: { "X-Vault-Namespace": ns, "Content-Type": "application/json" },
body: JSON.stringify({ role_id: process.env.ROLE_ID, secret_id: process.env.SECRET_ID }),
});
if (!login.ok) throw new Error(`Login failed: ${login.status}`);
const { auth } = await login.json(); // auth.client_token, auth.lease_duration (seconds)
// Read the latest version.
const res = await fetch(`${base}/v1/secret/data/payments/db`, {
headers: { "X-Vault-Token": auth.client_token, "X-Vault-Namespace": ns },
});
if (!res.ok) throw new Error(`Secret read failed: ${res.status}`);
const { data } = (await res.json()).data; // { username: "app", password: "..." }

HTTP (curl)

Every request carries X-Vault-Namespace, and every request after login carries X-Vault-Token.

H=(-H "X-Vault-Namespace: $VAULT_NAMESPACE")
# Sign in
VAULT_TOKEN=$(curl -s -X POST "$VAULT_ADDR/v1/auth/approle/login" "${H[@]}" \
-d "{\"role_id\": \"$ROLE_ID\", \"secret_id\": \"$SECRET_ID\"}" | jq -r '.auth.client_token')
H+=(-H "X-Vault-Token: $VAULT_TOKEN")
# Read the latest version, or ?version=2 for an older one
curl -s "$VAULT_ADDR/v1/secret/data/payments/db" "${H[@]}" | jq '.data.data'
# List a folder
curl -s "$VAULT_ADDR/v1/secret/metadata/payments?list=true" "${H[@]}" | jq '.data.keys'
# Write a new version, replacing version 3
curl -s -X POST "$VAULT_ADDR/v1/secret/data/payments/db" "${H[@]}" \
-d '{"options": {"cas": 3}, "data": {"username": "app", "password": "new-password"}}'
# Delete and undelete versions
curl -s -X POST "$VAULT_ADDR/v1/secret/delete/payments/db" "${H[@]}" -d '{"versions": [4]}'
curl -s -X POST "$VAULT_ADDR/v1/secret/undelete/payments/db" "${H[@]}" -d '{"versions": [4]}'
# Renew the token
curl -s -X POST "$VAULT_ADDR/v1/auth/token/renew-self" "${H[@]}"

A read answers:

{
"data": {
"data": { "username": "app", "password": "s3cr3t" },
"metadata": { "version": 3, "created_time": "2026-11-25T08:00:00Z", "deletion_time": "", "destroyed": false }
}
}

Which Vault API paths you can use

PathMethodsFor
/v1/secret/data/<path>, /v1/ibee-managed/data/<path>GET (both); POST, PUT, PATCH, DELETE (secret/ only)Read and write values
/v1/secret/metadata/<path>, /v1/ibee-managed/metadata/<path>All, including LISTVersions, settings and listing
/v1/secret/delete/<path>, /undelete/, /destroy/POST, PUTVersion actions
/v1/auth/approle/loginPOST, PUTSign in
/v1/auth/token/lookup-self, /renew-self, /revoke-selfGET (lookup), POST, PUTYour own token

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 agent does both for you.
  • Retry with backoff. A 429 means a rate limit; wait at least a second and retry, with a limit on attempts. A 503 “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

RequestsLimit
Reading values (GET …/data/…) and token lookup100 per second, per namespace and IP address
Writes, deletes, version actions, listing, metadata, token renew and revoke, and the CLI’s store check10 per second per namespace, shared by all clients
Logins5 per second per IP address
Everything in one namespace500 per second
Everything from one IP address200 per second
Request body64 KiB

See Limits.

Troubleshooting

You seeWhat it meansWhat to do
404 with an empty bodyNo X-Vault-Namespace header, or a path that isn’t available (such as sys/)Set VAULT_NAMESPACE, and use the paths above
404 {"errors":["namespace not found"]}The namespace is wrongCopy it from Connect
403 {"errors":["permission denied"]}The token expired, is for another namespace, or lacks access to that pathSign in again; check the credential’s access and folder
400 “check-and-set parameter did not match the current version”Someone saved a newer versionRead the secret again and retry with its version
400 “check-and-set parameter required for this call”The secret has Require check-and-set onSend cas (-cas=N in the CLI)
404 on a read with deletion_time setThe latest version is deletedUndelete it or save a new version
429A rate limitBack off and retry; cache reads
503 “OpenBao leader is changing; retry the request”A brief server handoverRetry after a moment
Every write answers 403 permission denied, but reads work, for all credentialsThe workspace is read-only (restricted)See Workspace states
Every read answers 403 permission deniedThe workspace is suspendedSee Workspace states

More in Troubleshooting.