# Vaults

> A vault for each user, each group and the realm, each with one owner who decides who else reaches it.

Every user in the realm has a vault of their own, every group has one its members share, and the realm has one for
the organization's secrets. Each vault has one owner, and the owner decides who else reaches each secret in it. There
is nothing to create: a vault is there the first time its owner writes to it.

| Capability | What it gives you |
|---|---|
| [Personal vaults](#personal-vaults) | A vault for each user, which only they and those they choose reach |
| [Group vaults](#group-vaults) | A vault for each group, shared by its members while they are members |
| [The realm's vault](#the-realms-vault) | The organization's own secrets, which outlive any account |
| [Deleting an owner](/secrets-store/vaults/owner-deletion/) | A deleted user's or group's secrets, key, grants and shares go with them |

## Before you begin

- **Who:** any user signed in to the realm, for their own vault and their groups' vaults. The realm's vault is for
  realm administrators: members of a group holding `RealmOwner`, or a privilege of your own that allows `MODIFY` on
  secrets. See [Delegated administration](/platform/realms/delegated-administration/).
- **Where:** the API. Today every task is an API call; there are no screens yet.
- **First:** a realm administrator has turned the store on. See [Realm settings](/secrets-store/realm-settings/).

## How it works

A request names the vault it means in its address, under `https://foobar.cvyuh.com/api/v0/vault/managed/v1`:

| Vault | Owner | Who has every right in it | Addressed as |
|---|---|---|---|
| Personal | a user | that user | `me`, or `user/maya` |
| Group | a group | every member, while they are a member | `group/engineering` |
| Realm | the realm | the realm's administrators | `realm` |

Every right means reading, writing and deleting every secret in the vault, and giving or taking back
[grants](/secrets-store/sharing/grants/) on them. Anyone else reaches a secret only through a grant on it, or, for a
personal vault, through [emergency access](/secrets-store/emergency-access/).

### Personal vaults

Each user's own vault, addressed as `me` by its owner and as `user/<user id>` by anyone reaching it through a grant
or emergency access. It is sealed under the user's own key, so a realm administrator acting as themselves can't read,
write or grant anyone's personal secrets. Someone who can sign in as the user can; see
[Who can read a secret](/secrets-store/guides/who-can-read-a-secret/).

### Group vaults

A group's vault belongs to the group, not to whoever wrote each secret: a member reads what another member wrote, and
someone removed from the group is refused from their next request. It is sealed under the group's own key: see
[Group keys](/secrets-store/keys-and-protection/group-keys/).

### The realm's vault

The organization's own secrets, such as infrastructure credentials. Every realm administrator reaches them, and no one
else does unless an administrator grants it. It is sealed under the realm's secrets key: see
[Key rotation](/secrets-store/keys-and-protection/key-rotation/).

## Set it up

Nothing to set up for each vault. A realm administrator turns the store on once, and every vault is then ready: see
[Realm settings](/secrets-store/realm-settings/).

A secret is written straight into the vault it belongs in. For example, a member of `engineering` keeps the team's
deploy key in the group's vault ([Call the API](/develop/api/) shows how to get `$CVYUH_SESSION`):

```sh
curl https://foobar.cvyuh.com/api/v0/vault/managed/v1/group/engineering/data/deploy/key \
  -H "Cookie: x-cvyuh-token=$CVYUH_SESSION" \
  -H "Content-Type: application/json" \
  -d '{ "data": { "key": "<deploy key>" } }'
```

## When it fails

| Answer | When | What to do |
|---|---|---|
| `409` | The store isn't turned on for the realm | A realm administrator turns it on |
| `404` in a personal vault | The caller has no access, or the path isn't there: a personal vault doesn't say which | Ask the owner for a grant |
| `403` in a group's or the realm's vault | The caller isn't a member, or isn't a realm administrator, and holds no grant | Ask for membership or a grant |
| `404`, "no such vault" | The address isn't `me`, `user/<id>`, `group/<id>` or `realm` | Fix the address |
| `404` for another realm | The session is for a different realm | Sign in to the realm the vault is in |

## Limits and defaults

| Limit | Value |
|---|---|
| Vaults per user | one personal vault, plus one per group they're in, plus the realm's if they administer it |
| Secrets per vault | no fixed limit |
| Moving a secret between vaults | not offered; read it and write it into the other |

## Audit record

Every call to a vault is an `ACCESS` record under its caller, and every change a change record on the secret. See
[Secrets audit trail](/secrets-store/keys-and-protection/audit-trail/).

## Good to know

- **A personal vault doesn't say whether a path exists.** Someone with no access is told it isn't there (`404`). A
  group's or the realm's vault refuses them instead (`403`), since who owns it is no secret.
- **A secret never changes vault.** It is written into one vault and stays there.
- **Only in its own realm.** A vault is reached only by a user signed in to the realm it is in.
- **Users own vaults; apps and agents don't yet.** Every call is made by a signed-in user, and acts as that user. See
  [What's next for vaults](/secrets-store/vaults/whats-next/#machine-access).
- **Answers carry their content under `data`.** A call that changes something and has nothing to report answers `204`.

## Coming next

Machine access for apps, services and agents, whether a user's first vault is sealed or managed, and your own secrets
manager reached through the realm: see [What's next for vaults](/secrets-store/vaults/whats-next/).

## Related

- [Store a secret](/secrets-store/guides/store-a-secret/): your own vault, start to finish.
- [Share secrets with a team](/secrets-store/guides/team-secrets/): a group's vault.
- [Keep the organization's secrets](/secrets-store/guides/organization-secrets/): the realm's vault.
- [Who can read a secret](/secrets-store/guides/who-can-read-a-secret/): every way into a vault.
