Skip to content

fix(skills-sync): authenticate via credential helper, guarantee clone cleanup - #124

Merged
bketelsen merged 1 commit into
mainfrom
cockpit/worker-5be24bec4a09e592
Aug 25, 2026
Merged

fix(skills-sync): authenticate via credential helper, guarantee clone cleanup#124
bketelsen merged 1 commit into
mainfrom
cockpit/worker-5be24bec4a09e592

Conversation

@bketelsen

Copy link
Copy Markdown
Contributor

Summary

  • The consumer clone URL embedded ORG_PAT directly (https://x-access-token:${GH_TOKEN}@github.com/...), leaving the secret in the clone's stored origin URL and in a raw process argument.
  • Every mktemp consumer clone leaked on every exit path except success: clone failure, an unknown skill, containment failure, and any git/PR failure all continued or exited without removing it.

Change

  • scripts/lib/skills-sync-auth.sh: skills_sync_credential_helper — a git credential helper (git-credential(1)) that reads GH_TOKEN from its own process environment when git invokes it. The template string contains the literal characters $GH_TOKEN, never the token's value, so neither the clone's origin URL, argv, nor the clone's .git/config ever holds the secret.
  • scripts/lib/skills-sync-repo.sh: skills_sync_run_repo — the per-repo clone/mirror/PR orchestration, now a single function whose mktemp clone is bound to a trap ... RETURN, guaranteeing removal on every return path (clone failure, unknown skill, containment failure, git/PR failure, and success).
  • scripts/sync-skills.sh now just parses the config and calls skills_sync_run_repo per repo — same branch name, target repos, token permissions, and PR semantics as before (verbatim log messages, PR title/body, and force-push behavior preserved).

Test plan

  • test/sync-skills-auth.test.mjs (new): the credential helper never contains a literal token, and wired up via a real git credential fill it correctly resolves GH_TOKEN from the environment.
  • test/sync-skills-run-repo.test.mjs (new): with stubbed git/gh (no network, no GitHub mutation), the mktemp clone directory is removed after — success, clone failure, push failure, an unknown skill, and a containment escape.
  • npm run verify — 33/33 tests pass (node --test test/*.test.mjs, plus docs/organization/script-syntax gates).

Risk tier: 2 — security-sensitive automation script and its git-credential handling change; no product surface, no new permissions.

…clone cleanup

The clone URL embedded ORG_PAT directly (visible in argv and stored as the
clone's origin), and the mktemp consumer clone leaked on every failure and
early-exit path — only the success path removed it.

Extract skills_sync_credential_helper (a git credential helper that reads
GH_TOKEN from its own environment, never a URL or argument) and
skills_sync_run_repo (a per-repo function whose RETURN trap removes its
mktemp clone on every exit path) into sourceable libs, and add regression
coverage for both properties using stubbed git/gh.

Co-Authored-By: Claude Sonnet 5 <noreply@anthropic.com>
@bketelsen
bketelsen marked this pull request as ready for review August 25, 2026 01:03
@bketelsen
bketelsen added this pull request to the merge queue Aug 25, 2026
Merged via the queue into main with commit ac6a2d5 Aug 25, 2026
3 checks passed
@bketelsen
bketelsen deleted the cockpit/worker-5be24bec4a09e592 branch August 25, 2026 01:07
@bketelsen bketelsen changed the title security(skills-sync): authenticate via credential helper, guarantee clone cleanup fix(skills-sync): authenticate via credential helper, guarantee clone cleanup Aug 25, 2026
bketelsen added a commit that referenced this pull request Aug 25, 2026
#124 changed scripts/lib/skills-sync-repo.sh to clone and push as
`git -c credential.helper=<helper> <subcommand> ...`. The hermetic
harness's fake git only recognised `clone` as $1, so the real
github.com URL passed straight through to the real binary and CI's
docs-gate failed both tests with an authentication error.

- Locate the subcommand by skipping `-c <value>` pairs and flags (the
  same detection test/sync-skills-run-repo.test.mjs uses), and rewrite
  the frostyard clone URL by pattern rather than by argv position.
- Accept the credential-helper prefix on the asserted push line.
- Carry the sibling test's rsync fallback so the harness stays runnable
  in sandboxes without a system rsync.

Co-Authored-By: Claude Fable 5 <noreply@anthropic.com>
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