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

+15 -9
View File
@@ -19,7 +19,7 @@
# 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:
# - 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
# in felhom.eu/documentation/tests/golden-<version>-*/);
# - 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)."
return 0
fi
local hubpw="${HUB_PW:-}" page floor golden agent minagent bake hubtag
if [[ -z "$hubpw" ]]; then
# The hub's scoped access token (felhom.eu `05` §17, hub ≥ 0.152.0) — floor:read opens the Configuration page.
# 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
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"
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
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"
fi
[[ -n "$HUB_URL" ]] || { error "In-use list: the hub's address is unknown (set HUB_URL)."; return 1; }
page="$(mktemp)"
# Basic auth through -u; NEVER -w '%{redirect_url}' (it prints the password, R-580).
curl -fsS --max-time 20 -u ":${hubpw}" -o "$page" "${HUB_URL}/configuration" 2>/dev/null \
|| { rm -f "$page"; error "In-use list: GET ${HUB_URL}/configuration failed."; return 1; }
hubpw=""
hdr="$(mktemp)"; chmod 600 "$hdr"
printf 'Authorization: Bearer %s\n' "$hubtok" > "$hdr"
hubtok=""
# 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/"$//')"
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/".*//')"