# Group keys

> A group's secrets sealed under the group's own key, which opens only on a member's sign-in.

A group's vault is sealed under a key that belongs to the group. Only a member's sign-in reaches it, and only while
they are a member. A realm administrator who isn't in the group, acting as themselves, can't read its secrets, and
someone who leaves the group loses them from their next request.

## Before you begin

- **Who:** any member of the group. A realm administrator creates the group and manages its members, with
  `RealmOwner` or a privilege of your own that allows changing groups (see
  [Delegated administration](/platform/realms/delegated-administration/)).
- **Where:** the API. There are no screens yet.
- **First:** the store is on, and the group exists with its members.

## How it works

The group's key is made the first time a member opens the group's vault, to read or to write. That same first open
publishes the group's public key, so a [grant](/secrets-store/sharing/grants/) to the group can be sealed to it: a
grant to a group is one copy, opened by whichever member reads it.

Every open runs on the member's own sign-in, and the realm's audit trail records which member it was.

## Set it up

There's nothing to set up. The first member to open the `engineering` group's vault makes its key, for example by
listing it ([Call the API](/develop/api/) shows how to get `$CVYUH_SESSION`):

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

An empty vault answers `404` to a listing; the key is made all the same.

## What members see

- A member reads and writes every secret in the group's vault, and gives grants on them.
- Someone who isn't a member is refused (`403`): who owns a group's vault is no secret, so the store doesn't pretend
  the path is missing.
- A member who is removed is refused from their next request. What they already read stays with them.

## When it fails

| Answer | When | What to do |
|---|---|---|
| `403` | The caller isn't a member of the group | A realm administrator adds them to the group |
| `404` on a grant to the group | No member has opened the group's vault yet, so it has no key to seal to | A member opens the vault once, then grant again |
| `404` on the group | No group has that id | Check the group id |

## Troubleshooting

| Symptom | Cause | Fix |
|---|---|---|
| A grant to the group answers `404` though the group exists | No member has opened its vault yet | A member lists the vault once, as above |
| A grant from the group's vault stopped opening for its grantee | The member who last wrote the secret was deleted | A member writes the secret again. See [Grants](/secrets-store/sharing/grants/#good-to-know) |

## Audit record

Each member's read or write is an `ACCESS` record under that member, and each write is a change record on the secret
under that member. The key itself writes no record when it is made. When the group is deleted, the destruction of its
key is a `DELETED` change record. See [Secrets audit trail](/secrets-store/keys-and-protection/audit-trail/).

## Good to know

- **A realm administrator can't read a group's key** acting as themselves. They can see that it exists, and it is
  destroyed when the group is deleted. See [Deleting an owner](/secrets-store/vaults/owner-deletion/).
- **Removing a member doesn't change the key.** The member never held it, and is refused at their next request.
  Change any secret they used: removal can't take back what they already read.
- **No grant to a group until a member opens its vault.** Until then the group has no key to seal to.
- **Whoever manages a group's members decides who shares its vault.** Keep that right to people you would trust with
  the secrets.

## Related

- [Share secrets with a team](/secrets-store/guides/team-secrets/): a group's vault, start to finish.
- [Sealing per owner](/secrets-store/keys-and-protection/sealing/): every owner's key.
- [Vaults](/secrets-store/vaults/): what a group's members may do.
