gitea-image-prune: read the hub with the scoped token HUB_TOKEN, not HUB_PW (felhom 09 §3 decision 251)

Claude-Session: https://claude.ai/code/session_012qRErfCoiTkvDK9N5XHbzb
This commit is contained in:
admin committed 2026-10-15 13:08:49 +02:00
1 parent c9d5ed575c
commit 393af2292f
5 files changed
+29 -21

No files matched your search

+8
View File
@@ -2,6 +2,14 @@
All notable changes to the operator helper scripts. Newest on top. All notable changes to the operator helper scripts. Newest on top.
## 2026-10-15
### Changed — `gitea-image-prune.sh` reads the hub with its scoped token, not the operator password
- The in-use list reads the hub's Configuration page with `HUB_TOKEN` (felhom.eu `05` §17, hub ≥ 0.152.0, needs
`floor:read`), from env or `~/.config/credentials` via `read_credential.py`; sent through a 0600 header file, never on
a command line. `HUB_PW` is no longer read (`09` §3 decision 251). Live dry-run 2026-10-15: 6 in-use versions read,
deleted 0. `tests/test-prune-plan.sh` passes.
## 2026-10-01 ## 2026-10-01
### Changed — `gitea-image-prune.sh`: the retention rule (Felhom `09` §3 decision 62, R-750) ### Changed — `gitea-image-prune.sh`: the retention rule (Felhom `09` §3 decision 62, R-750)
+1 -1
View File
@@ -112,7 +112,7 @@ GITEA_TOKEN=… ./gitea-image-prune.sh
A prune keeps the **newest 20** versions of every package **plus every version in use**, whatever `--keep` or A prune keeps the **newest 20** versions of every package **plus every version in use**, whatever `--keep` or
`--older-than` says: the controller floor, the vouched golden, the vouched agent and its `min_agent` (read from the `--older-than` says: the controller floor, the vouched golden, the vouched agent and its `min_agent` (read from the
hub's operator Configuration page with `HUB_PW` — env, or `~/.config/credentials` through hub's operator Configuration page with the scoped hub token `HUB_TOKEN` (needs `floor:read`; hub ≥ 0.152.0) — env, or `~/.config/credentials` through
`felhom.eu/scripts/read_credential.py`), every `gitea.dooplex.hu/admin/<pkg>:<tag>` the vouched golden baked (its `felhom.eu/scripts/read_credential.py`), every `gitea.dooplex.hu/admin/<pkg>:<tag>` the vouched golden baked (its
`bake.log` under `felhom.eu/documentation/tests/`), and the hub image `felhom.eu/manifests/hub.yaml` runs. The dry-run `bake.log` under `felhom.eu/documentation/tests/`), and the hub image `felhom.eu/manifests/hub.yaml` runs. The dry-run
prints each kept version with its reason. **If any of these cannot be read, the prune refuses (exit 3).** Nothing runs prints each kept version with its reason. **If any of these cannot be read, the prune refuses (exit 3).** Nothing runs
+4 -10
View File
@@ -1,12 +1,6 @@
# REPORT — gitea-image-prune.sh gets the retention rule (2026-10-01) # REPORT — gitea-image-prune.sh uses the hub token (2026-10-15)
Felhom `09` §3 decision 62 (operator ruling, R-750). Full report: `felhom.eu/REPORT-calibre-name-and-prune-2026-10-01.md`. Felhom `09` §3 decision 251 (operator ruling 2026-10-15 11:38). Full report: `felhom.eu/REPORT-hub-tokens.md`.
- **Rule:** keep the newest 20 + every version in use (floor, vouched golden, vouched agent, `min_agent`, the golden's - The in-use list now reads the hub with the scoped token `HUB_TOKEN` (`floor:read`), not the operator password.
baked images, the running hub); refuse (exit 3) when the in-use list cannot be read; `--apply` only by a person. - Proof: `tests/test-prune-plan.sh` passes (rc 0); a live dry-run read 6 in-use versions through the token and deleted 0.
- **Test:** `tests/test-prune-plan.sh` — 7 checks pass; red-proof: the in-use check removed from `is_protected` → 3 fail
(the plan deletes 5 and lists 0.262.0).
- **Live dry-run, 2026-10-01 (nothing deleted):** in use — controller 0.285.0, golden 0.285.0, agent 0.138.0 and 0.131.0,
hub 0.126.0, felhom-samba 1.1.0. Would delete: felhom-controller 70 tags, felhom-hub 8; every other package nothing.
Evidence: `felhom.eu/documentation/audits/calibre-name-and-prune-2026-10-01/B/`.
- **No `--apply` was run.**
+15 -9
View File
@@ -19,7 +19,7 @@
# A prune keeps the newest 20 versions of each package (--keep defaults to 20 when # A prune keeps the newest 20 versions of each package (--keep defaults to 20 when
# pruning) PLUS every version in use, whatever --keep or --older-than says: # pruning) PLUS every version in use, whatever --keep or --older-than says:
# - the vouched golden, the controller floor, the vouched agent and its min_agent # - the vouched golden, the controller floor, the vouched agent and its min_agent
# (read from the hub's operator Configuration page — Basic auth, HUB_PW); # (read from the hub's operator Configuration page — the scoped token HUB_TOKEN, floor:read);
# - every gitea.dooplex.hu/admin/<pkg>:<tag> the vouched golden BAKED (its bake.log # - every gitea.dooplex.hu/admin/<pkg>:<tag> the vouched golden BAKED (its bake.log
# in felhom.eu/documentation/tests/golden-<version>-*/); # in felhom.eu/documentation/tests/golden-<version>-*/);
# - the hub image the GitOps manifest runs (felhom.eu/manifests/hub.yaml). # - the hub image the GitOps manifest runs (felhom.eu/manifests/hub.yaml).
@@ -443,24 +443,30 @@ load_vouch_protect() {
info "In-use list from the test fixture: ${#VOUCH_PROTECT[@]} version(s)." info "In-use list from the test fixture: ${#VOUCH_PROTECT[@]} version(s)."
return 0 return 0
fi fi
local hubpw="${HUB_PW:-}" page floor golden agent minagent bake hubtag # The hub's scoped access token (felhom.eu `05` §17, hub ≥ 0.152.0) — floor:read opens the Configuration page.
if [[ -z "$hubpw" ]]; then # Not the operator password any more (`09` §3 decision 251). The token goes to curl through a 0600 header file,
# never on a command line, and is never printed.
local hubtok="${HUB_TOKEN:-}" page floor golden agent minagent bake hubtag hdr
if [[ -z "$hubtok" ]]; then
local cred="${FELHOM_EU}/scripts/read_credential.py" f local cred="${FELHOM_EU}/scripts/read_credential.py" f
f="$(mktemp)" f="$(mktemp)"
if [[ -r "$cred" ]] && python3 "$cred" HUB_PW "$f" >/dev/null 2>&1; then hubpw="$(cat "$f")"; fi if [[ -r "$cred" ]] && python3 "$cred" HUB_TOKEN "$f" >/dev/null 2>&1; then hubtok="$(cat "$f")"; fi
rm -f "$f" rm -f "$f"
fi fi
[[ -n "$hubpw" ]] || { error "In-use list: no HUB_PW (env or ~/.config/credentials) — cannot read the vouch."; return 1; } [[ -n "$hubtok" ]] || { error "In-use list: no HUB_TOKEN (env or ~/.config/credentials) — cannot read the vouch."; return 1; }
if [[ -z "$HUB_URL" ]]; then if [[ -z "$HUB_URL" ]]; then
local ip; ip="$(sudo -n kubectl -n felhom-system get svc hub -o jsonpath='{.spec.clusterIP}' 2>/dev/null || true)" local ip; ip="$(sudo -n kubectl -n felhom-system get svc hub -o jsonpath='{.spec.clusterIP}' 2>/dev/null || true)"
[[ -n "$ip" ]] && HUB_URL="http://${ip}:8080" [[ -n "$ip" ]] && HUB_URL="http://${ip}:8080"
fi fi
[[ -n "$HUB_URL" ]] || { error "In-use list: the hub's address is unknown (set HUB_URL)."; return 1; } [[ -n "$HUB_URL" ]] || { error "In-use list: the hub's address is unknown (set HUB_URL)."; return 1; }
page="$(mktemp)" page="$(mktemp)"
# Basic auth through -u; NEVER -w '%{redirect_url}' (it prints the password, R-580). hdr="$(mktemp)"; chmod 600 "$hdr"
curl -fsS --max-time 20 -u ":${hubpw}" -o "$page" "${HUB_URL}/configuration" 2>/dev/null \ printf 'Authorization: Bearer %s\n' "$hubtok" > "$hdr"
|| { rm -f "$page"; error "In-use list: GET ${HUB_URL}/configuration failed."; return 1; } hubtok=""
hubpw="" # NEVER -w '%{redirect_url}' (R-580).
curl -fsS --max-time 20 -H @"$hdr" -o "$page" "${HUB_URL}/configuration" 2>/dev/null \
|| { rm -f "$page" "$hdr"; error "In-use list: GET ${HUB_URL}/configuration failed (token missing scope floor:read, expired or revoked?)."; return 1; }
rm -f "$hdr"
floor="$(grep -o 'name="min_controller_version" value="[^"]*"' "$page" | head -1 | sed 's/.*value="//; s/"$//')" floor="$(grep -o 'name="min_controller_version" value="[^"]*"' "$page" | head -1 | sed 's/.*value="//; s/"$//')"
golden="$(tr '\n' ' ' < "$page" | grep -o '<select name="golden_version".*</select>' | grep -o '<option value="[^"]*"[^>]*selected' | head -1 | sed 's/<option value="//; s/".*//')" golden="$(tr '\n' ' ' < "$page" | grep -o '<select name="golden_version".*</select>' | grep -o '<option value="[^"]*"[^>]*selected' | head -1 | sed 's/<option value="//; s/".*//')"
agent="$(tr '\n' ' ' < "$page" | grep -o '<select name="agent_version".*' | grep -o '<option value="[^"]*"[^>]*selected' | head -1 | sed 's/<option value="//; s/".*//')" agent="$(tr '\n' ' ' < "$page" | grep -o '<select name="agent_version".*' | grep -o '<option value="[^"]*"[^>]*selected' | head -1 | sed 's/<option value="//; s/".*//')"
+1 -1
View File
@@ -36,7 +36,7 @@ out="$(run "$T/empty")"
printf '%s\n' "$out" | sed -n '/Would delete/,/DRY-RUN/p' | grep -qE '^ +0\.262\.0' && ok "red: without the in-use list 0.262.0 WOULD be deleted" || bad "red-proof: 0.262.0 not deleted even without protection — the test proves nothing" printf '%s\n' "$out" | sed -n '/Would delete/,/DRY-RUN/p' | grep -qE '^ +0\.262\.0' && ok "red: without the in-use list 0.262.0 WOULD be deleted" || bad "red-proof: 0.262.0 not deleted even without protection — the test proves nothing"
# 3. an unreadable in-use list refuses (never 'protect nothing') # 3. an unreadable in-use list refuses (never 'protect nothing')
out="$(PRUNE_TEST_VERSIONS="$T/versions.json" HUB_PW= HUB_URL=http://127.0.0.1:9 FELHOM_EU=/nonexistent bash "$S" --repo felhom-controller prune --no-sizes --log "$T/log" 2>&1)"; rc=$? out="$(PRUNE_TEST_VERSIONS="$T/versions.json" HUB_TOKEN= HUB_URL=http://127.0.0.1:9 FELHOM_EU=/nonexistent bash "$S" --repo felhom-controller prune --no-sizes --log "$T/log" 2>&1)"; rc=$?
[[ $rc -eq 3 ]] && printf '%s\n' "$out" | grep -q 'REFUSING to prune' && ok "unreadable in-use list -> refused (exit 3)" || bad "case 3 rc=$rc: $(printf '%s\n' "$out" | tail -2)" [[ $rc -eq 3 ]] && printf '%s\n' "$out" | grep -q 'REFUSING to prune' && ok "unreadable in-use list -> refused (exit 3)" || bad "case 3 rc=$rc: $(printf '%s\n' "$out" | tail -2)"
exit $fail exit $fail