1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
|
# 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
| what happens | 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 slot with a new type, and no way back for some records
Two types, each a shape of its own ([design.md](design.md), 5.1), and a
converter in each direction:
T1 application/x-enstate-hosts1+json { name, addr }
T2 application/x-enstate-hosts2+json { name, addrs: [ … ] }
converters T1 -> T2: addr -> [ addr ]
T2 -> T1: addrs -> addr, only if there is exactly one
S1 fleet/hosts T1
S2 fleet/hosts T2
| what happens | stored | seen |
|---|---|---|
| G1 runs | S1: ne = { addr: a } | T1: ne = a |
| switch to G2 | S1: ne = { addr: a } | T2: ne = [ a ] |
| under G2, ne gets a second address | S2: ne = { addrs: [ a, b ] } | T2: ne = [ a, b ] |
| roll back to G1 | refused | |
- The rollback is refused before switching. The converter from T2 to T1
objects ([design.md](design.md), 5.2): `fleet/hosts/ne: two addresses,
T1 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 steps, one for each
direction.
| what happens | 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 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 converter or step that only works for some content (case 2's
way back) makes whether a rollback is possible depend on the data. The
deploy tool can ask the receptor before switching; at boot it can't.
|