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).
Write with check-and-set
Section titled “Write with check-and-set”-
Read the secret and note its version, shown as
data.metadata.version. Say it is3:Terminal window curl https://foobar.cvyuh.com/api/v0/vault/managed/v1/group/engineering/data/deploy/key \-H "Cookie: x-cvyuh-token=$CVYUH_SESSION" -
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>" } }' -
If no one wrote in between, your write is version 4. If someone did, the realm answers
400and 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.
Make it required
Section titled “Make it required”So no one can forget, require check-and-set for the path:
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.
Check it worked
Section titled “Check it worked”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.
Undo it
Section titled “Undo it”Lift the path’s requirement by sending { "cas_required": false } to the same address. A path can’t lift the realm’s.
Related
Section titled “Related”- Check-and-set: how it works.
- Versions: what each write makes.