# Plan for an emergency

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

If `maya` were away or unable to act, someone might need the passwords only she holds. With
[emergency access](/secrets-store/emergency-access/) she names that user now. They can ask at any time, but get in
only after a delay she chooses, and never if she refuses within it.

No notice is sent when the nominee asks: `maya` refuses only if she checks. She chooses a delay longer than the gap
between her checks.

**Before you start:** your nominee, here `ben`, has used the store at least once, so they have a key the realm can
seal yours to. Each of you is signed in with your own session in `$CVYUH_SESSION` ([Call the API](/develop/api/)
shows how).

## Nominate someone

<Steps>

1. As `maya`, nominate `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`, in state `idle`. Leave out `delay` for the realm's
   default, a week.

2. If `ben` ever needs her secrets, he asks:

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

   The state becomes `waiting`, and the delay starts. `maya` isn't told.

3. `maya` checks her nominations on a schedule shorter than the delay, with a `GET` on
   `https://foobar.cvyuh.com/api/v0/vault/managed/v1/emergency`. A nomination under `nominated` with
   `state: "waiting"` is a request. Within the delay, she can refuse:

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

   His request ends. He can ask again, and the delay starts again.

4. Once the delay passes unrefused, the state is `granted`, and `ben` reads her personal vault:

   ```sh
   curl "https://foobar.cvyuh.com/api/v0/vault/managed/v1/user/maya/metadata?list=true" \
     -H "Cookie: x-cvyuh-token=$CVYUH_SESSION"
   ```

   He can read every version and list the vault, and write nothing. Her group and realm vaults aren't reached.

</Steps>

## Check it worked

A `GET` on `https://foobar.cvyuh.com/api/v0/vault/managed/v1/emergency` lists the nominations you made under
`nominated` and those naming you under `nominatedFor`, each with its `grantor`, `nominee`, `delay` and `state`.

## Undo it

Either of you ends the nomination at once:

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

<Aside type="note" title="After a nominee gets in">
  Your key is replaced at your next access, and every grant's copy is sealed again. Refuse or withdraw then, and
  nothing you write afterwards is under a key the nominee ever held.
</Aside>

## Related

- [Emergency access](/secrets-store/emergency-access/): every rule.
- [Who can read a secret](/secrets-store/guides/who-can-read-a-secret/): every way into your vault.
