# Give someone access to a secret

> Let a colleague or a group read one of your secrets until a time you choose, then see and take back what you gave.

`ben` needs the staging database password for the next two weeks. `maya` doesn't want to send it over chat, and
doesn't want him to see anything else in her vault. A [grant](/secrets-store/sharing/grants/) gives him that one
secret, read from the realm under his own sign-in, and it ends by itself.

**Before you start:** the secret, `db/staging`, is in a vault you own: your own, a group's you're a member of, or, as
a realm administrator, the realm's. Your colleague has used the store at least once, so they have a key to seal their
copy to. You are signed in with your session in `$CVYUH_SESSION` ([Call the API](/develop/api/) shows how).

## Give the grant

<Steps>

1. Choose the access. `use` lets them read the current value and nothing more. `view` also lets them read older
   versions and the secret's metadata, and see it when they list your vault.

2. Give the grant, with an end time:

   ```sh
   curl https://foobar.cvyuh.com/api/v0/vault/managed/v1/me/grants/db/staging \
     -H "Cookie: x-cvyuh-token=$CVYUH_SESSION" \
     -H "Content-Type: application/json" \
     -d '{ "user": "ben", "access": "use", "validTo": "<RFC 3339 time>" }'
   ```

   To grant a whole team, send `"group": "engineering"` in place of `user`. The realm answers `201` with the grant and
   its `edgeId`. Keep the `edgeId` if you'll take the grant back early.

3. Tell your colleague the path. They find it with a `GET` on
   `https://foobar.cvyuh.com/api/v0/vault/managed/v1/shared`, and read it at
   `https://foobar.cvyuh.com/api/v0/vault/managed/v1/user/maya/data/db/staging`.

</Steps>

## Check it worked

List the secret's grants:

```sh
curl https://foobar.cvyuh.com/api/v0/vault/managed/v1/me/grants/db/staging \
  -H "Cookie: x-cvyuh-token=$CVYUH_SESSION"
```

Each grant shows who it names, its `access`, its `validTo`, who gave it (`grantedBy`), and `live`: whether it still
gives access right now.

## Undo it

To end a grant before its time, delete it by its `edgeId`:

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

The realm answers `204`, and their copy of the secret is gone at once. A grant that has already reached its end time
gives nothing, but stays in the list, marked not live, until you delete it.

<Aside type="tip" title="Someone is leaving">
  A realm administrator can remove every grant to a user, in every vault, in one call, without reading any of the
  secrets. See [Offboard someone](/secrets-store/guides/offboard-someone/).
</Aside>

## Related

- [Grants](/secrets-store/sharing/grants/): how grants work, and what each access level allows.
- [Send a secret once](/secrets-store/guides/send-a-secret-once/): for a secret someone needs a single time.
- [Share secrets with a team](/secrets-store/guides/team-secrets/): when the secret belongs to the team, not to you.
