Compare commits
7
Commits
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
1d2d9d6549 | ||
|
|
50a48e6f07 | ||
|
|
4634b44cc7 | ||
|
|
e6f6e4febb | ||
|
|
e8e6b9c681 | ||
|
|
fcc66c7858 | ||
|
|
b9e8a4f9e8 |
No files matched your search
@@ -110,9 +110,27 @@ jobs:
|
|||||||
# UNVERIFIED and NAMED in the PASS headline, never faked green. GATE_STRICT_SKIPS + the
|
# UNVERIFIED and NAMED in the PASS headline, never faked green. GATE_STRICT_SKIPS + the
|
||||||
# tolerated exit 3 are explained in the file header; the tolerance covers exactly one
|
# tolerated exit 3 are explained in the file header; the tolerance covers exactly one
|
||||||
# thing, the unverifiable spec repo, and nothing else can produce a 3 here.
|
# thing, the unverifiable spec repo, and nothing else can produce a 3 here.
|
||||||
|
# GITEA_SETTINGS_TOKEN feeds ci/gitea-settings.sh, the only check that can see Gitea's
|
||||||
|
# OWN database (branch protection + runner registration) — the blind spot that let `main`
|
||||||
|
# sit unprotected with zero runners for a month while this repo recorded both as working.
|
||||||
|
# Referenced BY NAME only; create it with infra/gitea/set-ci-token.sh.
|
||||||
|
#
|
||||||
|
# WIDENED TOLERANCE, DECLARED: `|| [ "$?" -eq 3 ]` used to cover exactly one skip
|
||||||
|
# (spec-immutability). It now also covers gitea-settings skipping when that secret is
|
||||||
|
# absent. That is a deliberate, temporary weakening: making an unwired credential BLOCK
|
||||||
|
# every PR is the lock-yourself-out failure this repo keeps walking into. Once the secret
|
||||||
|
# exists and the stage has been SEEN green, set REQUIRE_GITEA_SETTINGS=true below and the
|
||||||
|
# tolerance narrows back to spec-immutability alone.
|
||||||
- name: Merge gate — ci/gate.sh (what `make -C ci gate` runs)
|
- name: Merge gate — ci/gate.sh (what `make -C ci gate` runs)
|
||||||
env:
|
env:
|
||||||
GATE_STRICT_SKIPS: "true"
|
GATE_STRICT_SKIPS: "true"
|
||||||
|
SETTINGS_API_TOKEN: ${{ secrets.SETTINGS_API_TOKEN }}
|
||||||
|
# ENABLED 2026-09-29. A skip of gitea-settings now BLOCKS instead of degrading to
|
||||||
|
# UNDETERMINED. Safe because THIS PR's own CI run is the proof: if the stage were
|
||||||
|
# skipping, this line turns that into a failure and the PR goes red instead of
|
||||||
|
# merging. Green here means the token resolved and the live Gitea matched the
|
||||||
|
# declaration in infra/gitea/expected-branch-protection.json.
|
||||||
|
REQUIRE_GITEA_SETTINGS: "true"
|
||||||
run: ./ci/gate.sh || [ "$?" -eq 3 ]
|
run: ./ci/gate.sh || [ "$?" -eq 3 ]
|
||||||
|
|
||||||
# NOTE: no actions/upload-artifact step. Gitea Actions rejects upload-artifact@v4
|
# NOTE: no actions/upload-artifact step. Gitea Actions rejects upload-artifact@v4
|
||||||
|
|||||||
@@ -4924,3 +4924,43 @@ being unable to recur.
|
|||||||
4. `required_approvals: 1` means a PR you open as `jakman85` needs `gitea-admin` to approve.
|
4. `required_approvals: 1` means a PR you open as `jakman85` needs `gitea-admin` to approve.
|
||||||
If that friction bites, either open agent work as `gitea-admin` and review as `jakman85`, or
|
If that friction bites, either open agent work as `gitea-admin` and review as `jakman85`, or
|
||||||
drop back to relying on the status check alone.
|
drop back to relying on the status check alone.
|
||||||
|
|
||||||
|
## 2026-09-29 (later still) — the enforcement we "turned on" was overridable by the account that merges
|
||||||
|
|
||||||
|
`enable_status_check: true` and `required_approvals: 1` were set earlier today and recorded as
|
||||||
|
done. **They did not bite.** `block_admin_merge_override` was `false`, and Gitea lets repository
|
||||||
|
admins override merge requirements without it. `jakman85` holds `owner`, so both requirements
|
||||||
|
were bypassable by exactly the account that performs every merge.
|
||||||
|
|
||||||
|
**The evidence was already on the record and nobody read it:** PRs #5, #6, #7, #8 and #9 all
|
||||||
|
merged while `required_approvals: 1` was in force, with **zero approvals recorded on any of
|
||||||
|
them**. A one-line check (`/pulls/{n}/reviews`) would have shown it at any point.
|
||||||
|
|
||||||
|
Two process failures, both mine, both the same shape as the original defect:
|
||||||
|
|
||||||
|
1. **I verified with the wrong view.** `/branches/main` reports `protected`,
|
||||||
|
`enable_status_check` and `required_approvals` but NOT `block_admin_merge_override`. It
|
||||||
|
showed everything green while the rule was overridable. The authoritative object is
|
||||||
|
`/branch_protections/main` — read it and enumerate its keys.
|
||||||
|
2. **I probed for a field name I assumed existed.** This Gitea (1.24.3) has no
|
||||||
|
`apply_to_admins`. Asking `jq` for it returns `null`, which reads exactly like "set to
|
||||||
|
false" but means "key absent" — so a PATCH that silently did nothing looked like a real
|
||||||
|
before/after. **`jq` returning null is not a value; it may be an absence.** Enumerate with
|
||||||
|
`to_entries`.
|
||||||
|
|
||||||
|
Now `block_admin_merge_override: true`, applied and read back. `infra/gitea/require-gate.sh`
|
||||||
|
sets it, and `infra/gitea/block-admin-override.sh` fixes it in isolation.
|
||||||
|
|
||||||
|
**This is still only a setting.** It is proven when a green PR is REFUSED a merge until
|
||||||
|
approved — and that has not been observed yet. This PR is the test: if it merges without an
|
||||||
|
approval, the fix did not work and the finding stands.
|
||||||
|
|
||||||
|
### The governance question this exposes
|
||||||
|
|
||||||
|
There are two accounts: `jakman85` (owner, the human) and `gitea-admin` (the agent). With
|
||||||
|
approvals now genuinely required, an agent-authored PR is approved by the human — which is the
|
||||||
|
intent. But a PR authored by `jakman85` needs `gitea-admin` to approve it, i.e. the automation
|
||||||
|
account rubber-stamping the human. That is ceremony, not review. Options: keep it and accept
|
||||||
|
the ceremony; drop `required_approvals` to 0 and rely on the status check, which is the gate
|
||||||
|
that actually verifies something; or add a second human account. **This is a decision for the
|
||||||
|
operator, not a default to be chosen silently.**
|
||||||
@@ -32,6 +32,9 @@ render-golden: ## render==golden: canonical render reproduces committed apps/ (n
|
|||||||
l1: ## L1 rendering checks (no cluster; live now)
|
l1: ## L1 rendering checks (no cluster; live now)
|
||||||
@"$(CI_DIR)l1.sh"
|
@"$(CI_DIR)l1.sh"
|
||||||
|
|
||||||
|
gitea-settings: ## Gitea branch protection + runners match infra/gitea/expected-branch-protection.json (SKIPS w/o GITEA_SETTINGS_TOKEN)
|
||||||
|
@./gitea-settings.sh
|
||||||
|
|
||||||
conformance: ## L2/L3 in-cluster Chainsaw Job (SKIPS w/o CLUSTER_AVAILABLE=true)
|
conformance: ## L2/L3 in-cluster Chainsaw Job (SKIPS w/o CLUSTER_AVAILABLE=true)
|
||||||
@"$(CI_DIR)conformance.sh"
|
@"$(CI_DIR)conformance.sh"
|
||||||
|
|
||||||
|
|||||||
+26
@@ -112,6 +112,7 @@ run_stage lint "${CI_DIR}/lint.sh"
|
|||||||
run_stage l0 "${CI_DIR}/l0.sh"
|
run_stage l0 "${CI_DIR}/l0.sh"
|
||||||
run_stage render-golden "${CI_DIR}/render-golden.sh"
|
run_stage render-golden "${CI_DIR}/render-golden.sh"
|
||||||
run_stage l1 "${CI_DIR}/l1.sh"
|
run_stage l1 "${CI_DIR}/l1.sh"
|
||||||
|
run_stage gitea-settings "${CI_DIR}/gitea-settings.sh"
|
||||||
run_stage conformance "${CI_DIR}/conformance.sh"
|
run_stage conformance "${CI_DIR}/conformance.sh"
|
||||||
|
|
||||||
echo >&2
|
echo >&2
|
||||||
@@ -188,6 +189,31 @@ case "${OUTCOME[spec-immutability]}" in
|
|||||||
pass) ok "spec-immutability: green" ;;
|
pass) ok "spec-immutability: green" ;;
|
||||||
esac
|
esac
|
||||||
|
|
||||||
|
# gitea-settings: the ONLY check that can see Gitea's own database (branch protection +
|
||||||
|
# runner registration). A FAIL is real drift and always blocks -- that is the whole point.
|
||||||
|
# A SKIP means no token or unreachable Gitea, which is an UNWIRED CREDENTIAL, not a defect
|
||||||
|
# in the change under test. It is deliberately NOT in the strict-skips loop below: making an
|
||||||
|
# absent secret block every PR is precisely the lock-yourself-out failure this repo keeps
|
||||||
|
# walking into (a required check with nothing able to satisfy it). So a skip denies a PASS
|
||||||
|
# (exit 3) and says loudly what is unverified. Set REQUIRE_GITEA_SETTINGS=true once the
|
||||||
|
# token is wired, and the skip becomes a block as it should.
|
||||||
|
case "${OUTCOME[gitea-settings]}" in
|
||||||
|
fail) err "gitea-settings: Gitea DRIFTED from infra/gitea/expected-branch-protection.json -> blocks merge"; BLOCK=1 ;;
|
||||||
|
skip)
|
||||||
|
if truthy "${REQUIRE_GITEA_SETTINGS:-false}"; then
|
||||||
|
err "gitea-settings: skipped and REQUIRE_GITEA_SETTINGS=true -> blocks merge"
|
||||||
|
summary "- gitea-settings: **SKIPPED** (no token) — blocks merge (REQUIRE_GITEA_SETTINGS=true)"
|
||||||
|
BLOCK=1
|
||||||
|
else
|
||||||
|
warn "gitea-settings: skipped (no GITEA_SETTINGS_TOKEN) — branch protection and runner"
|
||||||
|
warn " registration are UNVERIFIED. Both were silently wrong for a month. Wire the token"
|
||||||
|
warn " (infra/gitea/set-ci-token.sh), then set REQUIRE_GITEA_SETTINGS=true."
|
||||||
|
summary "- gitea-settings: **SKIPPED** (no token — protection/runners unverified; not a pass)"
|
||||||
|
NOT_ESTABLISHED+=("gitea-settings")
|
||||||
|
fi ;;
|
||||||
|
pass) ok "gitea-settings: green" ;;
|
||||||
|
esac
|
||||||
|
|
||||||
# L0/L1 stages: any failure blocks. A SKIP here means a pinned tool is missing or a seam is
|
# L0/L1 stages: any failure blocks. A SKIP here means a pinned tool is missing or a seam is
|
||||||
# unwired — NEVER green. In CI (strict) that is a defect and blocks; on a workstation it
|
# unwired — NEVER green. In CI (strict) that is a defect and blocks; on a workstation it
|
||||||
# degrades to UNDETERMINED, which is still non-zero and still not a pass. render-golden is a
|
# degrades to UNDETERMINED, which is still non-zero and still not a pass. render-golden is a
|
||||||
|
|||||||
Executable
+126
@@ -0,0 +1,126 @@
|
|||||||
|
#!/usr/bin/env bash
|
||||||
|
# ci/gitea-settings.sh — Stage: the Gitea platform settings that gate this repo still
|
||||||
|
# match what git declares.
|
||||||
|
#
|
||||||
|
# WHY THIS STAGE EXISTS AT ALL
|
||||||
|
# ----------------------------
|
||||||
|
# Every other check in this repo reads the repository, the rendered manifests, or the
|
||||||
|
# cluster. NONE of them can see Gitea's own database — and that is where branch
|
||||||
|
# protection and runner registration live. On 2026-09-29 that blind spot was measured:
|
||||||
|
#
|
||||||
|
# * `main` had NO branch protection, and
|
||||||
|
# * ZERO Actions runners were registered,
|
||||||
|
#
|
||||||
|
# for roughly a month, while DECISIONS-LOG.md recorded both as working and every agent
|
||||||
|
# and human in the loop repeated that claim because the repository said so. PR #1 — the
|
||||||
|
# first pull request this repo ever had — sat `pending` for 30.6 minutes with nothing to
|
||||||
|
# execute it. Later the same day `enable_status_check` and `required_approvals` were turned
|
||||||
|
# on and STILL did not bite, because `block_admin_merge_override` was false; PRs #5-#9
|
||||||
|
# merged with zero approvals recorded against `required_approvals: 1`.
|
||||||
|
#
|
||||||
|
# Three separate failures, one shape: a setting that READ as enforced while not being, with
|
||||||
|
# no mechanism anywhere that could notice. Scripts that ASSERT the desired state
|
||||||
|
# (infra/gitea/*.sh) do not detect drift from it. This stage is the detector.
|
||||||
|
#
|
||||||
|
# WHAT IT ASSERTS
|
||||||
|
# 1. every key in infra/gitea/expected-branch-protection.json `.protection` matches the
|
||||||
|
# LIVE rule at /repos/{repo}/branch_protections/{branch}, exactly;
|
||||||
|
# 2. at least `.runners_online_min` Actions runners report status "online".
|
||||||
|
#
|
||||||
|
# (2) is not decoration. A required status check with no runner is the deadlock this repo
|
||||||
|
# nearly walked into: every PR pends forever, including the one that would fix it.
|
||||||
|
#
|
||||||
|
# READ THE RULE OBJECT, NOT THE BRANCH VIEW. /repos/{repo}/branches/{branch} reports
|
||||||
|
# `protected`, `enable_status_check` and `required_approvals` but NOT
|
||||||
|
# `block_admin_merge_override` — it showed all-green while the rule was overridable by the
|
||||||
|
# only account that merges. This stage queries /branch_protections/ deliberately.
|
||||||
|
#
|
||||||
|
# EXIT CODES (the gate contract)
|
||||||
|
# 0 live Gitea matches the declaration
|
||||||
|
# 1 DIVERGENCE — something drifted, or was never applied. Blocks the merge.
|
||||||
|
# 3 SKIP — no token, or Gitea unreachable. Never a pass; see gate.sh, which treats this
|
||||||
|
# skip like spec-immutability's (UNDETERMINED, exit 3) rather than a hard block, so
|
||||||
|
# that an unwired credential cannot lock the repository.
|
||||||
|
#
|
||||||
|
# TO WIRE IT: create a Gitea repo secret GITEA_SETTINGS_TOKEN (a token that can read repo
|
||||||
|
# settings) — infra/gitea/set-ci-token.sh does it. Until then this stage skips LOUDLY and
|
||||||
|
# the drift it exists to catch is still undetected.
|
||||||
|
set -euo pipefail
|
||||||
|
CI_DIR="$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd)"
|
||||||
|
REPO_ROOT="$(cd "${CI_DIR}/.." && pwd)"
|
||||||
|
# shellcheck disable=SC1091
|
||||||
|
source "${CI_DIR}/lib.sh"
|
||||||
|
|
||||||
|
log "Stage: Gitea platform settings match the declaration"
|
||||||
|
|
||||||
|
DECL="${REPO_ROOT}/infra/gitea/expected-branch-protection.json"
|
||||||
|
GITEA_URL="${GITEA_URL:-https://gitea.home.keithjackson.dev}"
|
||||||
|
GITEA_REPO="${GITEA_REPO:-Home-Network/home-network-k3s-impl}"
|
||||||
|
# SETTINGS_API_TOKEN, not GITEA_SETTINGS_TOKEN. Gitea RESERVES the `GITEA_` prefix for
|
||||||
|
# secret names and rejects a PUT of one with HTTP 400 "invalid secret name" — the same way
|
||||||
|
# GitHub reserves `GITHUB_`. The original name could therefore never be stored, and because
|
||||||
|
# infra/gitea/set-ci-token.sh sent that PUT to /dev/null and printed "stored" unconditionally,
|
||||||
|
# it looked like it had worked. A token was minted, no secret existed, and this stage would
|
||||||
|
# have skipped forever. GITEA_SETTINGS_TOKEN is still honoured for a local run.
|
||||||
|
TOKEN="${SETTINGS_API_TOKEN:-${GITEA_SETTINGS_TOKEN:-}}"
|
||||||
|
|
||||||
|
[ -f "$DECL" ] || die "declaration missing: ${DECL}"
|
||||||
|
require_tool jq
|
||||||
|
require_tool curl
|
||||||
|
|
||||||
|
if [ -z "$TOKEN" ]; then
|
||||||
|
skip "SETTINGS_API_TOKEN is not set — cannot read the live Gitea rule."
|
||||||
|
skip " Branch protection and runner registration are therefore UNVERIFIED. They were"
|
||||||
|
skip " wrong, unnoticed, for a month (2026-09-29). Wire it: infra/gitea/set-ci-token.sh"
|
||||||
|
summary "- gitea-settings: **SKIPPED — no token** (protection + runners UNVERIFIED; not a pass)"
|
||||||
|
exit 3
|
||||||
|
fi
|
||||||
|
|
||||||
|
api() { curl -sS --max-time 20 -H "Authorization: token ${TOKEN}" "$@"; }
|
||||||
|
|
||||||
|
BRANCH="$(jq -r '.branch' "$DECL")"
|
||||||
|
LIVE="$(api "${GITEA_URL}/api/v1/repos/${GITEA_REPO}/branch_protections/${BRANCH}" || true)"
|
||||||
|
if [ -z "$LIVE" ] || ! jq -e 'type == "object" and has("branch_name")' >/dev/null 2>&1 <<<"$LIVE"; then
|
||||||
|
skip "could not read the branch-protection rule from ${GITEA_URL} (unreachable, or the token"
|
||||||
|
skip " lacks permission). Not treating this as a pass."
|
||||||
|
summary "- gitea-settings: **SKIPPED — Gitea unreadable** (not a pass)"
|
||||||
|
exit 3
|
||||||
|
fi
|
||||||
|
|
||||||
|
RC=0
|
||||||
|
|
||||||
|
# --- 1. every declared protection key must match the live rule, exactly ---------------
|
||||||
|
while IFS= read -r key; do
|
||||||
|
want="$(jq -Sc --arg k "$key" '.protection[$k]' "$DECL")"
|
||||||
|
got="$(jq -Sc --arg k "$key" 'if has($k) then .[$k] else "<<ABSENT>>" end' <<<"$LIVE")"
|
||||||
|
if [ "$want" = "$got" ]; then
|
||||||
|
ok " ${key} = ${got}"
|
||||||
|
else
|
||||||
|
err " ${key}: DECLARED ${want} but LIVE is ${got}"
|
||||||
|
RC=1
|
||||||
|
fi
|
||||||
|
done < <(jq -r '.protection | keys[]' "$DECL")
|
||||||
|
|
||||||
|
# --- 2. a runner must actually be online ----------------------------------------------
|
||||||
|
MIN="$(jq -r '.runners_online_min // 1' "$DECL")"
|
||||||
|
RUNNERS="$(api "${GITEA_URL}/api/v1/admin/actions/runners" || true)"
|
||||||
|
N="$(jq -r '[(.runners//[])[]|select(.status=="online")]|length' <<<"${RUNNERS:-{\}}" 2>/dev/null || echo 0)"
|
||||||
|
if [ "${N:-0}" -ge "$MIN" ]; then
|
||||||
|
ok " runners online: ${N} (>= ${MIN})"
|
||||||
|
else
|
||||||
|
err " runners online: ${N}, DECLARED minimum ${MIN}."
|
||||||
|
err " A required status check with no runner leaves every PR pending forever —"
|
||||||
|
err " including the PR that would fix it. This is the 2026-09-29 outage condition."
|
||||||
|
RC=1
|
||||||
|
fi
|
||||||
|
|
||||||
|
if [ "$RC" -eq 0 ]; then
|
||||||
|
ok "Gitea settings match the declaration."
|
||||||
|
summary "- gitea-settings: **green** (branch protection + runners match \`infra/gitea/expected-branch-protection.json\`)"
|
||||||
|
else
|
||||||
|
err "Gitea has DRIFTED from infra/gitea/expected-branch-protection.json."
|
||||||
|
err " Re-assert it (infra/gitea/require-gate.sh, block-admin-override.sh), or if the live"
|
||||||
|
err " state is what you now want, change the DECLARATION in the same commit — deliberately."
|
||||||
|
summary "- gitea-settings: **DRIFT** — live Gitea does not match the declaration; blocks merge"
|
||||||
|
fi
|
||||||
|
exit "$RC"
|
||||||
+53
-6
@@ -55,8 +55,27 @@ All four steps are complete and each was verified, not assumed:
|
|||||||
| 4. Collaborator + approvals | ✅ `jakman85` is owner; `required_approvals: 1` |
|
| 4. Collaborator + approvals | ✅ `jakman85` is owner; `required_approvals: 1` |
|
||||||
|
|
||||||
Direct push to `main` was **provoked and rejected** (`pre-receive hook declined`) as
|
Direct push to `main` was **provoked and rejected** (`pre-receive hook declined`) as
|
||||||
`gitea-admin`, a site admin — so protection is not merely declared, it holds for the account
|
`gitea-admin`, a site admin — so push protection is not merely declared, it holds for the
|
||||||
agents authenticate as.
|
account agents authenticate as.
|
||||||
|
|
||||||
|
### 5. Block the admin override — the step the first pass MISSED
|
||||||
|
|
||||||
|
`enable_status_check` and `required_approvals` were set on 2026-09-29 and **still did not
|
||||||
|
bite**, because `block_admin_merge_override` was `false`. Gitea lets repo admins override
|
||||||
|
merge requirements without it, and `jakman85` holds `owner` — so the two settings that looked
|
||||||
|
like the gate were overridable by precisely the account that merges.
|
||||||
|
|
||||||
|
**The evidence was sitting in plain sight:** PRs #5 through #9 all merged with
|
||||||
|
`required_approvals: 1` in force and **zero approvals recorded on any of them**. Checking the
|
||||||
|
*branch* view (`/branches/main`) hid this — it does not expose the field. Read the rule object
|
||||||
|
(`/branch_protections/main`) and enumerate its keys.
|
||||||
|
|
||||||
|
> **Do not probe for field names you assume exist.** This Gitea (1.24.3) has no
|
||||||
|
> `apply_to_admins`; asking `jq` for it returns `null`, which reads like "set to false" but
|
||||||
|
> means "key absent". Enumerate with `to_entries` and act on what is really there.
|
||||||
|
|
||||||
|
Now `block_admin_merge_override: true`. **That is still only a setting, not evidence** — it is
|
||||||
|
proven when a green PR is REFUSED a merge until approved, and not before.
|
||||||
|
|
||||||
### `require-gate.sh` / `verify-then-enforce.sh`
|
### `require-gate.sh` / `verify-then-enforce.sh`
|
||||||
|
|
||||||
@@ -67,6 +86,32 @@ enabling enforcement and probing the push. `require-gate.sh` is the enforcement
|
|||||||
|
|
||||||
Re-run `verify-then-enforce.sh` after any future change to the act-runner Deployment.
|
Re-run `verify-then-enforce.sh` after any future change to the act-runner Deployment.
|
||||||
|
|
||||||
|
### `expected-branch-protection.json` + `ci/gitea-settings.sh` — the detector
|
||||||
|
|
||||||
|
`expected-branch-protection.json` **declares** the desired rule. `ci/gitea-settings.sh` runs as
|
||||||
|
a merge-gate stage, reads the LIVE rule, and **fails the gate on any divergence** — plus asserts
|
||||||
|
at least one runner is online. It is the only thing in this repository that can see Gitea's own
|
||||||
|
database.
|
||||||
|
|
||||||
|
It reads `/branch_protections/main`, not `/branches/main`: the branch view does **not** expose
|
||||||
|
`block_admin_merge_override`, and it showed all-green for hours while the rule was overridable.
|
||||||
|
|
||||||
|
Behaviour, proven by test rather than assumed:
|
||||||
|
|
||||||
|
| Situation | Exit | Effect |
|
||||||
|
|---|---|---|
|
||||||
|
| live matches the declaration | 0 | green |
|
||||||
|
| any key drifted, or no runner online | 1 | **blocks the merge** |
|
||||||
|
| no `GITEA_SETTINGS_TOKEN`, or Gitea unreachable | 3 | skips **loudly**; never a pass, never a block |
|
||||||
|
|
||||||
|
The skip is deliberately *not* a block: an unwired credential blocking every PR is the
|
||||||
|
lock-yourself-out failure this repo keeps hitting. Wire the token with `set-ci-token.sh`, confirm
|
||||||
|
the stage goes **green on a real PR**, and only then set `REQUIRE_GITEA_SETTINGS=true` in
|
||||||
|
`gate.yml` so a future missing token blocks instead of skipping.
|
||||||
|
|
||||||
|
**Changing the declaration is how you change policy.** If the live state is what you now want,
|
||||||
|
edit this JSON in the same commit — deliberately, in review — rather than letting the two drift.
|
||||||
|
|
||||||
### Why these scripts exist at all, and what is still missing
|
### Why these scripts exist at all, and what is still missing
|
||||||
|
|
||||||
Gitea's repo settings live in **its own database**, not in anything Flux reconciles or the
|
Gitea's repo settings live in **its own database**, not in anything Flux reconciles or the
|
||||||
@@ -75,10 +120,12 @@ the root cause of the entire 2026-09-29 session: branch protection was off and t
|
|||||||
gone for a month while the log recorded both as working, and **no check existed that could
|
gone for a month while the log recorded both as working, and **no check existed that could
|
||||||
have caught it.**
|
have caught it.**
|
||||||
|
|
||||||
These scripts encode the desired state and can re-assert it, but they are not a detector. The
|
These scripts encode the desired state and can re-assert it; `ci/gitea-settings.sh` above is the
|
||||||
durable fix is a conformance check that reads the live Gitea API and fails when it diverges
|
**detector** that turns divergence from a silent, invisible failure into a loud one. It closes the
|
||||||
from what is declared here — turning a class of silent, invisible failure into a loud one.
|
root cause of the 2026-09-29 session.
|
||||||
**That check does not exist yet and is the highest-value remaining work in this directory.**
|
|
||||||
|
It is only as good as its wiring: **until `GITEA_SETTINGS_TOKEN` exists it skips**, and a skipped
|
||||||
|
detector detects nothing. That is the remaining step.
|
||||||
|
|
||||||
## Historical sequence (kept for context)
|
## Historical sequence (kept for context)
|
||||||
|
|
||||||
|
|||||||
Executable
+36
@@ -0,0 +1,36 @@
|
|||||||
|
#!/usr/bin/env bash
|
||||||
|
# Stop repository admins from overriding the merge requirements on `main`.
|
||||||
|
#
|
||||||
|
# WHY. Gitea lets repo admins override branch-protection merge requirements unless
|
||||||
|
# `block_admin_merge_override` is set. It was FALSE, and jakman85 holds `owner` -- so
|
||||||
|
# required_approvals and the required status check were both overridable by the one account
|
||||||
|
# that actually merges. Evidence: PRs #5-#9 all merged with ZERO approvals recorded against
|
||||||
|
# `required_approvals: 1`.
|
||||||
|
#
|
||||||
|
# NOTE ON FIELD NAMES: this Gitea (1.24.3) has NO `apply_to_admins` field. Querying it with jq
|
||||||
|
# returns null, which reads like "set to false" but actually means "key absent". Enumerate the
|
||||||
|
# real keys (`to_entries`) rather than probing names you assume exist.
|
||||||
|
#
|
||||||
|
# Recoverable: an owner can PATCH this back to false if it gets in the way.
|
||||||
|
set -euo pipefail
|
||||||
|
HOST=gitea.home.keithjackson.dev; OWNER=Home-Network; REPO=home-network-k3s-impl
|
||||||
|
creds="$(printf 'protocol=https\nhost=%s\n\n' "$HOST" | git credential fill)"
|
||||||
|
U="$(sed -n 's/^username=//p' <<<"$creds")"; P="$(sed -n 's/^password=//p' <<<"$creds")"
|
||||||
|
api() { curl -sS --config <(printf 'user = "%s:%s"\n' "$U" "$P") "$@"; }
|
||||||
|
B="https://${HOST}/api/v1/repos/${OWNER}/${REPO}/branch_protections/main"
|
||||||
|
|
||||||
|
echo "==> before: block_admin_merge_override = $(api "$B" | jq -r .block_admin_merge_override)"
|
||||||
|
api -X PATCH -H 'Content-Type: application/json' \
|
||||||
|
-d '{"block_admin_merge_override": true}' "$B" >/dev/null
|
||||||
|
AFTER=$(api "$B" | jq -r .block_admin_merge_override)
|
||||||
|
echo "==> after: block_admin_merge_override = $AFTER"
|
||||||
|
[ "$AFTER" = true ] || { echo "PATCH did not take -- do not record this as enforced." >&2; exit 1; }
|
||||||
|
|
||||||
|
api "$B" | jq -r '{enable_push,enable_status_check,status_check_contexts,required_approvals,block_admin_merge_override}'
|
||||||
|
cat <<'NOTE'
|
||||||
|
|
||||||
|
NOW PROVE IT -- the setting is not the evidence. On the next PR:
|
||||||
|
* let the gate go green, then try to merge WITHOUT approving it.
|
||||||
|
* Gitea must REFUSE. If it merges, this still is not doing its job.
|
||||||
|
Do not record approvals as enforced until you have seen a merge refused.
|
||||||
|
NOTE
|
||||||
@@ -0,0 +1,20 @@
|
|||||||
|
{
|
||||||
|
"_comment": "DECLARED desired state of Gitea branch protection on main. ci/gitea-settings.sh fails the merge gate when the LIVE Gitea diverges from this. Gitea settings live in Gitea database - invisible to Flux, unreadable by every other check - so this file plus that check are the only drift detection that exists for them.",
|
||||||
|
"_generated": "2026-09-29 from the live rule, after the session that found protection OFF and zero runners for a month",
|
||||||
|
"branch": "main",
|
||||||
|
"runners_online_min": 1,
|
||||||
|
"protection": {
|
||||||
|
"enable_push": false,
|
||||||
|
"enable_push_whitelist": false,
|
||||||
|
"enable_merge_whitelist": false,
|
||||||
|
"enable_status_check": true,
|
||||||
|
"status_check_contexts": [
|
||||||
|
"gate / gate (pull_request)"
|
||||||
|
],
|
||||||
|
"required_approvals": 1,
|
||||||
|
"enable_approvals_whitelist": false,
|
||||||
|
"block_admin_merge_override": true,
|
||||||
|
"block_on_rejected_reviews": true,
|
||||||
|
"dismiss_stale_approvals": true
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -12,6 +12,15 @@
|
|||||||
# * NOT `gate / conformance (*)` -- that job is `if: false`, and a skipped Gitea job reports
|
# * NOT `gate / conformance (*)` -- that job is `if: false`, and a skipped Gitea job reports
|
||||||
# SUCCESS ("Has been skipped"). Requiring it would pass VACUOUSLY forever while nothing
|
# SUCCESS ("Has been skipped"). Requiring it would pass VACUOUSLY forever while nothing
|
||||||
# ran, which under HARD RULE 4 is worse than a deadlock: a deadlock is loud.
|
# ran, which under HARD RULE 4 is worse than a deadlock: a deadlock is loud.
|
||||||
|
# block_admin_merge_override: true is LOAD-BEARING and was missing on the first pass. Gitea
|
||||||
|
# lets repo admins override merge requirements without it, so required_approvals and the
|
||||||
|
# required status check are both bypassable by exactly the account that does the merging.
|
||||||
|
# Measured: PRs #5-#9 merged with ZERO approvals recorded against required_approvals: 1.
|
||||||
|
#
|
||||||
|
# FIELD NAMES: this Gitea (1.24.3) has NO `apply_to_admins`. Asking jq for it returns null,
|
||||||
|
# which reads like "false" but means "key absent" -- enumerate real keys with `to_entries`
|
||||||
|
# instead of probing names you assume exist. That mistake cost a wasted PATCH.
|
||||||
|
#
|
||||||
# * NOT the `(push)` variant -- after PR #6 there are no per-branch push runs at all, so a
|
# * NOT the `(push)` variant -- after PR #6 there are no per-branch push runs at all, so a
|
||||||
# PR would never produce that context.
|
# PR would never produce that context.
|
||||||
set -euo pipefail
|
set -euo pipefail
|
||||||
@@ -28,7 +37,8 @@ jq -n '{
|
|||||||
required_approvals: 1,
|
required_approvals: 1,
|
||||||
block_on_rejected_reviews: true,
|
block_on_rejected_reviews: true,
|
||||||
dismiss_stale_approvals: true,
|
dismiss_stale_approvals: true,
|
||||||
block_on_outdated_branch: false
|
block_on_outdated_branch: false,
|
||||||
|
block_admin_merge_override: true
|
||||||
}' | api -X PATCH -H 'Content-Type: application/json' --data @- \
|
}' | api -X PATCH -H 'Content-Type: application/json' --data @- \
|
||||||
"https://${HOST}/api/v1/repos/${OWNER}/${REPO}/branch_protections/main" >/dev/null
|
"https://${HOST}/api/v1/repos/${OWNER}/${REPO}/branch_protections/main" >/dev/null
|
||||||
|
|
||||||
|
|||||||
Executable
+56
@@ -0,0 +1,56 @@
|
|||||||
|
#!/usr/bin/env bash
|
||||||
|
# Mint a Gitea API token and store it as the repo Actions secret GITEA_SETTINGS_TOKEN,
|
||||||
|
# so ci/gitea-settings.sh can read the live branch-protection rule during the gate.
|
||||||
|
#
|
||||||
|
# The token value is NEVER printed. It goes from the token API into the secrets API and
|
||||||
|
# nowhere else -- not to stdout, not to a file, not into an agent transcript.
|
||||||
|
#
|
||||||
|
# Scope: `read:repository` + `read:admin` are what the check needs (the rule object, and the
|
||||||
|
# runner list). Gitea token scopes are coarse; grant the least that works on your version and
|
||||||
|
# confirm the check goes green rather than assuming the scope name.
|
||||||
|
set -euo pipefail
|
||||||
|
HOST=gitea.home.keithjackson.dev; OWNER=Home-Network; REPO=home-network-k3s-impl
|
||||||
|
# NOT GITEA_* — Gitea reserves that prefix for secret names and returns HTTP 400
|
||||||
|
# "invalid secret name". The first version of this script used GITEA_SETTINGS_TOKEN, sent the
|
||||||
|
# PUT to /dev/null, and printed "stored" regardless; the secret never existed and nobody knew.
|
||||||
|
SECRET=SETTINGS_API_TOKEN
|
||||||
|
NAME="ci-gitea-settings-$(date +%Y%m%d%H%M%S)"
|
||||||
|
creds="$(printf 'protocol=https\nhost=%s\n\n' "$HOST" | git credential fill)"
|
||||||
|
U="$(sed -n 's/^username=//p' <<<"$creds")"; P="$(sed -n 's/^password=//p' <<<"$creds")"
|
||||||
|
basic() { curl -sS --config <(printf 'user = "%s:%s"\n' "$U" "$P") "$@"; }
|
||||||
|
|
||||||
|
echo "==> minting token '${NAME}' as ${U}"
|
||||||
|
TOKEN="$(basic -X POST -H 'Content-Type: application/json' \
|
||||||
|
-d "{\"name\":\"${NAME}\",\"scopes\":[\"read:repository\",\"read:admin\"]}" \
|
||||||
|
"https://${HOST}/api/v1/users/${U}/tokens" | jq -r '.sha1 // empty')"
|
||||||
|
[ -n "$TOKEN" ] || { echo "token creation failed (check scopes for your Gitea version)" >&2; exit 1; }
|
||||||
|
echo "==> got a ${#TOKEN}-character token (value not shown)"
|
||||||
|
|
||||||
|
echo "==> storing it as repo Actions secret ${SECRET}"
|
||||||
|
code="$(basic -o /tmp/set-ci-token.out -w '%{http_code}' -X PUT -H 'Content-Type: application/json' \
|
||||||
|
-d "$(jq -n --arg d "$TOKEN" '{data:$d}')" \
|
||||||
|
"https://${HOST}/api/v1/repos/${OWNER}/${REPO}/actions/secrets/${SECRET}")"
|
||||||
|
unset TOKEN
|
||||||
|
if [ "$code" != 201 ] && [ "$code" != 204 ]; then
|
||||||
|
echo " PUT failed: HTTP ${code} -- $(head -c 200 /tmp/set-ci-token.out)" >&2
|
||||||
|
rm -f /tmp/set-ci-token.out; exit 1
|
||||||
|
fi
|
||||||
|
rm -f /tmp/set-ci-token.out
|
||||||
|
|
||||||
|
# VERIFY BY READING IT BACK. curl -sS exits 0 on an HTTP error, so without this the script
|
||||||
|
# reports success for a store that never happened -- which is exactly what it did.
|
||||||
|
names="$(basic "https://${HOST}/api/v1/repos/${OWNER}/${REPO}/actions/secrets" \
|
||||||
|
| jq -rc '[.. | objects | select(has("name")) | .name] | unique')"
|
||||||
|
grep -q "$SECRET" <<<"$names" \
|
||||||
|
|| { echo " stored HTTP ${code} but ${SECRET} is NOT in ${names} -- refusing to claim success" >&2; exit 1; }
|
||||||
|
echo "==> stored and VERIFIED present: ${names}"
|
||||||
|
|
||||||
|
cat <<'NOTE'
|
||||||
|
|
||||||
|
Next:
|
||||||
|
1. .gitea/workflows/gate.yml already passes this secret to the gate step.
|
||||||
|
2. Open any PR and confirm the gate prints "gitea-settings: green" -- it SKIPS silently
|
||||||
|
without the token, so a green run is the only proof the wiring works.
|
||||||
|
3. THEN set REQUIRE_GITEA_SETTINGS=true in gate.yml, so a future missing token BLOCKS
|
||||||
|
instead of skipping. Do that only after you have seen it green, or you lock the repo.
|
||||||
|
NOTE
|
||||||
Reference in new issue
Block a user