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.
Before you begin
Section titled “Before you begin”- 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.
How it works
Section titled “How it works”A write or a change carries "options": { "cas": <n> }:
cas sent | The write goes through when |
|---|---|
| none | always, unless check-and-set is required |
0 | the 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.
Set it up
Section titled “Set it up”Write deploy/key in the engineering group’s vault, based on version 3 (Call the API shows how to
get $CVYUH_SESSION):
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.casRequiredtotrue. See Realm settings.
When it fails
Section titled “When it fails”| Answer | When | What 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 version | Read 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 none | Send options.cas |
400 with cas: 0 | The path already exists | Read it, and write with its version instead |
Limits and defaults
Section titled “Limits and defaults”| Limit | Default | Range |
|---|---|---|
| Check-and-set required, realm-wide | false | true or false |
| Check-and-set required, one path | false | true or false; can add the requirement, never lift the realm’s |
Troubleshooting
Section titled “Troubleshooting”| Symptom | Cause | Fix |
|---|---|---|
A scheduled job’s writes all fail with 400 | It writes without cas and the realm now requires it | Have the job read the version first and send it |
| Two writers keep failing each other | Both retry with the version they read before the other’s write | Read again after each failure before retrying |
Audit record
Section titled “Audit record”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.
Good to know
Section titled “Good to know”- A path can add the requirement, never lift it. A path’s
cas_required: falsedoesn’t override the realm’smanaged.casRequired. - Changes count too. A
PATCHto the path’sdatatakescasthe same way. cas: 0creates only. Use it to write a secret only if no one has written it yet.
Related
Section titled “Related”- Change a secret safely: the task, start to finish.
- Versions: what each write makes.