# Limit a secret's history

> Choose how many versions a secret keeps, let old versions lapse after a time, and label a secret with your own notes.

Old credentials kept around are a risk. You can cap how many versions a secret keeps, have each version read as
deleted a set time after it was written, and label the secret so others know what it is for.

**Before you start:** you can write the secret: here, `db/prod/root` in your own vault. You are signed in with your
session in `$CVYUH_SESSION` ([Call the API](/develop/api/) shows how).

## Set the limits

<Steps>

1. Keep only two versions:

   ```sh
   curl -X PATCH https://foobar.cvyuh.com/api/v0/vault/managed/v1/me/metadata/db/prod/root \
     -H "Cookie: x-cvyuh-token=$CVYUH_SESSION" \
     -H "Content-Type: application/json" \
     -d '{ "max_versions": 2 }'
   ```

   From the next write, versions past the limit are dropped for good.

2. Let each version lapse thirty days after it is written:

   ```sh
   curl -X PATCH https://foobar.cvyuh.com/api/v0/vault/managed/v1/me/metadata/db/prod/root \
     -H "Cookie: x-cvyuh-token=$CVYUH_SESSION" \
     -H "Content-Type: application/json" \
     -d '{ "delete_version_after": "720h" }'
   ```

   This applies to versions written from now on. A lapsed version reads as deleted, and can be undeleted until it is
   destroyed or dropped.

3. Add labels, as text:

   ```sh
   curl -X PATCH https://foobar.cvyuh.com/api/v0/vault/managed/v1/me/metadata/db/prod/root \
     -H "Cookie: x-cvyuh-token=$CVYUH_SESSION" \
     -H "Content-Type: application/json" \
     -d '{ "custom_metadata": { "team": "engineering", "rotates": "monthly" } }'
   ```

   A label sent as `null` is removed. `POST` in place of `PATCH` replaces every label.

</Steps>

Each call answers `204`.

## Check it worked

A `GET` on `https://foobar.cvyuh.com/api/v0/vault/managed/v1/me/metadata/db/prod/root` shows `max_versions`,
`delete_version_after` and `custom_metadata`. After the third write, `oldest_version` moves up.

## Undo it

Set `max_versions` to `0` and `delete_version_after` to `0s` to take the realm's defaults again. See
[Set the realm's defaults](/secrets-store/guides/set-the-realms-defaults/).

## Related

- [Metadata](/secrets-store/secrets/metadata/): every field, and its limits.
- [Realm settings](/secrets-store/realm-settings/): the defaults a path takes.
