@ouro.bot/cli 0.1.0-alpha.733 → 0.1.0-alpha.734
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/changelog.json +25 -0
- package/deploy/unraid/Dockerfile +27 -0
- package/deploy/unraid/README.txt +1368 -0
- package/deploy/unraid/audit-container-spec.sh +4 -0
- package/deploy/unraid/container-runtime.json +1 -0
- package/deploy/unraid/sanctuary-acceptance-adapter.sh +37 -0
- package/deploy/unraid/sanctuary-acceptance-contract.json +200 -0
- package/deploy/unraid/sanctuary-acceptance-harness.sh +23 -0
- package/deploy/unraid/sanctuary-deployment-target.mjs +705 -0
- package/deploy/unraid/sanctuary-safe-rename.py +24 -0
- package/deploy/unraid/sanctuary-unit16-host-broker.mjs +1777 -0
- package/deploy/unraid/sanctuary-unit16-run.sh +502 -0
- package/deploy/unraid/sanctuary-unit18-target-audit.sh +27 -0
- package/deploy/unraid/sanctuary.ouro/agent.json +24 -0
- package/deploy/unraid/sanctuary.ouro/arc/README.md +3 -0
- package/deploy/unraid/sanctuary.ouro/bundle-meta.json +5 -0
- package/deploy/unraid/sanctuary.ouro/habits/sanctuary-health.md +8 -0
- package/deploy/unraid/sanctuary.ouro/provider-readiness.json +18 -0
- package/deploy/unraid/sanctuary.ouro/psyche/ASPIRATIONS.md +3 -0
- package/deploy/unraid/sanctuary.ouro/psyche/IDENTITY.md +3 -0
- package/deploy/unraid/sanctuary.ouro/psyche/LORE.md +3 -0
- package/deploy/unraid/sanctuary.ouro/psyche/SOUL.md +5 -0
- package/deploy/unraid/sanctuary.ouro/psyche/TACIT.md +7 -0
- package/deploy/unraid/sanctuary.ouro/tool-profiles.json +21 -0
- package/deploy/unraid/sanctuary.xml +25 -0
- package/dist/heart/approval-files.js +113 -0
- package/dist/heart/approval-store.js +168 -9
- package/dist/heart/auth/auth-flow.js +17 -1
- package/dist/heart/autonomy-budget.js +44 -1
- package/dist/heart/awaiting/await-scheduler.js +6 -2
- package/dist/heart/config.js +8 -0
- package/dist/heart/core.js +117 -132
- package/dist/heart/daemon/cli-exec.js +73 -1
- package/dist/heart/daemon/cli-help.js +5 -0
- package/dist/heart/daemon/cli-parse.js +6 -4
- package/dist/heart/daemon/container-credential-bootstrap.js +185 -0
- package/dist/heart/daemon/container-healthcheck.js +94 -0
- package/dist/heart/daemon/container-runtime.js +84 -0
- package/dist/heart/daemon/container-spec-auditor-main.js +156 -0
- package/dist/heart/daemon/container-spec-auditor.js +156 -0
- package/dist/heart/daemon/daemon-bootstrap-startup.js +41 -0
- package/dist/heart/daemon/daemon-entry.js +116 -28
- package/dist/heart/daemon/daemon-health.js +10 -0
- package/dist/heart/daemon/daemon.js +92 -5
- package/dist/heart/daemon/runtime-logging.js +6 -0
- package/dist/heart/daemon/runtime-mode.js +13 -2
- package/dist/heart/daemon/sanctuary-acceptance-adapter.js +2365 -0
- package/dist/heart/daemon/sanctuary-acceptance-harness.js +1624 -0
- package/dist/heart/daemon/sanctuary-acceptance-marker.js +267 -0
- package/dist/heart/daemon/sanctuary-acceptance-scenarios.js +985 -0
- package/dist/heart/daemon/sanctuary-scheduler-liveness.js +227 -0
- package/dist/heart/daemon/sanctuary-scheduler-origin.js +126 -0
- package/dist/heart/daemon/sense-manager.js +25 -6
- package/dist/heart/daemon/supercronic-supervisor.js +267 -0
- package/dist/heart/habits/habit-scheduler.js +7 -3
- package/dist/heart/identity.js +13 -3
- package/dist/heart/provider-credentials.js +9 -1
- package/dist/heart/provider-models.js +8 -0
- package/dist/heart/provider-ping.js +5 -2
- package/dist/heart/providers/openai-compatible.js +177 -0
- package/dist/heart/runtime-credentials.js +217 -8
- package/dist/heart/sense-truth.js +2 -0
- package/dist/heart/tool-approval.js +1 -0
- package/dist/heart/turn-context.js +8 -0
- package/dist/mind/prompt.js +9 -0
- package/dist/nerves/coverage/source-scanner.js +4 -4
- package/dist/nerves/index.js +75 -9
- package/dist/nerves/runtime.js +12 -0
- package/dist/repertoire/tool-arguments.js +39 -0
- package/dist/repertoire/tools-unraid.js +353 -0
- package/dist/repertoire/tools.js +19 -1
- package/dist/repertoire/unraid-client.js +155 -0
- package/dist/repertoire/unraid-restart.js +130 -0
- package/dist/senses/private-runtime-worker.js +3 -2
- package/dist/senses/sanctuary-grounding.js +118 -0
- package/dist/senses/sanctuary-health-acceptance-probe-entry.js +12 -0
- package/dist/senses/sanctuary-health-acceptance-probe.js +772 -0
- package/dist/senses/sanctuary-health-runner.js +146 -0
- package/dist/senses/sanctuary-health.js +447 -0
- package/dist/senses/sanctuary-interactive-control.js +306 -0
- package/dist/senses/sanctuary-runtime.js +206 -0
- package/dist/senses/shared-turn.js +11 -3
- package/dist/senses/telegram-approval-runtime.js +526 -0
- package/dist/senses/telegram-audit-ledger.js +220 -0
- package/dist/senses/telegram-client.js +1471 -0
- package/dist/senses/telegram-entry.js +80 -0
- package/dist/senses/telegram.js +1232 -0
- package/npm-shrinkwrap.json +6558 -0
- package/package.json +4 -2
|
@@ -0,0 +1,1368 @@
|
|
|
1
|
+
Mendelow Cloud Butler operator runbook
|
|
2
|
+
|
|
3
|
+
The production container is ouro-butler. It runs as UID/GID 10001, publishes no
|
|
4
|
+
ports, uses host networking only so its loopback-only Unraid GraphQL client can
|
|
5
|
+
reach 127.0.0.1, mounts only the runtime and sanctuary.ouro bundle paths from
|
|
6
|
+
the Unraid template, and uses restart policy unless-stopped.
|
|
7
|
+
|
|
8
|
+
Start/stop:
|
|
9
|
+
docker start ouro-butler
|
|
10
|
+
docker stop ouro-butler
|
|
11
|
+
|
|
12
|
+
Status and health:
|
|
13
|
+
docker inspect --format '{{.State.Status}} {{.State.Health.Status}}' ouro-butler
|
|
14
|
+
docker logs --tail 200 ouro-butler
|
|
15
|
+
|
|
16
|
+
Effective-spec audit helper:
|
|
17
|
+
Run Update and Restore command sequences from a root shell with `set -eu`.
|
|
18
|
+
Before either sequence, define this helper. It captures one actual container
|
|
19
|
+
inspect and its reviewed image inspect without printing either, invokes the
|
|
20
|
+
packaged auditor from IMAGE_ID, and removes its mode-0600 inputs on success
|
|
21
|
+
or shell exit:
|
|
22
|
+
audit_effective() {
|
|
23
|
+
(
|
|
24
|
+
AUDIT_CONTAINER=$1
|
|
25
|
+
AUDIT_EXPECTED_IMAGE=$2
|
|
26
|
+
INSPECT_DIR=$(mktemp -d /mnt/user/appdata/ouro-butler/staging/inspect.XXXXXX) || return $?
|
|
27
|
+
trap 'rm -f -- "$INSPECT_DIR/container.json" "$INSPECT_DIR/image.json"; rmdir -- "$INSPECT_DIR"' EXIT || return $?
|
|
28
|
+
chmod 0700 "$INSPECT_DIR" || return $?
|
|
29
|
+
umask 077 || return $?
|
|
30
|
+
docker inspect "$AUDIT_CONTAINER" >"$INSPECT_DIR/container.json" || return $?
|
|
31
|
+
docker image inspect "$AUDIT_EXPECTED_IMAGE" >"$INSPECT_DIR/image.json" || return $?
|
|
32
|
+
chmod 0600 "$INSPECT_DIR/container.json" "$INSPECT_DIR/image.json" || return $?
|
|
33
|
+
docker run --rm --pull=never --network=none \
|
|
34
|
+
--entrypoint /opt/ouro/deploy/unraid/audit-container-spec.sh \
|
|
35
|
+
--mount "type=bind,src=$INSPECT_DIR/container.json,dst=/audit/container.json,readonly" \
|
|
36
|
+
--mount "type=bind,src=$INSPECT_DIR/image.json,dst=/audit/image.json,readonly" \
|
|
37
|
+
"$IMAGE_ID" --inspect /audit/container.json --image-inspect /audit/image.json --expected-image "$AUDIT_EXPECTED_IMAGE" || return $?
|
|
38
|
+
rm -f -- "$INSPECT_DIR/container.json" "$INSPECT_DIR/image.json" || return $?
|
|
39
|
+
rmdir -- "$INSPECT_DIR" || return $?
|
|
40
|
+
trap - EXIT || return $?
|
|
41
|
+
)
|
|
42
|
+
}
|
|
43
|
+
Define these helpers in the same root shell. Each autostart change uses
|
|
44
|
+
Unraid's authenticated loopback WebGUI endpoint with the live root-session
|
|
45
|
+
CSRF token supplied only on request stdin. Requests have hard connection and
|
|
46
|
+
total timeouts, discard response bodies, and read back the durable array
|
|
47
|
+
autostart state without writing its backing file directly:
|
|
48
|
+
set_butler_autostart() {
|
|
49
|
+
(
|
|
50
|
+
AUTOSTART_CONTAINER=$1
|
|
51
|
+
AUTOSTART_ENABLED=$2
|
|
52
|
+
case "$AUTOSTART_CONTAINER" in
|
|
53
|
+
ouro-butler|ouro-butler-staging|ouro-butler-rollback|ouro-butler-legacy-evidence) ;;
|
|
54
|
+
*) return 1 ;;
|
|
55
|
+
esac
|
|
56
|
+
case "$AUTOSTART_ENABLED" in true|false) ;; *) return 1 ;; esac
|
|
57
|
+
AUTOSTART_CSRF_FILE=/var/local/emhttp/var.ini
|
|
58
|
+
test -f "$AUTOSTART_CSRF_FILE" || return $?
|
|
59
|
+
AUTOSTART_CSRF_TOKEN=$(awk -F= '$1 == "csrf_token" {
|
|
60
|
+
value = $2
|
|
61
|
+
sub(/^"/, "", value)
|
|
62
|
+
sub(/"$/, "", value)
|
|
63
|
+
print value
|
|
64
|
+
}' "$AUTOSTART_CSRF_FILE") || return $?
|
|
65
|
+
test -n "$AUTOSTART_CSRF_TOKEN" || return $?
|
|
66
|
+
case "$AUTOSTART_CSRF_TOKEN" in *[!A-Za-z0-9._-]*) return 1 ;; esac
|
|
67
|
+
printf '%s' "action=autostart&container=$AUTOSTART_CONTAINER&auto=$AUTOSTART_ENABLED&wait=0&csrf_token=$AUTOSTART_CSRF_TOKEN" | \
|
|
68
|
+
curl --silent --show-error --fail --request POST \
|
|
69
|
+
--connect-timeout 5 --max-time 15 \
|
|
70
|
+
--header 'Content-Type: application/x-www-form-urlencoded' \
|
|
71
|
+
--data-binary @- --output /dev/null \
|
|
72
|
+
http://127.0.0.1/plugins/dynamix.docker.manager/include/UpdateConfig.php || return $?
|
|
73
|
+
)
|
|
74
|
+
}
|
|
75
|
+
verify_butler_autostart() {
|
|
76
|
+
(
|
|
77
|
+
EXPECTED_AUTOSTART_COUNTS=$1
|
|
78
|
+
AUTOSTART_FILE=/var/lib/docker/unraid-autostart
|
|
79
|
+
test -f "$AUTOSTART_FILE" || return $?
|
|
80
|
+
AUTOSTART_COUNTS=$(awk '
|
|
81
|
+
$1 == "ouro-butler" { production++ }
|
|
82
|
+
$1 == "ouro-butler-staging" { staging++ }
|
|
83
|
+
$1 == "ouro-butler-rollback" { rollback++ }
|
|
84
|
+
$1 == "ouro-butler-legacy-evidence" { legacy++ }
|
|
85
|
+
END { printf "%d %d %d %d", production + 0, staging + 0, rollback + 0, legacy + 0 }
|
|
86
|
+
' "$AUTOSTART_FILE") || return $?
|
|
87
|
+
test "$AUTOSTART_COUNTS" = "$EXPECTED_AUTOSTART_COUNTS" || return $?
|
|
88
|
+
)
|
|
89
|
+
}
|
|
90
|
+
disable_butler_autostart() {
|
|
91
|
+
set_butler_autostart ouro-butler-staging false || return $?
|
|
92
|
+
set_butler_autostart ouro-butler-rollback false || return $?
|
|
93
|
+
set_butler_autostart ouro-butler-legacy-evidence false || return $?
|
|
94
|
+
set_butler_autostart ouro-butler false || return $?
|
|
95
|
+
verify_butler_autostart "0 0 0 0" || return $?
|
|
96
|
+
}
|
|
97
|
+
enable_butler_autostart() {
|
|
98
|
+
set_butler_autostart ouro-butler-staging false || return $?
|
|
99
|
+
set_butler_autostart ouro-butler-rollback false || return $?
|
|
100
|
+
set_butler_autostart ouro-butler-legacy-evidence false || return $?
|
|
101
|
+
set_butler_autostart ouro-butler true || return $?
|
|
102
|
+
verify_butler_autostart "1 0 0 0" || return $?
|
|
103
|
+
}
|
|
104
|
+
This bounded wait accepts only Docker's healthy state. The image healthcheck
|
|
105
|
+
verifies fresh daemon state plus exactly one managed Telegram process and one
|
|
106
|
+
managed scheduler process. It fails immediately on an exited, dead, or
|
|
107
|
+
unhealthy container and times out after four minutes:
|
|
108
|
+
wait_butler_ready() {
|
|
109
|
+
WAIT_CONTAINER=$1
|
|
110
|
+
WAIT_NOW=$(date +%s) || return $?
|
|
111
|
+
WAIT_DEADLINE=$(( WAIT_NOW + 240 ))
|
|
112
|
+
while :; do
|
|
113
|
+
WAIT_NOW=$(date +%s) || return $?
|
|
114
|
+
test "$WAIT_NOW" -lt "$WAIT_DEADLINE" || break
|
|
115
|
+
WAIT_STATE=$(docker inspect --format '{{.State.Status}} {{.State.Health.Status}}' "$WAIT_CONTAINER") || return $?
|
|
116
|
+
if test "$WAIT_STATE" = "running healthy"; then
|
|
117
|
+
return 0
|
|
118
|
+
fi
|
|
119
|
+
case "$WAIT_STATE" in
|
|
120
|
+
exited\ *|dead\ *|*\ unhealthy) return 1 ;;
|
|
121
|
+
esac
|
|
122
|
+
sleep 5 || return $?
|
|
123
|
+
done
|
|
124
|
+
return 1
|
|
125
|
+
}
|
|
126
|
+
Define these fail-closed image and topology helpers in the same shell. They use
|
|
127
|
+
exact Docker image IDs and exact container names; no mutation is performed:
|
|
128
|
+
validate_exact_image_id() {
|
|
129
|
+
VALIDATE_IMAGE_ID=$1
|
|
130
|
+
case "$VALIDATE_IMAGE_ID" in
|
|
131
|
+
sha256:*) VALIDATE_IMAGE_HEX=${VALIDATE_IMAGE_ID#sha256:} ;;
|
|
132
|
+
*) return 1 ;;
|
|
133
|
+
esac
|
|
134
|
+
test "${#VALIDATE_IMAGE_HEX}" -eq 64 || return $?
|
|
135
|
+
case "$VALIDATE_IMAGE_HEX" in
|
|
136
|
+
*[!0-9a-f]*) return 1 ;;
|
|
137
|
+
esac
|
|
138
|
+
docker image inspect "$VALIDATE_IMAGE_ID" >/dev/null || return $?
|
|
139
|
+
}
|
|
140
|
+
assert_only_running_butler() {
|
|
141
|
+
EXPECTED_RUNNING_BUTLER=$1
|
|
142
|
+
RUNNING_BUTLER_NAMES=$(docker container ls --format '{{.Names}}') || return $?
|
|
143
|
+
RUNNING_BUTLER_COUNTS=$(printf '%s\n' "$RUNNING_BUTLER_NAMES" | awk -v expected="$EXPECTED_RUNNING_BUTLER" '
|
|
144
|
+
{
|
|
145
|
+
if ($0 == "ouro-butler" || $0 == "ouro-butler-staging" || $0 == "ouro-butler-rollback" || $0 == "ouro-butler-legacy-evidence") {
|
|
146
|
+
butlers++
|
|
147
|
+
if ($0 == expected) matching++
|
|
148
|
+
}
|
|
149
|
+
}
|
|
150
|
+
END { printf "%d %d", butlers + 0, matching + 0 }
|
|
151
|
+
') || return $?
|
|
152
|
+
test "$RUNNING_BUTLER_COUNTS" = "1 1" || return $?
|
|
153
|
+
}
|
|
154
|
+
assert_update_topology() {
|
|
155
|
+
EXPECTED_ROLLBACK_IMAGE_ID=$1
|
|
156
|
+
UPDATE_CONTAINER_NAMES=$(docker container ls -a --format '{{.Names}}') || return $?
|
|
157
|
+
UPDATE_NAME_COUNTS=$(printf '%s\n' "$UPDATE_CONTAINER_NAMES" | awk '
|
|
158
|
+
$0 == "ouro-butler" { production++ }
|
|
159
|
+
$0 == "ouro-butler-staging" { staging++ }
|
|
160
|
+
$0 == "ouro-butler-rollback" { rollback++ }
|
|
161
|
+
$0 == "ouro-butler-legacy-evidence" { legacy++ }
|
|
162
|
+
END {
|
|
163
|
+
printf "%d %d %d %d", production + 0, staging + 0, rollback + 0, legacy + 0
|
|
164
|
+
}
|
|
165
|
+
') || return $?
|
|
166
|
+
case "$UPDATE_NAME_COUNTS" in
|
|
167
|
+
"1 0 0 0"|"1 0 1 0"|"1 0 0 1"|"1 0 1 1") ;;
|
|
168
|
+
*) return 1 ;;
|
|
169
|
+
esac
|
|
170
|
+
UPDATE_PRODUCTION_RUNNING=$(docker inspect --format '{{.State.Running}}' ouro-butler) || return $?
|
|
171
|
+
test "$UPDATE_PRODUCTION_RUNNING" = true || return $?
|
|
172
|
+
UPDATE_PRODUCTION_IMAGE_ID=$(docker inspect --format '{{.Image}}' ouro-butler) || return $?
|
|
173
|
+
test "$UPDATE_PRODUCTION_IMAGE_ID" = "$EXPECTED_ROLLBACK_IMAGE_ID" || return $?
|
|
174
|
+
case "$UPDATE_NAME_COUNTS" in
|
|
175
|
+
"1 0 1 0"|"1 0 1 1")
|
|
176
|
+
UPDATE_ROLLBACK_RUNNING=$(docker inspect --format '{{.State.Running}}' ouro-butler-rollback) || return $?
|
|
177
|
+
test "$UPDATE_ROLLBACK_RUNNING" = false || return $?
|
|
178
|
+
UPDATE_ROLLBACK_IMAGE_ID=$(docker inspect --format '{{.Image}}' ouro-butler-rollback) || return $?
|
|
179
|
+
test "$UPDATE_ROLLBACK_IMAGE_ID" = "$EXPECTED_ROLLBACK_IMAGE_ID" || return $?
|
|
180
|
+
;;
|
|
181
|
+
esac
|
|
182
|
+
case "$UPDATE_NAME_COUNTS" in
|
|
183
|
+
"1 0 0 1"|"1 0 1 1")
|
|
184
|
+
UPDATE_LEGACY_RUNNING=$(docker inspect --format '{{.State.Running}}' ouro-butler-legacy-evidence) || return $?
|
|
185
|
+
test "$UPDATE_LEGACY_RUNNING" = false || return $?
|
|
186
|
+
UPDATE_LEGACY_IMAGE_ID=$(docker inspect --format '{{.Image}}' ouro-butler-legacy-evidence) || return $?
|
|
187
|
+
validate_exact_image_id "$UPDATE_LEGACY_IMAGE_ID" || return $?
|
|
188
|
+
;;
|
|
189
|
+
esac
|
|
190
|
+
assert_only_running_butler ouro-butler || return $?
|
|
191
|
+
}
|
|
192
|
+
validate_sanctuary_roots() {
|
|
193
|
+
(
|
|
194
|
+
VALIDATE_RUNTIME_ROOT=$1
|
|
195
|
+
VALIDATE_AGENT_ROOT=$2
|
|
196
|
+
test -d "$VALIDATE_RUNTIME_ROOT" || return $?
|
|
197
|
+
test -d "$VALIDATE_AGENT_ROOT" || return $?
|
|
198
|
+
VALIDATE_BAD_SHAPE=$(find "$VALIDATE_RUNTIME_ROOT" "$VALIDATE_AGENT_ROOT" -xdev \( -type l -o \( ! -type d -a ! -type f \) \) -print -quit) || return $?
|
|
199
|
+
test -z "$VALIDATE_BAD_SHAPE" || return $?
|
|
200
|
+
for VALIDATE_REQUIRED_FILE in \
|
|
201
|
+
agent.json bundle-meta.json provider-readiness.json tool-profiles.json \
|
|
202
|
+
psyche/SOUL.md habits/sanctuary-health.md; do
|
|
203
|
+
test -s "$VALIDATE_AGENT_ROOT/$VALIDATE_REQUIRED_FILE" || return $?
|
|
204
|
+
done
|
|
205
|
+
test -d "$VALIDATE_RUNTIME_ROOT/vault-unlock" || return $?
|
|
206
|
+
VALIDATE_UNLOCK_FILES=$(find "$VALIDATE_RUNTIME_ROOT/vault-unlock" -xdev -mindepth 1 -maxdepth 1 -type f -name '*.secret' -size +0c -print) || return $?
|
|
207
|
+
test "$(printf '%s\n' "$VALIDATE_UNLOCK_FILES" | awk 'NF { count++ } END { print count + 0 }')" = 1 || return $?
|
|
208
|
+
test ! -e "$VALIDATE_RUNTIME_ROOT/container-credentials.json" || return $?
|
|
209
|
+
test ! -e "$VALIDATE_RUNTIME_ROOT/container-credentials.json.consuming" || return $?
|
|
210
|
+
VALIDATE_WRONG_OWNER=$(find "$VALIDATE_RUNTIME_ROOT" "$VALIDATE_AGENT_ROOT" -xdev \( ! -user 10001 -o ! -group 10001 \) -print -quit) || return $?
|
|
211
|
+
test -z "$VALIDATE_WRONG_OWNER" || return $?
|
|
212
|
+
VALIDATE_WRONG_DIR_MODE=$(find "$VALIDATE_RUNTIME_ROOT" "$VALIDATE_AGENT_ROOT" -xdev -type d ! -perm 0700 -print -quit) || return $?
|
|
213
|
+
test -z "$VALIDATE_WRONG_DIR_MODE" || return $?
|
|
214
|
+
VALIDATE_WRONG_FILE_MODE=$(find "$VALIDATE_RUNTIME_ROOT" "$VALIDATE_AGENT_ROOT" -xdev -type f ! -perm 0600 -print -quit) || return $?
|
|
215
|
+
test -z "$VALIDATE_WRONG_FILE_MODE" || return $?
|
|
216
|
+
)
|
|
217
|
+
}
|
|
218
|
+
assert_restore_preflight() {
|
|
219
|
+
(
|
|
220
|
+
test -n "${BACKUP_ROOT-}" || return 1
|
|
221
|
+
test -n "${IMAGE_ID-}" || return 1
|
|
222
|
+
case "$BACKUP_ROOT" in
|
|
223
|
+
/*) ;;
|
|
224
|
+
*) return 1 ;;
|
|
225
|
+
esac
|
|
226
|
+
test "$BACKUP_ROOT" != / || return $?
|
|
227
|
+
RESTORE_BACKUP_ROOT=$(cd -- "$BACKUP_ROOT" && pwd -P) || return $?
|
|
228
|
+
test "$RESTORE_BACKUP_ROOT" = "$BACKUP_ROOT" || return $?
|
|
229
|
+
test -d "$BACKUP_ROOT/runtime/.ouro-cli" || return $?
|
|
230
|
+
test -d "$BACKUP_ROOT/agent/sanctuary.ouro" || return $?
|
|
231
|
+
validate_sanctuary_roots "$BACKUP_ROOT/runtime/.ouro-cli" "$BACKUP_ROOT/agent/sanctuary.ouro" || return $?
|
|
232
|
+
validate_exact_image_id "$IMAGE_ID" || return $?
|
|
233
|
+
RESTORE_CONTAINER_NAMES=$(docker container ls -a --format '{{.Names}}') || return $?
|
|
234
|
+
RESTORE_NAME_COUNTS=$(printf '%s\n' "$RESTORE_CONTAINER_NAMES" | awk '
|
|
235
|
+
$0 == "ouro-butler" { production++ }
|
|
236
|
+
$0 == "ouro-butler-staging" { staging++ }
|
|
237
|
+
$0 == "ouro-butler-rollback" { rollback++ }
|
|
238
|
+
$0 == "ouro-butler-legacy-evidence" { legacy++ }
|
|
239
|
+
END {
|
|
240
|
+
printf "%d %d %d %d", production + 0, staging + 0, rollback + 0, legacy + 0
|
|
241
|
+
}
|
|
242
|
+
') || return $?
|
|
243
|
+
case "$RESTORE_NAME_COUNTS" in
|
|
244
|
+
"1 0 0 0"|"1 0 0 1") ;;
|
|
245
|
+
*) return 1 ;;
|
|
246
|
+
esac
|
|
247
|
+
RESTORE_PRODUCTION_RUNNING=$(docker inspect --format '{{.State.Running}}' ouro-butler) || return $?
|
|
248
|
+
test "$RESTORE_PRODUCTION_RUNNING" = true || return $?
|
|
249
|
+
RESTORE_PRODUCTION_IMAGE_ID=$(docker inspect --format '{{.Image}}' ouro-butler) || return $?
|
|
250
|
+
validate_exact_image_id "$RESTORE_PRODUCTION_IMAGE_ID" || return $?
|
|
251
|
+
if test "$RESTORE_NAME_COUNTS" = "1 0 0 1"; then
|
|
252
|
+
RESTORE_LEGACY_RUNNING=$(docker inspect --format '{{.State.Running}}' ouro-butler-legacy-evidence) || return $?
|
|
253
|
+
test "$RESTORE_LEGACY_RUNNING" = false || return $?
|
|
254
|
+
RESTORE_LEGACY_IMAGE_ID=$(docker inspect --format '{{.Image}}' ouro-butler-legacy-evidence) || return $?
|
|
255
|
+
validate_exact_image_id "$RESTORE_LEGACY_IMAGE_ID" || return $?
|
|
256
|
+
fi
|
|
257
|
+
assert_only_running_butler ouro-butler || return $?
|
|
258
|
+
)
|
|
259
|
+
}
|
|
260
|
+
ensure_sanctuary_machine_identity() {
|
|
261
|
+
MACHINE_PATH=$1
|
|
262
|
+
test ! -L "$MACHINE_PATH" || return 1
|
|
263
|
+
/usr/local/bin/node -e '
|
|
264
|
+
const fs = require("node:fs");
|
|
265
|
+
const path = process.argv[1];
|
|
266
|
+
const valid = value => value && value.schemaVersion === 1 && value.machineId === "sanctuary"
|
|
267
|
+
&& typeof value.createdAt === "string" && typeof value.updatedAt === "string"
|
|
268
|
+
&& Array.isArray(value.hostnameAliases);
|
|
269
|
+
if (fs.existsSync(path)) {
|
|
270
|
+
if (!valid(JSON.parse(fs.readFileSync(path, "utf8")))) process.exit(1);
|
|
271
|
+
process.exit(0);
|
|
272
|
+
}
|
|
273
|
+
const now = new Date().toISOString();
|
|
274
|
+
const value = { schemaVersion: 1, machineId: "sanctuary", createdAt: now, updatedAt: now, hostnameAliases: [] };
|
|
275
|
+
const temporary = `${path}.tmp.${process.pid}`;
|
|
276
|
+
fs.writeFileSync(temporary, `${JSON.stringify(value, null, 2)}\n`, { mode: 0o600, flag: "wx" });
|
|
277
|
+
fs.renameSync(temporary, path);
|
|
278
|
+
' "$MACHINE_PATH" || return $?
|
|
279
|
+
chown 10001:10001 "$MACHINE_PATH" || return $?
|
|
280
|
+
chmod 0600 "$MACHINE_PATH" || return $?
|
|
281
|
+
sync -f "$MACHINE_PATH" || return $?
|
|
282
|
+
}
|
|
283
|
+
prepare_canonical_sanctuary_roots() {
|
|
284
|
+
PREPARE_IMAGE_ID=$1
|
|
285
|
+
validate_exact_image_id "$PREPARE_IMAGE_ID" || return $?
|
|
286
|
+
PREPARE_RUNTIME_ROOT=/mnt/user/appdata/ouro-butler/runtime/.ouro-cli
|
|
287
|
+
PREPARE_AGENT_ROOT=/mnt/user/appdata/ouro-butler/agent/sanctuary.ouro
|
|
288
|
+
install -d -m 0700 -o 10001 -g 10001 "$PREPARE_RUNTIME_ROOT" || return $?
|
|
289
|
+
install -d -m 0700 -o 10001 -g 10001 "$PREPARE_AGENT_ROOT" || return $?
|
|
290
|
+
ensure_sanctuary_machine_identity "$PREPARE_RUNTIME_ROOT/machine.json" || return $?
|
|
291
|
+
if test ! -f "$PREPARE_AGENT_ROOT/agent.json"; then
|
|
292
|
+
PREPARE_EXISTING_ENTRY=$(find "$PREPARE_AGENT_ROOT" -mindepth 1 -print -quit) || return $?
|
|
293
|
+
test -z "$PREPARE_EXISTING_ENTRY" || return $?
|
|
294
|
+
! docker container inspect ouro-butler-bundle-bootstrap >/dev/null 2>&1 || return 1
|
|
295
|
+
docker run --rm --pull=never --network=none --name ouro-butler-bundle-bootstrap --user 10001:10001 \
|
|
296
|
+
--mount "type=bind,src=$PREPARE_RUNTIME_ROOT,dst=/home/ouro/.ouro-cli" \
|
|
297
|
+
--mount "type=bind,src=$PREPARE_AGENT_ROOT,dst=/home/ouro/AgentBundles/sanctuary.ouro" \
|
|
298
|
+
--entrypoint /bin/sh "$PREPARE_IMAGE_ID" -ceu '
|
|
299
|
+
cp -R /opt/ouro/deploy/unraid/sanctuary.ouro/. /home/ouro/AgentBundles/sanctuary.ouro/
|
|
300
|
+
find /home/ouro/AgentBundles/sanctuary.ouro -type d -exec chmod 0700 {} +
|
|
301
|
+
find /home/ouro/AgentBundles/sanctuary.ouro -type f -exec chmod 0600 {} +
|
|
302
|
+
' || return $?
|
|
303
|
+
! docker container inspect ouro-butler-bundle-bootstrap >/dev/null 2>&1 || return 1
|
|
304
|
+
fi
|
|
305
|
+
for PREPARE_REQUIRED_FILE in \
|
|
306
|
+
agent.json bundle-meta.json provider-readiness.json tool-profiles.json \
|
|
307
|
+
psyche/SOUL.md habits/sanctuary-health.md; do
|
|
308
|
+
test -f "$PREPARE_AGENT_ROOT/$PREPARE_REQUIRED_FILE" || return $?
|
|
309
|
+
done
|
|
310
|
+
PREPARE_WRONG_OWNER=$(find "$PREPARE_RUNTIME_ROOT" "$PREPARE_AGENT_ROOT" \( ! -user 10001 -o ! -group 10001 \) -print -quit) || return $?
|
|
311
|
+
test -z "$PREPARE_WRONG_OWNER" || return $?
|
|
312
|
+
PREPARE_WRONG_DIR_MODE=$(find "$PREPARE_RUNTIME_ROOT" "$PREPARE_AGENT_ROOT" -type d ! -perm 0700 -print -quit) || return $?
|
|
313
|
+
test -z "$PREPARE_WRONG_DIR_MODE" || return $?
|
|
314
|
+
PREPARE_WRONG_FILE_MODE=$(find "$PREPARE_RUNTIME_ROOT" "$PREPARE_AGENT_ROOT" -type f ! -perm 0600 -print -quit) || return $?
|
|
315
|
+
test -z "$PREPARE_WRONG_FILE_MODE" || return $?
|
|
316
|
+
}
|
|
317
|
+
install_from_legacy_staging() {
|
|
318
|
+
ADOPTION_CONTAINER_NAMES=$(docker container ls -a --format '{{.Names}}') || return $?
|
|
319
|
+
ADOPTION_NAME_COUNTS=$(printf '%s\n' "$ADOPTION_CONTAINER_NAMES" | awk '
|
|
320
|
+
$0 == "ouro-butler" { production++ }
|
|
321
|
+
$0 == "ouro-butler-staging" { staging++ }
|
|
322
|
+
$0 == "ouro-butler-rollback" { rollback++ }
|
|
323
|
+
$0 == "ouro-butler-legacy-evidence" { legacy++ }
|
|
324
|
+
END {
|
|
325
|
+
printf "%d %d %d %d", production + 0, staging + 0, rollback + 0, legacy + 0
|
|
326
|
+
}
|
|
327
|
+
') || return $?
|
|
328
|
+
test "$ADOPTION_NAME_COUNTS" = "0 1 0 0" || return $?
|
|
329
|
+
assert_only_running_butler ouro-butler-staging || return $?
|
|
330
|
+
LEGACY_STAGING_IMAGE_ID=$(docker inspect --format '{{.Image}}' ouro-butler-staging) || return $?
|
|
331
|
+
validate_exact_image_id "$LEGACY_STAGING_IMAGE_ID" || return $?
|
|
332
|
+
validate_exact_image_id "$IMAGE_ID" || return $?
|
|
333
|
+
prepare_canonical_sanctuary_roots "$IMAGE_ID" || return $?
|
|
334
|
+
bootstrap_sanctuary_vault "$IMAGE_ID" /mnt/user/appdata/ouro-butler/runtime/container-credentials.json || return $?
|
|
335
|
+
LEGACY_EVIDENCE_ROOT=/mnt/user/appdata/ouro-butler/legacy-evidence
|
|
336
|
+
LEGACY_EVIDENCE_DIR="$LEGACY_EVIDENCE_ROOT/${LEGACY_STAGING_IMAGE_ID#sha256:}"
|
|
337
|
+
install -d -m 0700 -o 0 -g 0 "$LEGACY_EVIDENCE_ROOT" || return $?
|
|
338
|
+
mkdir -m 0700 "$LEGACY_EVIDENCE_DIR" || return $?
|
|
339
|
+
docker container inspect ouro-butler-staging >"$LEGACY_EVIDENCE_DIR/container.json" || return $?
|
|
340
|
+
docker image inspect "$LEGACY_STAGING_IMAGE_ID" >"$LEGACY_EVIDENCE_DIR/image.json" || return $?
|
|
341
|
+
chmod 0600 "$LEGACY_EVIDENCE_DIR/container.json" "$LEGACY_EVIDENCE_DIR/image.json" || return $?
|
|
342
|
+
sync -f "$LEGACY_EVIDENCE_DIR/container.json" || return $?
|
|
343
|
+
sync -f "$LEGACY_EVIDENCE_DIR/image.json" || return $?
|
|
344
|
+
sync -f "$LEGACY_EVIDENCE_DIR" || return $?
|
|
345
|
+
disable_butler_autostart || return $?
|
|
346
|
+
if docker stop ouro-butler-staging \
|
|
347
|
+
&& CURRENT_LEGACY_STAGING_IMAGE_ID=$(docker inspect --format '{{.Image}}' ouro-butler-staging) \
|
|
348
|
+
&& test "$CURRENT_LEGACY_STAGING_IMAGE_ID" = "$LEGACY_STAGING_IMAGE_ID" \
|
|
349
|
+
&& test "$(docker inspect --format '{{.State.Running}}' ouro-butler-staging)" = false \
|
|
350
|
+
&& docker rename ouro-butler-staging ouro-butler-legacy-evidence \
|
|
351
|
+
&& CURRENT_LEGACY_EVIDENCE_IMAGE_ID=$(docker inspect --format '{{.Image}}' ouro-butler-legacy-evidence) \
|
|
352
|
+
&& test "$CURRENT_LEGACY_EVIDENCE_IMAGE_ID" = "$LEGACY_STAGING_IMAGE_ID" \
|
|
353
|
+
&& test "$(docker inspect --format '{{.State.Running}}' ouro-butler-legacy-evidence)" = false \
|
|
354
|
+
&& docker create --name ouro-butler-staging --network host --restart unless-stopped --user 10001:10001 \
|
|
355
|
+
--mount "type=bind,src=/mnt/user/appdata/ouro-butler/runtime/.ouro-cli,dst=/home/ouro/.ouro-cli" \
|
|
356
|
+
--mount "type=bind,src=/mnt/user/appdata/ouro-butler/agent/sanctuary.ouro,dst=/home/ouro/AgentBundles/sanctuary.ouro" \
|
|
357
|
+
"$IMAGE_ID" \
|
|
358
|
+
&& audit_effective ouro-butler-staging "$IMAGE_ID" \
|
|
359
|
+
&& docker start ouro-butler-staging \
|
|
360
|
+
&& assert_only_running_butler ouro-butler-staging \
|
|
361
|
+
&& wait_butler_ready ouro-butler-staging \
|
|
362
|
+
&& docker stop ouro-butler-staging \
|
|
363
|
+
&& test "$(docker inspect --format '{{.Image}}' ouro-butler-staging)" = "$IMAGE_ID" \
|
|
364
|
+
&& docker rm ouro-butler-staging \
|
|
365
|
+
&& docker create --name ouro-butler --network host --restart unless-stopped --user 10001:10001 \
|
|
366
|
+
--mount "type=bind,src=/mnt/user/appdata/ouro-butler/runtime/.ouro-cli,dst=/home/ouro/.ouro-cli" \
|
|
367
|
+
--mount "type=bind,src=/mnt/user/appdata/ouro-butler/agent/sanctuary.ouro,dst=/home/ouro/AgentBundles/sanctuary.ouro" \
|
|
368
|
+
"$IMAGE_ID" \
|
|
369
|
+
&& audit_effective ouro-butler "$IMAGE_ID" \
|
|
370
|
+
&& docker start ouro-butler \
|
|
371
|
+
&& assert_only_running_butler ouro-butler \
|
|
372
|
+
&& wait_butler_ready ouro-butler \
|
|
373
|
+
&& enable_butler_autostart; then
|
|
374
|
+
return 0
|
|
375
|
+
else
|
|
376
|
+
ADOPTION_STATUS=$?
|
|
377
|
+
fi
|
|
378
|
+
ADOPTION_RECOVERY_NAMES=$(docker container ls -a --format '{{.Names}}') || return $?
|
|
379
|
+
case "
|
|
380
|
+
$ADOPTION_RECOVERY_NAMES
|
|
381
|
+
" in
|
|
382
|
+
*"
|
|
383
|
+
ouro-butler
|
|
384
|
+
"*)
|
|
385
|
+
ADOPTION_PARTIAL_IMAGE_ID=$(docker inspect --format '{{.Image}}' ouro-butler) || return $?
|
|
386
|
+
test "$ADOPTION_PARTIAL_IMAGE_ID" = "$IMAGE_ID" || return $?
|
|
387
|
+
docker stop ouro-butler >/dev/null 2>&1 || true
|
|
388
|
+
docker rm --force ouro-butler || return $?
|
|
389
|
+
;;
|
|
390
|
+
esac
|
|
391
|
+
ADOPTION_RECOVERY_NAMES=$(docker container ls -a --format '{{.Names}}') || return $?
|
|
392
|
+
case "
|
|
393
|
+
$ADOPTION_RECOVERY_NAMES
|
|
394
|
+
" in
|
|
395
|
+
*"
|
|
396
|
+
ouro-butler-staging
|
|
397
|
+
"*)
|
|
398
|
+
CURRENT_LEGACY_STAGING_IMAGE_ID=$(docker inspect --format '{{.Image}}' ouro-butler-staging) || return $?
|
|
399
|
+
case "$CURRENT_LEGACY_STAGING_IMAGE_ID" in
|
|
400
|
+
"$IMAGE_ID")
|
|
401
|
+
docker stop ouro-butler-staging >/dev/null 2>&1 || true
|
|
402
|
+
docker rm --force ouro-butler-staging || return $?
|
|
403
|
+
;;
|
|
404
|
+
"$LEGACY_STAGING_IMAGE_ID")
|
|
405
|
+
docker stop ouro-butler-staging >/dev/null 2>&1 || return $?
|
|
406
|
+
test "$(docker inspect --format '{{.State.Running}}' ouro-butler-staging)" = false || return $?
|
|
407
|
+
docker rename ouro-butler-staging ouro-butler-legacy-evidence || return $?
|
|
408
|
+
;;
|
|
409
|
+
*) return 1 ;;
|
|
410
|
+
esac
|
|
411
|
+
;;
|
|
412
|
+
esac
|
|
413
|
+
CURRENT_LEGACY_EVIDENCE_IMAGE_ID=$(docker inspect --format '{{.Image}}' ouro-butler-legacy-evidence) || return $?
|
|
414
|
+
test "$CURRENT_LEGACY_EVIDENCE_IMAGE_ID" = "$LEGACY_STAGING_IMAGE_ID" || return $?
|
|
415
|
+
test "$(docker inspect --format '{{.State.Running}}' ouro-butler-legacy-evidence)" = false || return $?
|
|
416
|
+
return "$ADOPTION_STATUS"
|
|
417
|
+
}
|
|
418
|
+
validate_sanctuary_legacy_import_marker() {
|
|
419
|
+
IMPORT_MARKER=$1
|
|
420
|
+
IMPORT_SOURCE=$2
|
|
421
|
+
test -f "$IMPORT_MARKER" && test ! -L "$IMPORT_MARKER" || return 1
|
|
422
|
+
test "$(stat -c '%u:%g %a' "$IMPORT_MARKER")" = "10001:10001 600" || return 1
|
|
423
|
+
/usr/local/bin/node -e '
|
|
424
|
+
const crypto = require("node:crypto");
|
|
425
|
+
const fs = require("node:fs");
|
|
426
|
+
const marker = JSON.parse(fs.readFileSync(process.argv[1], "utf8"));
|
|
427
|
+
const sourceDigest = `sha256:${crypto.createHash("sha256").update(fs.readFileSync(process.argv[2])).digest("hex")}`;
|
|
428
|
+
if (JSON.stringify(Object.keys(marker).sort()) !== JSON.stringify(["importedAt", "machineId", "schemaVersion", "sourceDigest"])) process.exit(1);
|
|
429
|
+
if (marker.schemaVersion !== 1 || marker.machineId !== "sanctuary" || marker.sourceDigest !== sourceDigest) process.exit(1);
|
|
430
|
+
if (!Number.isFinite(Date.parse(marker.importedAt))) process.exit(1);
|
|
431
|
+
' "$IMPORT_MARKER" "$IMPORT_SOURCE"
|
|
432
|
+
}
|
|
433
|
+
record_sanctuary_legacy_import_marker() {
|
|
434
|
+
IMPORT_MARKER=$1
|
|
435
|
+
IMPORT_SOURCE=$2
|
|
436
|
+
test ! -e "$IMPORT_MARKER" || return 1
|
|
437
|
+
IMPORT_MARKER_TMP=$(mktemp "${IMPORT_MARKER}.tmp.XXXXXX") || return $?
|
|
438
|
+
trap 'rm -f -- "$IMPORT_MARKER_TMP"' EXIT || return $?
|
|
439
|
+
/usr/local/bin/node -e '
|
|
440
|
+
const crypto = require("node:crypto");
|
|
441
|
+
const fs = require("node:fs");
|
|
442
|
+
const sourceDigest = `sha256:${crypto.createHash("sha256").update(fs.readFileSync(process.argv[2])).digest("hex")}`;
|
|
443
|
+
const marker = { schemaVersion: 1, machineId: "sanctuary", sourceDigest, importedAt: new Date().toISOString() };
|
|
444
|
+
fs.writeFileSync(process.argv[1], `${JSON.stringify(marker)}\n`, { mode: 0o600, flag: "w" });
|
|
445
|
+
' "$IMPORT_MARKER_TMP" "$IMPORT_SOURCE" || return $?
|
|
446
|
+
chown 10001:10001 "$IMPORT_MARKER_TMP" || return $?
|
|
447
|
+
chmod 0600 "$IMPORT_MARKER_TMP" || return $?
|
|
448
|
+
mv -f -- "$IMPORT_MARKER_TMP" "$IMPORT_MARKER" || return $?
|
|
449
|
+
sync -f "$IMPORT_MARKER" || return $?
|
|
450
|
+
sync -f "$(dirname "$IMPORT_MARKER")" || return $?
|
|
451
|
+
trap - EXIT || return $?
|
|
452
|
+
}
|
|
453
|
+
bootstrap_sanctuary_vault() {
|
|
454
|
+
BOOTSTRAP_IMAGE_ID=$1
|
|
455
|
+
BOOTSTRAP_LEGACY_CREDENTIAL_SOURCE=${2-}
|
|
456
|
+
validate_exact_image_id "$BOOTSTRAP_IMAGE_ID" || return $?
|
|
457
|
+
case "$BOOTSTRAP_LEGACY_CREDENTIAL_SOURCE" in
|
|
458
|
+
""|/mnt/user/appdata/ouro-butler/runtime/container-credentials.json) ;;
|
|
459
|
+
*) return 1 ;;
|
|
460
|
+
esac
|
|
461
|
+
BOOTSTRAP_RUNTIME_ROOT=/mnt/user/appdata/ouro-butler/runtime/.ouro-cli
|
|
462
|
+
BOOTSTRAP_AGENT_ROOT=/mnt/user/appdata/ouro-butler/agent/sanctuary.ouro
|
|
463
|
+
for BOOTSTRAP_CONTAINER in ouro-butler-vault-status ouro-butler-vault-bootstrap ouro-butler-credential-bootstrap ouro-butler-provider-readiness; do
|
|
464
|
+
! docker container inspect "$BOOTSTRAP_CONTAINER" >/dev/null 2>&1 || return 1
|
|
465
|
+
done
|
|
466
|
+
VAULT_STATUS=$(docker run --rm --pull=never --network host --name ouro-butler-vault-status --user 10001:10001 \
|
|
467
|
+
--mount "type=bind,src=$BOOTSTRAP_RUNTIME_ROOT,dst=/home/ouro/.ouro-cli" \
|
|
468
|
+
--mount "type=bind,src=$BOOTSTRAP_AGENT_ROOT,dst=/home/ouro/AgentBundles/sanctuary.ouro" \
|
|
469
|
+
--entrypoint node "$BOOTSTRAP_IMAGE_ID" /opt/ouro/dist/heart/daemon/ouro-entry.js \
|
|
470
|
+
vault status --agent sanctuary --store plaintext-file) || return $?
|
|
471
|
+
! docker container inspect ouro-butler-vault-status >/dev/null 2>&1 || return 1
|
|
472
|
+
case "
|
|
473
|
+
$VAULT_STATUS
|
|
474
|
+
" in
|
|
475
|
+
*"
|
|
476
|
+
vault locator: not configured in agent.json
|
|
477
|
+
"*) VAULT_ACTION=create ;;
|
|
478
|
+
*"
|
|
479
|
+
vault locator: agent.json
|
|
480
|
+
"*)
|
|
481
|
+
case "
|
|
482
|
+
$VAULT_STATUS
|
|
483
|
+
" in
|
|
484
|
+
*"
|
|
485
|
+
local unlock: available
|
|
486
|
+
"*) VAULT_ACTION=none ;;
|
|
487
|
+
*"
|
|
488
|
+
local unlock: missing
|
|
489
|
+
"*) VAULT_ACTION=unlock ;;
|
|
490
|
+
*) return 1 ;;
|
|
491
|
+
esac
|
|
492
|
+
;;
|
|
493
|
+
*) return 1 ;;
|
|
494
|
+
esac
|
|
495
|
+
if test "$VAULT_ACTION" != none; then
|
|
496
|
+
docker run --rm -it --pull=never --network host --name ouro-butler-vault-bootstrap --user 10001:10001 \
|
|
497
|
+
--mount "type=bind,src=$BOOTSTRAP_RUNTIME_ROOT,dst=/home/ouro/.ouro-cli" \
|
|
498
|
+
--mount "type=bind,src=$BOOTSTRAP_AGENT_ROOT,dst=/home/ouro/AgentBundles/sanctuary.ouro" \
|
|
499
|
+
--entrypoint node "$BOOTSTRAP_IMAGE_ID" /opt/ouro/dist/heart/daemon/ouro-entry.js \
|
|
500
|
+
vault "$VAULT_ACTION" --agent sanctuary --store plaintext-file || return $?
|
|
501
|
+
! docker container inspect ouro-butler-vault-bootstrap >/dev/null 2>&1 || return 1
|
|
502
|
+
fi
|
|
503
|
+
VERIFIED_VAULT_STATUS=$(docker run --rm --pull=never --network host --name ouro-butler-vault-status --user 10001:10001 \
|
|
504
|
+
--mount "type=bind,src=$BOOTSTRAP_RUNTIME_ROOT,dst=/home/ouro/.ouro-cli" \
|
|
505
|
+
--mount "type=bind,src=$BOOTSTRAP_AGENT_ROOT,dst=/home/ouro/AgentBundles/sanctuary.ouro" \
|
|
506
|
+
--entrypoint node "$BOOTSTRAP_IMAGE_ID" /opt/ouro/dist/heart/daemon/ouro-entry.js \
|
|
507
|
+
vault status --agent sanctuary --store plaintext-file) || return $?
|
|
508
|
+
! docker container inspect ouro-butler-vault-status >/dev/null 2>&1 || return 1
|
|
509
|
+
case "
|
|
510
|
+
$VERIFIED_VAULT_STATUS
|
|
511
|
+
" in
|
|
512
|
+
*"
|
|
513
|
+
vault locator: agent.json
|
|
514
|
+
"*) ;;
|
|
515
|
+
*) return 1 ;;
|
|
516
|
+
esac
|
|
517
|
+
case "
|
|
518
|
+
$VERIFIED_VAULT_STATUS
|
|
519
|
+
" in
|
|
520
|
+
*"
|
|
521
|
+
local unlock: available
|
|
522
|
+
"*) ;;
|
|
523
|
+
*) return 1 ;;
|
|
524
|
+
esac
|
|
525
|
+
if test -n "$BOOTSTRAP_LEGACY_CREDENTIAL_SOURCE"; then
|
|
526
|
+
BOOTSTRAP_CREDENTIAL_SOURCE="$BOOTSTRAP_RUNTIME_ROOT/container-credentials.json"
|
|
527
|
+
BOOTSTRAP_CREDENTIAL_CLAIM="$BOOTSTRAP_CREDENTIAL_SOURCE.consuming"
|
|
528
|
+
test -f "$BOOTSTRAP_LEGACY_CREDENTIAL_SOURCE" || return $?
|
|
529
|
+
test ! -L "$BOOTSTRAP_LEGACY_CREDENTIAL_SOURCE" || return $?
|
|
530
|
+
BOOTSTRAP_LEGACY_METADATA=$(stat -c '%u:%g %a' "$BOOTSTRAP_LEGACY_CREDENTIAL_SOURCE") || return $?
|
|
531
|
+
test "$BOOTSTRAP_LEGACY_METADATA" = "10001:10001 600" || return $?
|
|
532
|
+
BOOTSTRAP_IMPORT_MARKER="$BOOTSTRAP_RUNTIME_ROOT/legacy-credentials-imported.json"
|
|
533
|
+
if test -e "$BOOTSTRAP_IMPORT_MARKER"; then
|
|
534
|
+
validate_sanctuary_legacy_import_marker "$BOOTSTRAP_IMPORT_MARKER" "$BOOTSTRAP_LEGACY_CREDENTIAL_SOURCE" || return $?
|
|
535
|
+
test ! -e "$BOOTSTRAP_CREDENTIAL_SOURCE" || return 1
|
|
536
|
+
test ! -e "$BOOTSTRAP_CREDENTIAL_CLAIM" || return 1
|
|
537
|
+
else
|
|
538
|
+
if test -e "$BOOTSTRAP_CREDENTIAL_SOURCE"; then
|
|
539
|
+
test -f "$BOOTSTRAP_CREDENTIAL_SOURCE" || return $?
|
|
540
|
+
test ! -L "$BOOTSTRAP_CREDENTIAL_SOURCE" || return $?
|
|
541
|
+
test "$(stat -c '%u:%g %a' "$BOOTSTRAP_CREDENTIAL_SOURCE")" = "10001:10001 600" || return $?
|
|
542
|
+
cmp -s "$BOOTSTRAP_LEGACY_CREDENTIAL_SOURCE" "$BOOTSTRAP_CREDENTIAL_SOURCE" || return $?
|
|
543
|
+
elif test -e "$BOOTSTRAP_CREDENTIAL_CLAIM"; then
|
|
544
|
+
test -f "$BOOTSTRAP_CREDENTIAL_CLAIM" || return $?
|
|
545
|
+
test ! -L "$BOOTSTRAP_CREDENTIAL_CLAIM" || return $?
|
|
546
|
+
test "$(stat -c '%u:%g %a' "$BOOTSTRAP_CREDENTIAL_CLAIM")" = "10001:10001 600" || return $?
|
|
547
|
+
cmp -s "$BOOTSTRAP_LEGACY_CREDENTIAL_SOURCE" "$BOOTSTRAP_CREDENTIAL_CLAIM" || return $?
|
|
548
|
+
else
|
|
549
|
+
BOOTSTRAP_CREDENTIAL_TMP=$(mktemp "$BOOTSTRAP_RUNTIME_ROOT/container-credentials.json.tmp.XXXXXX") || return $?
|
|
550
|
+
trap 'rm -f -- "$BOOTSTRAP_CREDENTIAL_TMP"' EXIT || return $?
|
|
551
|
+
install -m 0600 -o 10001 -g 10001 "$BOOTSTRAP_LEGACY_CREDENTIAL_SOURCE" "$BOOTSTRAP_CREDENTIAL_TMP" || return $?
|
|
552
|
+
cmp -s "$BOOTSTRAP_LEGACY_CREDENTIAL_SOURCE" "$BOOTSTRAP_CREDENTIAL_TMP" || return $?
|
|
553
|
+
sync -f "$BOOTSTRAP_CREDENTIAL_TMP" || return $?
|
|
554
|
+
mv -f -- "$BOOTSTRAP_CREDENTIAL_TMP" "$BOOTSTRAP_CREDENTIAL_SOURCE" || return $?
|
|
555
|
+
sync -f "$BOOTSTRAP_RUNTIME_ROOT" || return $?
|
|
556
|
+
trap - EXIT || return $?
|
|
557
|
+
fi
|
|
558
|
+
docker run --rm --pull=never --network host --name ouro-butler-credential-bootstrap --user 10001:10001 \
|
|
559
|
+
--mount "type=bind,src=$BOOTSTRAP_RUNTIME_ROOT,dst=/home/ouro/.ouro-cli" \
|
|
560
|
+
--mount "type=bind,src=$BOOTSTRAP_AGENT_ROOT,dst=/home/ouro/AgentBundles/sanctuary.ouro" \
|
|
561
|
+
--entrypoint node "$BOOTSTRAP_IMAGE_ID" -e '
|
|
562
|
+
const { loadContainerCredentialBootstrap } = require("/opt/ouro/dist/heart/daemon/container-credential-bootstrap.js")
|
|
563
|
+
loadContainerCredentialBootstrap(["sanctuary"]).then(
|
|
564
|
+
() => process.exit(0),
|
|
565
|
+
() => { process.stderr.write("credential bootstrap failed\n"); process.exit(1) },
|
|
566
|
+
)
|
|
567
|
+
' || return $?
|
|
568
|
+
! docker container inspect ouro-butler-credential-bootstrap >/dev/null 2>&1 || return 1
|
|
569
|
+
test ! -e "$BOOTSTRAP_CREDENTIAL_SOURCE" || return $?
|
|
570
|
+
test ! -e "$BOOTSTRAP_CREDENTIAL_CLAIM" || return $?
|
|
571
|
+
record_sanctuary_legacy_import_marker "$BOOTSTRAP_IMPORT_MARKER" "$BOOTSTRAP_LEGACY_CREDENTIAL_SOURCE" || return $?
|
|
572
|
+
validate_sanctuary_legacy_import_marker "$BOOTSTRAP_IMPORT_MARKER" "$BOOTSTRAP_LEGACY_CREDENTIAL_SOURCE" || return $?
|
|
573
|
+
fi
|
|
574
|
+
test -f "$BOOTSTRAP_LEGACY_CREDENTIAL_SOURCE" || return $?
|
|
575
|
+
test ! -L "$BOOTSTRAP_LEGACY_CREDENTIAL_SOURCE" || return $?
|
|
576
|
+
test "$(stat -c '%u:%g %a' "$BOOTSTRAP_LEGACY_CREDENTIAL_SOURCE")" = "$BOOTSTRAP_LEGACY_METADATA" || return $?
|
|
577
|
+
fi
|
|
578
|
+
docker run --rm --pull=never --network host --name ouro-butler-provider-readiness --user 10001:10001 \
|
|
579
|
+
--mount "type=bind,src=$BOOTSTRAP_RUNTIME_ROOT,dst=/home/ouro/.ouro-cli" \
|
|
580
|
+
--mount "type=bind,src=$BOOTSTRAP_AGENT_ROOT,dst=/home/ouro/AgentBundles/sanctuary.ouro" \
|
|
581
|
+
--entrypoint /bin/sh "$BOOTSTRAP_IMAGE_ID" -ceu '
|
|
582
|
+
umask 077
|
|
583
|
+
READINESS_STARTED_AT=$(node -e "process.stdout.write(new Date().toISOString())")
|
|
584
|
+
node /opt/ouro/dist/heart/daemon/ouro-entry.js check --agent sanctuary --lane outward
|
|
585
|
+
node /opt/ouro/dist/heart/daemon/ouro-entry.js check --agent sanctuary --lane inner
|
|
586
|
+
node -e "
|
|
587
|
+
const fs = require(\"node:fs\");
|
|
588
|
+
const agentPath = process.argv[2];
|
|
589
|
+
const readinessPath = process.argv[3];
|
|
590
|
+
const agent = JSON.parse(fs.readFileSync(agentPath, \"utf8\"));
|
|
591
|
+
const readiness = JSON.parse(fs.readFileSync(readinessPath, \"utf8\"));
|
|
592
|
+
if (readiness.schemaVersion !== 1 || !readiness.lanes || typeof readiness.lanes !== \"object\") process.exit(1);
|
|
593
|
+
for (const [lane, facing] of [[\"outward\", \"humanFacing\"], [\"inner\", \"agentFacing\"]]) {
|
|
594
|
+
const entry = readiness.lanes[lane];
|
|
595
|
+
const binding = agent[facing];
|
|
596
|
+
if (!entry || !binding || entry.agentName !== \"sanctuary\" || entry.lane !== lane) process.exit(1);
|
|
597
|
+
if (entry.status !== \"ready\" || entry.provider !== binding.provider || entry.model !== binding.model) process.exit(1);
|
|
598
|
+
if (!Number.isFinite(Date.parse(entry.checkedAt)) || Date.parse(entry.checkedAt) < Date.parse(process.argv[1])) process.exit(1);
|
|
599
|
+
if (typeof entry.credentialRevision !== \"string\" || entry.credentialRevision.length === 0) process.exit(1);
|
|
600
|
+
}
|
|
601
|
+
" "$READINESS_STARTED_AT" \
|
|
602
|
+
/home/ouro/AgentBundles/sanctuary.ouro/agent.json \
|
|
603
|
+
/home/ouro/AgentBundles/sanctuary.ouro/state/providers/readiness.json
|
|
604
|
+
' || return $?
|
|
605
|
+
! docker container inspect ouro-butler-provider-readiness >/dev/null 2>&1 || return 1
|
|
606
|
+
validate_sanctuary_roots "$BOOTSTRAP_RUNTIME_ROOT" "$BOOTSTRAP_AGENT_ROOT" || return $?
|
|
607
|
+
}
|
|
608
|
+
run_sanctuary_docker() {
|
|
609
|
+
/usr/bin/timeout -s KILL 20 /usr/bin/docker "$@"
|
|
610
|
+
}
|
|
611
|
+
run_sanctuary_unraid_api() {
|
|
612
|
+
/usr/bin/timeout -s KILL 20 /usr/local/sbin/unraid-api "$@"
|
|
613
|
+
}
|
|
614
|
+
run_sanctuary_node() {
|
|
615
|
+
/usr/local/bin/node "$@"
|
|
616
|
+
}
|
|
617
|
+
resolve_sanctuary_unraid_key() {
|
|
618
|
+
run_sanctuary_node -e '
|
|
619
|
+
const fs = require("node:fs");
|
|
620
|
+
const root = "/boot/config/plugins/dynamix.my.servers/keys";
|
|
621
|
+
const expected = process.argv[1];
|
|
622
|
+
const found = [];
|
|
623
|
+
for (const name of fs.readdirSync(root)) {
|
|
624
|
+
if (!/^[A-Za-z0-9._:-]+\.json$/.test(name)) process.exit(1);
|
|
625
|
+
const path = `${root}/${name}`;
|
|
626
|
+
const stat = fs.lstatSync(path);
|
|
627
|
+
if (!stat.isFile() || stat.isSymbolicLink()) process.exit(1);
|
|
628
|
+
const value = JSON.parse(fs.readFileSync(path, "utf8"));
|
|
629
|
+
if (value.id === expected) found.push({ path, name: value.name });
|
|
630
|
+
}
|
|
631
|
+
if (found.length !== 1 || typeof found[0].name !== "string" || !/^[A-Za-z0-9 ._:-]+$/.test(found[0].name)) process.exit(1);
|
|
632
|
+
process.stdout.write(`${found[0].path}\t${found[0].name}`);
|
|
633
|
+
' "$1"
|
|
634
|
+
}
|
|
635
|
+
sanctuary_revoked_key_recovery_path() {
|
|
636
|
+
case "$1" in ''|*[!A-Za-z0-9._:-]*) return 1 ;; esac
|
|
637
|
+
printf '%s/%s.json' /mnt/user/appdata/ouro-butler/acceptance/revoked-key-proof "$1"
|
|
638
|
+
}
|
|
639
|
+
validate_sanctuary_revoked_key_recovery() {
|
|
640
|
+
test -f "$1" && test ! -L "$1" || return 1
|
|
641
|
+
test "$(stat -c '%u:%g %a' "$1")" = "0:0 600" || return 1
|
|
642
|
+
}
|
|
643
|
+
preserve_sanctuary_revoked_key() {
|
|
644
|
+
KEY_ID=$1
|
|
645
|
+
KEY_SOURCE=$2
|
|
646
|
+
RECOVERY_ROOT=/mnt/user/appdata/ouro-butler/acceptance/revoked-key-proof
|
|
647
|
+
test -f "$KEY_SOURCE" && test ! -L "$KEY_SOURCE" || return 1
|
|
648
|
+
if test ! -e "$RECOVERY_ROOT"; then
|
|
649
|
+
install -d -m 0700 -o root -g root "$RECOVERY_ROOT" || return $?
|
|
650
|
+
fi
|
|
651
|
+
test -d "$RECOVERY_ROOT" && test ! -L "$RECOVERY_ROOT" || return 1
|
|
652
|
+
test "$(stat -c '%u:%g %a' "$RECOVERY_ROOT")" = "0:0 700" || return 1
|
|
653
|
+
RECOVERY_PATH=$(sanctuary_revoked_key_recovery_path "$KEY_ID") || return $?
|
|
654
|
+
test ! -e "$RECOVERY_PATH" || return 1
|
|
655
|
+
RECOVERY_TMP=$(mktemp "$RECOVERY_ROOT/$KEY_ID.json.tmp.XXXXXX") || return $?
|
|
656
|
+
trap 'rm -f -- "$RECOVERY_TMP"' EXIT || return $?
|
|
657
|
+
install -m 0600 -o root -g root "$KEY_SOURCE" "$RECOVERY_TMP" || return $?
|
|
658
|
+
cmp -s "$KEY_SOURCE" "$RECOVERY_TMP" || return 1
|
|
659
|
+
mv -f -- "$RECOVERY_TMP" "$RECOVERY_PATH" || return $?
|
|
660
|
+
sync -f "$RECOVERY_ROOT" || return $?
|
|
661
|
+
trap - EXIT || return $?
|
|
662
|
+
}
|
|
663
|
+
clear_sanctuary_revoked_key() {
|
|
664
|
+
RECOVERY_PATH=$(sanctuary_revoked_key_recovery_path "$1") || return $?
|
|
665
|
+
test -f "$RECOVERY_PATH" && test ! -L "$RECOVERY_PATH" || return 1
|
|
666
|
+
test "$(stat -c '%u:%g %a' "$RECOVERY_PATH")" = "0:0 600" || return 1
|
|
667
|
+
rm -f -- "$RECOVERY_PATH" || return $?
|
|
668
|
+
sync -f "$(dirname "$RECOVERY_PATH")" || return $?
|
|
669
|
+
}
|
|
670
|
+
verify_vault_backed_unraid_key() {
|
|
671
|
+
KEY_ID=$1
|
|
672
|
+
CAPABILITY=$2
|
|
673
|
+
case "$KEY_ID" in ''|*[!A-Za-z0-9._:-]*) return 1 ;; esac
|
|
674
|
+
case "$CAPABILITY" in read-only|bounded-write) ;; *) return 1 ;; esac
|
|
675
|
+
IMAGE_DIGEST=${IMAGE_ID#sha256:}
|
|
676
|
+
test "$IMAGE_DIGEST" != "$IMAGE_ID" || return 1
|
|
677
|
+
test "${#IMAGE_DIGEST}" -eq 64 || return 1
|
|
678
|
+
case "$IMAGE_DIGEST" in *[!0-9a-f]*) return 1 ;; esac
|
|
679
|
+
test "$(run_sanctuary_docker image inspect --format '{{.Id}}' "$IMAGE_ID")" = "$IMAGE_ID" || return $?
|
|
680
|
+
KEY_TARGET=$(resolve_sanctuary_unraid_key "$KEY_ID") || return $?
|
|
681
|
+
KEY_PATH=${KEY_TARGET%% *}
|
|
682
|
+
test "$KEY_PATH" != "$KEY_TARGET" || return 1
|
|
683
|
+
test -f "$KEY_PATH" && test ! -L "$KEY_PATH" || return 1
|
|
684
|
+
VERIFY_RESULT=$(run_sanctuary_docker run --rm --pull=never --network host \
|
|
685
|
+
--user 0:0 \
|
|
686
|
+
--mount type=bind,src=/mnt/user/appdata/ouro-butler/runtime/.ouro-cli,dst=/home/ouro/.ouro-cli,readonly \
|
|
687
|
+
--mount type=bind,src=/mnt/user/appdata/ouro-butler/agent/sanctuary.ouro,dst=/home/ouro/AgentBundles/sanctuary.ouro,readonly \
|
|
688
|
+
--mount type=bind,src="$KEY_PATH",dst=/run/ouro-acceptance/unraid-key.json,readonly \
|
|
689
|
+
--entrypoint /opt/ouro/deploy/unraid/sanctuary-acceptance-adapter.sh \
|
|
690
|
+
"$IMAGE_ID" vault-probe "$KEY_ID" "$CAPABILITY") || return $?
|
|
691
|
+
printf '%s' "$VERIFY_RESULT" | run_sanctuary_node -e '
|
|
692
|
+
let input = "";
|
|
693
|
+
process.stdin.setEncoding("utf8");
|
|
694
|
+
process.stdin.on("data", chunk => { input += chunk; });
|
|
695
|
+
process.stdin.on("end", () => {
|
|
696
|
+
const value = JSON.parse(input);
|
|
697
|
+
const expectedId = process.argv[1];
|
|
698
|
+
const expectedCapability = process.argv[2];
|
|
699
|
+
const expectedProof = expectedCapability === "read-only"
|
|
700
|
+
? "read-authorized-write-denied"
|
|
701
|
+
: "read-authorized-write-reached-not-found";
|
|
702
|
+
if (JSON.stringify(Object.keys(value).sort()) !== JSON.stringify(["capability", "keyId", "proof", "valid"])) process.exit(1);
|
|
703
|
+
if (value.valid !== true || value.keyId !== expectedId || value.capability !== expectedCapability) process.exit(1);
|
|
704
|
+
if (value.proof !== expectedProof) process.exit(1);
|
|
705
|
+
});
|
|
706
|
+
' "$KEY_ID" "$CAPABILITY" || return $?
|
|
707
|
+
}
|
|
708
|
+
inventory_unraid_key_ids() {
|
|
709
|
+
IMAGE_DIGEST=${IMAGE_ID#sha256:}
|
|
710
|
+
test "$IMAGE_DIGEST" != "$IMAGE_ID" || return 1
|
|
711
|
+
test "${#IMAGE_DIGEST}" -eq 64 || return 1
|
|
712
|
+
case "$IMAGE_DIGEST" in *[!0-9a-f]*) return 1 ;; esac
|
|
713
|
+
test "$(run_sanctuary_docker image inspect --format '{{.Id}}' "$IMAGE_ID")" = "$IMAGE_ID" || return $?
|
|
714
|
+
INVENTORY_RESULT=$(printf '%s' '{"operation":"closed-inventory"}' | \
|
|
715
|
+
run_sanctuary_docker run --rm -i --pull=never --network none \
|
|
716
|
+
--user 0:0 --read-only \
|
|
717
|
+
--mount type=bind,src=/boot/config/plugins/dynamix.my.servers/keys,dst=/boot/config/plugins/dynamix.my.servers/keys,readonly \
|
|
718
|
+
--entrypoint /opt/ouro/deploy/unraid/sanctuary-acceptance-adapter.sh "$IMAGE_ID") || return $?
|
|
719
|
+
printf '%s' "$INVENTORY_RESULT" | run_sanctuary_node -e '
|
|
720
|
+
let input = "";
|
|
721
|
+
process.stdin.setEncoding("utf8");
|
|
722
|
+
process.stdin.on("data", chunk => { input += chunk; });
|
|
723
|
+
process.stdin.on("end", () => {
|
|
724
|
+
const value = JSON.parse(input);
|
|
725
|
+
if (!value || JSON.stringify(Object.keys(value)) !== JSON.stringify(["keys"]) || !Array.isArray(value.keys)) process.exit(1);
|
|
726
|
+
for (const key of value.keys) {
|
|
727
|
+
if (!key || JSON.stringify(Object.keys(key).sort()) !== JSON.stringify(["id", "roles", "scope"])) process.exit(1);
|
|
728
|
+
if (!/^[A-Za-z0-9._:-]+$/.test(key.id)) process.exit(1);
|
|
729
|
+
if (!["read-only", "bounded-write", "legacy-write"].includes(key.scope) || key.roles !== "none") process.exit(1);
|
|
730
|
+
process.stdout.write(`${key.id}\t${key.scope}\t${key.roles}\n`);
|
|
731
|
+
}
|
|
732
|
+
});
|
|
733
|
+
' || return $?
|
|
734
|
+
}
|
|
735
|
+
revoke_unraid_key_exact() {
|
|
736
|
+
KEY_ID=$1
|
|
737
|
+
case "$KEY_ID" in ''|*[!A-Za-z0-9._:-]*) return 1 ;; esac
|
|
738
|
+
test "${REVOKED_KEY_FD_OPEN:-no}" = no || return 1
|
|
739
|
+
KEY_TARGET=$(resolve_sanctuary_unraid_key "$KEY_ID") || return $?
|
|
740
|
+
KEY_PATH=${KEY_TARGET%% *}
|
|
741
|
+
KEY_NAME=${KEY_TARGET#* }
|
|
742
|
+
test "$KEY_PATH" != "$KEY_TARGET" || return 1
|
|
743
|
+
test -f "$KEY_PATH" && test ! -L "$KEY_PATH" || return $?
|
|
744
|
+
preserve_sanctuary_revoked_key "$KEY_ID" "$KEY_PATH" || return $?
|
|
745
|
+
if ! REVOKE_RESULT=$(run_sanctuary_unraid_api apikey --name "$KEY_NAME" --delete --json); then
|
|
746
|
+
return 1
|
|
747
|
+
fi
|
|
748
|
+
if ! printf '%s' "$REVOKE_RESULT" | run_sanctuary_node -e '
|
|
749
|
+
let input = "";
|
|
750
|
+
process.stdin.setEncoding("utf8");
|
|
751
|
+
process.stdin.on("data", chunk => { input += chunk; });
|
|
752
|
+
process.stdin.on("end", () => {
|
|
753
|
+
const value = JSON.parse(input);
|
|
754
|
+
const expectedId = process.argv[1];
|
|
755
|
+
const expectedName = process.argv[2];
|
|
756
|
+
if (value.deleted !== 1 || !Array.isArray(value.keys) || value.keys.length !== 1) process.exit(1);
|
|
757
|
+
if (value.keys[0].id !== expectedId || value.keys[0].name !== expectedName) process.exit(1);
|
|
758
|
+
});
|
|
759
|
+
' "$KEY_ID" "$KEY_NAME"; then
|
|
760
|
+
return 1
|
|
761
|
+
fi
|
|
762
|
+
}
|
|
763
|
+
verify_revoked_unraid_key_rejected() {
|
|
764
|
+
KEY_ID=$1
|
|
765
|
+
case "$KEY_ID" in ''|*[!A-Za-z0-9._:-]*) return 1 ;; esac
|
|
766
|
+
REVOKED_KEY_RECOVERY_PATH=$(sanctuary_revoked_key_recovery_path "$KEY_ID") || return $?
|
|
767
|
+
validate_sanctuary_revoked_key_recovery "$REVOKED_KEY_RECOVERY_PATH" || return $?
|
|
768
|
+
IMAGE_DIGEST=${IMAGE_ID#sha256:}
|
|
769
|
+
test "$IMAGE_DIGEST" != "$IMAGE_ID" || return 1
|
|
770
|
+
test "${#IMAGE_DIGEST}" -eq 64 || return 1
|
|
771
|
+
case "$IMAGE_DIGEST" in *[!0-9a-f]*) return 1 ;; esac
|
|
772
|
+
test "$(run_sanctuary_docker image inspect --format '{{.Id}}' "$IMAGE_ID")" = "$IMAGE_ID" || return 1
|
|
773
|
+
REJECT_ATTEMPT=0
|
|
774
|
+
while test "$REJECT_ATTEMPT" -lt 3; do
|
|
775
|
+
REJECT_ATTEMPT=$((REJECT_ATTEMPT + 1))
|
|
776
|
+
if REJECT_RESULT=$(run_sanctuary_docker run --rm -i --pull=never --network host \
|
|
777
|
+
--user 10001:10001 --read-only \
|
|
778
|
+
--entrypoint /bin/sh "$IMAGE_ID" -ceu \
|
|
779
|
+
'exec 3<&0; exec /opt/ouro/deploy/unraid/sanctuary-acceptance-adapter.sh revoked-probe "$1" "$2" 3<&3' \
|
|
780
|
+
sanctuary-revoked-probe "$KEY_ID" http://127.0.0.1/graphql <"$REVOKED_KEY_RECOVERY_PATH") \
|
|
781
|
+
&& printf '%s' "$REJECT_RESULT" | run_sanctuary_node -e '
|
|
782
|
+
let input = "";
|
|
783
|
+
process.stdin.setEncoding("utf8");
|
|
784
|
+
process.stdin.on("data", chunk => { input += chunk; });
|
|
785
|
+
process.stdin.on("end", () => {
|
|
786
|
+
const value = JSON.parse(input);
|
|
787
|
+
if (JSON.stringify(Object.keys(value).sort()) !== JSON.stringify(["id", "rejected", "status"])) process.exit(1);
|
|
788
|
+
if (value.rejected !== true || value.id !== process.argv[1] || ![401, 403].includes(value.status)) process.exit(1);
|
|
789
|
+
});
|
|
790
|
+
' "$KEY_ID"; then
|
|
791
|
+
clear_sanctuary_revoked_key "$KEY_ID" || return $?
|
|
792
|
+
return 0
|
|
793
|
+
fi
|
|
794
|
+
test "$REJECT_ATTEMPT" -lt 3 || return 1
|
|
795
|
+
sleep 2
|
|
796
|
+
done
|
|
797
|
+
return 1
|
|
798
|
+
}
|
|
799
|
+
Update:
|
|
800
|
+
Build and verify a new ouro-butler:<version> image first. The tag is only a
|
|
801
|
+
lookup handle and never authorizes container creation. Resolve and validate
|
|
802
|
+
the exact local Docker image ID before staging:
|
|
803
|
+
IMAGE_TAG=ouro-butler:<version>
|
|
804
|
+
IMAGE_ID=$(docker image inspect --format '{{.Id}}' "$IMAGE_TAG")
|
|
805
|
+
printf '%s\n' "$IMAGE_ID" | grep -Eq '^sha256:[0-9a-f]{64}$'
|
|
806
|
+
docker image inspect "$IMAGE_ID" >/dev/null
|
|
807
|
+
Initial install/adoption is a separate terminal path for the verified live
|
|
808
|
+
legacy state: no production or rollback, exactly one running (possibly
|
|
809
|
+
unhealthy) ouro-butler-staging, and no legacy-evidence container. Run this and
|
|
810
|
+
stop; do not continue into the normal update below:
|
|
811
|
+
install_from_legacy_staging
|
|
812
|
+
That function never applies the canonical auditor to the known-noncanonical
|
|
813
|
+
legacy container or restarts it. It verifies and pins the legacy image,
|
|
814
|
+
provisions the absent canonical roots from the exact target image's packaged
|
|
815
|
+
Sanctuary skeleton, proves required files plus exact ownership/modes, and runs
|
|
816
|
+
same-image vault bootstrap and provider readiness before durably snapshotting
|
|
817
|
+
both exact container and image inspect records. Any preparation, vault, or
|
|
818
|
+
readiness failure returns while legacy remains running with autostart
|
|
819
|
+
untouched. It then stops and rechecks the legacy container and renames it to
|
|
820
|
+
stopped ouro-butler-legacy-evidence. A fresh canonical staging container is
|
|
821
|
+
created from exact IMAGE_ID and canonical binds, audited, started, proven to
|
|
822
|
+
be the only running Butler, readiness-checked, then stopped and removed only
|
|
823
|
+
after its image is rechecked. Only then is fresh canonical production created,
|
|
824
|
+
audited, started, readiness-checked, and placed in bare production autostart.
|
|
825
|
+
Failure removes only partial target-image staging/production containers,
|
|
826
|
+
quarantines the exact legacy container without deletion or restart, leaves
|
|
827
|
+
autostart disabled, and propagates the original status.
|
|
828
|
+
For a normal update, preflight the canonical topology before any autostart or
|
|
829
|
+
container mutation. Production must be the only running Butler poller;
|
|
830
|
+
staging must be absent; rollback may be absent or one stopped container with
|
|
831
|
+
the exact production image. A stopped legacy-evidence container is preserved.
|
|
832
|
+
Disable every Butler name in Unraid's array-autostart file and verify that
|
|
833
|
+
result before stopping production. First resolve and validate the exact image
|
|
834
|
+
ID of the known-good production container while it is still running, so a
|
|
835
|
+
lookup failure cannot strand a renamed container:
|
|
836
|
+
ROLLBACK_IMAGE_ID=$(docker inspect --format '{{.Image}}' ouro-butler)
|
|
837
|
+
validate_exact_image_id "$ROLLBACK_IMAGE_ID"
|
|
838
|
+
if assert_update_topology "$ROLLBACK_IMAGE_ID"; then
|
|
839
|
+
:
|
|
840
|
+
else
|
|
841
|
+
UPDATE_PREFLIGHT_STATUS=$?
|
|
842
|
+
(exit "$UPDATE_PREFLIGHT_STATUS")
|
|
843
|
+
fi
|
|
844
|
+
audit_effective ouro-butler "$ROLLBACK_IMAGE_ID"
|
|
845
|
+
Only after that topology gate, stage copies of the packaged template and
|
|
846
|
+
runtime policy at these paths:
|
|
847
|
+
STAGED_TEMPLATE=/mnt/user/appdata/ouro-butler/staging/sanctuary.xml
|
|
848
|
+
STAGED_RUNTIME_POLICY=/mnt/user/appdata/ouro-butler/staging/container-runtime.json
|
|
849
|
+
Replace sha256:REPLACE_WITH_EXACT_LOCAL_IMAGE_ID in the staged template at
|
|
850
|
+
$STAGED_TEMPLATE with exactly $IMAGE_ID. Before docker create, run the
|
|
851
|
+
packaged auditor from that exact image ID with both staged inputs mounted
|
|
852
|
+
read-only:
|
|
853
|
+
docker run --rm --pull=never --network=none \
|
|
854
|
+
--entrypoint /opt/ouro/deploy/unraid/audit-container-spec.sh \
|
|
855
|
+
--mount "type=bind,src=$STAGED_TEMPLATE,dst=/audit/sanctuary.xml,readonly" \
|
|
856
|
+
--mount "type=bind,src=$STAGED_RUNTIME_POLICY,dst=/audit/container-runtime.json,readonly" \
|
|
857
|
+
"$IMAGE_ID" --template /audit/sanctuary.xml --runtime-policy /audit/container-runtime.json --expected-image "$IMAGE_ID"
|
|
858
|
+
Guard the atomic autostart disable separately. If it fails, production has not
|
|
859
|
+
been touched and the captured status is propagated:
|
|
860
|
+
if disable_butler_autostart; then
|
|
861
|
+
:
|
|
862
|
+
else
|
|
863
|
+
AUTOSTART_DISABLE_STATUS=$?
|
|
864
|
+
(exit "$AUTOSTART_DISABLE_STATUS")
|
|
865
|
+
fi
|
|
866
|
+
Define the stale-rollback cleanup used by the preparation guard:
|
|
867
|
+
remove_stopped_rollback_if_present() {
|
|
868
|
+
EXPECTED_STALE_ROLLBACK_IMAGE_ID=$1
|
|
869
|
+
ROLLBACK_CONTAINER_NAMES=$(docker container ls -a --format '{{.Names}}') || return $?
|
|
870
|
+
case "
|
|
871
|
+
$ROLLBACK_CONTAINER_NAMES
|
|
872
|
+
" in
|
|
873
|
+
*"
|
|
874
|
+
ouro-butler-rollback
|
|
875
|
+
"*)
|
|
876
|
+
ROLLBACK_RUNNING=$(docker inspect --format '{{.State.Running}}' ouro-butler-rollback) || return $?
|
|
877
|
+
test "$ROLLBACK_RUNNING" = false || return $?
|
|
878
|
+
CURRENT_STALE_ROLLBACK_IMAGE_ID=$(docker inspect --format '{{.Image}}' ouro-butler-rollback) || return $?
|
|
879
|
+
test "$CURRENT_STALE_ROLLBACK_IMAGE_ID" = "$EXPECTED_STALE_ROLLBACK_IMAGE_ID" || return $?
|
|
880
|
+
docker rm ouro-butler-rollback || return $?
|
|
881
|
+
;;
|
|
882
|
+
esac
|
|
883
|
+
}
|
|
884
|
+
Stop production, remove only a stopped stale rollback, rename the known-good
|
|
885
|
+
container, and verify it remains stopped in one explicit preparation guard:
|
|
886
|
+
if docker stop ouro-butler \
|
|
887
|
+
&& remove_stopped_rollback_if_present "$ROLLBACK_IMAGE_ID" \
|
|
888
|
+
&& docker rename ouro-butler ouro-butler-rollback \
|
|
889
|
+
&& test "$(docker inspect --format '{{.State.Running}}' ouro-butler-rollback)" = false; then
|
|
890
|
+
:
|
|
891
|
+
else
|
|
892
|
+
PRODUCTION_PREPARATION_STATUS=$?
|
|
893
|
+
if docker container inspect ouro-butler >/dev/null 2>&1; then
|
|
894
|
+
if docker container inspect ouro-butler-rollback >/dev/null 2>&1; then
|
|
895
|
+
docker stop ouro-butler-rollback >/dev/null 2>&1 || true
|
|
896
|
+
CURRENT_ROLLBACK_IMAGE_ID=$(docker inspect --format '{{.Image}}' ouro-butler-rollback)
|
|
897
|
+
test "$CURRENT_ROLLBACK_IMAGE_ID" = "$ROLLBACK_IMAGE_ID"
|
|
898
|
+
docker rm --force ouro-butler-rollback >/dev/null 2>&1 || true
|
|
899
|
+
fi
|
|
900
|
+
! docker container inspect ouro-butler-rollback >/dev/null 2>&1
|
|
901
|
+
audit_effective ouro-butler "$ROLLBACK_IMAGE_ID"
|
|
902
|
+
docker start ouro-butler
|
|
903
|
+
assert_only_running_butler ouro-butler
|
|
904
|
+
wait_butler_ready ouro-butler
|
|
905
|
+
enable_butler_autostart
|
|
906
|
+
elif docker container inspect ouro-butler-rollback >/dev/null 2>&1; then
|
|
907
|
+
docker stop ouro-butler-rollback >/dev/null 2>&1 || true
|
|
908
|
+
test "$(docker inspect --format '{{.Image}}' ouro-butler-rollback)" = "$ROLLBACK_IMAGE_ID"
|
|
909
|
+
docker rename ouro-butler-rollback ouro-butler
|
|
910
|
+
audit_effective ouro-butler "$ROLLBACK_IMAGE_ID"
|
|
911
|
+
docker start ouro-butler
|
|
912
|
+
assert_only_running_butler ouro-butler
|
|
913
|
+
wait_butler_ready ouro-butler
|
|
914
|
+
enable_butler_autostart
|
|
915
|
+
fi
|
|
916
|
+
(exit "$PRODUCTION_PREPARATION_STATUS")
|
|
917
|
+
fi
|
|
918
|
+
Preparation failure therefore either restores the still-named exact production
|
|
919
|
+
after removing any stale rollback, or renames the exact stopped rollback back;
|
|
920
|
+
both recoveries re-audit, start, bounded-wait, atomically restore production-only
|
|
921
|
+
autostart, and propagate the original failure. If neither exact container can
|
|
922
|
+
be found, the failure propagates with Butler autostart disabled.
|
|
923
|
+
Put the entire post-rename staging phase in one explicit conditional so
|
|
924
|
+
`set -eu` cannot bypass rollback at the create, effective-audit, start, or
|
|
925
|
+
bounded-readiness boundary. Staging uses the exact image ID with no command,
|
|
926
|
+
environment, port, device, capability, privilege, or extra mount override.
|
|
927
|
+
A passing staging container is stopped and removed inside the same condition,
|
|
928
|
+
completing the poller handoff before production creation:
|
|
929
|
+
if docker create --name ouro-butler-staging --network host --restart unless-stopped --user 10001:10001 \
|
|
930
|
+
--mount "type=bind,src=/mnt/user/appdata/ouro-butler/runtime/.ouro-cli,dst=/home/ouro/.ouro-cli" \
|
|
931
|
+
--mount "type=bind,src=/mnt/user/appdata/ouro-butler/agent/sanctuary.ouro,dst=/home/ouro/AgentBundles/sanctuary.ouro" \
|
|
932
|
+
"$IMAGE_ID" \
|
|
933
|
+
&& audit_effective ouro-butler-staging "$IMAGE_ID" \
|
|
934
|
+
&& docker start ouro-butler-staging \
|
|
935
|
+
&& assert_only_running_butler ouro-butler-staging \
|
|
936
|
+
&& wait_butler_ready ouro-butler-staging \
|
|
937
|
+
&& docker stop ouro-butler-staging \
|
|
938
|
+
&& docker rm ouro-butler-staging; then
|
|
939
|
+
:
|
|
940
|
+
else
|
|
941
|
+
STAGING_ACTIVATION_STATUS=$?
|
|
942
|
+
if docker container inspect ouro-butler-staging >/dev/null 2>&1; then
|
|
943
|
+
docker stop ouro-butler-staging >/dev/null 2>&1 || true
|
|
944
|
+
PARTIAL_STAGING_IMAGE_ID=$(docker inspect --format '{{.Image}}' ouro-butler-staging)
|
|
945
|
+
test "$PARTIAL_STAGING_IMAGE_ID" = "$IMAGE_ID"
|
|
946
|
+
docker rm --force ouro-butler-staging >/dev/null 2>&1 || true
|
|
947
|
+
fi
|
|
948
|
+
! docker container inspect ouro-butler-staging >/dev/null 2>&1
|
|
949
|
+
CURRENT_ROLLBACK_IMAGE_ID=$(docker inspect --format '{{.Image}}' ouro-butler-rollback)
|
|
950
|
+
test "$CURRENT_ROLLBACK_IMAGE_ID" = "$ROLLBACK_IMAGE_ID"
|
|
951
|
+
docker rename ouro-butler-rollback ouro-butler
|
|
952
|
+
audit_effective ouro-butler "$ROLLBACK_IMAGE_ID"
|
|
953
|
+
docker start ouro-butler
|
|
954
|
+
assert_only_running_butler ouro-butler
|
|
955
|
+
wait_butler_ready ouro-butler
|
|
956
|
+
enable_butler_autostart
|
|
957
|
+
(exit "$STAGING_ACTIVATION_STATUS")
|
|
958
|
+
fi
|
|
959
|
+
The failure arm safely handles staging that was never created, remains
|
|
960
|
+
stopped, is running, or exited: it force-removes any partial staging state,
|
|
961
|
+
verifies the name is absent, restores and re-audits the old production against
|
|
962
|
+
its exact pre-recorded image ID, starts and bounded-waits it, atomically
|
|
963
|
+
restores production-only autostart, and propagates the original failure.
|
|
964
|
+
At no point may production and staging run together against the same Telegram token.
|
|
965
|
+
Create and activate production from the same exact image ID and exact authority
|
|
966
|
+
in one explicit conditional so `set -eu` cannot exit before rollback. Only a
|
|
967
|
+
successful create, effective audit, start, stopped rollback assertion, and
|
|
968
|
+
bounded readiness wait may enable production autostart. Any failure captures
|
|
969
|
+
the activation status, safely removes a partially created new production if it
|
|
970
|
+
exists, restores the stopped rollback container, audits it against its exact
|
|
971
|
+
old image ID, proves it ready, atomically enables only production autostart,
|
|
972
|
+
and then propagates the original activation failure:
|
|
973
|
+
if docker create --name ouro-butler --network host --restart unless-stopped --user 10001:10001 \
|
|
974
|
+
--mount "type=bind,src=/mnt/user/appdata/ouro-butler/runtime/.ouro-cli,dst=/home/ouro/.ouro-cli" \
|
|
975
|
+
--mount "type=bind,src=/mnt/user/appdata/ouro-butler/agent/sanctuary.ouro,dst=/home/ouro/AgentBundles/sanctuary.ouro" \
|
|
976
|
+
"$IMAGE_ID" \
|
|
977
|
+
&& audit_effective ouro-butler "$IMAGE_ID" \
|
|
978
|
+
&& docker start ouro-butler \
|
|
979
|
+
&& assert_only_running_butler ouro-butler \
|
|
980
|
+
&& test "$(docker inspect --format '{{.State.Running}}' ouro-butler-rollback)" = false \
|
|
981
|
+
&& wait_butler_ready ouro-butler \
|
|
982
|
+
&& enable_butler_autostart; then
|
|
983
|
+
:
|
|
984
|
+
else
|
|
985
|
+
PRODUCTION_ACTIVATION_STATUS=$?
|
|
986
|
+
if docker container inspect ouro-butler >/dev/null 2>&1; then
|
|
987
|
+
docker stop ouro-butler >/dev/null 2>&1 || true
|
|
988
|
+
PARTIAL_PRODUCTION_IMAGE_ID=$(docker inspect --format '{{.Image}}' ouro-butler)
|
|
989
|
+
test "$PARTIAL_PRODUCTION_IMAGE_ID" = "$IMAGE_ID"
|
|
990
|
+
docker rm --force ouro-butler >/dev/null 2>&1 || true
|
|
991
|
+
fi
|
|
992
|
+
! docker container inspect ouro-butler >/dev/null 2>&1
|
|
993
|
+
CURRENT_ROLLBACK_IMAGE_ID=$(docker inspect --format '{{.Image}}' ouro-butler-rollback)
|
|
994
|
+
test "$CURRENT_ROLLBACK_IMAGE_ID" = "$ROLLBACK_IMAGE_ID"
|
|
995
|
+
docker rename ouro-butler-rollback ouro-butler
|
|
996
|
+
audit_effective ouro-butler "$ROLLBACK_IMAGE_ID"
|
|
997
|
+
docker start ouro-butler
|
|
998
|
+
assert_only_running_butler ouro-butler
|
|
999
|
+
wait_butler_ready ouro-butler
|
|
1000
|
+
enable_butler_autostart
|
|
1001
|
+
(exit "$PRODUCTION_ACTIVATION_STATUS")
|
|
1002
|
+
fi
|
|
1003
|
+
Keep ouro-butler-rollback stopped until the new production container is proven
|
|
1004
|
+
or the explicit rollback arm restores it.
|
|
1005
|
+
Never create a container from the mutable lookup tag.
|
|
1006
|
+
|
|
1007
|
+
Backup:
|
|
1008
|
+
Stop ouro-butler, then snapshot both of these directories together:
|
|
1009
|
+
/mnt/user/appdata/ouro-butler/runtime/.ouro-cli
|
|
1010
|
+
/mnt/user/appdata/ouro-butler/agent/sanctuary.ouro
|
|
1011
|
+
A routine backup must not contain container-credentials.json or
|
|
1012
|
+
container-credentials.json.consuming. If either exists, credential migration
|
|
1013
|
+
is pending or failed and must be reconciled before taking the backup.
|
|
1014
|
+
|
|
1015
|
+
Restore:
|
|
1016
|
+
Set BACKUP_ROOT to the exact verified snapshot containing `runtime/.ouro-cli`
|
|
1017
|
+
and `agent/sanctuary.ouro`, and set IMAGE_ID to its recorded local image ID.
|
|
1018
|
+
Before any autostart, root, or container mutation, run the nounset-safe input,
|
|
1019
|
+
backup-root, image, and topology preflight. It requires a nonempty canonical
|
|
1020
|
+
absolute BACKUP_ROOT (not /), both exact required directories, an exact local
|
|
1021
|
+
sha256 image ID, canonical production as the only running Butler poller, no
|
|
1022
|
+
staging or rollback, and at most one exact stopped legacy-evidence container:
|
|
1023
|
+
if assert_restore_preflight; then
|
|
1024
|
+
:
|
|
1025
|
+
else
|
|
1026
|
+
RESTORE_PREFLIGHT_STATUS=$?
|
|
1027
|
+
(exit "$RESTORE_PREFLIGHT_STATUS")
|
|
1028
|
+
fi
|
|
1029
|
+
Guard the atomic autostart disable before stopping or removing any Butler
|
|
1030
|
+
container. Failure propagates while the existing production remains untouched:
|
|
1031
|
+
if disable_butler_autostart; then
|
|
1032
|
+
:
|
|
1033
|
+
else
|
|
1034
|
+
RESTORE_AUTOSTART_DISABLE_STATUS=$?
|
|
1035
|
+
(exit "$RESTORE_AUTOSTART_DISABLE_STATUS")
|
|
1036
|
+
fi
|
|
1037
|
+
Stop and remove only ouro-butler, restore both roots without stale files,
|
|
1038
|
+
restore exact ownership, validate the image, and create/audit/start/bounded-wait
|
|
1039
|
+
the restored production inside one explicit condition. The initial tolerant
|
|
1040
|
+
stop plus inspected force-removal safely handles an already absent or stopped
|
|
1041
|
+
container:
|
|
1042
|
+
if { docker stop ouro-butler >/dev/null 2>&1 || true; } \
|
|
1043
|
+
&& {
|
|
1044
|
+
if docker container inspect ouro-butler >/dev/null 2>&1; then
|
|
1045
|
+
docker rm --force ouro-butler
|
|
1046
|
+
else
|
|
1047
|
+
:
|
|
1048
|
+
fi
|
|
1049
|
+
} \
|
|
1050
|
+
&& ! docker container inspect ouro-butler >/dev/null 2>&1 \
|
|
1051
|
+
&& rsync -a --delete "$BACKUP_ROOT/runtime/.ouro-cli/" /mnt/user/appdata/ouro-butler/runtime/.ouro-cli/ \
|
|
1052
|
+
&& rsync -a --delete "$BACKUP_ROOT/agent/sanctuary.ouro/" /mnt/user/appdata/ouro-butler/agent/sanctuary.ouro/ \
|
|
1053
|
+
&& chown -R 10001:10001 /mnt/user/appdata/ouro-butler/runtime/.ouro-cli /mnt/user/appdata/ouro-butler/agent/sanctuary.ouro \
|
|
1054
|
+
&& validate_sanctuary_roots /mnt/user/appdata/ouro-butler/runtime/.ouro-cli /mnt/user/appdata/ouro-butler/agent/sanctuary.ouro \
|
|
1055
|
+
&& docker image inspect "$IMAGE_ID" >/dev/null \
|
|
1056
|
+
&& docker create --name ouro-butler --network host --restart unless-stopped --user 10001:10001 \
|
|
1057
|
+
--mount "type=bind,src=/mnt/user/appdata/ouro-butler/runtime/.ouro-cli,dst=/home/ouro/.ouro-cli" \
|
|
1058
|
+
--mount "type=bind,src=/mnt/user/appdata/ouro-butler/agent/sanctuary.ouro,dst=/home/ouro/AgentBundles/sanctuary.ouro" \
|
|
1059
|
+
"$IMAGE_ID" \
|
|
1060
|
+
&& audit_effective ouro-butler "$IMAGE_ID" \
|
|
1061
|
+
&& docker start ouro-butler \
|
|
1062
|
+
&& assert_only_running_butler ouro-butler \
|
|
1063
|
+
&& wait_butler_ready ouro-butler \
|
|
1064
|
+
&& enable_butler_autostart; then
|
|
1065
|
+
:
|
|
1066
|
+
else
|
|
1067
|
+
RESTORE_ACTIVATION_STATUS=$?
|
|
1068
|
+
if docker container inspect ouro-butler >/dev/null 2>&1; then
|
|
1069
|
+
docker stop ouro-butler >/dev/null 2>&1 || true
|
|
1070
|
+
PARTIAL_RESTORE_IMAGE_ID=$(docker inspect --format '{{.Image}}' ouro-butler)
|
|
1071
|
+
test "$PARTIAL_RESTORE_IMAGE_ID" = "$IMAGE_ID"
|
|
1072
|
+
docker rm --force ouro-butler >/dev/null 2>&1 || true
|
|
1073
|
+
fi
|
|
1074
|
+
! docker container inspect ouro-butler >/dev/null 2>&1
|
|
1075
|
+
(exit "$RESTORE_ACTIVATION_STATUS")
|
|
1076
|
+
fi
|
|
1077
|
+
A restore has no retained old container or pre-restore data root to roll back
|
|
1078
|
+
to. Any stop/remove, data replacement, ownership, image validation, create,
|
|
1079
|
+
audit, start, or readiness failure therefore reaches the same cleanup arm,
|
|
1080
|
+
leaves all Butler autostart entries disabled, and propagates the captured
|
|
1081
|
+
failure for operator repair or a verified restore retry.
|
|
1082
|
+
|
|
1083
|
+
Credential recovery:
|
|
1084
|
+
The one canonical Telegram identity is display name `Mendelow Cloud Butler`,
|
|
1085
|
+
username `MendelowCloudButlerBot`, numeric bot ID `8541786263`. Treat any
|
|
1086
|
+
different display name, username, numeric ID, or fallback handle as a hard
|
|
1087
|
+
preflight failure; do not start polling or send a test message.
|
|
1088
|
+
Run `bootstrap_sanctuary_vault "$IMAGE_ID"` interactively before installing
|
|
1089
|
+
credentials. It uses only fresh `--rm` containers from that exact image as
|
|
1090
|
+
UID/GID 10001 with the canonical two binds; create/unlock is the sole `-it`
|
|
1091
|
+
action so the master secret remains on the hidden terminal prompt.
|
|
1092
|
+
Its first read-only `vault status` is authoritative: it runs `vault create`
|
|
1093
|
+
only when the locator is absent, runs `vault unlock` only when the locator
|
|
1094
|
+
exists but local unlock is missing, and does not prompt when local unlock is
|
|
1095
|
+
already available. It then requires the configured locator, available local
|
|
1096
|
+
unlock, and successful auth verification. Never guess from a failed status
|
|
1097
|
+
command.
|
|
1098
|
+
Initial legacy adoption passes the exact legacy envelope path as the helper's
|
|
1099
|
+
second argument. After vault availability, the helper validates and atomically
|
|
1100
|
+
copies that envelope into the canonical runtime root, imports it with a fresh
|
|
1101
|
+
same-image one-shot container, and requires both canonical source and claim to
|
|
1102
|
+
be absent before provider readiness. The exact legacy source remains untouched
|
|
1103
|
+
as rollback evidence until canonical acceptance completes.
|
|
1104
|
+
Restore or unlock the Sanctuary agent vault, then run provider refresh.
|
|
1105
|
+
/mnt/user/appdata/ouro-butler/runtime/.ouro-cli/container-credentials.json
|
|
1106
|
+
exists only for a one-time migration: if
|
|
1107
|
+
used, install it atomically as root with ownership 10001:10001 and mode 0600.
|
|
1108
|
+
Startup atomically claims it as container-credentials.json.consuming and
|
|
1109
|
+
writes every credential class into the unlocked Sanctuary vault before deleting the claimed envelope.
|
|
1110
|
+
Only then does it refresh the daemon's in-memory credentials.
|
|
1111
|
+
If validation or any vault write fails, startup fails closed and preserves
|
|
1112
|
+
container-credentials.json.consuming for the next startup to reconcile.
|
|
1113
|
+
Restore or create/unlock the configured agent vault, then restart the same
|
|
1114
|
+
reviewed image and let it retry the preserved claim. If both the source and
|
|
1115
|
+
claimed envelope exist and they are safe regular 0600 files owned by the
|
|
1116
|
+
runtime user, startup resumes automatically only when they are byte-for-byte identical:
|
|
1117
|
+
it durably removes the redundant unclaimed source and continues the existing claim.
|
|
1118
|
+
If they differ, the repair is human-required: stop the Butler, securely compare and quarantine
|
|
1119
|
+
the two envelopes, then restore exactly one reviewed envelope at the source path.
|
|
1120
|
+
Never print either envelope's contents or place them in logs or command arguments.
|
|
1121
|
+
After successful import, both files
|
|
1122
|
+
are absent and the vault is the only credential source of truth.
|
|
1123
|
+
Never print or place credential values in logs, templates, command arguments,
|
|
1124
|
+
backups, or this runbook.
|
|
1125
|
+
|
|
1126
|
+
Packaged deployment-target containment gates:
|
|
1127
|
+
Unit 16 is fixed to the `staging` profile and therefore targets only
|
|
1128
|
+
`ouro-butler-staging`; it does not require `ouro-butler` to exist. Before the
|
|
1129
|
+
broker starts, the packaged deployment auditor captures all present canonical
|
|
1130
|
+
production/staging/rollback identities in one Docker inspect, verifies the
|
|
1131
|
+
target image, `unless-stopped`, host networking, matching GraphQL and durable
|
|
1132
|
+
file autostart identity/state for every present canonical container,
|
|
1133
|
+
and exactly one running Butler, then repeats the canonical snapshot to reject
|
|
1134
|
+
races. It binds the target PID and exact Docker cgroup-v2 path to the inspected
|
|
1135
|
+
container ID; Unit 16 carries that immutable ID into every launcher and broker
|
|
1136
|
+
Docker operation and binds it to the GraphQL PrefixedID suffix. It scans every
|
|
1137
|
+
cgroup process and requires stable before/after process, owned-socket, and
|
|
1138
|
+
listener inventories. Between the two canonical topology captures, it verifies
|
|
1139
|
+
the exact immutable-ID target is running and unpaused, pauses that ID without
|
|
1140
|
+
changing restart or autostart state, and performs every cgroup, all-thread
|
|
1141
|
+
descriptor, TCP, UDP, and Unix observation inside that one quiesced window,
|
|
1142
|
+
including two matching complete terminal snapshots; nonconvergence fails
|
|
1143
|
+
closed after eight attempts. It always makes bounded exact-ID unpause attempts,
|
|
1144
|
+
verifies the same ID and PID resumed their original running, unpaused state,
|
|
1145
|
+
and only then performs the final full-profile topology capture. It
|
|
1146
|
+
rejects every owned UDP listener and every externally reachable owned TCP listener. Only loopback
|
|
1147
|
+
Mailbox port 6876 plus stream-listening endpoints at the fixed daemon and
|
|
1148
|
+
acceptance Unix control paths are permitted; all other named Unix endpoint
|
|
1149
|
+
types (including datagrams) fail closed. Inherited descriptors for the same
|
|
1150
|
+
socket inode are deduplicated, while unknown loopback ports, wildcard/host-address
|
|
1151
|
+
listeners, process/socket/listener drift, or ambiguous ownership fail closed.
|
|
1152
|
+
Unit 18 uses the separately packaged fixed final command, after rollback has
|
|
1153
|
+
been retained stopped:
|
|
1154
|
+
UNIT18_TARGET_TMP=$(mktemp /run/sanctuary-unit18-target-audit.sh.XXXXXX)
|
|
1155
|
+
/usr/bin/timeout -s KILL 20 /usr/bin/docker run --rm --pull=never --network none \
|
|
1156
|
+
--entrypoint /bin/cat "$IMAGE_ID" /opt/ouro/deploy/unraid/sanctuary-unit18-target-audit.sh >"$UNIT18_TARGET_TMP"
|
|
1157
|
+
chmod 0500 "$UNIT18_TARGET_TMP"
|
|
1158
|
+
"$UNIT18_TARGET_TMP" "$IMAGE_ID"
|
|
1159
|
+
rm -f -- "$UNIT18_TARGET_TMP"
|
|
1160
|
+
Neither packaged command accepts a container name or an open-ended profile.
|
|
1161
|
+
|
|
1162
|
+
Packaged Unit 16 acceptance execution:
|
|
1163
|
+
Use only the launcher packaged in the exact reviewed image. Install it without
|
|
1164
|
+
network access, then create the two private roots with the runtime UID/GID:
|
|
1165
|
+
UNIT16_ROOT=/mnt/user/appdata/ouro-butler/acceptance
|
|
1166
|
+
install -d -m 0700 -o 10001 -g 10001 "$UNIT16_ROOT/configs" "$UNIT16_ROOT/evidence"
|
|
1167
|
+
UNIT16_LAUNCHER_TMP=$(mktemp "$UNIT16_ROOT/sanctuary-unit16-run.sh.tmp.XXXXXX")
|
|
1168
|
+
/usr/bin/timeout -s KILL 20 /usr/bin/docker run --rm --pull=never --network none \
|
|
1169
|
+
--entrypoint /bin/cat "$IMAGE_ID" /opt/ouro/deploy/unraid/sanctuary-unit16-run.sh >"$UNIT16_LAUNCHER_TMP"
|
|
1170
|
+
install -m 0755 -o root -g root "$UNIT16_LAUNCHER_TMP" "$UNIT16_ROOT/sanctuary-unit16-run.sh"
|
|
1171
|
+
rm -f -- "$UNIT16_LAUNCHER_TMP"
|
|
1172
|
+
Never hand-author a Unit 16 config. Materialize it from the exact image, then
|
|
1173
|
+
execute it in the order below. Before every execution the launcher regenerates
|
|
1174
|
+
the config from the packaged fixed contract and requires byte-for-byte equality.
|
|
1175
|
+
The cursor snapshot is deliberately materialized and executed twice around the
|
|
1176
|
+
live scenario. Telegram bootstrap reads the new bot token from host file
|
|
1177
|
+
descriptor 3; callback injection reads the reviewed saved callback-update JSON
|
|
1178
|
+
from the same descriptor. The launcher explicitly maps host fd 3 to Docker
|
|
1179
|
+
stdin and then to in-container fd 3 only for those two commands. Neither value
|
|
1180
|
+
belongs in argv, shell history, a config file, or an unrelated command's stdin.
|
|
1181
|
+
Define this Bash helper in the root shell. It disables terminal echo while
|
|
1182
|
+
reading the token, opens an anonymous descriptor for the launcher, and unsets
|
|
1183
|
+
the short-lived shell value on either launcher success or failure:
|
|
1184
|
+
run_unit16_telegram_bootstrap() {
|
|
1185
|
+
local UNIT16_BOT_TOKEN UNIT16_BOT_STATUS
|
|
1186
|
+
printf 'Telegram bot token: ' >&2
|
|
1187
|
+
IFS= read -r -s UNIT16_BOT_TOKEN || return $?
|
|
1188
|
+
printf '\n' >&2
|
|
1189
|
+
if "$UNIT16_ROOT/sanctuary-unit16-run.sh" "$IMAGE_ID" telegram-bootstrap telegram-bootstrap.json \
|
|
1190
|
+
3< <(printf '%s\n' "$UNIT16_BOT_TOKEN"); then
|
|
1191
|
+
UNIT16_BOT_STATUS=0
|
|
1192
|
+
else
|
|
1193
|
+
UNIT16_BOT_STATUS=$?
|
|
1194
|
+
fi
|
|
1195
|
+
unset UNIT16_BOT_TOKEN
|
|
1196
|
+
return "$UNIT16_BOT_STATUS"
|
|
1197
|
+
}
|
|
1198
|
+
Stage the reviewed callback JSON at the fixed path below in the root-owned
|
|
1199
|
+
tmpfs inbox, then use this single fail-closed helper. It opens the input once,
|
|
1200
|
+
validates the opened descriptor and its original path refer to the same
|
|
1201
|
+
root-owned mode-0600 regular file, and invokes the launcher only afterward.
|
|
1202
|
+
Success overwrites, fsyncs, and unlinks the raw input. Any failure allocates a
|
|
1203
|
+
collision-free quarantine file atomically, copies and fsyncs the input into it,
|
|
1204
|
+
locks it to mode 000, then overwrites and removes the tmpfs source;
|
|
1205
|
+
no raw callback update remains loose in `/root` or the inbox.
|
|
1206
|
+
UNIT16_CALLBACK_INBOX=/run/ouro-unit16-callback-input
|
|
1207
|
+
UNIT16_CALLBACK_FILE=$UNIT16_CALLBACK_INBOX/callback-update.json
|
|
1208
|
+
UNIT16_CALLBACK_QUARANTINE_ROOT=$UNIT16_ROOT/callback-quarantine
|
|
1209
|
+
install -d -m 0700 -o root -g root "$UNIT16_CALLBACK_INBOX" "$UNIT16_CALLBACK_QUARANTINE_ROOT"
|
|
1210
|
+
run_unit16_callback_inject() {
|
|
1211
|
+
(
|
|
1212
|
+
UNIT16_CALLBACK_VALIDATED=no
|
|
1213
|
+
UNIT16_CALLBACK_STATUS=1
|
|
1214
|
+
unit16_callback_cleanup() {
|
|
1215
|
+
UNIT16_CALLBACK_STATUS=$?
|
|
1216
|
+
trap - EXIT HUP INT TERM
|
|
1217
|
+
if test -e "$UNIT16_CALLBACK_FILE" || test -L "$UNIT16_CALLBACK_FILE"; then
|
|
1218
|
+
if test "$UNIT16_CALLBACK_STATUS" -eq 0 && test "$UNIT16_CALLBACK_VALIDATED" = yes; then
|
|
1219
|
+
if ! truncate -s 0 /proc/self/fd/3 || ! sync -f /proc/self/fd/3 \
|
|
1220
|
+
|| ! rm -f -- "$UNIT16_CALLBACK_FILE" || ! sync -f "$UNIT16_CALLBACK_INBOX"; then
|
|
1221
|
+
UNIT16_CALLBACK_STATUS=1
|
|
1222
|
+
fi
|
|
1223
|
+
elif test -f "$UNIT16_CALLBACK_FILE" && test ! -L "$UNIT16_CALLBACK_FILE"; then
|
|
1224
|
+
UNIT16_CALLBACK_QUARANTINE_FILE=$(mktemp "$UNIT16_CALLBACK_QUARANTINE_ROOT/failed.XXXXXX") || UNIT16_CALLBACK_QUARANTINE_FILE=
|
|
1225
|
+
if test -n "$UNIT16_CALLBACK_QUARANTINE_FILE" \
|
|
1226
|
+
&& chmod 0600 "$UNIT16_CALLBACK_QUARANTINE_FILE" \
|
|
1227
|
+
&& cp -- "$UNIT16_CALLBACK_FILE" "$UNIT16_CALLBACK_QUARANTINE_FILE" \
|
|
1228
|
+
&& sync -f "$UNIT16_CALLBACK_QUARANTINE_FILE" \
|
|
1229
|
+
&& chmod 000 "$UNIT16_CALLBACK_QUARANTINE_FILE" \
|
|
1230
|
+
&& sync -f "$UNIT16_CALLBACK_QUARANTINE_ROOT"; then
|
|
1231
|
+
:
|
|
1232
|
+
else
|
|
1233
|
+
test -z "${UNIT16_CALLBACK_QUARANTINE_FILE-}" || rm -f -- "$UNIT16_CALLBACK_QUARANTINE_FILE"
|
|
1234
|
+
UNIT16_CALLBACK_STATUS=1
|
|
1235
|
+
fi
|
|
1236
|
+
if ! truncate -s 0 "$UNIT16_CALLBACK_FILE" || ! sync -f "$UNIT16_CALLBACK_FILE" \
|
|
1237
|
+
|| ! rm -f -- "$UNIT16_CALLBACK_FILE" || ! sync -f "$UNIT16_CALLBACK_INBOX"; then
|
|
1238
|
+
UNIT16_CALLBACK_STATUS=1
|
|
1239
|
+
fi
|
|
1240
|
+
else
|
|
1241
|
+
rm -f -- "$UNIT16_CALLBACK_FILE" || UNIT16_CALLBACK_STATUS=1
|
|
1242
|
+
sync -f "$UNIT16_CALLBACK_INBOX" || UNIT16_CALLBACK_STATUS=1
|
|
1243
|
+
fi
|
|
1244
|
+
fi
|
|
1245
|
+
exec 3<&-
|
|
1246
|
+
exit "$UNIT16_CALLBACK_STATUS"
|
|
1247
|
+
}
|
|
1248
|
+
trap unit16_callback_cleanup EXIT
|
|
1249
|
+
trap 'exit 129' HUP
|
|
1250
|
+
trap 'exit 130' INT
|
|
1251
|
+
trap 'exit 143' TERM
|
|
1252
|
+
test -d "$UNIT16_CALLBACK_INBOX" && test ! -L "$UNIT16_CALLBACK_INBOX" || exit 1
|
|
1253
|
+
test "$(stat -c '%F %u:%g %a' "$UNIT16_CALLBACK_INBOX")" = "directory 0:0 700" || exit 1
|
|
1254
|
+
test -d "$UNIT16_CALLBACK_QUARANTINE_ROOT" && test ! -L "$UNIT16_CALLBACK_QUARANTINE_ROOT" || exit 1
|
|
1255
|
+
test "$(stat -c '%F %u:%g %a' "$UNIT16_CALLBACK_QUARANTINE_ROOT")" = "directory 0:0 700" || exit 1
|
|
1256
|
+
test -f "$UNIT16_CALLBACK_FILE" && test ! -L "$UNIT16_CALLBACK_FILE" || exit 1
|
|
1257
|
+
exec 3<"$UNIT16_CALLBACK_FILE"
|
|
1258
|
+
test "$(stat -Lc '%F' /proc/self/fd/3)" = "regular file" || exit 1
|
|
1259
|
+
test "$(stat -c '%d:%i' "$UNIT16_CALLBACK_FILE")" = "$(stat -Lc '%d:%i' /proc/self/fd/3)" || exit 1
|
|
1260
|
+
UNIT16_CALLBACK_VALIDATED=yes
|
|
1261
|
+
test "$(stat -Lc '%F %u:%g %a' /proc/self/fd/3)" = "regular file 0:0 600" || exit 1
|
|
1262
|
+
"$UNIT16_ROOT/sanctuary-unit16-run.sh" "$IMAGE_ID" callback-inject callback-inject.json 3<&3
|
|
1263
|
+
)
|
|
1264
|
+
}
|
|
1265
|
+
"$UNIT16_ROOT/sanctuary-unit16-run.sh" "$IMAGE_ID" materialize telegram-bootstrap
|
|
1266
|
+
run_unit16_telegram_bootstrap
|
|
1267
|
+
"$UNIT16_ROOT/sanctuary-unit16-run.sh" "$IMAGE_ID" materialize cursor-snapshot before
|
|
1268
|
+
"$UNIT16_ROOT/sanctuary-unit16-run.sh" "$IMAGE_ID" cursor-snapshot cursor-snapshot.json
|
|
1269
|
+
# Perform the live scenario whose cursor movement is being measured.
|
|
1270
|
+
"$UNIT16_ROOT/sanctuary-unit16-run.sh" "$IMAGE_ID" materialize cursor-snapshot after
|
|
1271
|
+
"$UNIT16_ROOT/sanctuary-unit16-run.sh" "$IMAGE_ID" cursor-snapshot cursor-snapshot.json
|
|
1272
|
+
"$UNIT16_ROOT/sanctuary-unit16-run.sh" "$IMAGE_ID" materialize cursor-delta
|
|
1273
|
+
"$UNIT16_ROOT/sanctuary-unit16-run.sh" "$IMAGE_ID" cursor-delta cursor-delta.json
|
|
1274
|
+
"$UNIT16_ROOT/sanctuary-unit16-run.sh" "$IMAGE_ID" materialize callback-inject
|
|
1275
|
+
run_unit16_callback_inject
|
|
1276
|
+
"$UNIT16_ROOT/sanctuary-unit16-run.sh" "$IMAGE_ID" materialize unraid-key-rotate
|
|
1277
|
+
"$UNIT16_ROOT/sanctuary-unit16-run.sh" "$IMAGE_ID" unraid-key-rotate unraid-key-rotate.json
|
|
1278
|
+
"$UNIT16_ROOT/sanctuary-unit16-run.sh" "$IMAGE_ID" materialize reboot-request
|
|
1279
|
+
"$UNIT16_ROOT/sanctuary-unit16-run.sh" "$IMAGE_ID" reboot-request reboot-request.json
|
|
1280
|
+
# The preceding command captures and seals preflight evidence before it asks
|
|
1281
|
+
# the broker to stage the reboot, then seals the requested-phase evidence and
|
|
1282
|
+
# fsyncs the requested checkpoint before invoking the host reboot. Reconnect
|
|
1283
|
+
# only after Unraid and Docker are ready.
|
|
1284
|
+
"$UNIT16_ROOT/sanctuary-unit16-run.sh" "$IMAGE_ID" materialize reboot-resume
|
|
1285
|
+
"$UNIT16_ROOT/sanctuary-unit16-run.sh" "$IMAGE_ID" reboot-resume reboot-resume.json
|
|
1286
|
+
"$UNIT16_ROOT/sanctuary-unit16-run.sh" "$IMAGE_ID" materialize evidence-snapshot
|
|
1287
|
+
"$UNIT16_ROOT/sanctuary-unit16-run.sh" "$IMAGE_ID" evidence-snapshot evidence-snapshot.json
|
|
1288
|
+
# reboot-resume seals the changed boot identity and recovery milestones.
|
|
1289
|
+
# evidence-snapshot then runs the remaining scenarios sequentially with a
|
|
1290
|
+
# 72-minute aggregate bound; each completed scenario records provenance at
|
|
1291
|
+
# capture time and always clears its public gate, private marker, and receipt.
|
|
1292
|
+
"$UNIT16_ROOT/sanctuary-unit16-run.sh" "$IMAGE_ID" materialize evidence-bundle-index
|
|
1293
|
+
"$UNIT16_ROOT/sanctuary-unit16-run.sh" "$IMAGE_ID" evidence-bundle-index evidence-bundle-index.json
|
|
1294
|
+
"$UNIT16_ROOT/sanctuary-unit16-run.sh" "$IMAGE_ID" materialize evidence-bundle-verify
|
|
1295
|
+
"$UNIT16_ROOT/sanctuary-unit16-run.sh" "$IMAGE_ID" evidence-bundle-verify evidence-bundle-verify.json
|
|
1296
|
+
Each execution revalidates the immutable image and the production container's
|
|
1297
|
+
exact image ID. The main one-shot gets a read-only root filesystem, one writable
|
|
1298
|
+
evidence mount, narrowly selected runtime/bundle modes, and individual read-only
|
|
1299
|
+
image/container/health/boot fact files. Host-only operations cross an ephemeral
|
|
1300
|
+
root-owned private Unix socket (root:10001 mode 0660) to a root broker extracted
|
|
1301
|
+
from the same exact image. The broker accepts only fixed Unraid inventory/create/
|
|
1302
|
+
exact-revoke/rejection operations, exact fixed-target snapshots, and a
|
|
1303
|
+
two-phase reboot reservation/final commit. Reservation drains queued owner
|
|
1304
|
+
mutations and rejects new ones; after the requested checkpoint is fsynced, the
|
|
1305
|
+
broker repeats the array/parity/mover/durable-health preflight and invokes the
|
|
1306
|
+
fixed host reboot itself exactly once. The Unit 16 broker inspects only the
|
|
1307
|
+
deployment profile's attested immutable container ID (staging is
|
|
1308
|
+
`ouro-butler-staging`), requires its immutable image ID, writes that exact typed/redacted
|
|
1309
|
+
snapshot before accepting requests, and exposes a nonnegative Docker restart
|
|
1310
|
+
count. Both initial and refreshed snapshots share the same exact schema. The
|
|
1311
|
+
broker derives `autostartExact` from both the Unraid GraphQL `autoStart` value
|
|
1312
|
+
and exactly one staging entry in `/var/lib/docker/unraid-autostart`, derives
|
|
1313
|
+
`updaterDisabled` from `/opt/ouro/container-runtime.json` inside the exact image,
|
|
1314
|
+
and derives `vaultUnlocked`/`manualAuthRequired` from a bounded live Sanctuary
|
|
1315
|
+
vault-status command only when its non-secret summary proves the required
|
|
1316
|
+
Telegram runtime fields and both configured provider records were freshly read.
|
|
1317
|
+
Scenario handles remain private to the scenario adapter. The main one-shot
|
|
1318
|
+
never receives the Docker socket, Unraid key directory, or a host-root mount.
|
|
1319
|
+
Telegram bootstrap additionally brackets its one-shot with a host-controlled
|
|
1320
|
+
poller quiescence guard: it verifies the exact healthy staging container,
|
|
1321
|
+
assumes recovery responsibility before attempting the stop, stops it with a
|
|
1322
|
+
30-second grace bound, proves it is stopped, and mounts a
|
|
1323
|
+
root-owned typed zero-poller fact. Its exit/signal trap restarts that same exact
|
|
1324
|
+
container and waits up to 120 seconds for healthy recovery on both success and
|
|
1325
|
+
failure. It never reads or changes Unraid autostart configuration. Every command
|
|
1326
|
+
also receives a freshly generated, redacted typed container-inspect snapshot;
|
|
1327
|
+
raw container environment or credential values are never captured.
|
|
1328
|
+
Evidence-snapshot keeps the bundle mount read-only and overlays only the exact
|
|
1329
|
+
canonical `state/acceptance` directory as writable. It first stops the exact
|
|
1330
|
+
healthy staging container under recovery responsibility, then opens the
|
|
1331
|
+
directory with `O_DIRECTORY|O_NOFOLLOW` and bind-mounts from the inherited fd
|
|
1332
|
+
while no Sanctuary UID process is running. The launcher bind-pins that inode
|
|
1333
|
+
behind a root-only alias and back onto the canonical path against rename swaps,
|
|
1334
|
+
restarts the same exact image healthy, and compares the alias, canonical path,
|
|
1335
|
+
and staging container's inode before and after capture. Cleanup unmounts the
|
|
1336
|
+
canonical pin and then the alias. The staging daemon therefore sees the same
|
|
1337
|
+
inode used by the one-shot for marker correlation.
|
|
1338
|
+
|
|
1339
|
+
Audit and safety verification:
|
|
1340
|
+
Inspect AgentBundles/sanctuary.ouro/state/approvals for durable approval and
|
|
1341
|
+
restart-attempt receipts. Confirm no Docker socket/device/host-root mounts and
|
|
1342
|
+
no published ports with docker inspect. Confirm Config.Image equals the exact
|
|
1343
|
+
reviewed local image ID, not the build tag. The read key must reject Docker
|
|
1344
|
+
stop and restart mutations; only the separate write key may perform the one
|
|
1345
|
+
typed approved restart action.
|
|
1346
|
+
The packaged `unraid-key-rotate` command is the only canonical key-rotation
|
|
1347
|
+
authority. It inventories the two occupied canonical names by exact immutable
|
|
1348
|
+
ID, creates collision-safe `Butler RO Rotation <suffix>` and
|
|
1349
|
+
`Butler RW Rotation <suffix>` keys, stores and capability-probes both through
|
|
1350
|
+
the Sanctuary machine vault, and requires an exact four-key inventory. It then
|
|
1351
|
+
revokes both old IDs and proves each old credential receives a 401 or 403.
|
|
1352
|
+
Only after an exact inventory contains the temporary pair alone does it create,
|
|
1353
|
+
store, and probe the canonical `Butler RO` and `Butler RW` pair. It requires an
|
|
1354
|
+
exact four-key temporary-plus-canonical inventory, revokes and rejection-probes
|
|
1355
|
+
both temporary IDs, and finally requires exactly the canonical pair. Every
|
|
1356
|
+
unexpected key, duplicate, malformed permission set, role, name, inventory
|
|
1357
|
+
delta, or probe response fails closed.
|
|
1358
|
+
|
|
1359
|
+
Record only IDs, names, and permission sets in evidence; never raw key values.
|
|
1360
|
+
Raw credentials must not appear in argv, shell history, stdout, logs, or
|
|
1361
|
+
acceptance evidence. They may cross only the ephemeral private Unit 16 Unix
|
|
1362
|
+
socket in process memory. The narrow revocation-retry recovery records under
|
|
1363
|
+
`/mnt/user/appdata/ouro-butler/acceptance/revoked-key-proof` are the sole file
|
|
1364
|
+
exception: they are root-owned mode 0600 beneath a root-owned mode 0700
|
|
1365
|
+
directory, excluded from backup/evidence, streamed only on standard input to
|
|
1366
|
+
the bounded rejection probe, retained across failed retries, and durably
|
|
1367
|
+
deleted only after the exact authentication rejection is validated. Never
|
|
1368
|
+
substitute names for IDs when revoking keys.
|