From 393af2292f3803981e7fe719d9279e00550718f5 Mon Sep 17 00:00:00 2001 From: kisfenyo Date: Thu, 15 Oct 2026 13:08:49 +0200 Subject: [PATCH] =?UTF-8?q?gitea-image-prune:=20read=20the=20hub=20with=20?= =?UTF-8?q?the=20scoped=20token=20HUB=5FTOKEN,=20not=20HUB=5FPW=20(felhom?= =?UTF-8?q?=2009=20=C2=A73=20decision=20251)?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Claude-Session: https://claude.ai/code/session_012qRErfCoiTkvDK9N5XHbzb --- CHANGELOG.md | 8 ++++++++ README.md | 2 +- REPORT.md | 14 ++++---------- gitea-image-prune.sh | 24 +++++++++++++++--------- tests/test-prune-plan.sh | 2 +- 5 files changed, 29 insertions(+), 21 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 741d94a..45bcf79 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -2,6 +2,14 @@ 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 ### Changed — `gitea-image-prune.sh`: the retention rule (Felhom `09` §3 decision 62, R-750) diff --git a/README.md b/README.md index 5f7ad0a..84ac9d8 100644 --- a/README.md +++ b/README.md @@ -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 `--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/:` 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 prints each kept version with its reason. **If any of these cannot be read, the prune refuses (exit 3).** Nothing runs diff --git a/REPORT.md b/REPORT.md index 46ca7b4..7d4a77a 100644 --- a/REPORT.md +++ b/REPORT.md @@ -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 - baked images, the running hub); refuse (exit 3) when the in-use list cannot be read; `--apply` only by a person. -- **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.** +- The in-use list now reads the hub with the scoped token `HUB_TOKEN` (`floor:read`), not the operator password. +- Proof: `tests/test-prune-plan.sh` passes (rc 0); a live dry-run read 6 in-use versions through the token and deleted 0. diff --git a/gitea-image-prune.sh b/gitea-image-prune.sh index 7ff1787..830f6c5 100755 --- a/gitea-image-prune.sh +++ b/gitea-image-prune.sh @@ -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/: the vouched golden BAKED (its bake.log # in felhom.eu/documentation/tests/golden--*/); # - 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 '