# Share secrets with a team

> Keep a team's secrets in its group's vault, so access follows the group's membership with nothing to hand over.

A team's credentials belong to the team, not to whoever happened to write them. Kept in the group's vault, they are
sealed under the group's own key: every member reads and writes them, someone who joins the group reads what the
others wrote, and someone who leaves is refused from their next request.

**Before you start:** a realm administrator, holding `RealmOwner` or a privilege of your own that allows changing
groups, creates the group and manages its members; the members then keep the secrets, with no privilege of their own. Each call is made with the caller's own session in `$CVYUH_SESSION` ([Call the API](/develop/api/) shows
how).

## Keep the team's secrets

<Steps>

1. As a realm administrator, create the `engineering` group:

   ```sh
   curl "https://foobar.cvyuh.com/api/v0/am/objects/v1/group?id=engineering" \
     -H "Cookie: x-cvyuh-token=$CVYUH_SESSION" \
     -H "Content-Type: application/json" \
     -d '{ "displayName": "Engineering" }'
   ```

   The realm answers `201` with the group and its revision, `rev`.

2. Add `maya` and `ben` as members, one call each, with the group's current `rev`:

   ```sh
   curl https://foobar.cvyuh.com/api/v0/am/objects/v1/group/engineering/relationships/member \
     -H "Cookie: x-cvyuh-token=$CVYUH_SESSION" \
     -H "Content-Type: application/json" \
     -H 'If-Match: "<rev>"' \
     -d '{ "targetId": "maya" }'
   ```

3. As `maya`, write a team secret:

   ```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>" } }'
   ```

   The first member to open the group's vault makes the group's key.

4. As `ben`, read it:

   ```sh
   curl https://foobar.cvyuh.com/api/v0/vault/managed/v1/group/engineering/data/deploy/key \
     -H "Cookie: x-cvyuh-token=$CVYUH_SESSION"
   ```

</Steps>

## Check it worked

Someone not in the group who tries the same read is refused (`403`). Every member can also give
[grants](/secrets-store/sharing/grants/) on the group's secrets, for someone outside the team who needs one.

## Undo it

To take `ben` off the team, a realm administrator removes him from the group, with the group's current `rev`:

```sh
curl -X DELETE https://foobar.cvyuh.com/api/v0/am/objects/v1/group/engineering/relationships/member/ben \
  -H "Cookie: x-cvyuh-token=$CVYUH_SESSION" \
  -H 'If-Match: "<rev>"'
```

He is refused from his next request. What he already read stays with him: write new values for every secret in the
group's vault he used, and change the credential where it is used. If he was the last to write a secret that has
grants on it and is later deleted, writing it again also restarts those grants.

<Aside type="caution" title="Membership is access">
  Whoever decides a group's members decides who shares its vault. Keep that right to the people you would trust with
  the secrets.
</Aside>

## Related

- [Group keys](/secrets-store/keys-and-protection/group-keys/): how the group's key works.
- [Vaults](/secrets-store/vaults/): what members may do.
- [Give someone access to a secret](/secrets-store/guides/give-someone-access/): one secret, for someone outside the
  team.
