Skip to content
Secrets StoreMarkdown

Change a secret safely

When several users or tools write one secret, make each write name the version it replaces, so no change is silently lost.

API

The engineering team shares a deploy key, and a scheduled job rotates it too. If two of them write at once, one change can wipe out the other unseen. With check-and-set, each write names the version it was based on, and a write based on an old version fails instead.

Before you start: you are a member of engineering, signed in with your session in $CVYUH_SESSION (Call the API shows how).

  1. Read the secret and note its version, shown as data.metadata.version. Say it is 3:

    Terminal window
    curl https://foobar.cvyuh.com/api/v0/vault/managed/v1/group/engineering/data/deploy/key \
    -H "Cookie: x-cvyuh-token=$CVYUH_SESSION"
  2. Write, naming that version:

    Terminal window
    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 '{ "options": { "cas": 3 }, "data": { "key": "<new deploy key>" } }'
  3. If no one wrote in between, your write is version 4. If someone did, the realm answers 400 and says what the latest version is. Read again, decide, and write again with the new version.

To create a path only if it doesn’t exist yet, write with "cas": 0.

So no one can forget, require check-and-set for the path:

Terminal window
curl https://foobar.cvyuh.com/api/v0/vault/managed/v1/group/engineering/metadata/deploy/key \
-H "Cookie: x-cvyuh-token=$CVYUH_SESSION" \
-H "Content-Type: application/json" \
-d '{ "cas_required": true }'

For the whole realm, a realm administrator sets managed.casRequired to true: see Set the realm’s defaults. A write without cas then answers 400.

A GET on https://foobar.cvyuh.com/api/v0/vault/managed/v1/group/engineering/metadata/deploy/key shows cas_required: true and the current_version your write made.

Lift the path’s requirement by sending { "cas_required": false } to the same address. A path can’t lift the realm’s.