Lockwell

Docs · Use secrets

Secrets and versions

Your tenant is a KV v2 store with HashiCorp Vault's paths: data under /v1/lw-<team>/data/<path>, metadata under /v1/lw-<team>/metadata/<path>.

Write and read

# a new version of prod/DATABASE_URL (KV v2); "cas": 0 means "only if it doesn't exist yet"
curl -sf -H "X-Vault-Token: $VAULT_TOKEN" "$VAULT_ADDR/v1/lw-<team>/data/prod/DATABASE_URL" \
  -d '{"data": {"value": "postgres://app:…@db.internal/app"}, "options": {"cas": 0}}'

# read the current version, or any of the last ten
curl -sf -H "X-Vault-Token: $VAULT_TOKEN" "$VAULT_ADDR/v1/lw-<team>/data/prod/DATABASE_URL" | jq -r .data.data.value
curl -sf -H "X-Vault-Token: $VAULT_TOKEN" "$VAULT_ADDR/v1/lw-<team>/data/prod/DATABASE_URL?version=2"

"options": {"cas": N} writes only if the current version is N (0: only if it doesn't exist). Without it, a write always makes a new version.

Patch, diff and subkeys

# change one field, keep the rest: a JSON merge patch, check-and-set inside Vault
curl -sf -X PATCH -H "X-Vault-Token: $VAULT_TOKEN" "$VAULT_ADDR/v1/lw-<team>/data/prod/db" \
  -d '{"data": {"password": "…"}}'
# which fields version 4 changed against 3, never a value
curl -sf -H "X-Vault-Token: $VAULT_TOKEN" "$VAULT_ADDR/v1/lw-<team>/diff/prod/db?from=3&to=4" | jq .data
# the shape of a secret (field names, values null) for a reader who doesn't need the values
curl -sf -H "X-Vault-Token: $VAULT_TOKEN" "$VAULT_ADDR/v1/lw-<team>/subkeys/prod/db" | jq .data.subkeys

List, delete, undelete, destroy

# the secrets and subfolders of a folder
curl -sf -H "X-Vault-Token: $VAULT_TOKEN" "$VAULT_ADDR/v1/lw-<team>/metadata/prod/?list=true" | jq .data.keys
# soft-delete the current version, then bring it back
curl -sf -X DELETE -H "X-Vault-Token: $VAULT_TOKEN" "$VAULT_ADDR/v1/lw-<team>/data/prod/OLD_KEY"
curl -sf -H "X-Vault-Token: $VAULT_TOKEN" "$VAULT_ADDR/v1/lw-<team>/undelete/prod/OLD_KEY" -d '{"versions": [3]}'

Destroying a secret for good (every version) frees room in your plan. It's done by an owner or admin in the secrets editor, after typing the secret's name. A machine identity can't destroy.

Metadata

# keep 20 versions, require check-and-set, delete each version a week after it's written, and a note
curl -sf -H "X-Vault-Token: $VAULT_TOKEN" "$VAULT_ADDR/v1/lw-<team>/metadata/ci/DEPLOY_TOKEN" \
  -d '{"max_versions": 20, "cas_required": true, "delete_version_after": "168h", "custom_metadata": {"owner": "platform"}}'
curl -sf -H "X-Vault-Token: $VAULT_TOKEN" "$VAULT_ADDR/v1/lw-<team>/metadata/ci/DEPLOY_TOKEN" | jq .data

References

# a value made of other secrets' fields, written once, following them when they change
curl -sf -H "X-Vault-Token: $VAULT_TOKEN" "$VAULT_ADDR/v1/lw-<team>/data/prod/DATABASE_URL" \
  -d '{"data": {"value": "postgres://app:${lw-<team>/prod/db#password}@db.internal/app"}}'
# filled in only when a read asks, each reference checked and audited as the reader
curl -sf -H "X-Vault-Token: $VAULT_TOKEN" "$VAULT_ADDR/v1/lw-<team>/data/prod/DATABASE_URL?resolve=true"

References can nest five deep. A loop, a missing secret or field, or one the reader can't read is refused, naming the reference and never giving a value. $${ writes a literal ${.