# Emergency access

> Nominate someone who can reach your personal secrets if you can't, after a delay in which you can say no.

If you were away or unable to act, someone might need the passwords only you keep. Emergency access lets you name
that someone in advance. They can ask at any time, but they get in only after a delay you choose, and only if you
don't refuse within it.

You can refuse only if you know they asked, and today **no notice is sent** when a nominee asks. Check your
nominations yourself, and choose a delay long enough for you to notice.

## Before you begin

- **Who:** any user, for their own personal vault. No privilege is needed, and a realm administrator can't nominate
  for someone else.
- **Where:** the API. There are no screens yet.
- **First:** your nominee has used the store at least once, so the realm can seal your vault to them.

## How it works

A nomination moves through three states:

| Step | Who | State |
|---|---|---|
| Nominate | you, the grantor | `idle` |
| Ask | the nominee | `waiting`: the delay starts |
| Refuse | you, while a request stands | back to `idle` |
| The delay passes, unrefused | — | `granted`: the nominee may view |
| Withdraw, or decline | either of you | the nomination is gone |

Once `granted`, the nominee can read every version, the metadata and the listing of your personal vault, and make
[one-time shares](/secrets-store/sharing/one-time-shares/) of it. They write nothing, and reach none of your group or
realm vaults.

Only the nominee can open your vault, and only once let in. After they do, your vault is re-keyed at your next access,
and every [grant](/secrets-store/sharing/grants/)'s copy is sealed again, so nothing you write afterwards is under a
key they held.

## Set it up

Every call is under `https://foobar.cvyuh.com/api/v0/vault/managed/v1/emergency`
([Call the API](/develop/api/) shows how to get `$CVYUH_SESSION`).

1. Nominate someone. Here `maya` nominates `ben`, with a three-day delay:

   ```sh
   curl https://foobar.cvyuh.com/api/v0/vault/managed/v1/emergency \
     -H "Cookie: x-cvyuh-token=$CVYUH_SESSION" \
     -H "Content-Type: application/json" \
     -d '{ "nominee": "ben", "delay": 259200 }'
   ```

   The realm answers `201` with the nomination and its `id`. Leave out `delay` for the realm's default, a week unless
   your realm changed it.

2. Either of you sees it with a `GET` on the same address: the nominations you made under `nominated`, and those
   naming you under `nominatedFor`, each with its `id`, `grantor`, `nominee`, `delay`, `requestedAt`, `refusedAt` and
   `state`.

3. The nominee asks with a `POST` to `…/emergency/<id>/request`, and, once granted, reads your vault at
   `https://foobar.cvyuh.com/api/v0/vault/managed/v1/user/maya`.

You refuse a request with a `POST` to `…/emergency/<id>/refuse`. Either of you ends the nomination:

```sh
curl -X DELETE https://foobar.cvyuh.com/api/v0/vault/managed/v1/emergency/<id> \
  -H "Cookie: x-cvyuh-token=$CVYUH_SESSION"
```

The realm answers `204`.

## What each of you sees

- **The grantor** gets no message when the nominee asks. A `GET …/emergency` shows the nomination under `nominated`
  with `state: "waiting"` and its `requestedAt`. Check it on a schedule shorter than your delay.
- **The nominee** sees `state` move from `waiting` to `granted` when the delay has passed unrefused, and from then reads
  your vault as `user/<your id>`. Before that, your vault answers them `404`.
- **After a refusal,** the nominee sees `state: "idle"` and a `refusedAt` time.

## When it fails

| Answer | When | What to do |
|---|---|---|
| `404` nominating | The nominee doesn't exist, or hasn't used the store yet | They make any call to the store once, then nominate again |
| `400` nominating | You named yourself, or a delay of `0` | Name someone else; a delay is at least one second |
| `400` refusing, "no request stands" | The nominee hasn't asked, or you already refused | Nothing to refuse |
| `404` on a nomination | It isn't yours or doesn't name you, or it's gone | Check the `id` with `GET …/emergency` |
| `412` | The other side changed the nomination at the same moment | Read it again and retry |
| `404` reading the vault as nominee | The nomination isn't `granted` yet | Wait for the delay, or ask the grantor |

## Limits and defaults

| Limit | Default | Range | Set by |
|---|---|---|---|
| Delay | 604800 seconds (a week) | at least 1 second | `delay` on the nomination; `managed.emergencyDelayDefault` for the realm (1 second to ten years) |
| Nominations per user | no fixed limit | | |
| What a nominee reaches | your personal vault, read only | | |

## Troubleshooting

| Symptom | Cause | Fix |
|---|---|---|
| A nominee got in and you never saw the request | No notice is sent; the delay passed unrefused | Refuse or withdraw now, and change the secrets they could read. Choose a longer delay and check on a schedule |
| Nominating answers `404` for a colleague who exists | They haven't used the store yet | Ask them to make one call, such as `GET …/config` |
| The nominee still reads after you refuse | They read before the refusal | A refusal stops further reads; change any secret they read |

## Audit record

A nomination is a `CREATED` change record, a request or a refusal a `PATCHED` one, and a withdrawal a `DELETED` one,
each under who made it. Every read the nominee makes is an `ACCESS` record under the nominee. See
[Secrets audit trail](/secrets-store/keys-and-protection/audit-trail/).

## Good to know

- **Nothing before the delay.** A nomination alone, or a request still waiting, lets no one in.
- **No notice is sent.** Neither of you is told when the other acts. Check `GET …/emergency` yourself.
- **Pick the delay for how often you check.** If you look at your nominations weekly, a delay shorter than a week
  can pass unseen.
- **A refusal ends the request,** even after the delay has passed, and so ends the access. The nominee may ask again,
  and the delay starts again.
- **Only the two of you.** Only the nominee can ask, and only you can refuse. Anyone else is told the nomination isn't
  there.
- **A nominee keeps what they read.** Refusing or withdrawing stops further access; it can't take back what they
  already saw.

## Reference

| Field | What it sets |
|---|---|
| `nominee` | Who may ask, by user id |
| `delay` | Seconds from a request until the nominee is let in. Leave it out for the realm's default |

## Related

- [Plan for an emergency](/secrets-store/guides/emergency-access/): the task, start to finish.
- [Realm settings](/secrets-store/realm-settings/): the realm's default delay.
- [What's next for sealed vaults](/secrets-store/sealed-vaults/whats-next/#emergency-access): the same nomination,
  for sealed vaults.
