Skip to content
Secrets StoreMarkdown

Check-and-set

A write names the version it expects to replace, so two users changing one secret never silently overwrite each other.

AvailableAPI

When two users or two tools change the same secret at once, the later write would normally wipe out the earlier one without either noticing. With check-and-set, a write says which version it was based on. If someone else wrote first, the write fails instead, and the writer reads again and decides.

  • Who: anyone who may write the secret. Requiring check-and-set for one path is for anyone with every right in its vault; for the whole realm, a realm administrator (see Realm settings).
  • Where: the API. There are no screens yet.
  • First: know the latest version: read the secret, or its metadata.

A write or a change carries "options": { "cas": <n> }:

cas sentThe write goes through when
nonealways, unless check-and-set is required
0the path doesn’t exist yet
<n>version <n> is the latest

A write whose cas doesn’t match answers 400, and says what the latest version is. Two writes that arrive together are applied one after the other, each checked against the version the other left, so exactly one of them succeeds.

Write deploy/key in the engineering group’s vault, based on version 3 (Call the API shows how to get $CVYUH_SESSION):

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": "<deploy key>" } }'

To make every write name its version:

  • For one path, as its owner: POST { "cas_required": true } to the path’s metadata.
  • For the whole realm, as a realm administrator: set managed.casRequired to true. See Realm settings.
AnswerWhenWhat to do
400, “check-and-set parameter did not match the current version”Someone wrote since you read; the answer’s detail names the latest versionRead the latest, decide, and write again with its version
400, “check-and-set parameter required for this call”The path or the realm requires check-and-set and the write sent noneSend options.cas
400 with cas: 0The path already existsRead it, and write with its version instead
LimitDefaultRange
Check-and-set required, realm-widefalsetrue or false
Check-and-set required, one pathfalsetrue or false; can add the requirement, never lift the realm’s
SymptomCauseFix
A scheduled job’s writes all fail with 400It writes without cas and the realm now requires itHave the job read the version first and send it
Two writers keep failing each otherBoth retry with the version they read before the other’s writeRead again after each failure before retrying

A write that goes through is an UPDATED change record, as any write; a refused one changes nothing and is recorded only as an ACCESS record with its 400. Setting cas_required on a path is an UPDATED change record. See Secrets audit trail.

  • A path can add the requirement, never lift it. A path’s cas_required: false doesn’t override the realm’s managed.casRequired.
  • Changes count too. A PATCH to the path’s data takes cas the same way.
  • cas: 0 creates only. Use it to write a secret only if no one has written it yet.