diff options
| author | tv <tv@krebsco.de> | 2026-11-27 23:46:34 +0000 |
|---|---|---|
| committer | tv <tv@krebsco.de> | 2026-11-28 02:06:07 +0000 |
| commit | eba0bee47dc5da8cd1491c7bc33b9e22f6a929f0 (patch) | |
| tree | c74fa744466075651b2ced9f5ad9557d9d8dd00c /docs | |
| parent | 2d3d68b622ff62ee1404eda734a73c5e5c8d1397 (diff) | |
docs: design draft 3, migrations on paper
Partial submissions with required and optional items and groups, plan
before apply, formats by media type, a protocol for renderers, host
names by a resolver, refuse as the only policy; and the rule that a
generation change never rewrites the snapshot, which the cases in
migrations.md need.
Diffstat (limited to 'docs')
| -rw-r--r-- | docs/design.md | 418 | ||||
| -rw-r--r-- | docs/migrations.md | 104 |
2 files changed, 356 insertions, 166 deletions
diff --git a/docs/design.md b/docs/design.md index 6bfa168..50885f7 100644 --- a/docs/design.md +++ b/docs/design.md @@ -1,8 +1,10 @@ # enstate: state next to the store, a design draft -Draft 2, 2026-11-27. Nothing is built yet. Section 11 lists what is open. +Draft 3, 2026-11-27. Nothing is built yet. Section 11 lists what is open. The name, enstate, may change. An older model of state objects is in [state-object.md](state-object.md); section 9 says how it fits in. +[migrations.md](migrations.md) walks through the migration model with +three made-up cases. ## 1. The problem @@ -29,43 +31,53 @@ peer means deploying every host). hosts, authorized keys, host names, and have the running system pick it up. 2. A system declares what state it can consume. State that doesn't fit is - rejected as a whole, before anything changes, unless a policy says how - to go on without the part that doesn't fit. -3. State never rolls back when the generation does. Between two + refused, with the reason, before anything changes. +3. An operator can hand over a part of the state, see what it would do + before it is done, and say for each piece whether it must go in or may + be left out. +4. State never rolls back when the generation does. Between two generations that expect different state there is a migration. -4. Secrets are never in the store, never on a builder, never evaluated. -5. Independent of hrm and of NixOS: a program and file formats of its own. +5. Secrets are never in the store, never on a builder, never evaluated. +6. Independent of hrm and of NixOS: a program and file formats of its own. NixOS integrates it with a module; another system could, too. -Scope: the system's state first. Users' state (a user's keys, -tokens) and early state (the initrd's ssh host key, a disk's key) come -later, by the same mechanism where possible; nothing here may prevent -them. +Scope: the system's state first. Users' state (a user's keys, tokens) and +early state (the initrd's ssh host key, a disk's key) come later, by the +same mechanism where possible; nothing here may prevent them. Not goals: storing or generating secrets at the source (password-store and -the like stay), and configuration management (no code in snapshots, see -5.4). +the like stay), and configuration management (no code in what gets handed +over, see 5.6). ## 3. Words -One word per concept, and no word used for two things, so that -renaming stays a search and replace. All of them are working names. +One word per concept, and no word used for two things, so that renaming +stays a search and replace. All of them are working names. | word | meaning | |---|---| | **state** | all of it, as opposed to generations; never one piece | -| **channel** | one of "the other databases": a stream of snapshots with its own provider, order and cadence | +| **channel** | one of "the other databases": state with its own provider, order and cadence | | **slot** | a named place in a channel that a generation offers | -| **type** | what a slot holds: its format, how to validate it; types have **versions** | -| **entry** | the value of one slot in one snapshot | -| **snapshot** | a complete set of entries for one channel of one host | -| **order** | what makes one snapshot newer than another (a channel's choice) | -| **schema** | what one generation accepts: its channels, slots, types, views, reactions, policies | +| **entry** | what a file slot holds: one value | +| **record** | one element of a structured slot, under a key | +| **type** | what a slot holds, and how to check it; types have **versions** | +| **format** | how a value is encoded, named by a media type | +| **snapshot** | the whole content of one channel on one host at one moment | +| **submission** | what gets handed to the host: a set of items for one channel, complete or partial | +| **item** | one piece of a submission: an entry or a record to set or remove, and whether it is required | +| **group** | items of a submission that go in together or not at all | +| **plan** | what a submission would do: which items go in, which don't and why, how the views change, what reacts | +| **order** | what makes one snapshot the successor of another (a channel's choice) | +| **schema** | what one generation accepts: its channels, slots, types, views, reactions | | **view** | a file made from one or more slots, at a stable path, for programs to read | +| **renderer** | the program that makes a view | +| **validator** | the program that checks a slot's content | +| **converter** | the program that turns one version of a type into another | | **reaction** | what the system does when a view changes: reload or restart units | -| **receptor** | the program on the host that accepts or rejects snapshots, and migrates | -| **provider** | whatever makes snapshots and delivers them | -| **migration** | how state accepted under one schema becomes state for another | +| **receptor** | the program on the host that plans, accepts or refuses submissions, and migrates | +| **provider** | whatever makes submissions and delivers them | +| **migration** | how state accepted under one schema serves another | | **policy** | what to do with a slot that can't be filled | ## 4. The parts @@ -73,47 +85,77 @@ renaming stays a search and replace. All of them are working names. | part | where it lives | |---|---| | schema | in the generation (store); it is code, like the system | -| snapshot | made outside, handed to the host | +| submission | made outside, handed to the host | +| snapshot | on the host, kept by the receptor | | receptor | on the host, set up by activation; a small program run on demand, like an activation script, not a service; language secondary, Rust a candidate | -| provider | outside the host (a deploy tool), or an agent on it (a sync) | +| provider | outside the host (a deploy tool, an operator), or an agent on it (a sync) | A host would start with two channels: its own secrets (from the deploying host), and the fleet's public data (from a registry). ## 5. How it works -### 5.1 Slots: files and structured data (both) +### 5.1 Slots, types and formats -- A **file slot** holds bytes of some type: a private key, a certificate, - a ready-made file. Its type has a validator (the key parses). -- A **structured slot** holds records of a declared shape: host names with - their addresses, peers with their keys, users with their authorized - keys. It gets validated against that shape. +- A **file slot** holds one entry: a private key, a certificate, a + ready-made file. +- A **structured slot** holds records under keys: hosts with their + addresses and keys, users with their authorized keys. -Programs don't read slots, they read views. A file slot is its own view. -For structured slots the generation declares views with a renderer: a -pure function from records to a file (known hosts, a zone file, tincr's -host files), which the receptor runs. So one slot of host records can feed -several views, and each module renders the format it needs. +Every piece of state has an address: `CHANNEL/SLOT` for an entry, +`CHANNEL/SLOT/KEY` for a record. + +A slot has a type, and a type has versions. A type says which formats it +accepts, and comes with a validator. Formats are named by media types +(`application/json`, `application/x-pem-file`), so that the encoding can +change, or a type can accept several, without the design changing. +Records are JSON to start with. + +A validator sees a slot's whole content, not one record at a time, so it +can check what holds between records (no two hosts with one address), and +it names the addresses it objects to. + +### 5.2 Views and renderers + +Programs don't read slots, they read views: files at stable paths. A file +slot can be its own view. For anything else, the generation declares a +view with a renderer. + +What a renderer does depends on the data and on who reads it: host records +become known hosts for ssh, a zone file for a resolver, host files for +tincr. (Host names go to a resolver, not into `/etc/hosts`: that file is +the generation's in NixOS, and enstate doesn't touch what a generation +owns. How names get resolved can change.) So enstate doesn't define +renderers, only the protocol they follow: + +- the receptor hands the renderer the content of the slots it asked for, + in their formats, and a directory to write into; +- the renderer writes the view's files there and exits; it reads nothing + else, reaches no network, and gives the same output for the same input; +- the receptor compares what was written with what is in place, installs + it atomically, and runs the reactions of the views that changed. + +Because a renderer only writes into the directory it is given, the +receptor can run it without installing anything. That is what makes plans +(5.4) possible without each renderer having a dry-run mode of its own. A sketch of the NixOS side, names not final: ```nix -state.channels.secrets.slots."retiolum.ed25519_key" = { +enstate.channels.secrets.slots."retiolum.key" = { type = "ed25519-private-key"; secret = true; credentialFor = [ "tincr-retiolum" ]; # LoadCredential= follows reaction.restart = [ "tincr-retiolum" ]; - policy = "stop-consumers"; }; -state.channels.fleet.slots.hosts = { - type = "hosts"; # records: name, addresses, keys +enstate.channels.fleet.slots.hosts = { + type = "hosts"; # records under host names }; -state.views.ssh-known-hosts = { - from = [ "fleet.hosts" ]; - render = ./known-hosts.jq; # records -> file +enstate.views.ssh-known-hosts = { + from = [ "fleet/hosts" ]; + renderer = ./render-known-hosts; }; ``` @@ -122,125 +164,171 @@ system), the units' credentials, and the receptor's setup. Static configuration points at the views' stable paths (`GlobalKnownHostsFile /run/…/ssh-known-hosts`); what is behind them changes. -### 5.2 Handing over +### 5.3 Submissions + +A provider hands the receptor a submission for one channel: items, and a +manifest (the channel, optionally the snapshot it builds on, a checksum +per item). How it gets to the host is not the receptor's business: over +ssh from a deploy tool or an operator, or fetched by an agent. + +A submission is **complete** or **partial**: + +- complete: it is the channel's new content; what it doesn't mention goes. + For a provider that owns a channel, like a deploy tool with a host's + secrets. +- partial: it sets or removes the items it names and leaves the rest. For + an operator who adds a host and a key, or rotates one key. + +Each item says whether it is **required** or **optional**: -A provider gives the receptor a snapshot: one entry per slot, and a -manifest (channel, the schema it was made for, its place in the channel's -order, a checksum per entry). How it gets to the host is not the -receptor's business: over ssh from a deploy tool, or fetched by an agent. +- required: if this item can't go in, the whole submission is refused. +- optional: if this item can't go in, it is left out, with a warning, and + the rest goes on. -### 5.3 Accepting or rejecting +Items that belong together can be put in a **group**: the items of a group +go in together or not at all, and the group is required or optional as a +whole. Grouping is the submission's choice. Items outside a group stand +alone, so a submission can let an item in without its companion (a key +for a host whose record was left out), if that is what the operator +wants. -The receptor checks, without changing anything: +Example: an operator submits a new host record and a new authorized key, +both required. The validator objects to the host record (its address is +taken), so the submission is refused, with that message. The key still +has to change, so the operator submits the key alone; or submits both +again with the host record marked optional, and gets the key in and a +warning for the record. Had the two been an optional group, neither +would have gone in, with one warning. -- the channel exists in the running generation's schema; -- the snapshot is newer than the current one, by the channel's order; -- every entry has its slot's type and version, or can be migrated to it - (section 6); -- every slot is filled, or its policy says how to go on (section 7); -- where the schema asks for it, the snapshot is signed (section 8). +### 5.4 Plan, then apply -If a check fails, the snapshot is rejected as a whole, with the reasons. -Otherwise the receptor puts the new entries in place atomically, renders -the views, works out which views changed, and runs each reaction once -(reload or restart per unit, deduplicated). +The receptor works in two steps, and the first can be run alone, as a dry +run. -A snapshot can be **forced**: it is then accepted although it doesn't -fit, and the policies decide what happens to what it leaves unfilled. +**Plan.** Without changing anything, the receptor: -### 5.4 No code in snapshots +1. checks that the channel exists in the running generation's schema, and + the order (5.8); +2. applies the items to a copy of the current snapshot; +3. runs the validators on the result. Optional items that an objection + names are taken out, with their groups, and the check runs again; an + objection to a required item, or to something already in place, + refuses the submission; +4. checks that every slot the schema requires is filled; +5. runs the renderers into a scratch directory, and compares. -A snapshot is data. Validators, renderers, migrations, reactions and -policies all come from generations, never from a snapshot. So whoever can -deliver state can change values, but can't run anything, and a snapshot -can be inspected before it is accepted. +The plan says, for each item, whether it goes in, and if not, why; for +each view, how it would change (a diff for public views, only "changes" +for secret ones); and which reactions would run. -### 5.5 Where things are on the host +**Apply.** The same, and then: the new snapshot becomes current, the +views are installed atomically, and each reaction runs once (reload or +restart per unit, deduplicated). -- Accepted snapshots are kept on disk, so they survive a reboot, together - with the schema they were accepted under (section 6 needs it). Secrets - there are root's, as `/var/src/secrets` is today; later they can be - encrypted to the host's key. -- At boot and on each accept, the receptor materializes the views under +A submission that is refused changes nothing. + +### 5.5 Forcing + +Not in the first version. Later, a forced submission would go in although +it doesn't fit, and policies (section 7) would say what happens to what it +leaves unfilled. + +### 5.6 No code in submissions + +A submission is data. Validators, renderers, converters, migrations and +reactions all come from generations, never from a submission. So whoever +can deliver state can change values, but can't run anything, and a +submission can be inspected, and planned, before it is applied. + +### 5.7 Where things are on the host + +- The current snapshot of each channel is kept on disk, so it survives a + reboot, together with the schema it was accepted under (section 6 needs + it). Secrets there are root's, as `/var/src/secrets` is today; later + they can be encrypted to the host's key. +- At boot and on each apply, the receptor materializes the views under `/run` (memory): secret ones readable by root only and handed to services as systemd credentials; public ones readable by everyone. -### 5.6 Order +### 5.8 Order -Each channel chooses what makes a snapshot newer (maybe a format per -channel; UUIDs came to mind). An identifier alone doesn't order. +Each channel chooses what makes a snapshot the successor of another; +maybe a format per channel. An identifier alone (a UUID) doesn't order. Candidates: -- a **chain**: each snapshot has an id (a UUID, or the hash of its - content) and names the id it replaces. It is accepted only if that is - the current one. No clocks, no counters, and two providers can't - overwrite each other unnoticed. The provider has to ask the host what - is current. -- a **counter** or a **timestamp**: simpler for a provider that can't ask, - like a registry many hosts fetch from. - -Forcing skips the order check, and is recorded. +- a **chain**: each snapshot has an id, and a submission may name the + snapshot it builds on. If it does, it goes in only if that is the + current one, so two providers can't overwrite each other unnoticed. A + partial submission that names none applies to whatever is current. +- a **counter** or a **timestamp**: for a provider that can't ask the host + what is current, like a registry many hosts fetch from. ## 6. Migrations Generations differ in what they accept: a slot gets added, renamed, -removed, or its type changes. The state on the host was accepted under -one schema and has to serve another whenever the generation changes -(switch, rollback, boot) and no fresh snapshot is at hand. Between two +removed, split, or its type changes. The state on the host was accepted +under one schema and has to serve another whenever the generation changes +(switch, rollback, boot) and no fresh submission is at hand. Between two schemas there is a migration, ideally in both directions; that can't be demanded, so there are fallbacks. Generations don't form a line: any one may follow any other. So a migration can't be a numbered script per release. Instead it is put -together from parts, most of them implicit, to make having migrations +together from parts, most of them implicit, so that having migrations is simple: -1. **Same name, same type**: the entry carries over. This is most slots, - most of the time, and costs nothing to declare. -2. **Renames**: a slot says `renamedFrom`. Because the receptor keeps the - schema the state was accepted under, a rename declared by the newer - schema can also be undone when going back to the older generation, - which has never heard of the new name. -3. **Type versions**: a type's definition carries converters between its - versions, upward and, where possible, downward. They belong to the - type, not to a host's configuration, so they're written once. +1. **Same name, same type**: carries over. Most slots, most of the time; + nothing to declare. +2. **Renames**: a slot says `renamedFrom`. +3. **Type versions**: a type carries converters between its versions, + upward and, where possible, downward. They belong to the type, not to + a host's configuration, so they're written once. 4. **Derived slots**: a slot that can be computed from another (a public key from its private key, as in the state objects) gets filled on the host. 5. **Custom steps**: a program from the generation, for what the above - can't say. The escape hatch. -6. **Fallbacks**, per slot: keep an entry no slot wants any more (ignore - and report; it may be wanted again after a rollback), or drop it; and - for a slot left unfilled, its policy. + can't say (splitting one slot in two). The escape hatch. +6. **Fallback**: what no slot wants is kept and reported (it may be wanted + again after a rollback); a slot that can't be filled falls to the + policy (section 7). -Migrations are code from generations that ran or are about to run on this -host, and they run on the host, so secrets don't leave it. The receptor -keeps the previous schema (and what it needs of it) alive in the store. +Two rules make this work in both directions, and +[migrations.md](migrations.md) shows them at work: -A fresh snapshot made for the new schema beats a migration. The provider -knows what to make: the schema is a file in the system it deploys. +- **The receptor keeps the schema the snapshot was accepted under.** A + rename or a custom step declared by a newer schema can then be undone + for an older generation that has never heard of it: the way back comes + from the newer schema, which the state still carries. +- **A generation change never rewrites the snapshot.** The receptor + computes what the new generation sees from what is stored, and stores + that only when the next submission is applied under the new generation. + So switching to an older generation and back loses nothing, and a + conversion that drops something happens only when an operator hands + something over under the older generation, and the plan says what would + be dropped. -The order for a change that needs both state and system: first deliver a -snapshot that already has what the new generation wants (the old one -keeps and ignores it), then switch. With that, most switches need no -migration at all, and migrations are for the times nobody is there: -rollbacks and boots. +Migrations are code from generations that ran or are about to run on this +host, and they run on the host, so secrets don't leave it. The receptor +keeps what it needs of the stored schema alive in the store. -## 7. Policies +A fresh submission made for the new schema beats a migration, and the +provider knows what to make: the schema is a file in the system it +deploys. The order for a change that needs both: first submit what the +new generation wants (the old one keeps and ignores it), then switch. +With that, most switches need no migration, and migrations are for the +times nobody is there: rollbacks and boots. -A policy says what happens when a slot can't be filled: after a -migration that had no way, at boot into a generation that doesn't fit, -or on a forced snapshot. The same policies apply in all three cases. +## 7. Policy -- **refuse**: don't switch, don't accept. The default where refusing is - possible (before a switch, on a snapshot that isn't forced). -- **stop-consumers**: go on, and stop, or don't start, the units that need - the slot ("stop everything that doesn't work"). The default where - refusing isn't possible (at boot, when forced). -- **keep-last**: go on with the last entry that fit, where there is one. +One policy to start with: **refuse**. A submission that leaves a required +slot unfilled is refused; a switch to a generation whose required slots +the state can't fill, even by migrating, is refused before switching, with +the reason. -The schema knows each slot's consumers (credentials, views, reactions), -so the receptor can work out what to stop, and report it. +At boot nobody can refuse. For now, a slot that can't be filled then has +no views, and what needs them fails to start. More policies (stop what +can't work, keep the last value that fit), and forcing, come when they +turn out to be needed. ## 8. Trust (all of it, eventually) @@ -248,14 +336,14 @@ Three steps, each usable on its own: 1. **As today.** The host's ssh host key is the first key. It gets to the host as it does now (rsync over ssh), the authorized keys that allow - this are part of the generation, and root on the host hands snapshots + this are part of the generation, and root on the host hands submissions to the receptor. Transport is trusted because it is ssh. -2. **Signed snapshots.** The schema names the keys a channel accepts +2. **Signed submissions.** The schema names the keys a channel accepts signatures from. Then the fleet channel can be fetched from somewhere untrusted, like a federation, by an agent without privileges. -3. **Encrypted entries.** Secrets encrypted to the host's key, for - transport and at rest. The host key itself stays the exception that - step 1 provides, until that evolves. +3. **Encrypted items.** Secrets encrypted to the host's key, for transport + and at rest. The host key itself stays the exception that step 1 + provides, until that evolves. ## 9. How the state objects fit in @@ -265,10 +353,10 @@ ACTIVE) and the pipelines that move them. That is the provider's side, and this design is the last step of it: - SOURCE and the pipelines (generate, derive the public key, publish it) - happen outside the host, in the tool that makes snapshots. -- TARGET is the receptor's stored snapshot; ACTIVE is the views. -- REGISTRY is where the fleet channel's snapshots come from: every host's - public halves, composed per host. + happen outside the host, in the tool that makes submissions. +- TARGET is the receptor's snapshot; ACTIVE is the views. +- REGISTRY is where the fleet channel's submissions come from: every + host's public halves, composed per host. So one private key appears twice: in its own host's secrets channel, and, as its derived public half, in everyone's fleet channel. A rotation is one @@ -283,7 +371,7 @@ should be one list. | rotate a service's key | secrets | the key, as a systemd credential | restart or reload the service | | ssh known hosts | fleet | rendered from host records; `GlobalKnownHostsFile` | none, read at each use | | authorized keys | fleet | rendered from user records; `AuthorizedKeysFile` | none | -| host names | fleet | a zone file for a local resolver (DNS is the natural way), or `/etc/hosts` | reload the resolver | +| host names | fleet | a zone file for a local resolver; `/etc/hosts` stays the generation's | reload the resolver | | retiolum peers | fleet | tincr's host files, rendered from host records | reload tincr | | passwords (`shadow-overrides`) | secrets | read at activation today | needs a reaction of its own | @@ -300,42 +388,40 @@ What it would replace in hrm: ## 11. Open questions -1. **Does the migration model hold?** It rests on three things: the - receptor keeps the schema the state was accepted under; types carry - their own converters; structure changes are hints (`renamedFrom`, - derived). Cases to try it on, on paper: a renamed slot and a rollback; - a type with a new version and no way down; a slot split in two. -2. **How are structured types written?** The shape of records has to be - declared in the schema and checked by the receptor. Generated from - NixOS option types, a small language of its own, or an existing one - (JSON Schema)? And the entries themselves: JSON? -3. **What are renderers?** Pure functions from records to a file, run by - the receptor, from the generation. A fixed set of built-in formats, a - template language, jq, or any program in a sandbox? -4. **Policies**: are refuse, stop-consumers and keep-last the right set, - and the right defaults? Does stop-consumers stop only the units a slot - names, or everything that depends on them? -5. **Order**: chain, counter, or timestamp, per channel; what a forced - snapshot leaves behind for the next regular one. -6. **Names** (section 3), and the project's. +1. **Structured types**: how the shape of records is declared in the + schema and checked. Generated from NixOS option types, a small + language of its own, an existing one (JSON Schema), or left entirely to + the type's validator? +2. **The protocols** for validators, renderers and converters: how content + enters (files in a directory, or one document on standard input), and + how objections name addresses. +3. **Removing** in a partial submission, and removing the last record a + required slot has. +4. **Order**: chain, counter, or timestamp, per channel. +5. **At boot** with a slot that can't be filled: is "no views, consumers + fail" good enough until there are more policies? +6. **Names** (section 3). ## 12. A first version Small enough to try on one host, large enough to replace something real: -- one channel, file slots only, type `opaque` and one or two with - validators; order by chain; -- the receptor as a command: `check`, `accept` (with force), `migrate` - (on a generation change), `materialize` (at boot), `status`; -- migrations: same name carries over, `renamedFrom`, ignore and report; - policies: refuse and stop-consumers; -- a NixOS module: slot options, schema file, credentials, reactions, the - check before switching; +- one channel; file slots with type `opaque` and one or two with + validators; one structured slot with JSON records, a validator and a + renderer; +- submissions complete and partial, items required and optional, groups; +- the receptor as a command: `plan`, `apply`, `migrate` (on a generation + change), `materialize` (at boot), `status`; +- migrations: same name carries over, `renamedFrom`, kept and reported; + the two rules of section 6; policy: refuse; +- a NixOS module: slot and view options, schema file, credentials, + reactions, the check before switching; - a provider as a few lines in a deploy tool: pack a directory, copy it, - call `accept`; -- tested in a NixOS VM test: accept, reject (missing slot, wrong order, - bad type), rotate without switching, switch and roll back across a - rename with state in place, force and see consumers stopped. + call `plan` or `apply`; +- tested in a NixOS VM test: apply, refuse (missing slot, wrong order, a + validator's objection), an optional item left out with a warning, a plan + that changes nothing, rotate without switching, switch and roll back + across a rename with state in place. -Then: structured slots and views, the fleet channel and a registry, -signing, type versions with converters, encryption. +Then: more views, the fleet channel and a registry, signing, type versions +with converters, custom steps, forcing and policies, encryption. diff --git a/docs/migrations.md b/docs/migrations.md new file mode 100644 index 0000000..0d331a6 --- /dev/null +++ b/docs/migrations.md @@ -0,0 +1,104 @@ +# Migrations, on paper + +Three made-up cases for the model in [design.md](design.md), section 6. +Each has two generations, G1 and G2, with schemas S1 and S2. "Stored" +is the snapshot the receptor keeps, with the schema it was accepted under. +"Seen" is what the running generation's views are made from. + +The two rules: + +- the receptor keeps the schema the snapshot was accepted under; +- a generation change never rewrites the snapshot; what was computed for + the new generation gets stored when the next submission is applied + under it. + +## 1. A renamed slot, and a rollback + + S1 secrets/tinc.key ed25519-private-key + S2 secrets/retiolum.key ed25519-private-key, renamedFrom tinc.key + +| step | stored | seen by the running generation | +|---|---|---| +| G1 runs, key K submitted | S1: `tinc.key` = K | `tinc.key` = K | +| switch to G2 | S1: `tinc.key` = K | `retiolum.key` = K | +| rotate under G2: K' | S2: `retiolum.key` = K' | `retiolum.key` = K' | +| roll back to G1 | S2: `retiolum.key` = K' | `tinc.key` = K' | + +- Switching to G2: S2 wants `retiolum.key`, the stored snapshot has none. + S2 says it was `tinc.key`, so the receptor takes that. Nothing is + rewritten; the rotation is what stores state under S2. +- Rolling back: S1 wants `tinc.key` and knows nothing of a rename. The + stored schema, S2, does: the receptor reads its `renamedFrom` backwards. + G1 runs with the rotated key, not the one it last saw. + +Without the first rule the rollback would find no `tinc.key` and be +refused, or worse, find a kept copy of K. + +## 2. A type with a new version, and no way down for some records + + hosts v1 { name, addr } + hosts v2 { name, addrs: [ … ] } + converters up: addr -> [ addr ] + down: addrs -> addr, only if there is exactly one + + S1 fleet/hosts hosts v1 + S2 fleet/hosts hosts v2 + +| step | stored | seen | +|---|---|---| +| G1 runs | S1: ne = { addr: a } | v1: ne = a | +| switch to G2 | S1: ne = { addr: a } | v2: ne = [ a ] | +| under G2, ne gets a second address | S2: ne = { addrs: [ a, b ] } | v2: ne = [ a, b ] | +| roll back to G1 | refused | | + +- The rollback is refused before switching: `fleet/hosts/ne: two + addresses, hosts v1 holds one`. The policy is refuse, and the message + names the record. +- Ways on: a submission made for S1 (the provider decides which address ne + keeps), which the plan shows as dropping `b`; or staying on G2. +- Had ne kept one address, the rollback would go through, and switching + to G2 again would lose nothing, by the second rule: G1 only ever saw a + converted copy. +- At boot into G1 from the boot menu nobody can refuse: `fleet/hosts` has no + views there, and what reads them fails to start ([design.md](design.md), + section 7). + +## 3. A slot split in two + + S1 secrets/tls.pem certificate and key in one file + S2 secrets/tls.cert certificate + secrets/tls.key private key + step split: tls.pem -> tls.cert, tls.key + step join: tls.cert, tls.key -> tls.pem + +No rename or converter says this; S2 declares custom steps, one for each +direction. + +| step | stored | seen | +|---|---|---| +| G1 runs | S1: `tls.pem` = P | `tls.pem` = P | +| switch to G2 | S1: `tls.pem` = P | `tls.cert`, `tls.key` from split(P) | +| renew under G2 | S2: `tls.cert` = C', `tls.key` = K' | C', K' | +| roll back to G1 | S2: C', K' | `tls.pem` = join(C', K') | + +- As with the rename, the way back is the newer schema's: S1 can't know + `join`, the stored S2 has it. +- If S2 declared only `split`, the rollback after the renewal would be + refused: `secrets/tls.pem: nothing in S2 makes it`. Before the renewal + it would go through, because the stored snapshot is still S1's, with + `tls.pem` in it (second rule). +- Why not keep P around for that case: it would be the certificate from + before the renewal. What no slot wants is kept and reported, but never + used to fill a slot once something made from it has changed. + +## What the cases show + +- Renames need nothing but the declaration, in both directions. +- Converters and custom steps should come in pairs; where one direction is + missing or can't hold the data, the model refuses and names the address, + it doesn't guess. +- Both rules are needed: the first for every way back, the second so that + trying an older generation costs nothing. +- Open: a step that only works for some content (case 2's way down) makes + whether a rollback is possible depend on the data. The deploy tool can + ask the receptor before switching; at boot it can't. |
