Skip to content
Secrets StoreMarkdown

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.

API

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 shows how).

  1. Keep only two versions:

    Terminal window
    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:

    Terminal window
    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:

    Terminal window
    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.

Each call answers 204.

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.

Set max_versions to 0 and delete_version_after to 0s to take the realm’s defaults again. See Set the realm’s defaults.