FORGEJO_TOKEN is persisted in .git/config of every shared workdir — inject per invocation instead #195

Closed
opened 2026-10-15 02:58:56 +00:00 by ben · 3 comments
Owner

Filed from the 2026-10-14 infrastructure review (Claude Code session on Ben's workstation; four parallel read-only review passes over the root harness). Line anchors are against main at 3e50274.

Symptom

git-setup.sh:33,89 runs git remote set-url origin https://swarm:${FORGEJO_TOKEN}@git.matou.nz/<slug>.git on $HOME/swarm/<slug> — the merge-to-head parent whose common .git every worker container bind-mounts (main.mts worktrees mount). The same shape is inline in swarm.yml:183,190, triage.yml:161,168, resume-asks.yml:35,37, the workflow templates, and rehearsal-report.sh:329. Result: any worker (git remote get-url origin), any same-uid host process, and anyone reading the host disk gets the org-wide write token. prompt.md:172 and land-pr.sh:72 additionally place it in argv (ps-visible).

Proposed change

  • Keep origin credential-free. Authenticate per invocation: GIT_ASKPASS pointing at a tiny script that prints the token from /run/secrets/forgejo_token (sandbox) or $here/secrets/forgejo_token (host), or git -c credential.helper='!f(){ printf "username=swarm\npassword=%s\n" "$(cat <file>)"; }; f'.
  • Drop every set-url with an embedded token; git-setup.sh becomes the one place that configures the remote.
  • Rewrite prompt skeleton step 6's token-URL fallback to the same form.
  • One-off cleanup on each host: git remote set-url origin https://git.matou.nz/<slug>.git for every workdir.

Acceptance

  • grep -rn 'swarm:\${FORGEJO_TOKEN}@' --include='*.sh' --include='*.yml' --include='*.tmpl' --include='*.md' . returns nothing outside GOTCHAS.
  • tests/git-setup-test.sh asserts .git/config after setup contains no @git. credential.
  • GOTCHAS entry added.

out_of_scope

Per-repo bot users (#201).

_Filed from the 2026-10-14 infrastructure review (Claude Code session on Ben's workstation; four parallel read-only review passes over the root harness). Line anchors are against `main` at 3e50274._ ## Symptom `git-setup.sh:33,89` runs `git remote set-url origin https://swarm:${FORGEJO_TOKEN}@git.matou.nz/<slug>.git` on `$HOME/swarm/<slug>` — the merge-to-head parent whose common `.git` every worker container bind-mounts (`main.mts` worktrees mount). The same shape is inline in `swarm.yml:183,190`, `triage.yml:161,168`, `resume-asks.yml:35,37`, the workflow templates, and `rehearsal-report.sh:329`. Result: any worker (`git remote get-url origin`), any same-uid host process, and anyone reading the host disk gets the org-wide write token. `prompt.md:172` and `land-pr.sh:72` additionally place it in argv (`ps`-visible). ## Proposed change - Keep `origin` credential-free. Authenticate per invocation: `GIT_ASKPASS` pointing at a tiny script that prints the token from `/run/secrets/forgejo_token` (sandbox) or `$here/secrets/forgejo_token` (host), or `git -c credential.helper='!f(){ printf "username=swarm\npassword=%s\n" "$(cat <file>)"; }; f'`. - Drop every `set-url` with an embedded token; `git-setup.sh` becomes the one place that configures the remote. - Rewrite prompt skeleton step 6's token-URL fallback to the same form. - One-off cleanup on each host: `git remote set-url origin https://git.matou.nz/<slug>.git` for every workdir. ## Acceptance - `grep -rn 'swarm:\${FORGEJO_TOKEN}@' --include='*.sh' --include='*.yml' --include='*.tmpl' --include='*.md' .` returns nothing outside GOTCHAS. - `tests/git-setup-test.sh` asserts `.git/config` after setup contains no `@git.` credential. - GOTCHAS entry added. ## out_of_scope Per-repo bot users (#201).

This was generated by AI during triage.

Ruled by agent under ADR 0174 — veto anytime.

  • Ruling: ready-for-agent.
  • Why this is a two-way door: a security tightening (it narrows exposure of a shared bot token — an org-wide credential, not a personal one), revertible by restoring the set-url. The credential-helper plumbing fails CLOSED (a broken helper reds the push loudly), so an offline seam is an adequate gate, and the one-off host-workdir scrub is routine and re-runnable, not a one-way residue.
  • What proves it: the acceptance grep returning nothing outside GOTCHAS, and tests/git-setup-test.sh asserting .git/config carries no @git. credential while fetch/push still authenticate via the helper seam.

Agent Brief

Category: bug

Summary: Stop persisting the org-wide FORGEJO_TOKEN in origin's URL (it lands in the shared .git/config every worker bind-mounts, and in argv). Keep origin credential-free and supply the token per invocation.

Current behavior: git-setup.sh and several workflows/templates set origin to a URL embedding swarm:$FORGEJO_TOKEN@, so any worker, any same-uid host process, or anyone reading host disk recovers the write token; the prompt fallback and land-pr.sh also place it in argv.

Desired behavior: origin carries no credentials. Authentication is injected per invocation via a credential helper / GIT_ASKPASS that reads the token from a file (the sandbox secret path, or the host secrets path), and git-setup.sh is the single place that configures the remote. The prompt skeleton's token-URL fallback is rewritten to the same credential-helper form.

Key interfaces (contracts only):

  • The configured origin URL contains no user:token@host credential.
  • Git auth for fetch/clone/push is supplied at call time from a token file via a credential helper, both in-sandbox and host-side.
  • One remote-configuration code path (git-setup) owns remote setup; workflows/templates no longer embed the token inline.
  • No harness .sh/.yml/.tmpl/.md (outside GOTCHAS) embeds swarm:$FORGEJO_TOKEN@; no push command places the token in argv.

Acceptance criteria:

  • grep -rn 'swarm:${FORGEJO_TOKEN}@' --include='*.sh' --include='*.yml' --include='*.tmpl' --include='*.md' . returns nothing outside GOTCHAS (and both rendered .forgejo/workflows/* and their .tmpl sources are clean).
  • tests/git-setup-test.sh asserts .git/config after setup contains no @git. credential, and that fetch/push still authenticate via the helper seam.
  • The prompt-skeleton token fallback uses the credential-helper form (cutover fixtures re-proven).
  • A GOTCHAS entry is added in the same commit.
  • Full offline suite green.

Out of scope: Per-repo bot users / token scope-narrowing (#201). The one-off operational scrub of existing host workdirs (git remote set-url origin <credential-free>) is an ops follow-up, not part of this commit's verification.

> *This was generated by AI during triage.* **Ruled by agent under ADR 0174 — veto anytime.** - **Ruling:** `ready-for-agent`. - **Why this is a two-way door:** a security *tightening* (it narrows exposure of a shared bot token — an org-wide credential, not a personal one), revertible by restoring the `set-url`. The credential-helper plumbing fails CLOSED (a broken helper reds the push loudly), so an offline seam is an adequate gate, and the one-off host-workdir scrub is routine and re-runnable, not a one-way residue. - **What proves it:** the acceptance grep returning nothing outside GOTCHAS, and `tests/git-setup-test.sh` asserting `.git/config` carries no `@git.` credential while fetch/push still authenticate via the helper seam. ## Agent Brief **Category:** bug **Summary:** Stop persisting the org-wide `FORGEJO_TOKEN` in `origin`'s URL (it lands in the shared `.git/config` every worker bind-mounts, and in argv). Keep `origin` credential-free and supply the token per invocation. **Current behavior:** `git-setup.sh` and several workflows/templates set `origin` to a URL embedding `swarm:$FORGEJO_TOKEN@`, so any worker, any same-uid host process, or anyone reading host disk recovers the write token; the prompt fallback and `land-pr.sh` also place it in argv. **Desired behavior:** `origin` carries no credentials. Authentication is injected per invocation via a credential helper / `GIT_ASKPASS` that reads the token from a file (the sandbox secret path, or the host secrets path), and `git-setup.sh` is the single place that configures the remote. The prompt skeleton's token-URL fallback is rewritten to the same credential-helper form. **Key interfaces (contracts only):** - The configured `origin` URL contains no `user:token@host` credential. - Git auth for fetch/clone/push is supplied at call time from a token file via a credential helper, both in-sandbox and host-side. - One remote-configuration code path (git-setup) owns remote setup; workflows/templates no longer embed the token inline. - No harness `.sh`/`.yml`/`.tmpl`/`.md` (outside GOTCHAS) embeds `swarm:$FORGEJO_TOKEN@`; no push command places the token in argv. **Acceptance criteria:** - [ ] `grep -rn 'swarm:${FORGEJO_TOKEN}@' --include='*.sh' --include='*.yml' --include='*.tmpl' --include='*.md' .` returns nothing outside GOTCHAS (and both rendered `.forgejo/workflows/*` and their `.tmpl` sources are clean). - [ ] `tests/git-setup-test.sh` asserts `.git/config` after setup contains no `@git.` credential, and that fetch/push still authenticate via the helper seam. - [ ] The prompt-skeleton token fallback uses the credential-helper form (cutover fixtures re-proven). - [ ] A GOTCHAS entry is added in the same commit. - [ ] Full offline suite green. **Out of scope:** Per-repo bot users / token scope-narrowing (#201). The one-off operational scrub of existing host workdirs (`git remote set-url origin <credential-free>`) is an ops follow-up, not part of this commit's verification.

swarm-claim host=bens-mac-04 run=21816
(automated multi-host claim — lowest live claim id works this ticket)

swarm-claim host=bens-mac-04 run=21816 (automated multi-host claim — lowest live claim id works this ticket)

close-report for #195 — status blocked

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

envelope
{
  "issue": 195,
  "status": "blocked",
  "commits": [
    "cfb82baaf633bcca373c5e182b9ad4e005778bbe"
  ],
  "changed_files": [
    "STATUS.md",
    "docs/GOTCHAS.md",
    "docs/gotchas/70-the-org-wide-forgejo-token-rode-inside.md",
    "docs/journal/2026-10-15-195.md",
    "git-cred-lib.sh",
    "git-setup.sh",
    "onboarding/vendor-manifest",
    "tests/git-cred-lib-test.sh",
    "tests/git-setup-test.sh"
  ],
  "tests": [
    {
      "command": "bash tests/git-cred-lib-test.sh",
      "exit_code": 0
    },
    {
      "command": "bash tests/git-setup-test.sh",
      "exit_code": 0
    },
    {
      "command": "bash tests/docs-budget-test.sh",
      "exit_code": 0
    },
    {
      "command": "bash onboarding/tests/vendor-manifest-coverage-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": {
    "grep 'swarm:${FORGEJO_TOKEN}@' returns nothing outside GOTCHAS (incl. .forgejo/workflows/* + .tmpl sources)": "PARTIAL — git-setup.sh:33 cleaned (no match). BLOCKED for .forgejo/workflows/{swarm,triage,resume-asks}.yml and their .tmpl sources: editing the .tmpl alone reds onboarding/tests/self-workflows-drift-test.sh against the protected rendered .forgejo copies a swarm worker cannot touch. Deferred to ready-for-session #222.",
    "tests/git-setup-test.sh asserts .git/config contains no @git. credential and fetch/push authenticate via the helper seam": "MET — tests/git-setup-test.sh fixtures 1b/1c assert credential-free origin, no @git. in .git/config, the persisted credential helper fills swarm + the file token via `git credential fill`, and a pre-seeded leaked-token origin is scrubbed (git commit cfb82ba).",
    "the prompt-skeleton token fallback uses the credential-helper form (cutover fixtures re-proven)": "BLOCKED — the fallback lives in the protected .sandcastle/prompt-enrichments/workflow-verify.md (per-repo layer, fingerprinted protected); the root prompts/*.md skeletons carry no token. Deferred to ready-for-session #222.",
    "a GOTCHAS entry is added in the same commit": "MET — docs/GOTCHAS.md index row 70 + body docs/gotchas/70-the-org-wide-forgejo-token-rode-inside.md in commit cfb82ba.",
    "full offline suite green": "MET — the full offline suite (tests/*.sh + onboarding/tests/*.sh) passes with no FAIL lines."
  },
  "summary": "Landed the credential-free-origin + per-invocation token-helper foundation (git-cred-lib.sh + git-setup.sh + tests + GOTCHAS 70); the protected rendered/vendored copies and remaining root sites are blocked on a session (#222).",
  "reason": "Two acceptance clauses (the clean grep across the protected .forgejo/workflows/*.yml and their drift-locked .tmpl sources, and the prompt-skeleton/enrichment token fallback in the protected .sandcastle/ layer) can only be satisfied by editing protected paths and re-vendoring the pin, which a swarm worker cannot do (protected-paths-lib.sh rolls back any .forgejo//.sandcastle edit; editing the .tmpl sources alone reds self-workflows-drift-test.sh). Filed ready-for-session #222 for that remainder; the non-protected foundation is on origin/main.",
  "blockers": [
    "ready-for-session #222 — apply the git-cred-lib.sh helper to the protected .forgejo/workflows/{swarm,triage,resume-asks}.yml (re-rendered with their .tmpl sources), the workflow-verify.md prompt-enrichment push fallback, main.mts's sandbox worktree, land-pr.sh, and the rehearsal healer, then re-vendor the .sandcastle/ pin."
  ]
}
**close-report** for #195 — status `blocked` :white_check_mark: **close-report gates passed** — every claim verified against main; issue closed. <details><summary>envelope</summary> ```json { "issue": 195, "status": "blocked", "commits": [ "cfb82baaf633bcca373c5e182b9ad4e005778bbe" ], "changed_files": [ "STATUS.md", "docs/GOTCHAS.md", "docs/gotchas/70-the-org-wide-forgejo-token-rode-inside.md", "docs/journal/2026-10-15-195.md", "git-cred-lib.sh", "git-setup.sh", "onboarding/vendor-manifest", "tests/git-cred-lib-test.sh", "tests/git-setup-test.sh" ], "tests": [ { "command": "bash tests/git-cred-lib-test.sh", "exit_code": 0 }, { "command": "bash tests/git-setup-test.sh", "exit_code": 0 }, { "command": "bash tests/docs-budget-test.sh", "exit_code": 0 }, { "command": "bash onboarding/tests/vendor-manifest-coverage-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": { "grep 'swarm:${FORGEJO_TOKEN}@' returns nothing outside GOTCHAS (incl. .forgejo/workflows/* + .tmpl sources)": "PARTIAL — git-setup.sh:33 cleaned (no match). BLOCKED for .forgejo/workflows/{swarm,triage,resume-asks}.yml and their .tmpl sources: editing the .tmpl alone reds onboarding/tests/self-workflows-drift-test.sh against the protected rendered .forgejo copies a swarm worker cannot touch. Deferred to ready-for-session #222.", "tests/git-setup-test.sh asserts .git/config contains no @git. credential and fetch/push authenticate via the helper seam": "MET — tests/git-setup-test.sh fixtures 1b/1c assert credential-free origin, no @git. in .git/config, the persisted credential helper fills swarm + the file token via `git credential fill`, and a pre-seeded leaked-token origin is scrubbed (git commit cfb82ba).", "the prompt-skeleton token fallback uses the credential-helper form (cutover fixtures re-proven)": "BLOCKED — the fallback lives in the protected .sandcastle/prompt-enrichments/workflow-verify.md (per-repo layer, fingerprinted protected); the root prompts/*.md skeletons carry no token. Deferred to ready-for-session #222.", "a GOTCHAS entry is added in the same commit": "MET — docs/GOTCHAS.md index row 70 + body docs/gotchas/70-the-org-wide-forgejo-token-rode-inside.md in commit cfb82ba.", "full offline suite green": "MET — the full offline suite (tests/*.sh + onboarding/tests/*.sh) passes with no FAIL lines." }, "summary": "Landed the credential-free-origin + per-invocation token-helper foundation (git-cred-lib.sh + git-setup.sh + tests + GOTCHAS 70); the protected rendered/vendored copies and remaining root sites are blocked on a session (#222).", "reason": "Two acceptance clauses (the clean grep across the protected .forgejo/workflows/*.yml and their drift-locked .tmpl sources, and the prompt-skeleton/enrichment token fallback in the protected .sandcastle/ layer) can only be satisfied by editing protected paths and re-vendoring the pin, which a swarm worker cannot do (protected-paths-lib.sh rolls back any .forgejo//.sandcastle edit; editing the .tmpl sources alone reds self-workflows-drift-test.sh). Filed ready-for-session #222 for that remainder; the non-protected foundation is on origin/main.", "blockers": [ "ready-for-session #222 — apply the git-cred-lib.sh helper to the protected .forgejo/workflows/{swarm,triage,resume-asks}.yml (re-rendered with their .tmpl sources), the workflow-verify.md prompt-enrichment push fallback, main.mts's sandbox worktree, land-pr.sh, and the rehearsal healer, then re-vendor the .sandcastle/ pin." ] } ``` </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.

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