Skip to content

Commit 7cbc8f7

Browse files
authored
fix(email): detach the retained V1 mailbox after verified cutover (#6713)
* fix(email): detach the retained V1 mailbox after verified cutover * fix(email): verify startup against the detached V2 mailbox * fix(email): lock the V2 mailbox during bootstrap
1 parent 25dc8d2 commit 7cbc8f7

15 files changed

Lines changed: 309 additions & 436 deletions

‎k8s/providers/hetzner/apps/private-mail/kustomization.yaml‎

Lines changed: 1 addition & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,7 @@ patches:
2626
- path: patches/disable-admin-credential-seeding.yaml
2727
- path: patches/disable-maintainer-credential-seeding.yaml
2828
- path: patches/disable-agent-credential-seeding.yaml
29-
# Both encrypted claims use the same serving route across subsequent rollbacks.
29+
# Serve from the verified encrypted V2 claim while retaining the original PVC.
3030
- path: patches/serve-from-encrypted-storage.yaml
3131
# The server now consumes the encrypted claim, so deployment must wait for it
3232
# to bind instead of treating it as prepared storage.
@@ -68,13 +68,6 @@ patches:
6868
name: private-mail
6969
namespace: private-mail
7070
path: patches/trust-mail-load-balancer.yaml
71-
- target:
72-
group: apps
73-
version: v1
74-
kind: StatefulSet
75-
name: private-mail
76-
namespace: private-mail
77-
path: patches/copy-mail-to-v2.yaml
7871
# SMTP, submission and IMAPS are reachable from their own load balancer only.
7972
- target:
8073
group: cilium.io
@@ -114,4 +107,3 @@ replacements:
114107
namespace: private-mail
115108
fieldPaths:
116109
- spec.template.spec.initContainers.[name=select-mail-store].image
117-
- spec.template.spec.initContainers.[name=migrate-storage].image

‎k8s/providers/hetzner/apps/private-mail/patches/copy-mail-to-v2.yaml‎

Lines changed: 0 additions & 111 deletions
This file was deleted.

‎k8s/providers/hetzner/apps/private-mail/patches/route-serving-storage.yaml‎

Lines changed: 23 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
# Keep the selected config mount, and both encrypted stores, on setup and serving.
1+
# Keep the verified configuration and the original mount path of the V2 store.
22
- op: test
33
path: /spec/template/spec/initContainers/0/name
44
value: configure
@@ -20,31 +20,42 @@
2020
- op: replace
2121
path: /spec/template/spec/containers/0/volumeMounts/0/name
2222
value: serving-storage
23-
- op: add
23+
- op: test
24+
path: /spec/template/spec/initContainers/0/volumeMounts/1/name
25+
value: data
26+
- op: replace
2427
path: /spec/template/spec/initContainers/0/volumeMounts/1
2528
value:
2629
name: v2-data
2730
mountPath: /var/lib/stalwart-v2
31+
# The signed bootstrap image acquires its lock at the original mount path.
32+
# Both paths must reference the V2 filesystem so recovery and routing agree.
2833
- op: add
34+
path: /spec/template/spec/initContainers/0/volumeMounts/-
35+
value:
36+
name: v2-data
37+
mountPath: /var/lib/stalwart
38+
- op: test
39+
path: /spec/template/spec/containers/0/volumeMounts/1/name
40+
value: data
41+
- op: replace
2942
path: /spec/template/spec/containers/0/volumeMounts/1
3043
value:
3144
name: v2-data
3245
mountPath: /var/lib/stalwart-v2
3346
- op: test
34-
path: /spec/template/spec/volumes/1/name
35-
value: legacy-data
36-
- op: remove
37-
path: /spec/template/spec/volumes/1
47+
path: /spec/template/spec/volumes/0/name
48+
value: data
49+
- op: test
50+
path: /spec/template/spec/volumes/0/persistentVolumeClaim/claimName
51+
value: email-data-encrypted-v2
52+
- op: replace
53+
path: /spec/template/spec/volumes/0/name
54+
value: v2-data
3855
- op: add
3956
path: /spec/template/spec/volumes/0
4057
value:
4158
name: serving-storage
4259
emptyDir:
4360
medium: Memory
4461
sizeLimit: 1Mi
45-
- op: add
46-
path: /spec/template/spec/volumes/1
47-
value:
48-
name: v2-data
49-
persistentVolumeClaim:
50-
claimName: email-data-encrypted-v2
Lines changed: 11 additions & 41 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
# Rollbacks must select the same store that most recently accepted mail.
1+
# Accept only the V2 store which holds the completed migration.
22
- op: add
33
path: /spec/template/spec/initContainers/0
44
value:
@@ -9,50 +9,22 @@
99
args:
1010
- |
1111
set -eu
12-
old=/var/lib/stalwart
13-
next=/var/lib/stalwart-v2
12+
template_store=/var/lib/stalwart
13+
store=/var/lib/stalwart-v2
1414
template=/etc/private-mail-datastore/config.json
1515
route=/store-selection/config.json
16-
fence="$old/.private-mail-v1-fenced"
17-
receipt="$next/.private-mail-v2-copy-complete"
16+
receipt="$store/.private-mail-v2-copy-complete"
1817
refuse() { echo "Email storage route refused: $1." >&2; exit 1; }
19-
exists() { [ -e "$1" ] || [ -L "$1" ]; }
20-
valid_receipt() {
21-
[ -f "$1" ] && [ ! -L "$1" ] && [ "$(wc -l <"$1")" -eq 1 ] &&
22-
grep -Exq 'private-mail-longhorn-v2 [0-9a-f]{64}' "$1"
23-
}
24-
selected="$old"
25-
if exists "$receipt"; then
26-
valid_receipt "$receipt" || refuse "unverified V2 completion receipt"
27-
[ -d "$next/data" ] && [ ! -L "$next/data" ] || refuse "the V2 store is missing"
28-
if exists "$fence"; then
29-
valid_receipt "$fence" && cmp -s "$fence" "$receipt" || refuse "the V1 fence and V2 receipt disagree"
30-
else
31-
if exists "$fence.tmp"; then
32-
valid_receipt "$fence.tmp" && cmp -s "$fence.tmp" "$receipt" || refuse "incomplete V1 fence"
33-
else
34-
(set -C; cat "$receipt" >"$fence.tmp")
35-
fi
36-
sync
37-
mv -- "$fence.tmp" "$fence"
38-
sync
39-
fi
40-
selected="$next"
41-
elif exists "$fence" || exists "$fence.tmp"; then
42-
refuse "V1 was fenced and its V2 completion receipt is missing"
43-
fi
44-
[ -d "$selected/data" ] && [ ! -L "$selected/data" ] || refuse "the selected store is missing"
45-
[ "$(grep -Fc "\"$old/data\"" "$template")" -eq 1 ] || refuse "the datastore configuration path is unverified"
18+
[ -f "$receipt" ] && [ ! -L "$receipt" ] && [ "$(wc -l <"$receipt")" -eq 1 ] &&
19+
grep -Exq 'private-mail-longhorn-v2 [0-9a-f]{64}' "$receipt" || refuse "unverified V2 completion receipt"
20+
[ -d "$store/data" ] && [ ! -L "$store/data" ] || refuse "the V2 store is missing"
21+
[ "$(grep -Fc "\"$template_store/data\"" "$template")" -eq 1 ] || refuse "the datastore configuration path is unverified"
4622
tmp=$(mktemp /store-selection/.config.XXXXXX)
4723
trap 'rm -f -- "$tmp"' EXIT
48-
sed "s#\"$old/data\"#\"$selected/data\"#" "$template" >"$tmp"
49-
[ "$(grep -Fc "\"$selected/data\"" "$tmp")" -eq 1 ] || refuse "the selected datastore configuration is unverified"
24+
sed "s#\"$template_store/data\"#\"$store/data\"#" "$template" >"$tmp"
25+
[ "$(grep -Fc "\"$store/data\"" "$tmp")" -eq 1 ] || refuse "the selected datastore configuration is unverified"
5026
mv -- "$tmp" "$route"
51-
if [ "$selected" = "$next" ]; then
52-
echo "Email storage route selected Longhorn V2."
53-
else
54-
echo "Email storage route selected the original encrypted store."
55-
fi
27+
echo "Email storage route selected Longhorn V2."
5628
resources:
5729
requests:
5830
cpu: 10m
@@ -75,8 +47,6 @@
7547
- name: datastore
7648
mountPath: /etc/private-mail-datastore
7749
readOnly: true
78-
- name: data
79-
mountPath: /var/lib/stalwart
8050
- name: v2-data
8151
mountPath: /var/lib/stalwart-v2
8252
readOnly: true

‎k8s/providers/hetzner/apps/private-mail/patches/serve-from-encrypted-storage.yaml‎

Lines changed: 2 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,4 @@
1-
# The mail store is served from the encrypted claim (#5387). The original,
2-
# unencrypted claim stays declared and is mounted read-only only by the copy
3-
# step, so it is never written again and remains the rollback.
1+
# Serve the encrypted Longhorn V2 store. The original claims stay declared.
42
apiVersion: apps/v1
53
kind: StatefulSet
64
metadata:
@@ -18,8 +16,4 @@ spec:
1816
volumes:
1917
- name: data
2018
persistentVolumeClaim:
21-
claimName: email-data-encrypted
22-
- name: legacy-data
23-
persistentVolumeClaim:
24-
claimName: private-mail-data
25-
readOnly: true
19+
claimName: email-data-encrypted-v2

0 commit comments

Comments
 (0)