docs: config versions, digests and the adoption recipe (#522)
Documents versions, digests, --if-version (exit code 4), receipts, env effective and env digest in the carlos env section, with the adoption recipe as a worked example on app shop. Draft prose; the copy pass runs afterwards.
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
1 file changed,
+168
−0
docs/site/cli.md+168 −0
diff --git a/docs/site/cli.md b/docs/site/cli.md| index f0462cce6..de4ea827a 100644 |
| --- a/docs/site/cli.md |
| +++ b/docs/site/cli.md |
| @@ -985,6 +985,169 @@ not reach <host>"), with the two ways out: name the unit that runs the |
| process on the box, or opt the bundle into file delivery. A stamped route |
| the root pass will refuse is reported as blocked with the reason. |
| +#### Config versions and digests |
| + |
| +Every bundle has a version, and every var in it has a digest. They answer |
| +the question "has this changed since I last looked?" without you comparing |
| +values by eye. |
| + |
| +A version looks like `cv1:` followed by a hash of the bundle as it is stored. |
| +Two reads of a bundle nobody wrote give the same version, and any change to |
| +the bundle gives a new one. A bundle that has never been written has the |
| +version `none`, which is different from a bundle that exists and holds no |
| +vars. A version can come back: set a var to B and then back to A, and the |
| +bundle returns to its first version, because the stored bytes are the same |
| +again. |
| + |
| +A digest looks like `vd1:` followed by a hash of one var as it is stored. For |
| +a plain var that is its value, so the digest changes when the value does. For |
| +a secret it is the sealed envelope, which is different every time the secret |
| +is set. So setting a secret again, even to the same value, gives it a new |
| +digest, and a secret's digest tells you only that it was written, never what |
| +it holds. |
| + |
| +`carlos env list` prints the version in its header line, and `--digests` adds |
| +a `DIGEST` column. `carlos secrets list --digests` prints key names and |
| +digests, still no values. `--json` always carries the version and every |
| +digest. |
| + |
| +```sh |
| +carlos env list --app shop --digests |
| +``` |
| + |
| +```text |
| +shop (default, version cv1:3f0c…): |
| +KEY VALUE DIGEST |
| +LOG_LEVEL info vd1:91ab… |
| +REGION eu vd1:c7d2… |
| +``` |
| + |
| +A plain var's digest is as sensitive as its value. It is a hash of the value, |
| +so anyone holding the digest can test a guess against it. Treat it the way you |
| +treat the value: do not paste digests of plain vars into a report, ticket or |
| +channel that reaches more people than the value would. A secret's digest does |
| +not have this problem. |
| + |
| +`carlos env digest` computes a digest on your machine, with no console call, |
| +so you can compare it with what a listing or a write reports. |
| + |
| +```sh |
| +carlos env digest --kind env --value info |
| +carlos env digest --kind secret --envelope-file sent.envelope --sealed-to <fingerprint> |
| +``` |
| + |
| +For a secret you pass the envelope that was sent and, with `--sealed-to`, the |
| +fingerprint of the key it was sealed to. Both are part of the stored var, so |
| +both go into the digest. `carlos secrets set` does not save the envelope it |
| +sends, so the secret form is for a script that seals and sends for itself. |
| + |
| +`carlos env effective --app shop --host shop.example.com` shows what one |
| +route gets. It prints each layer's version (`default`, `environment` and |
| +`overlay`) and then one row per key with the layer it comes from and any |
| +lower layers that also set it, in a `HIDES` column. Use it when a var you |
| +set does not seem to take effect: it will say if a higher layer is |
| +covering it. `--json` prints the console's answer as it is. It shows the |
| +stored layers only. Values set on the box itself, such as an exec route's |
| +own `<host>.env`, are not in the bucket and are not shown. It works through |
| +a console, not in direct-bucket mode. |
| + |
| +#### Writing only if the bundle has not moved |
| + |
| +`carlos env set`, `carlos env unset`, `carlos secrets set` and `carlos |
| +secrets unset` take `--if-version <v>`. The write happens only if the bundle |
| +is still at version `v`, so you can read a bundle, decide what to change, and |
| +be sure nobody wrote in between. `--if-version none` means the write happens |
| +only if the bundle does not exist yet. |
| + |
| +```sh |
| +carlos env set --app shop --if-version cv1:3f0c… FEATURE_X=on |
| +``` |
| + |
| +If the bundle has moved, nothing is written, the command prints the current |
| +version and exits with code 4. Every other failure exits 1, so a script can |
| +tell "read again and decide" from "something is broken". The check is made by |
| +the console against the store, so it holds even if someone else writes at the |
| +same moment. For that reason `--if-version` needs a console: in direct-bucket |
| +mode it is refused before anything is written. A console whose store cannot |
| +make that guarantee refuses it too. |
| + |
| +With no `--if-version`, a write behaves as it always did. |
| + |
| +Every write prints a receipt of what the console stored: the names it set |
| +(`set:`), the names it removed (`removed:`), and any names you asked to |
| +remove that were not there (`not there:`), followed by the version after the |
| +write and the version before. If the write changed nothing, because every |
| +value was already what you sent, it says so and prints the version the bundle |
| +is still at. A write to a named environment also tells you if the default |
| +bundle changed while it ran. The two bundles are separate objects, so the |
| +console can report that but cannot prevent it; whether it matters is for you |
| +to decide. `--if-version` covers the bundle you wrote to, not the default. |
| + |
| +A receipt describes what is stored. It does not say that a process has |
| +picked the config up. That is a separate question, and the restart notice |
| +under it is still the place that answers it. |
| + |
| +#### Adding keys from a script without overwriting anyone |
| + |
| +A script that adds keys to a bundle other people also write needs to be sure |
| +of two things: that it did not overwrite or remove anything it was meant to |
| +leave alone, and that if its write is lost or refused it can tell what |
| +happened and try again safely. Take the app `shop` and a script that adds |
| +`AGENT_ISSUER` and `AGENT_TEAM`, and must leave `DATABASE_URL` and |
| +`LOG_LEVEL` as they are. |
| + |
| +1. **Baseline.** Read the bundle and keep its version and the digest of each |
| + key the script must preserve. |
| + |
| + ```sh |
| + carlos env list --app shop --digests --json |
| + ``` |
| + |
| + Keep `version`, and the `digest` of `LOG_LEVEL`. Do the same with `carlos |
| + secrets list --app shop --digests --json` for `DATABASE_URL`. |
| + |
| +2. **Write.** Pass the baseline version as `--if-version` and set only the |
| + new keys. |
| + |
| + ```sh |
| + carlos env set --app shop --if-version cv1:3f0c… \ |
| + AGENT_ISSUER=https://issuer.example.com AGENT_TEAM=shop |
| + ``` |
| + |
| +3. **Check the receipt.** On success the receipt's `set:` line should name |
| + exactly `AGENT_ISSUER` and `AGENT_TEAM`, and there should be no |
| + `removed:` line. To check the values, compare `carlos env digest --kind |
| + env --value <what you sent>` with the digest `carlos env list --digests` |
| + shows for the key. |
| + |
| +4. **If the answer was lost, or the write was refused with exit code 4, |
| + read again** and compare the bundle with your baseline. Exactly one of |
| + these applies to any read, and the first that matches wins: |
| + |
| + - A preserved key has a different digest from the baseline, or is gone. |
| + Stop. Something else changed what the script promised to leave alone. |
| + Do not retry and do not take a new baseline. |
| + - Every preserved key matches the baseline, and every new key is present |
| + with the digest of what you sent. The write landed. You are done. |
| + - Every preserved key matches the baseline, and no new key is present. |
| + The write did not land and nothing you care about moved. Retry from step |
| + 2 with `--if-version` set to the version you just read. |
| + - Every preserved key matches the baseline, but the new keys are only |
| + partly there, or one has a different digest or a different kind. Stop. |
| + Another writer touched the keys this script was adding. Do not |
| + overwrite them, do not take a new baseline, and report the conflict. |
| + |
| +The baseline is the digests of the keys you promised to preserve, not the |
| +bundle's version. That is deliberate. A write to some unrelated key between |
| +your attempts changes the version but not your baseline, so you do not have |
| +to start again, and a change to a key you promised to preserve can never be |
| +absorbed into a fresh baseline by accident. |
| + |
| +The `carlos secrets set` command does not give you the envelope it sent, so |
| +for a secret you can check that a key is present or absent and that its |
| +digest moved, but not that it equals what you sent. A script that needs that |
| +check seals and sends for itself. |
| + |
| ### carlos secrets |
| The same shape as `carlos env`, sealed. `list` prints key names and never |
| @@ -1009,6 +1172,11 @@ In direct-bucket mode, `carlos secrets set` refuses for any account that owns a |
| `carlos secrets fingerprint` prints the fingerprint of the `CARLOS_SECRETS_KEY` in `/etc/carlos/host.env`, or in the file you name with `--file`. It runs on your machine, calls no console and never prints the key. |
| +Versions, digests and `--if-version` work as they do for `carlos env`, see |
| +[Config versions and digests](#config-versions-and-digests). A secret's digest |
| +is taken over its sealed envelope, so it says nothing about the value and |
| +changes every time the secret is set, even to the same value. |
| + |
| An empty value is refused rather than stored. A command substitution that |
| produced nothing looks exactly like a real value at the point you type it, and |
| a stored empty secret usually surfaces much later as a feature quietly not |