verify-creds: forgejo_token probe requires GET /user 200, failing functional tokens without read:user scope #82

Closed
opened 2026-08-25 04:13:15 +00:00 by ben · 3 comments
Owner

Found during the Matou/matou-website install session (#62 acceptance, matou-website#2).

Symptom: onboard.sh verify-creds emits FAIL forgejo_token GET /user returned 403 (len=40) for the fleet swarm token, on every host. The same token returns 200 on the repo issues API and passed both claim-probes (matou-website #3/#4: ticket opened, claimed, closed) — full issue-write capability, which is the capability the probe exists to prove (#20 lesson).

Cause: _vc... onboard_verify_creds (onboarding/onboard-lib.sh ~line 809) gates on GET /user = 200 before the issue-write check. A Forgejo scoped token without read:user 403s there regardless of its issue scopes.

Options: (a) probe issue-write directly (e.g. against the target repo, as claim-probe already does) and drop the /user requirement, or (b) keep /user but only as a shape/auth hint, FAIL only on 401; or (c) document that the fleet token must carry read:user. The install prompt says "do not proceed with a FAIL outstanding" — a probe stricter than the capability it proves turns a healthy install into a false stop.

Offline test to update in the same commit: onboarding/tests (verify-creds shims).

Found during the Matou/matou-website install session (#62 acceptance, matou-website#2). **Symptom**: `onboard.sh verify-creds` emits `FAIL forgejo_token GET /user returned 403 (len=40)` for the fleet swarm token, on every host. The same token returns 200 on the repo issues API and passed both claim-probes (matou-website #3/#4: ticket opened, claimed, closed) — full issue-write capability, which is the capability the probe exists to prove (#20 lesson). **Cause**: `_vc`... `onboard_verify_creds` (onboarding/onboard-lib.sh ~line 809) gates on `GET /user` = 200 before the issue-write check. A Forgejo scoped token without `read:user` 403s there regardless of its issue scopes. **Options**: (a) probe issue-write directly (e.g. against the target repo, as claim-probe already does) and drop the /user requirement, or (b) keep /user but only as a shape/auth hint, FAIL only on 401; or (c) document that the fleet token must carry read:user. The install prompt says "do not proceed with a FAIL outstanding" — a probe stricter than the capability it proves turns a healthy install into a false stop. Offline test to update in the same commit: onboarding/tests (verify-creds shims).

This was generated by AI during triage.

Triage: ready-for-agent + bug

Ruled by agent under ADR 0174 — veto anytime.

Ruling: take option (b) — keep the GET /user probe, but as a shape/auth hint only: FAIL on 401 (and on a network-level failure), and on any other non-200 fall through to the issue-write probe and let that decide the verdict.

Why (b) and not the others:

  • (a) drop /user entirely loses a genuinely useful signal. A 401 distinguishes "this token is not a token" from "this token cannot write issues here", and the two need different fixes. Cheap to keep, so keep it.
  • (c) require read:user on the fleet token is the wrong direction on principle: it makes a working token carry a scope nothing in the harness consumes, purely to satisfy its own probe. Broadening a credential's scope to please a check is a posture change to justify, not a default — and it would have to be justified again on every host, for every consumer.
  • (b) preserves #20's actual lesson. #20 was not "prove the token is a token"; it was "a bot with repo.code write but not repo.issues write 403s every label write, and #19 looked like four clean closes". The authoritative probe is and remains forgejo_issue_write_probe. A gate in front of it that can veto a token the authoritative probe would pass is strictly a false-stop generator.

Why this is a two-way door: one conditional in one function plus its offline test, revertible by a later commit, provable by the onboard_verify_creds shims in onboarding/tests/onboard-lib-test.sh — no network, no live token. Not on the one-way-door list: it narrows nothing and grants nothing. It relaxes a probe, and the capability actually asserted (issue-write) is unchanged and still mandatory — a token that cannot write issues still FAILs, which is the whole point of the check.

Verification — confirmed at 9e2aaf6

In onboard_verify_creds, the forgejo_token arm reads:

fcode="$(curl … "$api_root/user")" || fcode=000
if [ "$fcode" != 200 ]; then _vc_emit FAIL forgejo_token "GET /user returned $fcode (len=${#ftok})"; break; fi
if FORGEJO_API="$fj_api" FORGEJO_TOKEN="$ftok" forgejo_issue_write_probe …

The break on any non-200 short-circuits the loop before forgejo_issue_write_probe ever runs. A Forgejo scoped token without read:user 403s at /user regardless of its issue scopes, so the probe reports FAIL for a token with full issue-write capability — exactly the symptom filed, and reproducible on every host because it is unconditional. The install-prompt.md contract ("do not proceed with a FAIL outstanding") then converts a healthy install into a false stop, which is what happened during the matou-website install (#62 acceptance, matou-website#2).

Agent Brief

Category: bug
Summary: verify-creds' forgejo_token probe fails a functional token because it requires GET /user 200 before — and instead of — the issue-write check that is the capability it exists to prove.

Current behavior: Any non-200 from GET /user emits FAIL forgejo_token GET /user returned <code> and skips the issue-write probe entirely. A scoped token lacking read:user therefore fails verification despite being able to open, claim, label and close issues.

Desired behavior: GET /user becomes a hint, not a gate. A 401 (the token is not valid at all) still FAILs immediately and says so — no point probing further. A network-level failure (no HTTP status at all) still FAILs, distinctly, as "could not reach the tracker" rather than as a token verdict. Any other status, 403 included, proceeds to the issue-write probe, whose result is the verdict. A PASS detail line should stay honest about what was actually proven — do not claim GET /user 200 when it returned 403.

Key interfaces:

  • onboard_verify_creds's forgejo_token arm — the branch structure is the change. Every path must still emit exactly one PASS/FAIL/SKIP line for the credential and set the aggregate rc accordingly.
  • forgejo_issue_write_probe — unchanged, and remains the authoritative capability check. A token that fails it still FAILs verification.
  • The hard rule in this function's header is unconditional and must survive the edit: the only bytes of a credential that may ever appear in output are its length (len=N). No status message may quote or echo a token.
  • The other probes in the function (CLAUDE token liveness, Mattermost /users/me + channel membership, the 0-byte secret class) are untouched.

Acceptance criteria:

  • A token that 403s at /user but passes the issue-write probe reports PASS.
  • A token that 403s at /user and fails the issue-write probe reports FAIL, with the issue-write reason (#20's message), not the /user one.
  • A token that 401s at /user reports FAIL without running the issue-write probe.
  • An unreachable tracker reports FAIL with a distinct, non-token-blaming reason.
  • The PASS detail line does not assert GET /user 200 unless it actually returned 200.
  • No output path can print any part of a token beyond len=N.
  • --json output keeps the same {credential,status,detail} shape for every new path.
  • onboarding/tests/onboard-lib-test.sh verify-creds shims updated in the same commit (repo rule) covering the 403-then-write-ok, 403-then-write-fail, and 401 cases.
  • Full offline suite green: for t in tests/*.sh onboarding/tests/*.sh; do case "$t" in *fakebin*|*fixtures*) continue;; esac; bash "$t" || echo "FAIL: $t"; done

Out of scope:

  • Changing what scopes the fleet token carries, or any live credential (one-way door — Ben's, out-of-band).
  • The Mattermost and CLAUDE-token probes.
  • install-prompt.md's "do not proceed with a FAIL outstanding" rule — it is correct; the probe is what was wrong.
  • preflight-triage.sh's separate permissions.push write probe (#20) — a different check, in a different script, and already right.
> *This was generated by AI during triage.* ## Triage: `ready-for-agent` + `bug` **Ruled by agent under ADR 0174 — veto anytime.** **Ruling:** take **option (b)** — keep the `GET /user` probe, but as a shape/auth *hint* only: `FAIL` on 401 (and on a network-level failure), and on any other non-200 fall through to the issue-write probe and let **that** decide the verdict. Why (b) and not the others: - **(a) drop `/user` entirely** loses a genuinely useful signal. A 401 distinguishes "this token is not a token" from "this token cannot write issues *here*", and the two need different fixes. Cheap to keep, so keep it. - **(c) require `read:user` on the fleet token** is the wrong direction on principle: it makes a working token carry a scope nothing in the harness consumes, purely to satisfy its own probe. Broadening a credential's scope to please a check is a posture change to justify, not a default — and it would have to be justified again on every host, for every consumer. - **(b)** preserves #20's actual lesson. #20 was not "prove the token is a token"; it was "a bot with `repo.code` write but not `repo.issues` write 403s every label write, and #19 looked like four clean closes". The authoritative probe is and remains `forgejo_issue_write_probe`. A gate in front of it that can veto a token the authoritative probe would pass is strictly a false-stop generator. **Why this is a two-way door:** one conditional in one function plus its offline test, revertible by a later commit, provable by the `onboard_verify_creds` shims in `onboarding/tests/onboard-lib-test.sh` — no network, no live token. Not on the one-way-door list: it *narrows* nothing and grants nothing. It relaxes a probe, and the capability actually asserted (issue-write) is unchanged and still mandatory — a token that cannot write issues still FAILs, which is the whole point of the check. ### Verification — confirmed at `9e2aaf6` In `onboard_verify_creds`, the forgejo_token arm reads: ``` fcode="$(curl … "$api_root/user")" || fcode=000 if [ "$fcode" != 200 ]; then _vc_emit FAIL forgejo_token "GET /user returned $fcode (len=${#ftok})"; break; fi if FORGEJO_API="$fj_api" FORGEJO_TOKEN="$ftok" forgejo_issue_write_probe … ``` The `break` on any non-200 short-circuits the loop **before** `forgejo_issue_write_probe` ever runs. A Forgejo scoped token without `read:user` 403s at `/user` regardless of its issue scopes, so the probe reports FAIL for a token with full issue-write capability — exactly the symptom filed, and reproducible on every host because it is unconditional. The `install-prompt.md` contract ("do not proceed with a FAIL outstanding") then converts a healthy install into a false stop, which is what happened during the matou-website install (#62 acceptance, matou-website#2). ## Agent Brief **Category:** bug **Summary:** `verify-creds`' forgejo_token probe fails a functional token because it requires `GET /user` 200 before — and instead of — the issue-write check that is the capability it exists to prove. **Current behavior:** Any non-200 from `GET /user` emits `FAIL forgejo_token GET /user returned <code>` and skips the issue-write probe entirely. A scoped token lacking `read:user` therefore fails verification despite being able to open, claim, label and close issues. **Desired behavior:** `GET /user` becomes a hint, not a gate. A 401 (the token is not valid at all) still FAILs immediately and says so — no point probing further. A network-level failure (no HTTP status at all) still FAILs, distinctly, as "could not reach the tracker" rather than as a token verdict. Any other status, 403 included, proceeds to the issue-write probe, whose result is the verdict. A PASS detail line should stay honest about what was actually proven — do not claim `GET /user 200` when it returned 403. **Key interfaces:** - `onboard_verify_creds`'s forgejo_token arm — the branch structure is the change. Every path must still emit exactly one `PASS`/`FAIL`/`SKIP` line for the credential and set the aggregate rc accordingly. - `forgejo_issue_write_probe` — unchanged, and remains the authoritative capability check. A token that fails it still FAILs verification. - The **hard rule** in this function's header is unconditional and must survive the edit: the only bytes of a credential that may ever appear in output are its length (`len=N`). No status message may quote or echo a token. - The other probes in the function (CLAUDE token liveness, Mattermost `/users/me` + channel membership, the 0-byte secret class) are untouched. **Acceptance criteria:** - [ ] A token that 403s at `/user` but passes the issue-write probe reports **PASS**. - [ ] A token that 403s at `/user` and fails the issue-write probe reports **FAIL**, with the issue-write reason (#20's message), not the `/user` one. - [ ] A token that 401s at `/user` reports FAIL without running the issue-write probe. - [ ] An unreachable tracker reports FAIL with a distinct, non-token-blaming reason. - [ ] The PASS detail line does not assert `GET /user 200` unless it actually returned 200. - [ ] No output path can print any part of a token beyond `len=N`. - [ ] `--json` output keeps the same `{credential,status,detail}` shape for every new path. - [ ] `onboarding/tests/onboard-lib-test.sh` verify-creds shims updated in the same commit (repo rule) covering the 403-then-write-ok, 403-then-write-fail, and 401 cases. - [ ] Full offline suite green: `for t in tests/*.sh onboarding/tests/*.sh; do case "$t" in *fakebin*|*fixtures*) continue;; esac; bash "$t" || echo "FAIL: $t"; done` **Out of scope:** - Changing what scopes the fleet token carries, or any live credential (one-way door — Ben's, out-of-band). - The Mattermost and CLAUDE-token probes. - `install-prompt.md`'s "do not proceed with a FAIL outstanding" rule — it is correct; the probe is what was wrong. - `preflight-triage.sh`'s separate `permissions.push` write probe (#20) — a different check, in a different script, and already right.

swarm-claim host=matou-dev-server-01 run=983
(automated multi-host claim — lowest live claim id works this ticket)

swarm-claim host=matou-dev-server-01 run=983 (automated multi-host claim — lowest live claim id works this ticket)

close-report for #82 — status success

✅ close-report gates passed — every claim verified against main; issue closed.

envelope
{
  "issue": 82,
  "status": "success",
  "commits": [
    "343d26f"
  ],
  "changed_files": [
    "STATUS.md",
    "onboarding/onboard-lib.sh",
    "onboarding/tests/onboard-lib-test.sh"
  ],
  "tests": [
    {
      "command": "bash onboarding/tests/onboard-lib-test.sh",
      "exit_code": 0
    },
    {
      "command": "for t in tests/*.sh onboarding/tests/*.sh; do case \"$t\" in *fakebin*|*fixtures*) continue;; esac; bash \"$t\" || echo FAIL: $t; done",
      "exit_code": 0
    }
  ],
  "criteria": {
    "403 at /user but issue-write passes reports PASS": "onboard-lib.sh: /user non-401/non-000 falls through to forgejo_issue_write_probe; test 4a (VC_FORGEJO_USER_CODE=403) asserts ^PASS forgejo_token and exit 0",
    "403 at /user and issue-write fails reports FAIL with the issue-write reason (#20)": "test 4b (403 + VC_FORGEJO_PUSH=false) asserts FAIL ...issue-write and that the reason does not blame /user",
    "401 at /user reports FAIL without running issue-write probe": "onboard-lib.sh emits FAIL on fcode=401 and breaks before the write probe; test 3 covers 401 FAIL",
    "unreachable tracker reports FAIL with a distinct non-token-blaming reason": "onboard-lib.sh FAILs on fcurl_rc!=0 or fcode=000 with 'could not reach the tracker'; test 4c (VC_FORGEJO_USER_CODE=000) asserts it",
    "PASS detail line does not assert GET /user 200 unless it returned 200": "PASS line prints 'repo issue-write ok (GET /user $fcode)'; test 4a asserts ! /user 200 in the PASS line",
    "no output path prints any token bytes beyond len=N": "every emit uses (len=${#ftok}); tests 4a/4c assert ! grep -qF FJ_TOK_VALUE",
    "--json keeps {credential,status,detail} shape for every new path": "all paths route through _vc_emit unchanged; no JSON structure touched",
    "onboard-lib-test.sh verify-creds shims updated same commit covering 403-then-write-ok, 403-then-write-fail, 401": "tests 4a/4b added (401 already present as test 3); all in commit 343d26f",
    "full offline suite green": "suite loop exit 0, onboard-lib 234 passed 0 failed"
  },
  "summary": "verify-creds' forgejo_token probe now treats GET /user as a shape/auth hint (FAIL early only on 401 or unreachable), letting forgejo_issue_write_probe be the verdict so a functional token without read:user no longer false-stops an install.",
  "blockers": []
}
**close-report** for #82 — status `success` :white_check_mark: **close-report gates passed** — every claim verified against main; issue closed. <details><summary>envelope</summary> ```json { "issue": 82, "status": "success", "commits": [ "343d26f" ], "changed_files": [ "STATUS.md", "onboarding/onboard-lib.sh", "onboarding/tests/onboard-lib-test.sh" ], "tests": [ { "command": "bash onboarding/tests/onboard-lib-test.sh", "exit_code": 0 }, { "command": "for t in tests/*.sh onboarding/tests/*.sh; do case \"$t\" in *fakebin*|*fixtures*) continue;; esac; bash \"$t\" || echo FAIL: $t; done", "exit_code": 0 } ], "criteria": { "403 at /user but issue-write passes reports PASS": "onboard-lib.sh: /user non-401/non-000 falls through to forgejo_issue_write_probe; test 4a (VC_FORGEJO_USER_CODE=403) asserts ^PASS forgejo_token and exit 0", "403 at /user and issue-write fails reports FAIL with the issue-write reason (#20)": "test 4b (403 + VC_FORGEJO_PUSH=false) asserts FAIL ...issue-write and that the reason does not blame /user", "401 at /user reports FAIL without running issue-write probe": "onboard-lib.sh emits FAIL on fcode=401 and breaks before the write probe; test 3 covers 401 FAIL", "unreachable tracker reports FAIL with a distinct non-token-blaming reason": "onboard-lib.sh FAILs on fcurl_rc!=0 or fcode=000 with 'could not reach the tracker'; test 4c (VC_FORGEJO_USER_CODE=000) asserts it", "PASS detail line does not assert GET /user 200 unless it returned 200": "PASS line prints 'repo issue-write ok (GET /user $fcode)'; test 4a asserts ! /user 200 in the PASS line", "no output path prints any token bytes beyond len=N": "every emit uses (len=${#ftok}); tests 4a/4c assert ! grep -qF FJ_TOK_VALUE", "--json keeps {credential,status,detail} shape for every new path": "all paths route through _vc_emit unchanged; no JSON structure touched", "onboard-lib-test.sh verify-creds shims updated same commit covering 403-then-write-ok, 403-then-write-fail, 401": "tests 4a/4b added (401 already present as test 3); all in commit 343d26f", "full offline suite green": "suite loop exit 0, onboard-lib 234 passed 0 failed" }, "summary": "verify-creds' forgejo_token probe now treats GET /user as a shape/auth hint (FAIL early only on 401 or unreachable), letting forgejo_issue_write_probe be the verdict so a functional token without read:user no longer false-stops an install.", "blockers": [] } ``` </details>
Sign in to join this conversation.
No milestone
No project
No assignees
2 participants
Notifications
Due date
The due date is invalid or out of range. Please use the format "yyyy-mm-dd".

No due date set.

Dependencies

No dependencies set.

Reference
Matou/dev-factory#82
No description provided.