Skip to content

fix(skills-sync): scope the ORG_PAT to the calls that authenticate - #131

Closed
bketelsen wants to merge 2 commits into
mainfrom
core-orgpat-scoped-env
Closed

bketelsen wants to merge 2 commits into
mainfrom
core-orgpat-scoped-env

Conversation

@bketelsen

Copy link
Copy Markdown
Contributor

Summary

The skills-sync workflow injects the org-wide, write-capable ORG_PAT as
GH_TOKEN for the whole ./scripts/sync-skills.sh step, and the script
re-exported it (export GH_TOKEN). Every descendant of the sync therefore
inherited a credential it does not need: the jq config reads in
scripts/sync-skills.sh, mktemp/realpath in
scripts/lib/skills-sync-repo.sh, the mkdir/rsync/printf copy path in
scripts/lib/skills-sync-containment.sh, and the local
git add/diff/checkout/commit against the temporary clone.

This is a least-privilege gap, not an observed leak: the credential
helper added in #124 already keeps the value out of remote URLs, argv, logs,
and repository files, and no exfiltration path was found. What changes is
blast radius — a token with Contents and Pull requests read/write across
every configured consumer repo was reachable from every subprocess rather
than only the four that authenticate.

scripts/lib/skills-sync-auth.sh gains two functions:

  • skills_sync_capture_token moves GH_TOKEN into a private (never
    exported) shell variable and unsets it, before the first subprocess runs.
  • skills_sync_authenticated <cmd...> re-supplies it as a single-command
    GH_TOKEN=... cmd assignment prefix. The prefix is consumed by the shell,
    so the value enters exactly one child's environment and never argv.

Only four calls are wrapped: the git clone, the git push, gh pr list,
and gh pr create. skills_sync_run_repo calls skills_sync_capture_token
itself, so the containment holds for direct callers of the library too, not
just the scripts/sync-skills.sh entry point.

Follows #124 (credential-helper value containment); this is the matching
environment containment. Documented in
docs/design/skills-sync-operations.md under "Trigger and authentication
contract".

Risk tier

Risk tier: 2 — security-sensitive automation script and its credential
handling; no product surface, no new permissions, no workflow change (the
workflow's env: GH_TOKEN mapping and permissions: {} are unchanged).

Docs housekeeping

  • Cross-links added in both directions (the design doc now links the
    auth script and both test files it describes)
  • Conformance aliases (ADR-0029) untouched — canonical targets edited
    instead

No new doc was created; docs/design/skills-sync-operations.md is a living
design doc updated in place, so no TEMPLATE.md start or new index line
applies. No new significant decision — this implements the least-privilege
posture ADR-0026's operations already assume.

Verification

Run in a clean worktree off origin/main at 44dfd0b.

  • make verify green — check:docs (59 docs, 469 links, 10 symlinks,
    all 1.000), check:organization, check:scripts
    (ok bash_syntax: 6/6), and node --test test/*.test.mjs:
    62 tests, 62 pass, 0 fail.
  • git status --porcelain empty after make verify.
  • Not a workflow change; .github/workflows/sync-skills.yml is untouched.
  • Scaffold unchanged — .agents/skills/frostyard-docs-site/scaffold/ not
    touched.

Tests run for this change specifically

node --test test/sync-skills-run-repo.test.mjs test/sync-skills.test.mjs test/sync-skills-auth.test.mjs test/sync-skills-containment.test.mjs — all
pass.

New: "supplies GH_TOKEN only to the subprocesses that authenticate to
GitHub"
(test/sync-skills-run-repo.test.mjs). Hermetic — a stubbed
git, gh, rsync, and realpath on PATH, a fake token, no network. Each
stub records only the string present or absent for its own environment,
never the token value, so the assertion log cannot leak a credential even if
the scoping regresses. It asserts the token-bearing set is exactly
git clone, git push, gh pr list, gh pr create, and asserts positively
that git add, git diff, git checkout, git commit, rsync, and
realpath each ran with it absent.

Mutation-checked: reverting skills_sync_capture_token's unset GH_TOKEN to
export GH_TOKEN (the pre-change behavior) fails the new test with all ten
of those subprocesses reported present; restoring it passes.

Unchanged and still green, proving the value containment from #124 survives:
skills_sync_credential_helper is a template, never the literal token value,
skills_sync_credential_helper authenticates git from the environment, not an argument, removes the clone directory and never leaks the token on a successful sync (asserts the fake token appears nowhere in the command log),
and the clone-fail / push-fail / unknown-skill / containment-escape cases.

bketelsen and others added 2 commits August 29, 2026 22:36
The workflow hands scripts/sync-skills.sh the org-wide, write-capable
ORG_PAT as an exported GH_TOKEN, and the script re-exported it. Every
descendant of the sync therefore inherited a credential it does not need:
the jq config reads, mktemp, realpath, the mkdir/rsync/printf copy path,
and the local git add/diff/checkout/commit against the temporary clone.
No leak was observed — the existing credential helper already keeps the
value out of URLs, argv, logs, and repository files — but the blast
radius of any one of those subprocesses was the whole org.

skills_sync_capture_token now moves the token into a private shell
variable and unsets it before the first subprocess runs, and
skills_sync_authenticated re-supplies it, as a single-command assignment
prefix (never argv), to exactly the four calls that authenticate to
GitHub: the clone, the push, and the two gh pull-request calls.

Regression coverage records only "present" or "absent" per subprocess,
never the token value, so the assertion log cannot itself leak a
credential even if the scoping regresses.

Co-Authored-By: Claude Opus 5 (1M context) <[email protected]>
@bketelsen bketelsen closed this Sep 24, 2026
@frostyard-machines
frostyard-machines deleted the core-orgpat-scoped-env branch November 22, 2026 04:21
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant