Store secrets in the Vault
The tokens and passwords an agent acts with, encrypted before they reach the database.
The Vault stores credentials your agent uses with other services, such as a shop's API token or a service password. Values are encrypted before storage with AES-256-GCM. Each Org has a data key, protected by a key held outside the database.
Tigby can decrypt the values to act on the agent's behalf. This is application-layer encryption, not zero-knowledge encryption. It protects the values in a stolen database dump or backup.
Namespaces
Secrets live in one namespace per scope: the Org's own, and one per Identity. An Identity Key reaches only its own Identity's namespace; an Admin Key reaches all of them.
Write
pass show shop/api | tigby vault set shop-token --identity @orderbotLeave the value off to read it from stdin. This keeps it out of the shell’s history and process
list. --description says what a secret is for; it is not secret and shows up in the list.
Read and list
tigby vault list --identity @orderbot
tigby vault get shop-token --identity @orderbottigby vault get prints the value and nothing else, so export SHOP_TOKEN="$(tigby vault get shop-token)" works. Into a pipe, a file or $(…) the value is written byte for byte. On a
terminal, a value holding control characters (an escape sequence, a carriage return, a Bidi
override) is shown with each of them as a visible escape such as \x1b or \u202e and every
backslash doubled, and a note on stderr says so, because the terminal would otherwise act on them.
--raw prints it unchanged there too.
A list carries names, sizes, dates and versions; no value is ever in a list. The REST API provides
the same operations under /api/vault/secrets. Use ?identity=orderbot to select an Identity's
namespace.
Two Instances, one secret
Every secret carries a version, and every write gives it a new one. The numbers come from one
counter the Org's secrets share, so a name's version only ever increases (across a delete and a new
write of the name too) and gaps are normal. The list, the metadata read, the value read and every
write answer with it, and the two reads also send it as the ETag header, the number in double
quotes, "3".
A write's answer has it in the body only.
Hand the version back in If-Match, and a write lands only if nothing has written the secret since you read it. That is what two Instances need when both may rotate one token: each reads, rotates, and writes with the version it read. The first write lands. The second is refused with vault_precondition_failed (412) and changes nothing, instead of silently replacing the token the first one just stored.
curl -i -H "Authorization: Bearer $TIGBY_API_KEY" \
https://api.tigby.eu/api/vault/secrets/shop-token/value
# ETag: "3"
# {"name":"shop-token","value":"…","version":3}
curl -X PUT -H "Authorization: Bearer $TIGBY_API_KEY" \
-H "Content-Type: application/json" \
-H 'If-Match: "3"' \
-d '{"value": "the rotated token"}' \
https://api.tigby.eu/api/vault/secrets/shop-tokenThe same with the TypeScript SDK:
import { revealVaultSecret, setVaultSecret, TigbyError } from "@tigby/sdk";
const { data: current } = await revealVaultSecret({ path: { name: "shop-token" } });
const rotated = await rotateAtTheShop(current.value);
try {
await setVaultSecret({
path: { name: "shop-token" },
body: { value: rotated },
headers: { "If-Match": `"${current.version}"` },
});
} catch (error) {
if (!(error instanceof TigbyError) || error.code !== "vault_precondition_failed") throw error;
// Another Instance wrote first: read the secret again and use what it stored.
}- On a
412, read the secret again and decide anew from what it holds now. Another Instance may already have done what you meant to do. If-Match: *writes only if the name holds a secret, whatever its version.If-None-Match: *creates only: a name that already holds a secret is refused with412instead of overwritten.- Delete takes
If-Matchthe same way. A name that holds nothing is a404, withIf-Matchor without it. - Quote the version.
If-Match: 3is not an entity tag and is refused withprecondition_invalid(400), and so is a header that cannot be read as a condition. A weak tag (W/"3") never matches. - Without either header a write replaces unconditionally, as it always has.
- A delete does not reset the version. A name written again after a delete gets a version it never had, so a version read before the delete is refused with
412rather than matching a secret its writer never saw.
The tigby_vault_get MCP Tool answers with the version, and tigby_vault_set and
tigby_vault_delete take it back as their if_match argument: the version in double quotes, "3".
tigby_vault_set also takes if_none_match. Both SDKs take the headers as optional arguments of
the write and the delete.